X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=gosa-core%2Finclude%2Fclass_listingSortIterator.inc;h=af18544aa898fe213b04fee7442e292b6c1fdaaa;hb=359619a1d3b790bd6a3f08b8c609ce57777d281f;hp=ddaf5c243818146a2cda7d5195affe11eb88d65f;hpb=f926687f254ba9d2da8e89665afe01e3356a9e42;p=gosa.git diff --git a/gosa-core/include/class_listingSortIterator.inc b/gosa-core/include/class_listingSortIterator.inc index ddaf5c243..af18544aa 100644 --- a/gosa-core/include/class_listingSortIterator.inc +++ b/gosa-core/include/class_listingSortIterator.inc @@ -23,7 +23,7 @@ class listingSortIterator implements Iterator { private $data; - public function __construct($data, $attribute, $type= "string") { + public function __construct($data, $direction, $attribute, $type= "string") { global $_sortAttribute; global $_sortType; $_sortAttribute= $attribute; @@ -52,16 +52,41 @@ class listingSortIterator implements Iterator { // Take a look at the several types switch ($_sortType) { case 'string': - return strnatcmp($a, $b); + return strcoll($a, $b); + case 'integer': + return $b - $a; + + case 'date': + if ($a == "") { + $a= "31.12.0000"; + } + if ($b == "") { + $b= "31.12.0000"; + } + list($d, $m, $y)= split('\.', $a); + $a= (int)sprintf("%04d%02d%02d", $y, $m, $d); + list($d, $m, $y)= split('\.', $b); + $b= (int)sprintf("%04d%02d%02d", $y, $m, $d); + return $b-$a; + + // Sort for string by default default: - die(sprintf(_("Cannot sort entries: method '%s' is unknown!"), $_sortType)); + return strcoll($a, $b); } } // Sort for attribute - usort($data, "attrSort"); - $this->data= $data; + if ($attribute != "") { + uasort($data, "attrSort"); + } + + // Invert if direction is set + if ($direction) { + $this->data= array_reverse($data, true); + } else { + $this->data= $data; + } } function rewind() {