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