Adds search on corps (Closes #911).
[platal.git] / classes / userfilter / conditions.inc.php
index 859a125..c689f0b 100644 (file)
@@ -339,8 +339,8 @@ class UFC_HasEmailRedirect extends UserFilterCondition
 {
     public function buildCondition(PlFilter $uf)
     {
-        $sub_redirect = $uf->addEmailRedirectFilter();
-        return 'ra' . $sub_redirect . '.flags = \'active\'';
+        $sub_redirect = $uf->addActiveEmailRedirectFilter();
+        return 'rf.redirect IS NOT NULL';
     }
 
     public function export()
@@ -988,7 +988,7 @@ class UFC_Email extends UserFilterCondition
 
         if (count($foreign) > 0) {
             $sub = $uf->addEmailRedirectFilter($foreign);
-            $cond[] = XDB::format('ra' . $sub . '.redirect IS NOT NULL OR ra.redirect IN {?}', $foreign);
+            $cond[] = XDB::format('ra' . $sub . '.redirect IS NOT NULL OR ra' . $sub . '.redirect IN {?}', $foreign);
         }
         if (count($local) > 0) {
             $sub = $uf->addAliasFilter($local);
@@ -1198,11 +1198,13 @@ class UFC_Corps extends UserFilterCondition
     const ORIGIN    = 2;
 
     private $corps;
+    private $id;
     private $type;
 
-    public function __construct($corps, $type = self::CURRENT)
+    public function __construct($corps, $id = null, $type = self::CURRENT)
     {
         $this->corps = $corps;
+        $this->id    = $id;
         $this->type  = $type;
     }
 
@@ -1214,8 +1216,14 @@ class UFC_Corps extends UserFilterCondition
          * pcec for profile_corps_enum - current
          */
         $sub = $uf->addCorpsFilter($this->type);
-        $cond = $sub . '.abbreviation = ' . $corps;
-        $cond .= ' AND ' . $uf->getVisibilityCondition($sub . '.corps_pub');
+        if (is_null($this->id)) {
+            $cond = $sub . '.abbreviation = ' . $this->corps;
+        } else {
+            $cond = $sub . '.id = ' . $this->id;
+        }
+        // XXX(x2006barrois): find a way to get rid of that hardcoded
+        // reference to 'pc'.
+        $cond .= ' AND ' . $uf->getVisibilityCondition('pc.corps_pub');
         return $cond;
     }
 }
@@ -1227,9 +1235,12 @@ class UFC_Corps extends UserFilterCondition
 class UFC_Corps_Rank extends UserFilterCondition
 {
     private $rank;
-    public function __construct($rank)
+    private $id;
+
+    public function __construct($rank, $id = null)
     {
         $this->rank = $rank;
+        $this->id   = $id;
     }
 
     public function buildCondition(PlFilter $uf)
@@ -1239,7 +1250,11 @@ class UFC_Corps_Rank extends UserFilterCondition
          * pcr for profile_corps_rank
          */
         $sub = $uf->addCorpsRankFilter();
-        $cond = $sub . '.abbreviation = ' . $rank;
+        if (is_null($this->id)) {
+            $cond = $sub . '.abbreviation = ' . $this->rank;
+        } else {
+            $cond = $sub . '.id = ' . $this->id;
+        }
         // XXX(x2006barrois): find a way to get rid of that hardcoded
         // reference to 'pc'.
         $cond .= ' AND ' . $uf->getVisibilityCondition('pc.corps_pub');