Port email/send
[platal.git] / classes / user.php
index 0123003..7db7df4 100644 (file)
@@ -85,7 +85,7 @@ class User extends PlUser
         if ($fqdn == $globals->mail->domain || $fqdn == $globals->mail->domain2) {
             $res = XDB::query('SELECT  a.uid
                                  FROM  accounts AS a
-                           INNER JOIN  aliases AS al ON (al.id = a.uid AND al.type IN (\'alias\', \'a_vie\'))
+                           INNER JOIN  aliases AS al ON (al.uid = a.uid AND al.type IN (\'alias\', \'a_vie\'))
                                 WHERE  al.alias = {?}', $mbox);
             if ($res->numRows()) {
                 return $res->fetchOneCell();
@@ -116,7 +116,7 @@ class User extends PlUser
                 list($alias, $alias_fqdn) = explode('@', $redir);
                 $res = XDB::query("SELECT  a.uid
                                      FROM  accounts AS a
-                                LEFT JOIN  aliases AS al ON (al.id = a.uid AND al.type IN ('alias', 'a_vie'))
+                                LEFT JOIN  aliases AS al ON (al.uid = a.uid AND al.type IN ('alias', 'a_vie'))
                                     WHERE  al.alias = {?}", $alias);
                 if ($res->numRows()) {
                     return $res->fetchOneCell();
@@ -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,
@@ -185,8 +185,9 @@ class User extends PlUser
                                       ' . $fields . '
                                 FROM  accounts AS a
                           INNER JOIN  account_types AS at ON (at.type = a.type)
-                           LEFT JOIN  aliases AS af ON (af.id = a.uid AND af.type = \'a_vie\')
-                           LEFT JOIN  aliases AS ab ON (ab.id = a.uid AND FIND_IN_SET(\'bestalias\', ab.flags))
+                           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 . '
@@ -432,7 +433,7 @@ class User extends PlUser
         $this->fillFromArray($watch);
     }
 
-    public function watch($type)
+    public function watchType($type)
     {
         $this->fetchWatchData();
         return $this->watch_actions->hasFlag($type);
@@ -471,7 +472,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  *
@@ -479,6 +480,23 @@ class User extends PlUser
                                                               WHERE  uid = {?}',
                                                  $this->id());
         }
+    }
+
+    public function iterContacts()
+    {
+        $this->fetchContacts();
+        return self::iterOverUIDs(array_keys($this->contacts));
+    }
+
+    public function getContacts()
+    {
+        $this->fetchContacts();
+        return self::getBulkUsersWithUIDs(array_keys($this->contacts));
+    }
+
+    public function isContact(PlUser &$user)
+    {
+        $this->fetchContacts();
         return isset($this->contacts[$user->id()]);
     }