Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Sort Users Online statistics

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 08-01-2010, 09:20 PM
 
Torres Torres is offline
 

Member
  
Join Date: Apr 2010
Posts: 26
 

Default Sort Users Online statistics

I'm not sure why I can't sort in the Statistics -> Users Online screen, but it was driving me crazy each time I used it. In anycase, this is what I did to sort it by "Last Entry" Date:

Create a new file called modifier.sortby.php with the following code, and place it in your \include\lib\smarty\plugins\ folder.

PHP 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 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($key01) == '-')
              {
                 
$d '-1';
                 
$key substr($key1);
              }
              if (
substr($key01) == '#')
              {
                 
$key substr($key1);
               
$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" );
?>


Next, locate the following line in \skin1\modules\Users_online\stats.tpl:

PHP Code:
{foreach from=$statistics item=v

Change it to this:

PHP Code:
{foreach from=$statistics|@sortby:"-current_date" item=v

That's it. This will sort the "Users online" by last entry date in descending order. If you want it in ascending order, just remove the minus sign or replace it with a # sign. You can sort by multiple fields by separating them with a comma.
__________________
X-Cart 4.3.2
X-SpecialOffers
Reply With Quote

The following 2 users thank Torres for this useful post:
chamberinternet (03-16-2015), Jerrad (11-24-2010)
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 01:23 AM.

   

 
X-Cart forums © 2001-2020