durangod Posted June 13, 2014 Share Posted June 13, 2014 (edited) I added a bunch of tlds and i wanted to sort them low to high which if i did that as a string it would be the same as doing it alphabetically. so far i have just done this via the new registered domain page, but i do plan to add it to other areas where i need it. so here is the mod... first create a new file called modifier.sorttld.php inside the file you will have this... <?php /* ************************************************************************************** * This file is used as a generic sort utility modifier for smarty. You can change the * sort type if you want, i use this now to only sort my tld's and that is all * by dave at www.icodemods.com ************************************************************************************** */ /* ************************************************************************ @input is an array @output is a sorted array by string low to high @usage example {foreach key=num item=listtld from=$tlds|@sorttld} asort Documentation is here http://www.php.net/manual/en/function.asort.php Alternate sort options are here http://www.php.net/manual/en/function.sort.php ************************************************************************ */ function smarty_modifier_sorttld($array) { asort($array, SORT_STRING); return $array; } $smarty->register_modifier( "sorttld", "smarty_modifier_sorttld" ); ?> place that file in includes/classes/Smarty/plugins then when you want to sort tlds low to high such as i did in templates/orderforms/comparison/adddomain.tpl all you have to do is this: original code: {foreach key=num item=listtld from=$tlds} Change it to this: {foreach key=num item=listtld from=$tlds|@sorttld} easy peasy.... hope this helps... Edited June 13, 2014 by durangod 0 Quote Link to comment Share on other sites More sharing options...
durangod Posted June 13, 2014 Author Share Posted June 13, 2014 (edited) i just happen to think there are also three places in comparison/configurproductdomain.tpl also if they click on a hosting package they will get that page. also the last option on that page does not have a tld, it is blank and allowed them to type it in for existing domain... {foreach key=num item=incartdomain from=$incartdomains|@sorttld} <option value="{$incartdomain}">{$incartdomain}</option> {/foreach} {foreach key=num item=listtld from=$registertlds|@sorttld} <option value="{$listtld}"{if $listtld eq $tld} selected="selected"{/if}>{$listtld}</option> {/foreach} {foreach key=num item=listtld from=$transfertlds|@sorttld} <option value="{$listtld}"{if $listtld eq $tld} selected="selected"{/if}>{$listtld}</option> {/foreach} Edited June 13, 2014 by durangod 0 Quote Link to comment Share on other sites More sharing options...
durangod Posted June 13, 2014 Author Share Posted June 13, 2014 Ok folks regarding the domainchecker sort, its a bit different because you actually have to grab the element and sort it by element of the array. referring to domainchecker.tpl I am using portal and it has an upper page (domain) and a lower page (domain by prices) This part of the sort mod is just for the lower part of the page. Because i can get the upper part to sort but it has a row meter of 5 per line and whenever i sort it it totally tosses off the rows so they are all over the place. So i will need to figure that out and possibly redo that section and then i will share that here with you.. BUT FOR THE LOWER PART ONLY (DOMAIN PRICING) HERE WE GO create a new php file and call it modifier.sortelem.php inside that file put this.. <?php /* ************************************************************************************** * This file is used as a sorty by element utility modifier for smarty. You can change the * sort type if you want, i use this now to only sort my tld's and that is all * by dave at www.icodemods.com ************************************************************************************** */ /* ******************************************************************************* @input is an array + element @output is a sorted array by string low to high by element keeping key assoc @usage example {foreach key=num item=tldpricelist from=$tldpricelist|@sortelem:tld} asort Documentation is here http://www.php.net/manual/en/function.asort.php Alternate sort options are here http://www.php.net/manual/en/function.sort.php ******************************************************************************** */ function smarty_modifier_sortelem($arr,$elem) { if(!$elem) { return $arr; //if no elem value just return the original array }else{ foreach($arr as $key=>$value) { $b[$key] = strtolower($value[$elem]); //results are just the tld elements in an array } asort($b, SORT_STRING); //now it is sorted low to high by tld which equates to alphabetical foreach($b as $tldkey=>$tldvalue) { $c[] = $arr[$tldkey]; } //now we have a new array $c that has all the original elements but is sorted by $elem value return $c; }//close else }//close function $smarty->register_modifier( "sortelem", "smarty_modifier_sortelem" ); ?> put this file in includes/classes/Smarty/plugins then open up portal/domainchecker.tpl and scroll down near the bottom original code is: {foreach key=num item=tldpricelist from=$tldpricelist} change it to this: {foreach key=num item=tldpricelist from=$tldpricelist|@sortelem:tld} save the file and run the page... the bottom portion is now sorted by tld. enjoy... when i get the upper part of the page row issue figured out i will be back to update... 0 Quote Link to comment Share on other sites More sharing options...
durangod Posted June 14, 2014 Author Share Posted June 14, 2014 (edited) the problem with the top portion of the page for domain checker is because the rows are done by $num which is the element KEY number which is nuts to do it that way.. sorry WHMCS thats a huge fail, i have never seen a listing done from element KEY number, its always done from a loop counter. I need some rest i will work on this when i get up.. Here is the code <tr> {foreach key=num item=listtld from=$tldslist} <td align="left"> <input type="checkbox" name="tlds[]" value="{$listtld}"{if in_array($listtld,$tlds)} checked{/if}/> {$listtld} </td> {if $num % 5 == 0}</tr><tr>{/if} {/foreach} </tr> its not a bug per say but it sure is not done in a standardized way.. you should never ever use element KEY number as a counter... use an $i loop or i belive smarty uses interation or actual {counter} ok i need rest... Edited June 14, 2014 by durangod 0 Quote Link to comment Share on other sites More sharing options...
durangod Posted June 14, 2014 Author Share Posted June 14, 2014 here is the fix for the sort for the upper part of the domain checker. I had to report it because i think it really need to be fixed globally. http://forum.whmcs.com/showthread.php?90110-Using-array-key-as-loop-counter-bad-idea&p=379506#post379506 the example code that is correct is how you want to do the upper part of the domain checker.. 0 Quote Link to comment Share on other sites More sharing options...
othellotech Posted October 28, 2014 Share Posted October 28, 2014 why do it everytime through smarty, when you could just use the sort order in the domainpricing table - script sorting those how you want and job done 0 Quote Link to comment Share on other sites More sharing options...
durangod Posted October 29, 2014 Author Share Posted October 29, 2014 because i wanted to share it and not everyone knows how to manipulate table data. 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.