Monday 25 January 2010 1:12:44 am
Hi Laurent, I have not used directly the classes from the extensions but I have extract it to my own class. save_eZ_attribute is not static so, you should call it from an ImportOperator instance :
function save_eZ_attribute( $contentObjectAttribute ) Otherwise, this my version of the method :
/**
* Sauve un attribut eZ d'un objet avec une nouvelle valeur.
* Cette méthode à l'avantage de gérer complétement les ObjectRelations et les RelationList.
* \arg $contentObjectAttribute Pointeur sur un attribut d'un objet
* \arg $value La valeur au format TXT
* \author Mugo Web Copyright (C) 2008 => extension data_import (http://projects.ez.no/data_import)
*/
function save_eZ_attribute( $contentObjectAttribute, $value )
{
switch( $contentObjectAttribute->attribute( 'data_type_string' ) )
{
case 'ezobjectrelation':
{
// Remove any exisiting value first from ezobjectrelation
/*
eZContentObject::removeContentObjectRelation( $contentObjectAttribute->attribute('data_int'),
$this->current_eZ_object->attribute('current_version'),
$this->current_eZ_object->attribute('id'),
$contentObjectAttribute->attribute('contentclassattribute_id')
);
*/
$contentObjectAttribute->setAttribute( 'data_int', 0 );
$contentObjectAttribute->store();
}
break;
case 'ezobjectrelationlist':
{
// Remove any exisiting value first from ezobjectrelationlist
$content = $contentObjectAttribute->content();
$relationList =& $content['relation_list'];
$newRelationList = array();
for ( $i = 0; $i < count( $relationList ); ++$i )
{
$relationItem = $relationList[$i];
eZObjectRelationListType::removeRelationObject( $contentObjectAttribute, $relationItem );
}
$content['relation_list'] =& $newRelationList;
$contentObjectAttribute->setContent( $content );
$contentObjectAttribute->store();
}
break;
}
// fromString returns false - even when it is successfull
// create a bug report for that
$contentObjectAttribute->fromString( $value );
$contentObjectAttribute->store();
} I hope this will help you. Damien
|