Array sorting

Author Message

Andrew Kelly

Friday 21 July 2006 6:45:36 am

I'm unable to sort a return set in the fetch function, becuase
the attribute I want to sort on is a custom attribute and not
supported.
It's basically a single selection so it SHOULD work, but it's not the
native single selection.

Is there any kind of operator to sort an existing array of content objects?
Or can somebody point me to the right place to start hacking? Where is the
code for the sort_by attribute functionality?

Andy

Kristof Coomans

Tuesday 25 July 2006 10:02:15 am

Hello Andy

The code for the sort_by parameter is in eZContentObjectTreeNode::createSortingSQLStrings (kernel/classes/ezcontentobjecttreenode.php).

Which datatype are you using? If it's not publicly available, can you post the code from the functions sortKeyType and sortKey?

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Andrew Kelly

Wednesday 26 July 2006 12:44:00 am

Hi Kristof,

The code for the sort_by parameter is in eZContentObjectTreeNode::createSortingSQLStrings (kernel/classes/ezcontentobjecttreenode.php).

Thanks for that.

Which datatype are you using? If it's not publicly available, can you post the code from the functions sortKeyType and sortKey?

Ah..
I think you caught me being stupid (and pointed me in the right direction).
The datatype in question is one I built myself (my first attempt at creating
a datatype actually) and is loosely based on the Fats Neutron verson of the country
datatype. I call it cfselection (content fed selection) and it's simply a rather vanilla
multiple selection, except that it takes its option list from the content tree. The data is
stored in a comma delimited string.
And I see that neither of the functions you've mentioned are even part of the
datatype which is probably a pretty good way towards an explanation and solution.

May I assume that these functions are called from somewhere outside the datatype itself?

Andy

Kristof Coomans

Wednesday 26 July 2006 1:11:43 am

May I assume that these functions are called from somewhere outside the datatype itself?

Yes, they are. The result of the function sortKey is stored in the db ezcontentobject_attribute table in the field sort_key_text or sort_key_int, depending on what the sortKeyType function returns. eZContentObjectTreeNode::createSortingSQLStrings will know which field to use by calling sortKeyType.

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Andrew Kelly

Wednesday 26 July 2006 3:29:39 am

Sorry, one more point of clarification:

This is sort_by 'attribute' that we're talking about, right?
Or maybe not? If these sort/key functions in the datatype are enough
to guarantee sorting, why does the documentation for sort_by attribute say
that only a hand full of datatypes are supported?

Is the documentation out of date? (Please say yes)

Kristof Coomans

Wednesday 26 July 2006 6:50:12 am

This is sort_by 'attribute' that we're talking about, right?

Yes, we are.

If these sort/key functions in the datatype are enough
to guarantee sorting, why does the documentation for sort_by attribute say
that only a hand full of datatypes are supported?

Not every datatype in the kernel has implemented these functions.

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Andrew Kelly

Wednesday 26 July 2006 7:27:10 am

But if I implement the functions in my datatype(s), then attribute sorting
will work correctly for them as well? Is that what you're telling me Kristof?

Andy

Kristof Coomans

Wednesday 26 July 2006 8:55:02 am

If you implement the functions then sorting will work for your datatype, indeed.

Good luck!

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Andrew Kelly

Thursday 27 July 2006 1:20:19 am

Thanks, Kristof.

Say, I sent you an e-mail the other day, using the address I found in
your sckcreatecopy extension. Did it not reach you?

Andy

Andrew Kelly

Thursday 27 July 2006 1:41:35 am

Kristof,

sorry, another question:

[me]May I assume that these functions are called from somewhere outside
the datatype itself?[/me]

[Kristof]Yes, they are. The result of the function sortKey is stored in the db
ezcontentobject_attribute table in the field sort_key_text or
sort_key_int, depending on what the sortKeyType function returns.
eZContentObjectTreeNode::createSortingSQLStrings will know which field to
use by calling sortKeyType.[/Kristof]

When are these sortKeys persisted to the DB?
When sorting works correctly, I'll have several thousand records to import. Do I need
to worry about the sort_key attributes with each record, or is that handled
by the core during normal object creation?

Andy

Kristof Coomans

Thursday 27 July 2006 1:47:01 am

I just replied :-)

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

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 03:25:59
Script start
Timing: Jan 19 2025 03:25:59
Module start 'layout'
Timing: Jan 19 2025 03:25:59
Module start 'content'
Timing: Jan 19 2025 03:26:00
Module end 'content'
Timing: Jan 19 2025 03:26:00
Script end

Main resources:

Total runtime1.2177 sec
Peak memory usage4,096.0000 KB
Database Queries81

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0057 590.1484152.6094
Module start 'layout' 0.00570.0033 742.757839.3984
Module start 'content' 0.00901.2068 782.1563649.5469
Module end 'content' 1.21580.0018 1,431.703124.2031
Script end 1.2176  1,455.9063 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00360.2962160.0002
Check MTime0.00140.1171160.0001
Mysql Total
Database connection0.00070.061310.0007
Mysqli_queries1.117791.7884810.0138
Looping result0.00080.0672790.0000
Template Total1.179596.920.5898
Template load0.00180.150220.0009
Template processing1.177796.716220.5888
Template load and register function0.00010.008010.0001
states
state_id_array0.00290.237010.0029
state_identifier_array0.00150.125520.0008
Override
Cache load0.00200.1640810.0000
Sytem overhead
Fetch class attribute can translate value0.00060.047320.0003
Fetch class attribute name0.00120.0980130.0001
XML
Image XML parsing0.00240.194120.0012
class_abstraction
Instantiating content class attribute0.00010.0059220.0000
General
dbfile0.00230.1913220.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
11content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
11content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
7content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
18content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
6content/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: 55
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs