othellotech Posted May 18, 2009 Share Posted May 18, 2009 drop the following into your ./libs/plugins/ folder as modifier.sortby.php <?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 at http://www.phpinsider.com/smarty-forum 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 ( ( \$c = (\$a['$key'] - \$b['$key'])) != 0 ) return $d * \$c;\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; } $smarty->register_modifier( "sortby", "smarty_modifier_sortby" ); ?> then you can modify and array at output time to a new sort order: e.g in ./admin/templates/clientsummary.tpl {foreach key=num from=$productsummary|@sortby:"dpackage,domain" item=product} will sort the client products in a more friendly package, name order see http://www.phpinsider.com/smarty-forum/viewtopic.php?t=1079 0 Quote Link to comment Share on other sites More sharing options...
aXeR Posted October 1, 2009 Share Posted October 1, 2009 Hi Rob Should this work 'as-is' as I've just had a web dev upload the file to the dir suggested and he's ammended the clientarea file to sort using: {foreach key=num from=$services|@sortby:"Active" item=service} However the clientarea now gives the error: Fatal error: Template error: [in <theme>/clientareaproducts.tpl line 21]: [plugin] modifier 'sortby' is not implemented (core.load_plugins.php, line 118) in <url to whmcs clinet portal>/includes/smarty/Smarty.class.php on line 1095 Any suggestions? 0 Quote Link to comment Share on other sites More sharing options...
othellotech Posted October 18, 2009 Author Share Posted October 18, 2009 at a guess "Active" is not a field in the array ... 0 Quote Link to comment Share on other sites More sharing options...
Lawrence Posted October 18, 2009 Share Posted October 18, 2009 at a guess "Active" is not a field in the array ... maybe try "domainstatus"? Active is just a value, not a field. 0 Quote Link to comment Share on other sites More sharing options...
sparky Posted October 18, 2009 Share Posted October 18, 2009 Look at the error... the modifier is not being loaded If you had put the file into the libs/plugins directory as per post #1and you are now using V4.1 then you will need to move the modifier file to includes/smarty/plugins directory The libs directory is no longer used for V4 0 Quote Link to comment Share on other sites More sharing options...
Lawrence Posted October 19, 2009 Share Posted October 19, 2009 Look at the error... the modifier is not being loaded If you had put the file into the libs/plugins directory as per post #1and you are now using V4.1 then you will need to move the modifier file to includes/smarty/plugins directory The libs directory is no longer used for V4 Your right, as I would think I am as well. The plugin needs to be uploaded to the proper folder, and he needs to reference the field name to sort by, not the content of a particular field. 0 Quote Link to comment Share on other sites More sharing options...
aXeR Posted October 19, 2009 Share Posted October 19, 2009 Thanks guys, I'll pass this information along 0 Quote Link to comment Share on other sites More sharing options...
aXeR Posted October 19, 2009 Share Posted October 19, 2009 Perfect, I have this working beautifully, you were right Sparky and Larwilliams - thanks! Also a big thanks to Rob too 0 Quote Link to comment Share on other sites More sharing options...
Lawrence Posted October 20, 2009 Share Posted October 20, 2009 Glad to hear you got it to work after 0 Quote Link to comment Share on other sites More sharing options...
frapincu Posted October 27, 2009 Share Posted October 27, 2009 You have an awesome collection of stuff and den, where exactly does your display case sit? 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.