X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;ds=sidebyside;f=classes%2Fprofile.php;h=130cd35649dc161b37fb92f20e2d4f8685588a70;hb=3e53a496dd11e5082bfefc22fc9322d80152edd6;hp=217a3f04a7431c0b5e65508bc8372bc05f60dd7b;hpb=e7b9396258bff20ea5ca4836ff82c2e2d44710e9;p=platal.git diff --git a/classes/profile.php b/classes/profile.php index 217a3f0..130cd35 100644 --- a/classes/profile.php +++ b/classes/profile.php @@ -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; } } }