Email alias form.
[platal.git] / classes / profile.php
index 217a3f0..130cd35 100644 (file)
@@ -23,30 +23,36 @@ class Profile
 {
     private $pid;
     private $hrpid;
+    private $promo;
+
+    private $data = array();
 
     private function __construct($login)
     {
         if ($login instanceof PlUser) {
-            $res = XDB::query('SELECT  p.pid, p.hrpid
+            $res = XDB::query('SELECT  p.pid, p.hrpid, pd.promo_display
                                  FROM  account_profiles AS ap
                            INNER JOIN  profiles AS p ON (p.pid = ap.pid)
+                           INNER JOIN  profile_display AS pd ON (pd.uid = p.pid)
                                 WHERE  ap.uid = {?} AND FIND_IN_SET(\'owner\', ap.perms)',
                              $login->id());
         } else if (is_numeric($login)) {
-            $res = XDB::query('SELECT  p.pid, p.hrpid
+            $res = XDB::query('SELECT  p.pid, p.hrpid, pd.promo_display
                                  FROM  profiles AS p
+                           INNER JOIN  profile_display AS pd ON (pd.uid = p.pid)
                                 WHERE  p.pid = {?}',
                               $login);
         } else {
-            $res = XDB::query('SELECT  p.pid, p.hrpid
+            $res = XDB::query('SELECT  p.pid, p.hrpid, pd.promo_display
                                  FROM  profiles AS p
+                           INNER JOIN  profile_display AS pd ON (pd.uid = p.pid)
                                 WHERE  p.hrpid = {?}',
                               $login);
         }
         if ($res->numRows() != 1) {
             throw new UserNotFoundException();
         }
-        list($this->pid, $this->hrpid) = $res->fetchOneRow();
+        list($this->pid, $this->hrpid, $this->promo) = $res->fetchOneRow();
     }
 
     public function id()
@@ -59,6 +65,36 @@ class Profile
         return $this->hrpid;
     }
 
+    public function promo()
+    {
+        return $this->promo;
+    }
+
+    public function __get($name)
+    {
+        if (property_exists($this, $name)) {
+            return $this->$name;
+        }
+
+        if (empty($this->data)) {
+            $this->data = XDB::fetchOneAssoc('SELECT  *
+                                                FROM  profiles
+                                               WHERE  pid = {?}',
+                                             $this->id());
+        }
+        if (isset($this->data[$name])) {
+            return $this->data[$name];
+        }
+
+        return null;
+    }
+
+    public function __isset($name)
+    {
+        return property_exists($this, $name) || isset($this->data[$name]);
+    }
+
+
     public function owner()
     {
         return User::getSilent($this);
@@ -70,7 +106,7 @@ class Profile
         try {
             return new Profile($login);
         } catch (UserNotFoundException $e) {
-            return false;
+            return null;
         }
     }
 }