X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fprofile.php;h=7af43e9d060723a1e7ac35279363c3bc35c974d1;hb=c52d86d1d876e6def108e1d458604cc9714c252d;hp=9c89e250bddb082e6cd80782e77b6e858526fb23;hpb=4ca15c312b905eea712b71d077c7a8b24f9d3b01;p=platal.git diff --git a/classes/profile.php b/classes/profile.php index 9c89e25..7af43e9 100644 --- a/classes/profile.php +++ b/classes/profile.php @@ -1,6 +1,6 @@ numRows() != 1) { + __autoload('PlUser'); throw new UserNotFoundException(); } $this->data = $res->fetchOneAssoc(); @@ -108,12 +112,12 @@ class Profile public function firstName() { - return $this->first_name; + return $this->firstname; } public function lastName() { - return $this->last_name; + return $this->lastname; } public function isFemale() @@ -153,19 +157,38 @@ class Profile /** Return the profile associated with the given login. */ - public static function get($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(); + if (!($login instanceof PlUser)) { + $user = User::getSilent($login); + if ($user && $user->hasProfile()) { + return $user->profile(); + } } return null; } } + + public static function getNameTypeId($type, $for_sql = false) + { + if (!S::has('name_types')) { + $table = XDB::fetchAllAssoc('type', 'SELECT id, type + FROM profile_name_enum'); + S::set('name_types', $table); + } else { + $table = S::v('name_types'); + } + if ($for_sql) { + return XDB::escape($table[$type]); + } else { + return $table[$type]; + } + } } // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: