9c89e250bddb082e6cd80782e77b6e858526fb23
2 /***************************************************************************
3 * Copyright (C) 2003-2008 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 $from = 'account_profiles AS ap
32 INNER JOIN profiles AS p ON (p.pid = ap.pid)';
33 $where = XDB
::format('ap.uid = {?} AND FIND_IN_SET(\'owner\', ap.perms)', $login->id());
34 } else if (is_numeric($login)) {
35 $from = 'profiles AS p';
36 $where = XDB
::format('p.pid = {?}', $login);
38 $from = 'profiles AS p';
39 $where = XDB
::format('p.hrpid = {?}', $login);
41 // XXX: Temporary, use data from auth_user_md5 (waiting for data from newdirectory
42 $res = XDB
::query('SELECT p.*, u.prenom AS first_name,
43 IF(u.nom_usage != "", u.nom_usage, u.nom) AS last_name,
45 CONCAT(u.prenom, " ", u.nom) AS short_name,
47 CONCAT(u.nom_usage, " (", u.nom, "),", u.prenom),
48 CONCAT(u.nom, ", ", u.prenom)) AS full_name
50 INNER JOIN auth_user_md5 AS u ON (u.user_id = p.pid)
51 INNER JOIN profile_display AS pd ON (pd.pid = p.pid)
53 if ($res->numRows() != 1) {
54 throw new UserNotFoundException();
56 $this->data
= $res->fetchOneAssoc();
57 $this->pid
= $this->data
['pid'];
58 $this->hrpid
= $this->data
['hrpid'];
66 public function hrid()
71 public function promo()
76 /** Print a name with the given formatting:
84 public function name($format)
86 return str_replace(array('%s', '%f', '%l', '%F', '%S', '%p'),
87 array($this->isFemale() ?
'•' : '',
88 $this->first_name
, $this->last_name
,
89 $this->full_name
, $this->short_name
,
90 $this->promo
), $format);
93 public function fullName($with_promo = false
)
96 return $this->full_name
. ' (' . $this->promo
. ')';
98 return $this->full_name
;
101 public function shortName($with_promo = false
)
104 return $this->short_name
. ' (' . $this->promo
. ')';
106 return $this->short_name
;
109 public function firstName()
111 return $this->first_name
;
114 public function lastName()
116 return $this->last_name
;
119 public function isFemale()
121 return $this->sex
== PlUser
::GENDER_FEMALE
;
124 public function data()
130 public function __get($name)
132 if (property_exists($this, $name)) {
136 if (isset($this->data
[$name])) {
137 return $this->data
[$name];
143 public function __isset($name)
145 return property_exists($this, $name) ||
isset($this->data
[$name]);
149 public function owner()
151 return User
::getSilent($this);
154 /** Return the profile associated with the given login.
156 public static function get($login) {
158 return new Profile($login);
159 } catch (UserNotFoundException
$e) {
160 /* Let say we can identify a profile using the identifiers of its owner.
162 $user = User
::getSilent($login);
163 if ($user && $user->hasProfile()) {
164 return $user->profile();
171 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: