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: Feb 18 2025 10:33:59
Script start
Timing: Feb 18 2025 10:33:59
Module start 'content'
Timing: Feb 18 2025 10:33:59
Module end 'content'
Timing: Feb 18 2025 10:33:59
Script end

Main resources:

Total runtime0.3188 sec
Peak memory usage4,096.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0147 587.3281180.8359
Module start 'content' 0.01470.0221 768.1641106.3359
Module end 'content' 0.03680.2819 874.5000525.5156
Script end 0.3187  1,400.0156 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00611.9122200.0003
Check MTime0.00270.8385200.0001
Mysql Total
Database connection0.00110.333410.0011
Mysqli_queries0.214967.41741410.0015
Looping result0.00130.40661390.0000
Template Total0.281388.210.2813
Template load0.00140.453610.0014
Template processing0.279887.770710.2798
Override
Cache load0.00100.312710.0010
Sytem overhead
Fetch class attribute can translate value0.00140.426310.0014
XML
Image XML parsing0.00030.108810.0003
General
dbfile0.01524.7826200.0008
String conversion0.00000.003230.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.0002 secs