This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit ezplatform.com

eZ Community » Forums » Developer » how to access the "email" value of...
expandshrink

how to access the "email" value of the ezusert type

how to access the "email" value of the ezusert type

Thursday 17 February 2005 12:39:15 pm - 5 replies

Hello

Here is my (quick) question.

I have a content object attribute identified by user_account of the ezuser type. I'd like to know how to access the email value of the user account in the attribute ?

here is the code I unsuccesfully tested

$dataMap = $object->dataMap();
$email = $dataMap['user_account']->attribute('email');

Any better idea ?

Olivier

Thursday 17 February 2005 12:51:07 pm

The user_account-attribute returns an object of the type ezuser. So the correct way to do this is:

    $dataMap = $object->dataMap();
    $user_obj = $dataMap['user_account']->content();
    $email = $user_obj->attribute( 'email' );

HTH

Tom

Thursday 17 February 2005 2:02:27 pm

Thanks it works great !

Btw how to know what is the eztype of the object attribute $user_obj obtained by

$user_obj = $dataMap[$attrib]->content();


?

I promise not to send silly question anymore ... today !

O.

Thursday 17 February 2005 3:30:22 pm

Hmm.. seeing the solutions already posted I'm wondering if I understand the question correctly.. But I always access the email value like this:

{$node.email}

Example from my working code:

{attribute_view_gui attribute=$current_user.email}

Thursday 17 February 2005 3:44:17 pm

Olivier,

The content() function of a contentobject attribute either returns a simple type (string, integer, boolean, float, array, ...) or an object of a "helper" class (e.g. ezuser). For simple types, you can use PHP's gettype() function. For objects, you can use PHP's get_class() function. Example:

$content = $dataMap[$attrib]->content();
$type = gettype( $content );

if( $type == 'object' )
{
  $type = get_class( $content );
}

print( $type );

You can also trace it through the PHP code if you're familiar with (sometimes) complex PHP code. That's the way Tom and I learned it.

Eivind,

$current_user is not a node object. I assume your $current_user is the result of a fetch of the currently logged in user. In that case, the result of the fetch is exactly the same than that of the content() function of a ezuser datatype.

Olivier's code:

print( get_class( $dataMap['user_account']->content ) );

and your code:

{get_class( $current_user )}

would both say the same thing: ezuser

The .email in the templates then translates to the ->attribute( 'email' ) in PHP code.

hth

Thursday 17 February 2005 4:41:27 pm

Eivind,

Thank you for your help

Hans,

OK I got it.

My PHP knowledge is getting old and I am lacking of some basics in PHP even if I write EZ extensions.

Also thank you for your job in mailinglist and XSLT extensions. I was actually rewriting a part of the mailinglist code to be able to send email to the user account email adress of an object.

For the moment I replaced in ezsckmailinglistype.php (line 114)

$attribContent = $dataMap[$attrib]->attribute('data_text');

by

$user_obj = $dataMap[$attrib]->content();
$email = $user_obj->attribute( 'email' );
if (isset($email) && $email!="") {
	$attribContent=$email;
}
else {
	$attribContent = $dataMap[$attrib]->attribute('data_text');
} 

It would be better to rewrite this with an accurate check of the type of the attribute object (the reason of my question actually) but it works.

Any thought ?

Olivier

Modified on Thursday 17 February 2005 4:43:37 pm by Olivier Pierret

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from