Dale Ray wrote:Parahead,

I hadn't thought about the fact that the second sort wouldn't kick in if the seconds weren't the same. To do what I need you have to eliminate the time from the sort completely since the events can have different time on the same day. So I guess this is more complicated than I thought, I end up needing to do this:

Sort by Date

Sort by another field

Sort by time

I think this will do what you want, the "sort by another field" above is the first field option you choose under the Sort Orders heading in the profile.

- Code: Select all
`$addon->addSortOrder('SortOrders_SortingDateThenFieldOne', 'Sort By Date Then Field Then Time');`

$Subs{'SortOrders_SortingDateThenFieldOne'} = <<'END_SUB';

sub SortOrders_SortingDateThenFieldOne {

return map { $_->[0] }

sort {

my ($SO_Second, $SO_Minute, $SO_Hour, $SO_Month_Day, $SO_Month, $SO_Year, $SO_Week_Day, $SO_IsDST) = localtime($a->[1]);

$da = "$SO_Year" . sprintf('%.2d', $SO_Month) . sprintf('%.2d', $SO_Month_Day);

$de = sprintf('%.2d', $SO_Hour) . sprintf('%.2d', $SO_Minute) . sprintf('%.2d', $SO_Second);

my ($SO_Second, $SO_Minute, $SO_Hour, $SO_Month_Day, $SO_Month, $SO_Year, $SO_Week_Day, $SO_IsDST) = localtime($b->[1]);

$db = "$SO_Year" . sprintf('%.2d', $SO_Month) . sprintf('%.2d', $SO_Month_Day);

$df = sprintf('%.2d', $SO_Hour) . sprintf('%.2d', $SO_Minute) . sprintf('%.2d', $SO_Second);

($dc = lc $a->[2]) =~ s/[\W_]+//g;

($dd = lc $b->[2]) =~ s/[\W_]+//g;

$da <=> $db || $dc cmp $dd || $de <=> $df }

map { [ $_, ($_->{'newstime'})[0], ($_->{$SortOrders_Field})[0]] } @_;

}

END_SUB

Dale Ray wrote:This is just a thought off the top of my head - to be more flexible the SortOrders could present in the settings a list of fields, a checkbox for the type of sort (alphabetic or numeric) and a check box for ascending or descending for that field. So you could

Sort by date ascending (oldest first)

Sort by another field descending numeric (say to count the most hits)

Sort by a third field alphabetic ascending

I don't know how hard it would be to construct the addon this way. I looked at the code in the addon and right now you have a sub for each sort choice in the settings. If you set up the settings the way I've described couldn't you have four sort routines (numeric ascending, number descending, alphabetic ascending, alphabetic descending) and then a master sub that 'directs the traffic')? I know that I may be completely off base here since I am not an experienced coder.

Yes, this can be done and is something I have thought about, the NewFilesAdvanced addon uses this technique you describe, with choosing fields and type of sort and this could be used in the SortOrders addon as well. The backward compatibility wouldnÃ‚Â´t be that good though...

Also, the placement of the choices at the profile settings page isnÃ‚Â´t very logical either, the main sorting option being quite far away from the actual choices of fields to use. This is something I have though one should fix as well...