Forums / Developer / Get node's attribute values

Get node's attribute values

Author Message

Jorge estévez

Monday 01 March 2010 7:04:50 pm

Hello,

I am developing a site with ez version 3.10.0

I am trying to go through all nodes at a cronjob.php file, I have managed to loop all nodes but I have not been able to access the elements of the attributes data, this is what I have:

$mynodeArray = $node->attribute( 'data_map' );

foreach ($mynodeArray as $theattribute => $v) {

echo "Attribute::: $ theattribute \n";

prints: the name of the attribute, this is OK

If I do a print_r($v);

I get:

[PersistentDataDirty] =>

[HTTPValue] =>

[Content] =>

[DisplayInfo] =>

[IsValid] =>

[ContentClassAttributeID] => 834

[ValidationError] =>

[ValidationLog] =>

[ContentClassAttributeIdentifier] => show_material

[ContentClassAttributeCanTranslate] =>

[ContentClassAttributeName] =>

[ContentClassAttributeIsInformationCollector] =>

[ContentClassAttributeIsRequired] =>

[InputParameters] =>

[HasValidationError] =>

[DataTypeCustom] =>

[ID] => 64592

[ContentObjectID] => 2086

[Version] => 13

[LanguageCode] => esl-ES

[LanguageID] => 2

[AttributeOriginalID] => 0

[SortKeyInt] => 1

[SortKeyString] =>

[DataTypeString] => ezboolean

[DataText] =>

[DataInt] => 1

[DataFloat] => 0

How do I access the attributes elements values? e.g. show_material (belonging to ContentClassAttributeIdentifier) and so forth

Thanks

Diseño Web Cuba
Web Design Cuba
www.elfosdesign.com

Nicolas Pastorino

Tuesday 02 March 2010 12:59:55 am

Hola Jorge,

Each element in the data_map array (called $mynodeArray in your case ) is a PHP object of the class eZContentObjectAttribute. They do explose the usual eZPersistentObject API, meaning that you can access most of their properties (be they database fields or more advanced, processed data) the classical :

$title = $titleContentAttribute->attribute( 'content' );

For example, if the attribute is of the 'Text' datataype ( kernel/classes/datatypes/ezstring/ezstringtype.php ), the above will populate the $title variable with the textual value entered when editing the object. Not all datatypes return the same type of value, some do return objects, usually in order to better structure the stored data.
The method mapped to the call above is : objectAttributeContent(), which you can inspect to understand the type of data returned.

Hope it helped,
Let us know how things go with your script,
Cheers !

--
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

Jorge estévez

Saturday 06 March 2010 5:46:07 am

Hello, really need help with this....

Having some problems here:

Again I am in an ez 3.10.0 version

I have been able to go trough all the nodes (for my defined classes) and also display its attributes (only if they are 'ezstring'), but php crashes when I get 1500 nodes...

The error:

PHP Script Interpreter ha detectado un problema y debe cerrarse. (traslating: PHP script interpreter has detected a problem and must shut down)

The ini file contains:

[datosparalistarproductos]
RootNodeList[]=177
laclase[modelo_de_producto]=name
laclase[una_pieza_gastronomico]=name

the code (commented):

<code>

<?php
// get values from content.ini
$ini = eZINI::instance( 'content.ini' );
// get starting node (begining from this node)
$rootNodeIDList = $ini->variable( 'datosparalistarproductos','RootNodeList' );
// get classes that I need
$clasesquequierobuscar = $ini->variable( 'datosparalistarproductos', 'laclase' );
$offset = 0;
$limit = 100;
// all the tree
foreach( $rootNodeIDList as $nodeID )
{

// get the root node
$rootNode = eZContentObjectTreeNode::fetch( $nodeID );

// for every class defined in the .ini
///
foreach ( $clasesquequierobuscar as $laclasequeletoca => $attributeIdentifier )
{
$offset = 0;
$counter = 0;

// objects must...
$params = array( 'ClassFilterType' => 'include',
'ClassFilterArray' => array( $laclasequeletoca ),
'Limitation' => array(),
'IgnoreVisibility' => true,
'MainNodeOnly' => true
);

//get subtree
$nodeArrayCount = $rootNode->subTreeCount( $params );

// if exists
if ( $nodeArrayCount > 0 )
{

do
{
$params['LoadDataMap'] = false;
$params['Limit'] = $limit;
$params['Offset'] = $offset;
//$params['SortBy'] = array( array( 'published', true ) );
$params['MainNodeOnly'] = true;


// ofset will be increased at the bottom for each loop
// limit will have the number of nodes to be looped (increased at the bottom)
echo("\n\n---------------offset: "); echo($offset);echo("\n");

$nodeArray = $rootNode->subTree($params);

// get all attributed of type 'ezstring'
// all attributes end with a ";" as the output will be imported in an excel file (separated by ";")
// if the attribute is empty then echo ";" as "empty value"
// for each node of the array
foreach ( $nodeArray as $node )
{
// get data_map
$arreglo_de_attributos = $node->attribute( 'data_map' );

// for each data_map array
foreach ($arreglo_de_attributos as $atributo) {
// if the attribute is 'ezstring'
if ($atributo->attribute( 'data_type_string' )=='ezstring')
{
// if it has NO echo a ";"
if($atributo->attribute( 'data_text' )=='') // null
{
echo ";";
}
else{
// if it has a value, trim \r \n and \0
$cadena=trim($atributo->attribute( 'data_text' ),"\r\n\0");
echo($cadena);
echo ";";
}
}
}

// a new line for the next node to be analized
echo "\n";

}

// update counter for the While loop
$counter += $limit;
// update offset to fetch the next bunch of nodes
$offset+=$limit;

} while( $counter < $nodeArrayCount and is_array( $nodeArray ) and count( $nodeArray ) > 0 );
}
}
}
?>

</code>

Really need help with this....

thanks

Diseño Web Cuba
Web Design Cuba
www.elfosdesign.com

Gaetano Giunta

Sunday 07 March 2010 5:50:57 am

The error happens because eZP is caching your objects in memory - after a while it runs out of memory.

Check in the forums for more info about the code needed to clear the cache in between passes of your loop.

eZContentObject::clearCache();

should be a good starting point

Principal Consultant International Business
Member of the Community Project Board

eZ debug

Timing: Jan 17 2025 23:35:46
Script start
Timing: Jan 17 2025 23:35:46
Module start 'content'
Timing: Jan 17 2025 23:35:47
Module end 'content'
Timing: Jan 17 2025 23:35:47
Script end

Main resources:

Total runtime0.7706 sec
Peak memory usage4,096.0000 KB
Database Queries199

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0061 588.8438180.8359
Module start 'content' 0.00610.6279 769.6797626.4297
Module end 'content' 0.63400.1358 1,396.1094341.3750
Script end 0.7698  1,737.4844 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00390.5042210.0002
Check MTime0.00150.1919210.0001
Mysql Total
Database connection0.00060.080210.0006
Mysqli_queries0.662785.99981990.0033
Looping result0.00200.26561970.0000
Template Total0.738895.920.3694
Template load0.00200.254420.0010
Template processing0.736895.617120.3684
Template load and register function0.00050.065410.0005
states
state_id_array0.00100.124610.0010
state_identifier_array0.00190.252220.0010
Override
Cache load0.00200.25701710.0000
Sytem overhead
Fetch class attribute can translate value0.00160.208840.0004
Fetch class attribute name0.00230.302860.0004
XML
Image XML parsing0.00190.249040.0005
class_abstraction
Instantiating content class attribute0.00000.006060.0000
General
dbfile0.00400.5138330.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/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
8content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
4content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 21
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs