Code

Display fixes
[gosa.git] / gosa-core / include / class_listingSortIterator.inc
index ddaf5c243818146a2cda7d5195affe11eb88d65f..7f46512e51c9ed003f086500b5f30eb1062e5915 100644 (file)
@@ -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; 
@@ -54,14 +54,23 @@ class listingSortIterator implements Iterator {
         case 'string':
           return strnatcmp($a, $b);
 
+        // Sort for string by default
         default:
-          die(sprintf(_("Cannot sort entries: method '%s' is unknown!"), $_sortType));
+          return strnatcmp($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() {