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

Monday 18 October 2010 1:38:30 am - 5 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.

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:

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

'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)

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

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

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: http://twitter.com/ezcommunity

t : http://twitter.com/jeanvoye
G+ : http://plus.tl/jeanvoye

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

eZ debug

Timing: Jan 17 2025 10:55:18
Script start
Timing: Jan 17 2025 10:55:18
Module start 'content'
Timing: Jan 17 2025 10:55:18
Module end 'content'
Timing: Jan 17 2025 10:55:18
Script end

Main resources:

Total runtime0.2857 sec
Peak memory usage6,144.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0081 677.3281214.7969
Module start 'content' 0.00810.0093 892.1250198.0469
Module end 'content' 0.01740.2682 1,090.17191,508.2109
Script end 0.2856  2,598.3828 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00772.6884200.0004
Check MTime0.00190.6513200.0001
Mysql Total
Database connection0.00140.501610.0014
Mysqli_queries0.203271.12711410.0014
Looping result0.00150.51321390.0000
Template Total0.267593.710.2675
Template load0.00351.225610.0035
Template processing0.264092.426710.2640
Override
Cache load0.00311.072310.0031
Sytem overhead
Fetch class attribute can translate value0.00070.261210.0007
XML
Image XML parsing0.00040.136510.0004
General
dbfile0.01505.2452200.0007
String conversion0.00000.002130.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0003 secs