Thursday 11 August 2005 7:48:45 am
I'm a little confused as to what you really want to do: edit attributes of a bunch of objects or edit attributes of a contentclass. I'll assume you want to change an attribute on a bunch of objects. First of all, you need to determine if you want all objects of a contentclass, or just a selection of them . If you want all objects, use this:
$objects =& eZContentObject::fetchSameClassList( $contentClassID );
If you prefer to work with the identifier of a contentclass instead of passing the ID directly into the above function, do this:
$class =& eZContentClass::fetchByIdentifier( $identifier );
if( is_object( $class ) ) // This is a safety check
{
$objects =& eZContentObject::fetchSameClassList( $class->attribute( 'id' );
...
}
If you want a selection of the objects, you can use the PHP equivalent of the template fetch('content','tree',...) call.
$nodes =& eZContentObjectTreeNode::subTree( $params, $nodeID );
For the params, I advise you to take a look at the first lines of that function to see their names (they're similar to the template names). $nodeID is what you'd call parent_node_id in the template version. NOTE: The subTree() function will return objects of the eZContentObjectTreeNode class. To get the contentobject, loop over the returned nodes and get the attribute 'object'. Now let's go to the next level and assume you're somewhere in your code where you're down to working with a single contentobject at a time. Again, there are two ways to access the attributes of a contentobject: by numerical id or by identifier (identifier = identifier of the contentclass attribute). By identifier is the best way.
$objectData =& $object->dataMap();
That will get the data map of an object: an associative array with the identifier of an attribute as key, and the contentobject attribute as value. Let's say objects of that class have a text line attribute with identifier 'title'.
// $attribute will be set to an object of the class eZContentObjectAttribute
$attribute =& $objectData['title'];
To actually change the content of that attribute, you'll have to follow some steps that are different for each datatype. You'll have to look at the code of the datatype that you want to change and adapt the example I'll give for text line aka ezstring.
$attribute->setAttribute( 'data_text', 'Hello World!' );
$attribute->store();
Don't forget the store()! This example is the most basic way of changing the value of an attribute. That should get you going... I hope.
Hans
http://blog.hansmelis.be
|