コード例 #1
0
 /**
  * This private method is used by the usort function in  the
  * orderSentWork and orderReceivedWork methods.
  * It compares 2 work-objects by 1 of the properties of that object, dictated by the
  * private property _orderBy
  *
  * @param unknown_type $a
  * @param unknown_type $b
  * @return -1, 0 or 1 dependent of the result of the comparison.
  */
 function _cmpWork($a, $b)
 {
     $sort = $this->_orderBy;
     $aval = $a->{$sort};
     $bval = $b->{$sort};
     if ($sort == 'recipients') {
         // The recipients property is an array so we do the comparison based on the first item of the recipients array
         $aval = $aval[0]['name'];
         $bval = $bval[0]['name'];
     }
     if ($sort == 'filesize') {
         // Filesize is not a string, so we use other comparison technique
         return $aval < $bval ? -1 : 1;
     } elseif ($sort == 'title') {
         // Natural order for sorting titles is more "human-friendly"
         return api_strnatcmp($aval, $bval);
     } else {
         return api_strcasecmp($aval, $bval);
     }
 }
コード例 #2
0
 public function sort_by_id($item1, $item2)
 {
     return api_strnatcmp($item1->get_id(), $item2->get_id());
 }
コード例 #3
0
 /**
  * @param $item1
  * @param $item2
  * @return int
  */
 function sort_by_name($item1, $item2)
 {
     return api_strnatcmp($item1->get_name(), $item2->get_name());
 }
コード例 #4
0
/**
 * Performs string comparison in so called "natural order", case insensitive, language sensitive, with extended multibyte support.
 * @param string $string1				The first string.
 * @param string $string2				The second string.
 * @param string $language (optional)	The language in which comparison is to be made. If language is omitted, interface language is assumed then.
 * @param string $encoding (optional)	The used internally by this function character encoding. If it is omitted, the platform character set will be used by default.
 * @return int							Returns < 0 if $string1 is less than $string2; > 0 if $string1 is greater than $string2; and 0 if the strings are equal.
 * This function is aimed at replacing the function strnatcasecmp() for human-language strings.
 * @link http://php.net/manual/en/function.strnatcasecmp
 */
function api_strnatcasecmp($string1, $string2, $language = null, $encoding = null)
{
    return api_strnatcmp(api_strtolower($string1, $encoding), api_strtolower($string2, $encoding), $language, $encoding);
}