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 18 2025 02:05:48
Script start
Timing: Jan 18 2025 02:05:48
Module start 'content'
Timing: Jan 18 2025 02:05:48
Module end 'content'
Timing: Jan 18 2025 02:05:49
Script end

Main resources:

Total runtime0.2745 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0119 588.6484180.8281
Module start 'content' 0.01190.0116 769.4766106.5625
Module end 'content' 0.02360.2507 876.0391523.6875
Script end 0.2743  1,399.7266 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00461.6659200.0002
Check MTime0.00150.5557200.0001
Mysql Total
Database connection0.00180.669610.0018
Mysqli_queries0.202573.79131410.0014
Looping result0.00160.59291390.0000
Template Total0.250091.110.2500
Template load0.00110.418210.0011
Template processing0.248990.679010.2489
Override
Cache load0.00080.276610.0008
Sytem overhead
Fetch class attribute can translate value0.00100.358910.0010
XML
Image XML parsing0.00040.143110.0004
General
dbfile0.00913.3186200.0005
String conversion0.00000.002630.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