From: Florent Bruneau Date: Sat, 6 Mar 2010 20:06:20 +0000 (+0100) Subject: Rewrite Profile::getNameTypeId using DirEnum. X-Git-Tag: xorg/1.0.0~332^2~95 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;ds=inline;h=69ef14a5ffac8efea722ccb8e412e11b3e6d98d9;p=platal.git Rewrite Profile::getNameTypeId using DirEnum. Signed-off-by: Florent Bruneau --- diff --git a/classes/profile.php b/classes/profile.php index 1b657c8..cdd639d 100644 --- a/classes/profile.php +++ b/classes/profile.php @@ -485,6 +485,7 @@ class Profile $order = ''; } + require_once 'directory.enums.inc.php'; return XDB::Iterator('SELECT p.*, p.sex = \'female\' AS sex, pe.entry_year, pe.grad_year, pn_f.name AS firstname, pn_l.name AS lastname, pn_n.name AS nickname, IF(pn_uf.name IS NULL, pn_f.name, pn_uf.name) AS firstname_ordinary, @@ -507,9 +508,12 @@ class Profile LEFT JOIN account_profiles AS ap ON (ap.pid = p.pid AND FIND_IN_SET(\'owner\', ap.perms)) WHERE p.pid IN {?} GROUP BY p.pid - ' . $order, self::getNameTypeId('firstname'), - self::getNameTypeId('lastname'), self::getNameTypeId('firstname_ordinary'), - self::getNameTypeId('lastname_ordinary'), self::getNameTypeId('nickname'), $pids); + ' . $order, + DirEnum::getID(DirEnum::NAMETYPES, 'firstname'), + DirEnum::getID(DirEnum::NAMETYPES, 'lastname'), + DirEnum::getID(DirEnum::NAMETYPES, 'firstname_ordinary'), + DirEnum::getID(DirEnum::NAMETYPES, 'lastname_ordinary'), + DirEnum::getID(DirEnum::NAMETYPES, 'nickname'), $pids); } public static function getPID($login) @@ -611,18 +615,6 @@ class Profile || $name == self::DN_SHORT || $name == self::DN_SORT; } - public static function getNameTypeId($type) - { - if (!S::has('name_types')) { - $table = new PlDict(XDB::fetchAllAssoc('type', 'SELECT id, type - FROM profile_name_enum')); - S::set('name_types', $table); - } else { - $table = S::v('name_types'); - } - return $table->i($type); - } - public static function rebuildSearchTokens($pid) { XDB::execute('DELETE FROM search_name diff --git a/include/directory.enums.inc.php b/include/directory.enums.inc.php index c116284..be5d83b 100644 --- a/include/directory.enums.inc.php +++ b/include/directory.enums.inc.php @@ -121,20 +121,28 @@ class DirEnum * @param $text Text to search in enum valuees * @param $mode Mode of search for those IDs (prefix/suffix/infix) */ - static public function getIDs() + static public function getIDs($type, $text, $mode = XDB::WILDCARD_EXACT) { - $args = func_get_args(); - $type = array_shift($args); if (!array_key_exists($type, self::$enumerations)) { self::init($type); } $obj = self::$enumerations[$type]; if ($obj->capabilities & DirEnumeration::HAS_OPTIONS) { - return call_user_func_array(array($obj, 'getIDs'), $args); + return call_user_func(array($obj, 'getIDs'), $text, $mode); } else { return array(); } } + + /** Retrieves a single ID for a given type. + * @param $type Type of the enum for which an ID is requested + * @param $text Text to search in enum values + * @param $mode Mode of search of that ID (prefix/suffix/infix/exact) + */ + static public function getID($type, $text, $mode = XDB::WILDCARD_EXACT) + { + return array_shift(self::getIDs($type, $text, $mode)); + } } // }}} @@ -593,4 +601,6 @@ class DE_Networking extends DirEnumeration protected $ac_unique = 'profile_networking.pid'; } // }}} + +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?>