Closed (outdated)
Project:
Views PHP
Version:
6.x-1.x-dev
Component:
Sort Handler
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
3 May 2011 at 14:27 UTC
Updated:
8 Feb 2021 at 23:21 UTC
Jump to comment: Most recent
Comments
Comment #1
infojunkieIn the Sort code section of the Sort field, you need to implement a comparison function for your custom field. The code should look something like this:
Basically, the function should return -1, 0, 1 depending on whether the field value in
$row1is less than, equal, or greater than the value in$row2.To find the name of your custom field, you can prepend something like
dsm($row1);to the code above (with Devel module enabled).Comment #2
thedavidmeister commentedthis is actually an invaluable little nugget of an explanation, although IMO using the ternary operator with nested comparisons makes the example unnecessarily hard to follow when you're aiming to make things *more* obvious for early adopters :P
below is how i got my gig guide, that used UNIX timestamps, to sort using only "day granularity" (since i was grouping the display by day) and then sort each day alphabetically by node title.
NOTE: without views_php, i had no way of changing the granularity of my date fields in the sort. Thanks for the great module!
EDIT: did some further testing, this doesn't quite do what i expected.. will get back to you with more refined code when i figure out how this is all supposed to work.
Comment #3
thedavidmeister commentedah, i totally munged the way arguments should be passed to strtotime.
this actually works:
Comment #4
infojunkie@thedavidmeister, thanks for the expanded explanation. Marking as fixed.
Comment #5
thedavidmeister commentedwell it is only half fixed really.. there's still no README.txt file provided with the project.
i'll open a separate issue for that though.
Comment #6
grasmash commentedSo it seems that if you use a Views PHP field as a sort handler, subsequent (views-generated) sort handlers do not work correctly? I'm assuming that's why you had to run strcmp() rather than simply adding a normal views title sort handler.
Is this true? If so, it needs to be noted in the help text for the sort handler.
Comment #7
liam morlandDrupal 6 is no longer supported. If this applies to a later version, please re-open and update the version.