Searches for companies like sth and not = sth.
[platal.git] / classes / userfilter.php
index 20696a0..e988793 100644 (file)
@@ -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)");
         }
     }
 
@@ -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);
     }
@@ -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);
         }
@@ -1668,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
@@ -2280,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) {