Jump to content

sorting tlds mod


Recommended Posts

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 by durangod
Link to comment
Share on other sites

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 by durangod
Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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 by durangod
Link to comment
Share on other sites

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..

Link to comment
Share on other sites

  • 4 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated