Rewrite Profile::getNameTypeId using DirEnum.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sat, 6 Mar 2010 20:06:20 +0000 (21:06 +0100)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sat, 6 Mar 2010 20:06:20 +0000 (21:06 +0100)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
classes/profile.php
include/directory.enums.inc.php

index 1b657c8..cdd639d 100644 (file)
@@ -485,6 +485,7 @@ class Profile
             $order = '';
         }
 
             $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,
         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
                            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)
     }
 
     public static function getPID($login)
@@ -611,18 +615,6 @@ class Profile
             || $name == self::DN_SHORT || $name == self::DN_SORT;
     }
 
             || $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
     public static function rebuildSearchTokens($pid)
     {
         XDB::execute('DELETE FROM  search_name
index c116284..be5d83b 100644 (file)
@@ -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)
      */
      * @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) {
         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();
         }
     }
         } 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';
 }
 // }}}
     protected $ac_unique = 'profile_networking.pid';
 }
 // }}}
+
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
 ?>
 ?>