Tuesday 31 March 2009 6:04:38 am
I think I managed creating my "arerelated" operator but I can't find how to pass the paraméters from template.
<b>1\ Installation seems OK...</b> I added the code below in \extension\ezwebin\autoloads\eztemplateautoload.php:
$eZTemplateOperatorArray[] = array( 'script' => 'extension/ezwebin/autoloads/arerelated.php',
'class' => 'arerelated',
'operator_names' => array( 'arerelated' ) );
And I regenerated autoload arrays from the admin interface, after creating the following template operator.
<b>2\ Operator should work...</b>
Then I created extension\ezwebin\autoloads\arerelated.php with this code :
<?php
class arerelated
{
function arerelated()
{ }
function operatorList()
{
return array( 'arerelated' ); }
function namedParameterPerOperator()
{
return true; }
function namedParameterList()
{
return array( 'arerelated' => array( 'object_id_from' => array( 'type' => 'integer',
'required' => true,
'default' => '' ),
'object_id_to' => array( 'type' => 'integer',
'required' => true,
'default' => '' )
) ); }
function modify( $tpl, $operatorName, $operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters )
{
$object_id_from = $namedParameters['object_id_from']; $object_id_to = $namedParameters['object_id_to'];
switch ( $operatorName )
{
case 'arerelated':
{
$object_from = eZContentObject::fetch( $object_id_from );
$object_to = eZContentObject::fetch( $object_id_to);
$relArray = $object_from->relatedObjects( false, false, 0, array( 'AsObject' => false ) ); $operatorValue = false;
// loop over array and compare with second parameter for related-to-id
// and set $operatorValue to true and break the loop if you find a match
foreach( $relArray as $rel )
{
if( $rel == $object_id_to )
{
$operatorValue = true;
break;
} }
}
}
} } ?> </code>One question yet : am I supposed to <b>compare objects or object_ids</b> ??? <b>3\ I can't pass the parameters</b> Now, my problem is that I can't find the template syntax to pass the NamedParameters to my new operator. I tried :
{if arerelated(array('object_id_from', $member_node.contentobject_id, 'object_id_to', $node.contentobject_id ))}
and
{if arerelated(hash('object_id_from', $member_node.contentobject_id, 'object_id_to', $node.contentobject_id ))}
but I think I am <b>lost within arrays</b>, despite deep survey of existing documentation and code analysis :-( Thanks in advance for your help :-)
|