id()); } else if (is_numeric($login)) { $from = 'profiles AS p'; $where = XDB::format('p.pid = {?}', $login); } else { $from = 'profiles AS p'; $where = XDB::format('p.hrpid = {?}', $login); } // XXX: Temporary, use data from auth_user_md5 (waiting for data from newdirectory $res = XDB::query('SELECT p.*, u.prenom AS first_name, IF(u.nom_usage != "", u.nom_usage, u.nom) AS last_name, pd.promo AS promo, CONCAT(u.prenom, " ", u.nom) AS short_name, IF(u.nom_usage != "", CONCAT(u.nom_usage, " (", u.nom, "),", u.prenom), CONCAT(u.nom, ", ", u.prenom)) AS full_name FROM ' . $from . ' INNER JOIN auth_user_md5 AS u ON (u.user_id = p.pid) INNER JOIN profile_display AS pd ON (pd.pid = p.pid) WHERE ' . $where); if ($res->numRows() != 1) { throw new UserNotFoundException(); } $this->data = $res->fetchOneAssoc(); $this->pid = $this->data['pid']; $this->hrpid = $this->data['hrpid']; } public function id() { return $this->pid; } public function hrid() { return $this->hrpid; } public function promo() { return $this->promo; } /** Print a name with the given formatting: * %s = • for women * %f = firstname * %l = lastname * %F = fullname * %S = shortname * %p = promo */ public function name($format) { return str_replace(array('%s', '%f', '%l', '%F', '%S', '%p'), array($this->isFemale() ? '•' : '', $this->first_name, $this->last_name, $this->full_name, $this->short_name, $this->promo), $format); } public function fullName($with_promo = false) { if ($with_promo) { return $this->full_name . ' (' . $this->promo . ')'; } return $this->full_name; } public function shortName($with_promo = false) { if ($with_promo) { return $this->short_name . ' (' . $this->promo . ')'; } return $this->short_name; } public function firstName() { return $this->first_name; } public function lastName() { return $this->last_name; } public function isFemale() { return $this->sex == PlUser::GENDER_FEMALE; } public function data() { $this->first_name; return $this->data; } public function __get($name) { if (property_exists($this, $name)) { return $this->$name; } 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); } /** Return the profile associated with the given login. */ public static function get($login) { try { return new Profile($login); } catch (UserNotFoundException $e) { /* Let say we can identify a profile using the identifiers of its owner. */ $user = User::getSilent($login); if ($user && $user->hasProfile()) { return $user->profile(); } return null; } } } // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?>