Merge UFC_Email and UFC_EmailList into a single class (UFC_Email).
[platal.git] / classes / user.php
index 77bacbf..9936c94 100644 (file)
@@ -170,7 +170,7 @@ class User extends PlUser
 
         $uids = array_map(array('XDB', 'escape'), $uids);
 
-        return XDB::iterator('SELECT  a.uid, a.hruid, a.registration_date,
+        return XDB::iterator('SELECT  a.uid, a.hruid, a.registration_date, ah.alias AS homonym,
                                       CONCAT(af.alias, \'@' . $globals->mail->domain . '\') AS forlife,
                                       CONCAT(af.alias, \'@' . $globals->mail->domain2 . '\') AS forlife_alternate,
                                       CONCAT(ab.alias, \'@' . $globals->mail->domain . '\') AS bestalias,
@@ -187,6 +187,7 @@ class User extends PlUser
                           INNER JOIN  account_types AS at ON (at.type = a.type)
                            LEFT JOIN  aliases AS af ON (af.uid = a.uid AND af.type = \'a_vie\')
                            LEFT JOIN  aliases AS ab ON (ab.uid = a.uid AND FIND_IN_SET(\'bestalias\', ab.flags))
+                           LEFT JOIN  aliases AS ah ON (ah.uid = a.uid AND ah.type = \'homonyme\')
                            LEFT JOIN  emails AS e ON (e.uid = a.uid AND e.flags = \'active\')
                            LEFT JOIN  email_options AS eo ON (eo.uid = a.uid)
                                    ' . $joins . '
@@ -204,7 +205,7 @@ class User extends PlUser
             && $this->gender !== null && $this->email_format !== null) {
             return;
         }
-        $this->fillFromArray(self::loadMainFieldsFromUIDs(array($this->user_id))->next());
+        $this->fillFromArray(self::loadMainFieldsFromUIDs(array($this->uid))->next());
     }
 
     // Specialization of the fillFromArray method, to implement hacks to enable
@@ -213,13 +214,6 @@ class User extends PlUser
     // stop being used actively.
     protected function fillFromArray(array $values)
     {
-        // It might happen that the 'user_id' field is called uid in some places
-        // (eg. in sessions), so we hard link uid to user_id to prevent useless
-        // SQL requests.
-        if (!isset($values['user_id']) && isset($values['uid'])) {
-            $values['user_id'] = $values['uid'];
-        }
-
         // Also, if display_name and full_name are not known, but the user's
         // surname and last name are, we can construct the former two.
         if (isset($values['prenom']) && isset($values['nom'])) {
@@ -277,14 +271,6 @@ class User extends PlUser
         return $this->profile()->promo();
     }
 
-    public function yearpromo()
-    {
-        if (!$this->hasProfile()) {
-            return 0;
-        }
-        return $this->profile()->yearpromo();
-    }
-
     public function firstName()
     {
         if (!$this->hasProfile()) {
@@ -479,7 +465,7 @@ class User extends PlUser
 
     // Contacts
     private $contacts = null;
-    public function isContact(PlUser &$user)
+    private function fetchContacts()
     {
         if (is_null($this->contacts)) {
             $this->contacts = XDB::fetchAllAssoc('contact', 'SELECT  *
@@ -487,7 +473,24 @@ class User extends PlUser
                                                               WHERE  uid = {?}',
                                                  $this->id());
         }
-        return isset($this->contacts[$user->id()]);
+    }
+
+    public function iterContacts()
+    {
+        $this->fetchContacts();
+        return Profile::iterOverPIDs(array_keys($this->contacts));
+    }
+
+    public function getContacts()
+    {
+        $this->fetchContacts();
+        return Profile::getBulkProfilesWithPIDs(array_keys($this->contacts));
+    }
+
+    public function isContact(Profile &$profile)
+    {
+        $this->fetchContacts();
+        return isset($this->contacts[$profile->id()]);
     }
 
     // Groupes X