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é

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 31 2025 00:31:54
Script start
Timing: Jan 31 2025 00:31:54
Module start 'layout'
Timing: Jan 31 2025 00:31:54
Module start 'content'
Timing: Jan 31 2025 00:31:54
Module end 'content'
Timing: Jan 31 2025 00:31:54
Script end

Main resources:

Total runtime0.0250 sec
Peak memory usage6,144.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0062 588.2656151.2266
Module start 'layout' 0.00620.0041 739.4922220.7188
Module start 'content' 0.01020.0133 960.21091,001.9609
Module end 'content' 0.02350.0015 1,962.171933.9922
Script end 0.0250  1,996.1641 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002710.8627140.0002
Check MTime0.00114.5222140.0001
Mysql Total
Database connection0.00072.787810.0007
Mysqli_queries0.002911.763830.0010
Looping result0.00000.116210.0000
Template Total0.00104.110.0010
Template load0.00083.320310.0008
Template processing0.00020.799110.0002
Override
Cache load0.00062.264910.0006
General
dbfile0.00031.131580.0000
String conversion0.00000.032440.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

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

Time used to render debug report: 0.0001 secs