Add stuff to enable sort of result.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Wed, 4 Feb 2009 07:33:03 +0000 (08:33 +0100)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Wed, 4 Feb 2009 07:33:03 +0000 (08:33 +0100)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
classes/userfilter.php

index 00f9ce9..7a4dd3b 100644 (file)
@@ -287,7 +287,7 @@ class UFC_Sex implements UserFilterCondition
         if ($this->sex != User::GENDER_MALE && $this->sex != User::GENDER_FEMALE) {
             return self::COND_FALSE;
         } else {
-            return XDB::format('p.sex = {?}', $this->sex);
+            return XDB::format('p.sex = {?}', $this->sex == User::GENDER_FEMALE ? 'female' : 'male');
         }
     }
 }
@@ -316,15 +316,22 @@ class UFC_Group implements UserFilterCondition
 class UserFilter
 {
     private $root;
+    private $sort = array();
     private $query = null;
+    private $orderby = null;
 
-    public function __construct($cond = null)
+    public function __construct($cond = null, $sort = null)
     {
         if (!is_null($cond)) {
             if ($cond instanceof UserFilterCondition) {
                 $this->setCondition($cond);
             }
         }
+        if (!is_null($sort)) {
+            if ($sort instanceof UserFilterOrder) {
+                $this->addSort($sort);
+            }
+        }
     }
 
     private function buildQuery()
@@ -338,6 +345,9 @@ class UserFilter
                                ' . $joins . '
                            WHERE  (' . $where . ')';
         }
+        if (is_null($this->sortby)) {
+            $this->sortby = '';
+        }
     }
 
     private function formatJoin(array $joins)
@@ -418,6 +428,12 @@ class UserFilter
         $this->query = null;
     }
 
+    public function addSort(UserFilterOrder &$sort)
+    {
+        $this->sort[] =& $sort;
+        $this->sortby = null;
+    }
+
     static public function getLegacy($promo_min, $promo_max)
     {
         if ($promo_min != 0) {