<?php
/**
 * display_list - Data structure for displaying search results. Used by result_list_view.
 *                FILE IS OBSOLETE. DELETE WHEN NECESSARY.
 *
 * @author $Author: dtong $
 * @version $Id: Utility.php,v 1.3 2011/04/05 15:18:44 dtong Exp $
 * @copyright Copyright (c) 2009, Tiller Software Co., Ltd.
*/
//class Utility {
    /*
    * @param array $ary the array we want to sort
    * @param string $clause a string specifying how to sort the array similar to SQL ORDER BY clause
    * @param bool $ascending that default sorts fall back to when no direction is specified
    * @return null
    */
/*
    public static function orderBy(&$ary, $clause, $ascending = true) {
        $clause = str_ireplace('order by', '', $clause);
        $clause = preg_replace('/\s+/', ' ', $clause);
        $keys = explode(',', $clause);
        $dirMap = array('desc' => 1, 'asc' => -1);
        $def = $ascending ? -1 : 1;

        $keyAry = array();
        $dirAry = array();
        foreach($keys as $key) {
            $key = explode(' ', trim($key));
            $keyAry[] = trim($key[0]);
            if(isset($key[1])) {
                $dir = strtolower(trim($key[1]));
                $dirAry[] = $dirMap[$dir] ? $dirMap[$dir] : $def;
            } else {
                $dirAry[] = $def;
            }
        }

        $fnBody = '';
        for($i = count($keyAry) - 1; $i >= 0; $i--) {
            $k = $keyAry[$i];
            $t = $dirAry[$i];
            $f = -1 * $t;
            $aStr = '$a[\''.$k.'\']';
            $bStr = '$b[\''.$k.'\']';
            if(strpos($k, '(') !== false) {
                $aStr = '$a->'.$k;
                $bStr = '$b->'.$k;
            }

            if($fnBody == '') {
                $fnBody .= "if({$aStr} == {$bStr}) { return 0; }\n";
            //    $fnBody .= "return ({$aStr} < {$bStr}) ? {$t} : {$f};\n";
             //   $fnBody .= "return strcmp($aStr, $bStr);$t $f\n";

            } else {
                $fnBody = "if({$aStr} == {$bStr}) {\n" . $fnBody . "}\n";
             //   $fnBody .= "return strcmp($bStr, $aStr);$t $f\n";
               // $fnBody .= "return ({$aStr} < {$bStr}) ? {$t} : {$f};\n";

            }

            //TODO: looks like same code if and else
            if ($f == -1) {
            	//$fnBody .= "return strcasecmp($aStr, $bStr);\n";
            	$fnBody .= "return strnatcasecmp ($aStr, $bStr);\n";
            } else {
            	//$fnBody .= "return strcasecmp($bStr, $aStr);\n";
            	$fnBody .= "return strnatcasecmp ($bStr, $aStr);\n";
            }
        }

        if($fnBody) {
        	//echo $fnBody;
            $sortFn = create_function('$a,$b', $fnBody);
            usort($ary, $sortFn);
        }
    }
}
?> */