{
private $pid;
private $hrpid;
+ private $data = array();
private function __construct($login)
{
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 (empty($this->data)) {
+ // XXX: Temporary, use data from auth_user_md5 (waiting for data from newdirectory
+ $this->data = XDB::fetchOneAssoc('SELECT p.*, u.prenom AS first_name,
+ IF(u.nom_usage != "", u.nom_usage, u.nom) AS last_name,
+ u.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 profiles AS p
+ INNER JOIN auth_user_md5 AS u ON (u.user_id = p.pid)
+ WHERE p.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);
try {
return new Profile($login);
} catch (UserNotFoundException $e) {
- return false;
+ /* 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;
}
}
}