Forums / Developer / Array sorting

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

eZ debug

Timing: Jan 19 2025 00:25:17
Script start
Timing: Jan 19 2025 00:25:17
Module start 'content'
Timing: Jan 19 2025 00:25:17
Module end 'content'
Timing: Jan 19 2025 00:25:17
Script end

Main resources:

Total runtime0.2063 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0075 587.5391180.8516
Module start 'content' 0.00750.0076 768.3906109.9375
Module end 'content' 0.01510.1911 878.3281538.7109
Script end 0.2062  1,417.0391 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00432.0919200.0002
Check MTime0.00180.8787200.0001
Mysql Total
Database connection0.00090.459010.0009
Mysqli_queries0.148672.02051410.0011
Looping result0.00180.87311390.0000
Template Total0.190792.410.1907
Template load0.00090.447810.0009
Template processing0.189791.963910.1897
Override
Cache load0.00060.299110.0006
Sytem overhead
Fetch class attribute can translate value0.00100.477910.0010
XML
Image XML parsing0.00030.153110.0003
General
dbfile0.00170.8291200.0001
String conversion0.00000.001830.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs