Well, I'm not convinced sortby is doing what it is meant to do - it doesn't matter what I put in the sortby string (whether sortby="sjfsd" or sortby="QUOTA_ID") - it just sorts the given array the same way.
It is possible I've not installed it correctly, never really used smarty modifiers and functions before...
So, back to the original question, how are subscription options currently sorted in Jamroom?
And is there any way I can get it to sort by quota_id instead of the default?
I mean if someone wanted to baby step me through installing the sortby modifier so that it worked, that would be great - otherwise I'll try and do it without adding something else in.
Found a slightly more up to date one - this is what I'm using. I also have functions uploaded but not sure if I need them or just this modifier file below...
Code
<?PHP
#
# sorts an array of named arrays by the supplied fields
# code by dholmes at jccc d0t net (taken from http://au.php.net/function.uasort)
# modified by cablehead, messju and pscs and trine
function array_sort_by_fields(&$data, $sortby){
static $sort_funcs = array();
if (empty($sort_funcs[$sortby]))
{
$code = "\$c=0;";
foreach (split(',', $sortby) as $key)
{
$d = '1';
if (substr($key, 0, 1) == '-')
{
$d = '-1';
$key = substr($key, 1);
}
if (substr($key, 0, 1) == '#')
{
$key = substr($key, 1);
$code .= "if ( \$a['$key'] > \$b['$key']) return $d * 1;\n";
$code .= "if ( \$a['$key'] < \$b['$key']) return $d * -1;\n";
}
else
{
$code .= "if ( (\$c = strcasecmp(\$a['$key'],\$b['$key'])) != 0 ) return $d * \$c;\n";
}
}
$code .= 'return $c;';
$sort_func = $sort_funcs[$sortby] = create_function('$a, $b', $code);
}
else
{
$sort_func = $sort_funcs[$sortby];
}
uasort($data, $sort_func);
}
#
# Modifier: sortby - allows arrays of named arrays to be sorted by a given field
#
function smarty_modifier_sortby($arrData,$sortfields) {
array_sort_by_fields($arrData,$sortfields);
return $arrData;
}
Hi Steve, I just got the mod from the forum smith.kyle linked to above - (he of the official smith.kyle Shoutcast nontheless).
I did find another site after some searching (I added the modifier code a while back), but I've not been able to find it again today. Actually, my code above is just directly from the forum with the modification on the last post added....
Joined: 27 Apr 2006
Posts: 22009
Location: Southern California
Posted: 01/17/08 19:51
Try doing this instead, create a file called modifier.sortby.php and put this in it:
Code
<?php
#
# sorts an array of named arrays by the supplied fields
# code by dholmes at jccc d0t net (taken from http://au.php.net/function.uasort)
# modified by cablehead, messju and pscs and trine
function smarty_modifier_sortby($array,$sortby)
{
function array_sort_by_fields($array, $sortby)
{
$sort_funcs = array();
"PHP Fatal error: Call to undefined function array_sort_by_fields() in /home3/rockscom/public_html/include/smarty/libs/plugins/modifier.sortby.php on line 36"
Cheers for all your help, I'm sure we'll crack it.
Joined: 27 Apr 2006
Posts: 22009
Location: Southern California
Posted: 01/17/08 20:07
Duh, I screwed something up. I edited the code above - recopy it and paste it to your file. Try putting the file in the jamroom/include/plugins/smarty/directory (not the one you have it in).
You know - that didn't seem to do anything... however the earlier version of the code, before people started adding fancy stuff to it, seems to work just fine.
I know it may be a bit memory intensive (what am I saying... I don't know &*^%... ) but this is what I'm using and what's working....
modifier.sortby.php - in the includes/smarty/libs/plugin directory
Code
<?php
#
# sorts an array of named arrays by the supplied fields
# code by dholmes at jccc d0t net
# taken from http://au.php.net/function.uasort
#
function array_sort_by_fields(&$data, $sortby){
if(is_array($sortby)) {
$sortby = join(',', $sortby);
}
uasort( $data,
create_function( '$a, $b', '
$skeys = split(\',\',\''.$sortby.'\');
foreach($skeys as $key){
if( ($c = strcasecmp($a[$key],$b[$key])) != 0 ){
return($c);
}
}
return($c); '));
}
#
# Modifier: sortby - allows arrays of named arrays to be sorted by a given field
#
function smarty_modifier_sortby($arrData, $sortfields) {
array_sort_by_fields($arrData, $sortfields);
return $arrData;
}