Forums / Developer / "top 10" template operator

"Please Note:
  • At the specific request of Ibexa we are changing this projects name to "Exponential" or "Exponential (CMS)" effective as of August, 11th 2025.
  • This project is not associated with the original eZ Publish software or its original developer, eZ Systems or Ibexa".

"top 10" template operator

Author Message

Norman Leutner

Wednesday 22 February 2006 1:39:37 am

Hi,

I'm trying to make a "top 10" template operator which gets a list of users and teir created objects:

function modify( &$tpl, &$operatorName, &$operatorParameters, &$rootNamespace,
                     &$currentNamespace, &$operatorValue, &$namedParameters )
    {
        switch ( $operatorName )
        {
            case 'topauthors':
            {
                
                $db =& eZDB::instance();                
                
                $query="SELECT `owner_id` , count( `owner_id` ) AS user_count
                        FROM `ezcontentobject` 
                        WHERE `contentclass_id` = '".$namedParameters['class_id']."'
                        AND `status` = '1'
                        GROUP BY `owner_id` 
                        ORDER BY `user_count` DESC 
                        LIMIT 0 , ".$namedParameters['limit'];

                $ResultArray = $db->arrayQuery( $query );                

                echo "<pre>Values:<br/>";
                var_dump ($ResultArray);
                echo "</pre>";                
                
                $operatorValue = $ResultArray;
                
            } break;
        }
    }

The function works fine, but I have the problem that the $ResultArray is not passed back to the template correctly:

<hr/>
{set $topten = topauthors('16','10')}
<hr/>
{$topten|attribute(show)}

The returned results is empty, even if the SQL returns the correct array.

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Attribute Type Value 

It seems like

$operatorValue = $ResultArray;

isn't the correct way to pass the array back to the template.

Can anyone give me a advice how to do that?

Thanks in advance

Mit freundlichen Grüßen
Best regards

Norman Leutner

____________________________________________________________
eZ Publish Platinum Partner - http://www.all2e.com
http://ez.no/partners/worldwide_partners/all2e_gmbh

Łukasz Serwatka

Wednesday 22 February 2006 1:49:52 am

Try with

<hr/> 
{def $topten = topauthors('16','10')} 
<hr/> 
{$topten|attribute(show)}

or

<hr/> 
{def $topten=''} 
{set $topten = topauthors('16','10')}
<hr/> 
{$topten|attribute(show)}

or


{topauthors('16','10')|attribute}

Problem is with {set} which assigns value to not defined variable.

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Norman Leutner

Wednesday 22 February 2006 2:11:34 am

Thanks Lukasz,

it works fine now....

Mit freundlichen Grüßen
Best regards

Norman Leutner

____________________________________________________________
eZ Publish Platinum Partner - http://www.all2e.com
http://ez.no/partners/worldwide_partners/all2e_gmbh

Łukasz Serwatka

Wednesday 22 February 2006 2:23:40 am

Great :)

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Norman Leutner

Wednesday 22 February 2006 2:57:07 am

I've added the operator to the contributions under:

http://ez.no/community/contribs/template_plugins/topauthors

maybe it's usefull for someone else...

Mit freundlichen Grüßen
Best regards

Norman Leutner

____________________________________________________________
eZ Publish Platinum Partner - http://www.all2e.com
http://ez.no/partners/worldwide_partners/all2e_gmbh