Forums / Discussions / Fetching User Objects with PHP - part 2

Monday 18 October 2010 1:38:30 am - 5 replies

» Read full tutorial


At the end of this tutorial you should be comfortable with exporting multiple users from PHP scripts into a external file using a cronjob. You should also be comfortable with filtering fetch statements in PHP.

Author Message

Jérôme Renard

Thursday 21 October 2010 7:54:13 am

Please do not use mail() but eZMailTransport::send instead, for an example, have a look here:


'Hope that helps :)

Marco Rogers

Tuesday 02 November 2010 1:43:40 pm

Maybe you can help me with a related issue. Recently had the task of pulling all users who have a particular role. There is a fetch user by role function. But it turns out that this only returns the users and groups that have the role explicitly assigned to them. It does not pick up users that inherit the role. And I can't use the subtree fetch you're talking about here because the attribute filter doesn't support querying user roles.

I ended up doing the next easiest thing which is to detect a user group with the role and do another fetch to get users under that group.

Here's a modified version of my code:

$judgeRole = eZRole::fetch( $roleId );
$judgeGroups = array();
$judges = $judgeRole->fetchUserByRole();

foreach($judges as $judge) {
    $classID = $judge['user_object']->ClassIdentifier;
    $content_object = $judge['user_object'];
      if($classID == 'user_group') {
        if( $content_object->Name == 'Awards Judges') {
              $children = eZFunctionHandler::execute('content', 'list',  array('parent_node_id' => $content_object->mainNodeID()
                                                                               , 'class_filter_type' => 'include'
                                                                               , 'class_filter_array' => array( 'user' )
                                                                               , 'depth' => 2));
              foreach($children as $child) {
                  $data_map = $child->dataMap();
                  $judge = $data_map['user_account']->content();
                  array_push($judges, $judge);
          } else {
              $judgeGroups[$content_object->attribute('id') . ''] = $content_object->Name;
      } else {
        array_push($judges, eZUser::fetch($content_object->attribute('id')));

Bruce Morrison

Tuesday 23 November 2010 11:27:36 pm

For those playing at home eZRole::fetchUsersByRole doesn't actually do what the name implies. It will return an array of hashes that contains the eZContentObjects that have been assigned to the role. It's up to you to check the type of Object and retrieve users (for any groups returned)


My Blog:
Follow me on twitter:
Consolidated eZ Publish Feed :

Sergey Gedeon

Wednesday 16 February 2011 1:13:45 am

Sometimes we need to disable limitations (e.g. when running the cronscript)

so code should be like this

$params = array( 'Depth' => $depth,
                 'ClassFilterType' => 'include',
                 'ClassFilterArray' => $includeClasses,
                 'Limitation' => array() );

To Live Is To Die...
To Die Is To Wake...

Nicolas Pastorino

Wednesday 16 February 2011 1:52:44 am


Sometimes we need to disable limitations (e.g. when running the cronscript)

so code should be like this

$params = array( 'Depth' => $depth,
                 'ClassFilterType' => 'include',
                 'ClassFilterArray' => $includeClasses,
                 'Limitation' => array() );

Thanks Sergey, good tip !

Nicolas Pastorino
Director Community - eZ
Member of the Community Project Board

eZ Publish Community on twitter:

t :
G+ :

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