2 /***************************************************************************
3 * Copyright (C) 2003-2009 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
26 private $data = array();
28 private function __construct($login)
30 if ($login instanceof PlUser
) {
31 $res = XDB
::query('SELECT p.pid, p.hrpid
32 FROM account_profiles AS ap
33 INNER JOIN profiles AS p ON (p.pid = ap.pid)
34 WHERE ap.uid = {?} AND FIND_IN_SET(\'owner\', ap.perms)',
36 } else if (is_numeric($login)) {
37 $res = XDB
::query('SELECT p.pid, p.hrpid
42 $res = XDB
::query('SELECT p.pid, p.hrpid
47 if ($res->numRows() != 1) {
48 throw new UserNotFoundException();
50 list($this->pid
, $this->hrpid
) = $res->fetchOneRow();
58 public function hrid()
63 public function promo()
68 /** Print a name with the given formatting:
76 public function name($format)
78 return str_replace(array('%s', '%f', '%l', '%F', '%S', '%p'),
79 array($this->isFemale() ?
'•' : '',
80 $this->first_name
, $this->last_name
,
81 $this->full_name
, $this->short_name
,
82 $this->promo
), $format);
85 public function fullName($with_promo = false
)
88 return $this->full_name
. ' (' . $this->promo
. ')';
90 return $this->full_name
;
93 public function shortName($with_promo = false
)
96 return $this->short_name
. ' (' . $this->promo
. ')';
98 return $this->short_name
;
101 public function firstName()
103 return $this->first_name
;
106 public function lastName()
108 return $this->last_name
;
111 public function isFemale()
113 return $this->sex
== PlUser
::GENDER_FEMALE
;
116 public function data()
122 public function __get($name)
124 if (property_exists($this, $name)) {
128 if (empty($this->data
)) {
129 // XXX: Temporary, use data from auth_user_md5 (waiting for data from newdirectory
130 $this->data
= XDB
::fetchOneAssoc('SELECT p.*, u.prenom AS first_name,
131 IF(u.nom_usage != "", u.nom_usage, u.nom) AS last_name,
133 CONCAT(u.prenom, " ", u.nom) AS short_name,
134 IF(u.nom_usage != "",
135 CONCAT(u.nom_usage, " (", u.nom, "),", u.prenom),
136 CONCAT(u.nom, ", ", u.prenom)) AS full_name
138 INNER JOIN auth_user_md5 AS u ON (u.user_id = p.pid)
142 if (isset($this->data
[$name])) {
143 return $this->data
[$name];
149 public function __isset($name)
151 return property_exists($this, $name) ||
isset($this->data
[$name]);
155 public function owner()
157 return User
::getSilent($this);
160 /** Return the profile associated with the given login.
162 public static function get($login) {
164 return new Profile($login);
165 } catch (UserNotFoundException
$e) {
166 /* Let say we can identify a profile using the identifiers of its owner.
168 $user = User
::getSilent($login);
169 if ($user && $user->hasProfile()) {
170 return $user->profile();
177 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: