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.