Fetching related objects of a specific class

Author Message

Brian Gerspacher

Friday 11 November 2005 11:43:32 am

I have user groups related to a product and want to retieve only the user groups related to that product (instead of all of the related content objects.) So far I can retieve all of the user groups in the system...

$userGroupClass =& eZContentClass::fetchByIdentifier('user_group');
$conditions = array('contentclass_id' => $userGroupClass->attribute('id'));
$groupObjects =& eZContentObject::fetchList(true, $conditions);

...and I know how to get all of the objects related to the product...

$productObject =& eZContentObject->fetch($myProductId);
$relatedObjects =& $productObject->relatedContentObjectArray();

...but I don't know how to get only the user groups related to the product. Is there an intuitive way to do this, or will I have to take one of the above approaches and loop over the results to pick out the objects I want?

Clemens T

Friday 11 November 2005 4:57:07 pm

I'd say just loop the related-objects array and create a new array and fill it with the object you want:

(pseudo code)

$myFilteredRelatedObject=array();
foreach($relatedObjects as $related)
{
      if($related->attribute('class_identifier')=='my_class_id')
      {
             $myFilteredRelatedObject[]=$related;
      }
}//$myFilteredRelatedObject contains the filtered objects.

off course this is pseudo code, but something like this should work (and yes.. I know that your approch is 'cleaner'.. but don't have any ez code here.. so can't check the ez classes.. that's why my answer is probably incomplete).

Good luck!
Clemens

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 19 2025 01:01:44
Script start
Timing: Jan 19 2025 01:01:44
Module start 'layout'
Timing: Jan 19 2025 01:01:44
Module start 'content'
Timing: Jan 19 2025 01:01:44
Module end 'content'
Timing: Jan 19 2025 01:01:44
Script end

Main resources:

Total runtime0.6356 sec
Peak memory usage4,096.0000 KB
Database Queries54

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0053 589.2891152.6406
Module start 'layout' 0.00530.0027 741.929739.4766
Module start 'content' 0.00800.6259 781.4063462.5938
Module end 'content' 0.63390.0016 1,244.00008.1250
Script end 0.6355  1,252.1250 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00330.5184160.0002
Check MTime0.00150.2314160.0001
Mysql Total
Database connection0.00080.121810.0008
Mysqli_queries0.589792.7841540.0109
Looping result0.00060.0972520.0000
Template Total0.599794.420.2999
Template load0.00210.330120.0010
Template processing0.597694.030220.2988
Template load and register function0.00030.040710.0003
states
state_id_array0.00090.138010.0009
state_identifier_array0.00080.118720.0004
Override
Cache load0.00160.2571140.0001
Sytem overhead
Fetch class attribute can translate value0.00130.211520.0007
Fetch class attribute name0.00140.227220.0007
XML
Image XML parsing0.00030.052720.0002
class_abstraction
Instantiating content class attribute0.00000.001120.0000
General
dbfile0.00300.4730100.0003
String conversion0.00000.001140.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
2content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
6content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
3content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 14
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs