eZ Community » Forums » Discussions » Fetching User Objects with PHP - part 2
expandshrink

Monday 18 October 2010 10:38:30 am - 6 replies

» Read full tutorial

Introduction

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.

Thursday 21 October 2010 4:54:13 pm

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

- http://github.com/ezsystems/ezpub...master/kernel/user/register.php#L315

'Hope that helps happy.gif Emoticon

Tuesday 02 November 2010 9: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')));
      }
  }

Modified on Tuesday 02 November 2010 9:45:00 pm by Marco Rogers

Wednesday 24 November 2010 8:27:36 am

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)

See http://pubsvn.ez.no/doxygen/trunk/html/ezrole_8php_source.html#l00791

Wednesday 16 February 2011 10: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() );

Wednesday 16 February 2011 10: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 !

Thursday 01 November 2012 5:54:42 pm

Thanks a lot David

It helps me a lot

The only things I need and I could net get the respond so far for it was what is the easiest way in PHP to get the Last_visit of a already fetched user (not the currently logged_in users)

 

Thanks

expandshrink

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

36 542 Users on board!

Forums menu

Proudly Developed with from