Forums / Developer / Fetch a class attribute by is ID only, in PHP

Fetch a class attribute by is ID only, in PHP

Author Message

Olivier Portier

Thursday 12 March 2009 3:45:27 am

Hi eZ Forum,

In PHP code, i fetched an object that have reverse related objects.
I got the reverse related list like this :

// Fetch object ID 1231
$object = eZContentObject::fetch( 1231 );

// Get all reverse relations grouped by attribute
$all_reverse_related_object_list = $object->reverseRelatedObjectList( false, 0, true, array( 'AllRelations' => true ) );

Now i got this in $all_reverse_related_object_list :

array(1) {
  [391]=>
  array(8) {
    [0]=>
    object(eZContentObject)#48 (22) {
      ["ID"]=>
      string(4) "1252"
      ["Name"]=>
      string(28) "My reverse related object title 1"
....
    [8]=>
    object(eZContentObject)#48 (22) {
      ["ID"]=>
      string(4) "1260"
      ["Name"]=>
      string(28) "My reverse related object title 8"
... }
}

My attribute ID is <b>391</b> and i would like to fetch this attribute, and check his identifier (media is the identifier). Without knowing from which content class is part of, neither his version, just fetching it by his ID.

I tried this :

$reverse_attribute = eZContentObjectAttribute::fetch( 391 );

or this

$reverse_attribute = eZContentObjectAttribute::fetchByClassAttributeID( 391 );

without any success.

Does any one could help me on this ?
Thanks
Olivier

Olivier Portier

Thursday 12 March 2009 8:33:02 am

The attribute ID is a ContentClassAttribute not a ContentObjectAttribute.
So to get the identifier of this attribute, i just have to do this :

        $reverse_attribute = eZContentClassAttribute::fetch( $attribute_id );
        $attribute_identifier = $reverse_attribute->attribute('identifier');

I reached my goal !!!
Olivier

André R.

Thursday 12 March 2009 9:54:47 am

In 4.1 you can also use eZContentClassAttribute::classAttributeIdentifierByID / classAttributeIDByIdentifier, this is cached so no db calls are done.

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Olivier Portier

Friday 13 March 2009 1:39:49 am

Great, it is much better like this :

    $reverse_attribute = eZContentClassAttribute::classAttributeIdentifierByID( 391 );

Thanks André

eZ debug

Timing: Jan 18 2025 10:28:09
Script start
Timing: Jan 18 2025 10:28:09
Module start 'content'
Timing: Jan 18 2025 10:28:10
Module end 'content'
Timing: Jan 18 2025 10:28:10
Script end

Main resources:

Total runtime0.9491 sec
Peak memory usage4,096.0000 KB
Database Queries197

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0058 587.8438180.8125
Module start 'content' 0.00580.8174 768.6563571.3281
Module end 'content' 0.82310.1259 1,339.9844336.7422
Script end 0.9490  1,676.7266 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00410.4302210.0002
Check MTime0.00150.1584210.0001
Mysql Total
Database connection0.00080.086310.0008
Mysqli_queries0.875892.27711970.0044
Looping result0.00200.20581950.0000
Template Total0.924497.420.4622
Template load0.00210.218920.0010
Template processing0.922397.184920.4612
Template load and register function0.00020.020710.0002
states
state_id_array0.00070.077310.0007
state_identifier_array0.00080.081220.0004
Override
Cache load0.00180.1929340.0001
Sytem overhead
Fetch class attribute can translate value0.00130.140230.0004
Fetch class attribute name0.00130.141060.0002
XML
Image XML parsing0.00120.128530.0004
class_abstraction
Instantiating content class attribute0.00000.001880.0000
General
dbfile0.00250.2640340.0001
String conversion0.00000.000630.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
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
4content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
4content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
12content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
4content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
6content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 32
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs