Get node's attribute values

Get node's attribute values

Monday 01 March 2010 7:04:50 pm - 3 replies

Modified on Monday 01 March 2010 7:10:42 pm by Jorge estévez

Author Message

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

You must be logged in to post messages in this topic!

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.