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

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 19:21:01
Script start
Timing: Jan 18 2025 19:21:01
Module start 'layout'
Timing: Jan 18 2025 19:21:01
Module start 'content'
Timing: Jan 18 2025 19:21:02
Module end 'content'
Timing: Jan 18 2025 19:21:02
Script end

Main resources:

Total runtime1.3282 sec
Peak memory usage4,096.0000 KB
Database Queries70

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0077 589.1797152.6406
Module start 'layout' 0.00770.0025 741.820339.4922
Module start 'content' 0.01021.3165 781.3125662.9375
Module end 'content' 1.32670.0014 1,444.250016.1250
Script end 1.3281  1,460.3750 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00380.2869160.0002
Check MTime0.00170.1309160.0001
Mysql Total
Database connection0.00220.162910.0022
Mysqli_queries1.248694.0119700.0178
Looping result0.00090.0649680.0000
Template Total1.289297.120.6446
Template load0.00280.209320.0014
Template processing1.286496.857420.6432
Template load and register function0.00010.010510.0001
states
state_id_array0.00090.068710.0009
state_identifier_array0.00310.236120.0016
Override
Cache load0.00250.1861600.0000
Sytem overhead
Fetch class attribute can translate value0.00150.115940.0004
Fetch class attribute name0.00100.078190.0001
XML
Image XML parsing0.00150.115640.0004
class_abstraction
Instantiating content class attribute0.00000.002590.0000
General
dbfile0.00170.1262270.0001
String conversion0.00000.000440.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
6content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
15content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
10content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 38
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs