Forums / Developer / Obain the NodeID if the only thing I have is the ObjectID?

Obain the NodeID if the only thing I have is the ObjectID?

Author Message

Clemens T

Friday 02 September 2005 3:33:50 am

Hey all
I'd like to know how to get the NodeID if I only have the ObjectID. I'm currently programming in PHP, so not in a template! This is because the eZCollaborationItem class doesn't hold the NodeID!

I think the problem is (partially) that I don't have the parent_id... so maybe through getting the parent_id.. I can use ::fetchNode(...)?

Any thoughts?

And another thing: when using the '->attribute( 'id' );' on an ezPublishObject, what does it return? Because sometimes the: myObject->ID works fine, but ->attribute( 'ID' ); doesn't..?

Thanks a lot!
Clemens

Roy Bøhmer

Friday 02 September 2005 3:59:50 am

IF you only have one node per object, or know you always are looking for the main node you can run this:

$contentObject =& eZContentObject::fetch($ObjectID);
$nodeID = $contentObject->mainNodeID();

Roy

Clemens T

Friday 02 September 2005 4:55:37 am

Thank you for the hint! I now have the following problem (I think). I'm editing the ezapprovecollaborationhandler.php file of the kernel classes of ezPublish. This handles the 'approve' action of an item. The object_id of this item is known (see first post), but when I execute your code, I don't get a valid $nodeID (or no NodeID at all.. when I do a print($nodeID).. nothing is printed). Any reason why this is.. maybe because the object is not yet published?

Thanks,
Clemens!

Luis Micunco

Thursday 04 December 2008 7:56:32 am

Try

$object =& eZContentObject::fetch( $objectID );
$nodeID = $object->attribute( 'main_node_id' );

André R.

Thursday 04 December 2008 9:58:36 am

Or (add the & like above if your on php 4):

$node = eZContentObjectTreeNode::findMainNode( $objectID, true );
$nodeId = $node->attribute('node_id');

Or if you don't need the node object, only node_id:

$nodeData = eZContentObjectTreeNode::fetchByContentObjectID( $objectID, false );
$nodeId = $nodeData['node_id'];

Tip Search for "n fetch" and "n find" in ezcontentobjecttreenode.php and ezcotententobject.php to see what kind of fetch functions you can use.

Tip2: To see what kind of attributes a class support(for classes that implements eZPersistantObject), see in the beginning of the class definition on the definition() function.
'fields' are attributes that are set when the object is constructed, while ''function_attributes" are attributes that are dynamically generated when you request them (they often need to fetch data from database before the return anything). One such example would be 'main_node_id' on eZContentObject.
In other words the first two examples needs two sql calls while these two needs one (I'm not saying that less is always better, cause it's not when your database starts to get a allot of traffic and you give it a complex sql instead of several simple ones, but enough about that..).

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

eZ debug

Timing: Jan 31 2025 01:22:54
Script start
Timing: Jan 31 2025 01:22:54
Module start 'content'
Timing: Jan 31 2025 01:22:54
Module end 'content'
Timing: Jan 31 2025 01:22:55
Script end

Main resources:

Total runtime0.1870 sec
Peak memory usage8,192.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0075 588.1875370.2578
Module start 'content' 0.00750.0147 958.44531,005.7500
Module end 'content' 0.02220.1648 1,964.19533,894.3359
Script end 0.1869  5,858.5313 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00432.2858200.0002
Check MTime0.00130.7081200.0001
Mysql Total
Database connection0.00110.593010.0011
Mysqli_queries0.094150.33021410.0007
Looping result0.00130.68931390.0000
Template Total0.164387.910.1643
Template load0.00090.484010.0009
Template processing0.163487.390210.1634
Override
Cache load0.00060.334710.0006
Sytem overhead
Fetch class attribute can translate value0.00180.983910.0018
XML
Image XML parsing0.00020.121410.0002
General
dbfile0.00814.3065200.0004
String conversion0.00000.002730.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