Displays proper information on promo marketing pages (Closes #1142).
[platal.git] / classes / userfilter.php
index 2931a05..e988793 100644 (file)
@@ -47,7 +47,7 @@ class UFC_HasProfile implements UserFilterCondition
     public function buildCondition(PlFilter &$uf)
     {
         $uf->requireProfiles();
-        return 'p.pid IS NOT NULL';
+        return '$PID IS NOT NULL';
     }
 }
 // }}}
@@ -156,7 +156,8 @@ class UFC_Promo implements UserFilterCondition
             UserFilter::assertGrade($this->grade);
         }
         if ($this->grade == UserFilter::DISPLAY && $this->comparison != '=') {
-            Platal::page()->killError('Comparison ' . $this->comparison . ' not allowed on displaid promo');
+            // XXX: we might try to guess the grade from the first char of the promo and forbid only '<= 2004', but allow '<= X2004'
+            Platal::page()->killError("Il n'est pas possible d'appliquer la comparaison '" . $this->comparison . "' aux promotions sans spĂ©cifier de formation (X/M/D)");
         }
     }
 
@@ -455,9 +456,9 @@ class UFC_Registered implements UserFilterCondition
     {
         $uf->requireAccounts();
         if ($this->active) {
-            $date = 'a.uid IS NOT NULL AND a.state = \'active\'';
+            $date = '$UID IS NOT NULL AND a.state = \'active\'';
         } else {
-            $date = 'a.uid IS NOT NULL AND a.state != \'pending\'';
+            $date = '$UID IS NOT NULL AND a.state != \'pending\'';
         }
         if (!is_null($this->comparison)) {
             $date .= ' AND a.registration_date != \'0000-00-00 00:00:00\' AND a.registration_date ' . $this->comparison . ' ' . XDB::format('{?}', $this->date->format('Y-m-d'));
@@ -938,7 +939,7 @@ class UFC_Job_Company implements UserFilterCondition
     public function buildCondition(PlFilter &$uf)
     {
         $sub = $uf->addJobCompanyFilter();
-        $cond  = $sub . '.' . $this->type . ' = ' . XDB::format('{?}', $this->value);
+        $cond  = $sub . '.' . $this->type . XDB::formatWildcards(XDB::WILDCARD_CONTAINS, $this->value);
         return $cond;
     }
 }
@@ -1048,7 +1049,7 @@ class UFC_Networking implements UserFilterCondition
         $conds = array();
         $conds[] = $sub . '.address ' . XDB::formatWildcards(XDB::WILDCARD_CONTAINS, $this->value);
         if ($this->type != -1) {
-            $conds[] = $sub . '.network_type = ' . XDB::format('{?}', $this->type);
+            $conds[] = $sub . '.nwid = ' . XDB::format('{?}', $this->type);
         }
         return implode(' AND ', $conds);
     }
@@ -1257,7 +1258,7 @@ class UFC_WatchRegistration extends UFC_UserRelated
         if (count($uids) == 0) {
             return PlFilterCondition::COND_FALSE;
         } else {
-            return XDB::format('a.uid IN {?}', $uids);
+            return XDB::format('$UID IN {?}', $uids);
         }
     }
 }
@@ -1420,6 +1421,12 @@ class UFO_Score extends UserFilterOrder
     {
         $toks = $uf->getNameTokens();
         $scores = array();
+
+        // If there weren't any sort tokens, we shouldn't sort by score, sort by NULL instead
+        if (count($toks) == 0) {
+            return 'NULL';
+        }
+
         foreach ($toks as $sub => $token) {
             $scores[] = XDB::format('SUM(' . $sub . '.score + IF (' . $sub . '.token = {?}, 5, 0) )', $token);
         }
@@ -1488,7 +1495,7 @@ class UFO_Uid extends UserFilterOrder
     protected function getSortTokens(PlFilter &$uf)
     {
         $uf->requireAccounts();
-        return 'a.uid';
+        return '$UID';
     }
 }
 // }}}
@@ -1514,7 +1521,7 @@ class UFO_Pid extends UserFilterOrder
     protected function getSortTokens(PlFilter &$uf)
     {
         $uf->requireProfiles();
-        return 'p.pid';
+        return '$PID';
     }
 }
 // }}}
@@ -1630,6 +1637,9 @@ class UserFilter extends PlFilter
         // available only once all UFC have set their conditions (UFO_Score)
         if (is_null($this->query)) {
             $where = $this->root->buildCondition($this);
+            $where = str_replace(array_keys($this->joinMetas),
+                                 $this->joinMetas,
+                                 $where);
         }
         if (is_null($this->orderby)) {
             $orders = array();
@@ -1641,6 +1651,9 @@ class UserFilter extends PlFilter
             } else {
                 $this->orderby = 'ORDER BY  ' . implode(', ', $orders);
             }
+            $this->orderby = str_replace(array_keys($this->joinMetas),
+                                         $this->joinMetas,
+                                         $this->orderby);
         }
         if (is_null($this->query)) {
             if ($this->with_accounts) {
@@ -1662,7 +1675,7 @@ class UserFilter extends PlFilter
         $this->buildQuery();
         $lim = $limit->getSql();
         $cond = '';
-        if (!is_null($uids)) {
+        if (!empty($uids)) {
             $cond = XDB::format(' AND a.uid IN {?}', $uids);
         }
         $fetched = XDB::fetchColumn('SELECT SQL_CALC_FOUND_ROWS  a.uid
@@ -1789,7 +1802,7 @@ class UserFilter extends PlFilter
 
     public function getUID($pos = 0)
     {
-        $uids =$this->getUIDList(null, new PlFilter(1, $pos));
+        $uids =$this->getUIDList(null, new PlLimit(1, $pos));
         if (count($uids) == 0) {
             return null;
         } else {
@@ -1805,7 +1818,7 @@ class UserFilter extends PlFilter
 
     public function getPID($pos = 0)
     {
-        $pids =$this->getPIDList(null, new PlFilter(1, $pos));
+        $pids =$this->getPIDList(null, new PlLimit(1, $pos));
         if (count($pids) == 0) {
             return null;
         } else {
@@ -2274,7 +2287,7 @@ class UserFilter extends PlFilter
                     $key = array($key);
                 }
                 $joins['e' . $sub] = PlSqlJoin::left('emails', '$ME.uid = $UID AND $ME.flags != \'filter\' 
-                                                               AND $ME.email IN {?}' . $key);
+                                                               AND $ME.email IN {?}', $key);
             }
         }
         foreach ($this->al as $sub=>$key) {