Changes geocoding engine to gmaps v3.
[platal.git] / classes / userfilter.php
index bef41c4..9dd25c6 100644 (file)
@@ -764,9 +764,9 @@ class UserFilter extends PlFilter
 
     /** EDUCATION
      */
-    const GRADE_ING = 'Ing.';
-    const GRADE_PHD = 'PhD';
-    const GRADE_MST = 'M%';
+    const GRADE_ING = Profile::DEGREE_X;
+    const GRADE_PHD = Profile::DEGREE_D;
+    const GRADE_MST = Profile::DEGREE_M;
     static public function isGrade($grade)
     {
         return ($grade !== 0) && ($grade == self::GRADE_ING || $grade == self::GRADE_PHD || $grade == self::GRADE_MST);
@@ -813,7 +813,7 @@ class UserFilter extends PlFilter
         foreach ($this->pepe as $grade => $sub) {
             if ($this->isGrade($grade)) {
                 $joins['pe' . $sub] = PlSqlJoin::left('profile_education', '$ME.eduid = pee.id AND $ME.pid = $PID');
-                $joins['pede' . $sub] = PlSqlJoin::inner('profile_education_degree_enum', '$ME.id = pe' . $sub . '.degreeid AND $ME.abbreviation LIKE {?}', $grade);
+                $joins['pede' . $sub] = PlSqlJoin::inner('profile_education_degree_enum', '$ME.id = pe' . $sub . '.degreeid AND $ME.degree LIKE {?}', $grade);
             } else {
                 $joins['pe' . $sub] = PlSqlJoin::left('profile_education', '$ME.pid = $PID');
                 $joins['pee' . $sub] = PlSqlJoin::inner('profile_education_enum', '$ME.id = pe' . $sub . '.eduid');
@@ -914,85 +914,78 @@ class UserFilter extends PlFilter
 
     /** EMAILS
      */
-    private $e = array();
+    private $ra = array();
+    /** Allows filtering by redirection.
+     * @param $email If null, enable a left join on the email redirection table
+     *  (email_redirect_account); otherwise, perform a left join on users having
+     *  that email as a redirection.
+     * @return Suffix to use to access the adequate table.
+     */
     public function addEmailRedirectFilter($email = null)
     {
         $this->requireAccounts();
-        return $this->register_optional($this->e, $email);
-    }
-
-    private $with_eo = false;
-    public function addEmailOptionsFilter()
+        return $this->register_optional($this->ra, $email);
+    }
+
+    const ALIAS_BEST      = 'bestalias';
+    const ALIAS_FORLIFE   = 'forlife';
+    const ALIAS_AUXILIARY = 'alias_aux';
+    private $sa = array();
+    /** Allows filtering by source email.
+     * @param $email If null, enable a left join on the email source table
+     *  (email_source_account); otherwise, perform a left join on users having
+     *  that email as a source email.
+     * @return Suffix to use to access the adequate table.
+     */
+    public function addAliasFilter($email = null)
     {
         $this->requireAccounts();
-        $this->with_eo = true;
-        return 'eo';
+        return $this->register_optional($this->sa, $email);
     }
 
-    private $ve = array();
-    public function addVirtualEmailFilter($email = null)
-    {
-        $this->addAliasFilter(self::ALIAS_FORLIFE);
-        return $this->register_optional($this->ve, $email);
-    }
-
-    const ALIAS_BEST    = 'bestalias';
-    const ALIAS_FORLIFE = 'forlife';
-    private $al = array();
-    public function addAliasFilter($alias = null)
+    private $with_rf = false;
+    /** Allows filtering by active redirection.
+     * @return Suffix to use to access the adequate table.
+     */
+    public function addActiveEmailRedirectFilter($email = null)
     {
         $this->requireAccounts();
-        return $this->register_optional($this->al, $alias);
+        $this->with_rf = true;
     }
 
     protected function emailJoins()
     {
         global $globals;
         $joins = array();
-        foreach ($this->e as $sub=>$key) {
-            if (is_null($key)) {
-                $joins['e' . $sub] = PlSqlJoin::left('emails', '$ME.uid = $UID AND $ME.flags != \'filter\'');
+        foreach ($this->ra as $sub => $redirections) {
+            if (is_null($redirections)) {
+                $joins['ra' . $sub] = PlSqlJoin::left('email_redirect_account', '$ME.uid = $UID AND $ME.type != \'imap\'');
             } else {
-                if (!is_array($key)) {
-                    $key = array($key);
+                if (!is_array($redirections)) {
+                    $key = array($redirections);
                 }
-                $joins['e' . $sub] = PlSqlJoin::left('emails', '$ME.uid = $UID AND $ME.flags != \'filter\'
-                                                               AND $ME.email IN {?}', $key);
+                $joins['ra' . $sub] = PlSqlJoin::left('email_redirect_account', '$ME.uid = $UID AND $ME.type != \'imap\'
+                                                                                 AND $ME.redirect IN {?}', $redirections);
             }
         }
-        foreach ($this->al as $sub=>$key) {
-            if (is_null($key)) {
-                $joins['al' . $sub] = PlSqlJoin::left('aliases', '$ME.uid = $UID AND $ME.type IN (\'alias\', \'a_vie\')');
+        foreach ($this->sa as $sub => $emails) {
+            if (is_null($emails)) {
+                $joins['sa' . $sub] = PlSqlJoin::left('email_source_account', '$ME.uid = $UID');
             } else if ($key == self::ALIAS_BEST) {
-                $joins['al' . $sub] = PlSqlJoin::left('aliases', '$ME.uid = $UID AND $ME.type IN (\'alias\', \'a_vie\') AND  FIND_IN_SET(\'bestalias\', $ME.flags)');
+                $joins['sa' . $sub] = PlSqlJoin::left('email_source_account', '$ME.uid = $UID AND FIND_IN_SET(\'bestalias\', $ME.flags)');
             } else if ($key == self::ALIAS_FORLIFE) {
-                $joins['al' . $sub] = PlSqlJoin::left('aliases', '$ME.uid = $UID AND $ME.type = \'a_vie\'');
-            } else {
-                if (!is_array($key)) {
-                    $key = array($key);
-                }
-                $joins['al' . $sub] = PlSqlJoin::left('aliases', '$ME.uid = $UID AND $ME.type IN (\'alias\', \'a_vie\')
-                                                                  AND $ME.alias IN {?}', $key);
-            }
-        }
-        foreach ($this->ve as $sub=>$key) {
-            if (is_null($key)) {
-                $joins['v' . $sub] = PlSqlJoin::left('virtual', '$ME.type = \'user\'');
+                $joins['sa' . $sub] = PlSqlJoin::left('email_source_account', '$ME.uid = $UID AND $ME.type = \'forlife\'');
+            } else if ($key == self::ALIAS_AUXILIARY) {
+                $joins['sa' . $sub] = PlSqlJoin::left('email_source_account', '$ME.uid = $UID AND $ME.type = \'alias_aux\'');
             } else {
-                if (!is_array($key)) {
-                    $key = array($key);
+                if (!is_array($emails)) {
+                    $key = array($emails);
                 }
-                $joins['v' . $sub] = PlSqlJoin::left('virtual', '$ME.type = \'user\' AND $ME.alias IN {?}', $key);
+                $joins['sa' . $sub] = PlSqlJoin::left('email_source_account', '$ME.uid = $UID AND $ME.email IN {?}', $emails);
             }
-            $joins['vr' . $sub] = PlSqlJoin::left('virtual_redirect',
-                                                  '$ME.vid = v' . $sub . '.vid
-                                                   AND ($ME.redirect IN (CONCAT(al_forlife.alias, \'@\', {?}),
-                                                                         CONCAT(al_forlife.alias, \'@\', {?}),
-                                                                         a.email))',
-                                                  $globals->mail->domain, $globals->mail->domain2);
         }
-        if ($this->with_eo) {
-            $joins['eo'] = PlSqlJoin::left('email_options', '$ME.uid = $UID');
+        if ($this->with_rf) {
+            $joins['rf'] = PlSqlJoin::left('email_redirect_account', '$ME.uid = $UID AND $ME.type != \'imap\' AND $ME.flags = \'active\'');;
         }
         return $joins;
     }
@@ -1053,10 +1046,10 @@ class UserFilter extends PlFilter
         $this->requireProfiles();
         $this->pc = true;
         if ($type == UFC_Corps::CURRENT) {
-            $pce['pcec'] = 'current_corpsid';
+            $this->pce['pcec'] = 'current_corpsid';
             return 'pcec';
         } else if ($type == UFC_Corps::ORIGIN) {
-            $pce['pceo'] = 'original_corpsid';
+            $this->pce['pceo'] = 'original_corpsid';
             return 'pceo';
         }
     }