"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

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 19 2025 01:17:41
Script start
Timing: Jan 19 2025 01:17:41
Module start 'layout'
Timing: Jan 19 2025 01:17:41
Module start 'content'
Timing: Jan 19 2025 01:17:42
Module end 'content'
Timing: Jan 19 2025 01:17:42
Script end

Main resources:

Total runtime0.9716 sec
Peak memory usage4,096.0000 KB
Database Queries63

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0060 589.1563152.6250
Module start 'layout' 0.00600.0025 741.781339.4453
Module start 'content' 0.00850.9611 781.2266581.4688
Module end 'content' 0.96960.0020 1,362.695316.1641
Script end 0.9716  1,378.8594 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00370.3791160.0002
Check MTime0.00140.1446160.0001
Mysql Total
Database connection0.00080.078210.0008
Mysqli_queries0.904193.0455630.0144
Looping result0.00070.0707610.0000
Template Total0.939896.720.4699
Template load0.00180.187520.0009
Template processing0.938096.535420.4690
Template load and register function0.00010.009710.0001
states
state_id_array0.00070.075110.0007
state_identifier_array0.00180.190120.0009
Override
Cache load0.00160.1607370.0000
Sytem overhead
Fetch class attribute can translate value0.00060.064520.0003
Fetch class attribute name0.00120.123170.0002
XML
Image XML parsing0.00110.115720.0006
class_abstraction
Instantiating content class attribute0.00000.0022100.0000
General
dbfile0.00160.1677250.0001
String conversion0.00000.000740.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
5content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
5content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
12content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
7content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 31
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs