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

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 29 2025 14:41:41
Script start
Timing: Jan 29 2025 14:41:41
Module start 'layout'
Timing: Jan 29 2025 14:41:41
Module start 'content'
Timing: Jan 29 2025 14:41:41
Module end 'content'
Timing: Jan 29 2025 14:41:41
Script end

Main resources:

Total runtime0.0125 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0041 588.1328151.2109
Module start 'layout' 0.00410.0024 739.343836.6484
Module start 'content' 0.00650.0046 775.992298.2656
Module end 'content' 0.01110.0013 874.257837.9922
Script end 0.0124  912.2500 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002519.7029140.0002
Check MTime0.00129.5953140.0001
Mysql Total
Database connection0.00054.192610.0005
Mysqli_queries0.002318.445030.0008
Looping result0.00000.072610.0000
Template Total0.00107.810.0010
Template load0.00086.303210.0008
Template processing0.00021.443410.0002
Override
Cache load0.00064.609310.0006
General
dbfile0.00108.226480.0001
String conversion0.00000.045940.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