Sorting by attribute (date / timestamp)

Author Message

Jani Tarvainen

Friday 08 May 2009 1:33:25 pm

I would like to sort articles using the publish_time -attribute and _not_ the publish time of the object. Documentation states that:

"The syntax for doing attribute level sorting is almost the same as for normal sorting. The only difference is that the ID number or the identifier of the target attribute must be specified. If the identifier is used then both the identifier of the class and the attribute must be specified (separated by a slash, like this: "my_class/my_attribute"). Attribute sorting can only be used if the returned collection contains the same type of nodes." -- http://ez.no/doc/ez_publish/technical_manual/4_0/reference/modules/content/fetch_functions/list

So I modified my fetch from


{def
	$nodes=fetch( 'content', 'list', hash(
		'parent_node_id', 123,
		'sort_by', array("published", false()),
		'depth',1,
		'class_filter_type',  'include',
		'class_filter_array', array( 'article' )
	))
}

to


{def
	$nodes=fetch( 'content', 'list', hash(
		'parent_node_id', 123,
		'sort_by', array("article/publish_date", false()),
		'depth',1,
		'class_filter_type',  'include',
		'class_filter_array', array( 'article' )
	))
}

but now I get no results, just an error: "Unknown sort field: article_tkl/publish_time" along with an SQL error "Query error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DESC' at line 50." This is because the query ends with ... ORDER BY DESC.

Is this a bug or am I doing something wrong?

--
http://ezpublish.fi/

Ivo Lukac

Friday 08 May 2009 1:53:04 pm

Try it like this:

{def
        $nodes=fetch( 'content', 'list', hash(
                'parent_node_id', 123,
                'sort_by', array("attribute", false(),"article/publish_date"),
                'depth',1,
                'class_filter_type', 'include',
                'class_filter_array', array( 'article' )
        ))
}

http://www.linkedin.com/in/ivolukac
http://www.netgen.hr/eng/blog
http://twitter.com/ilukac

Jani Tarvainen

Friday 08 May 2009 2:03:20 pm

Works like a charm. Thanks, Ivo!

If only I could read this from the docs... Well at least we'll have this example as documentation :)

--
http://ezpublish.fi/

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 18 2025 10:31:09
Script start
Timing: Jan 18 2025 10:31:09
Module start 'layout'
Timing: Jan 18 2025 10:31:09
Module start 'content'
Timing: Jan 18 2025 10:31:10
Module end 'content'
Timing: Jan 18 2025 10:31:10
Script end

Main resources:

Total runtime0.7083 sec
Peak memory usage4,096.0000 KB
Database Queries57

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0052 587.9375152.6250
Module start 'layout' 0.00520.0023 740.562539.4453
Module start 'content' 0.00750.6994 780.0078549.7109
Module end 'content' 0.70700.0013 1,329.718812.1563
Script end 0.7082  1,341.8750 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00300.4244160.0002
Check MTime0.00140.1935160.0001
Mysql Total
Database connection0.00070.102910.0007
Mysqli_queries0.658392.9459570.0115
Looping result0.00050.0709550.0000
Template Total0.682296.320.3411
Template load0.00220.314320.0011
Template processing0.680096.002620.3400
Template load and register function0.00010.017410.0001
states
state_id_array0.00090.133410.0009
state_identifier_array0.00160.227320.0008
Override
Cache load0.00190.2648200.0001
Sytem overhead
Fetch class attribute can translate value0.00060.090120.0003
Fetch class attribute name0.00140.194750.0003
XML
Image XML parsing0.00250.350620.0012
class_abstraction
Instantiating content class attribute0.00000.001760.0000
General
dbfile0.00240.3356230.0001
String conversion0.00000.001040.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
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
5content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
3content/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: 16
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs