Forums / Developer / how to access the "email" value of the ezusert type

"Please Note:
  • At the specific request of Ibexa we are changing this projects name to "Exponential" or "Exponential (CMS)" effective as of August, 11th 2025.
  • This project is not associated with the original eZ Publish software or its original developer, eZ Systems or Ibexa".

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

Author Message

Olivier Pierret

Thursday 17 February 2005 3:39:15 am

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

Tom Couwberghs

Thursday 17 February 2005 3:51:07 am

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

Olivier Pierret

Thursday 17 February 2005 5:02:27 am

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.

Eivind Marienborg

Thursday 17 February 2005 6:30:22 am

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}

Hans Melis

Thursday 17 February 2005 6:44:17 am

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

Hans
http://blog.hansmelis.be

Olivier Pierret

Thursday 17 February 2005 7:41:27 am

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