Tuesday 29 March 2011 4:47:10 am
Hi Martin, The eZFindResultNode was just an example of how one can extend an existing eZPersistenObject structure in non-intrusive mode. A more generic example would be the following :
class myCustomTreeNode extends eZContentObjectTreeNode
{
protected $customLocalAttribute;
function myCustomTreeNode( $rows = array() )
{
$this->eZContentObjectTreeNode( $rows );
$this->LocalAttributeValueList = array();
$this->LocalAttributeNameList = array( 'my_custom_local_attribute' );
}
function attribute( $attr, $noFunction = false )
{
$retVal = null;
switch ( $attr )
{
// Un-comment and implement for custom data retrieval.
/*
case 'my_custom_local_attribute':
{
$retVal = $this->customLocalAttribute;
} break;
*/
default:
{
if ( in_array( $attr, $this->LocalAttributeNameList ) )
{
$retVal = isset( $this->LocalAttributeValueList[$attr] ) ? $this->LocalAttributeValueList[$attr] : null;
}
else
{
$retVal = eZContentObjectTreeNode::attribute( $attr, $noFunction );
}
} break;
}
return $retVal;
}
function attributes()
{
return array_merge( $this->LocalAttributeNameList,
eZContentObjectTreeNode::attributes() );
}
function hasAttribute( $attr )
{
return ( in_array( $attr, $this->LocalAttributeNameList ) ||
eZContentObjectTreeNode::hasAttribute( $attr ) );
}
function setAttribute( $attr, $value )
{
switch( $attr )
{
// Un-comment and implement for custom data setting.
/*
case 'my_custom_local_attribute':
{
$this->customLocalAttribute = $value;
} break;
*/
default:
{
if ( in_array( $attr, $this->LocalAttributeNameList ) )
{
$this->LocalAttributeValueList[$attr] = $value;
}
else
{
eZContentObjectTreeNode::setAttribute( $attr, $value );
}
}
}
}
} As you can see, this approach does not permit to use the underlying table to store custom values. One rather works with in-memory values here. Another option (see commented-out bits above) is to use tier storage for the new, custom attributes.
I hope this helps, 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
|