Implement DirEnum::getOptionsArray()
authorRaphaël Barrois <raphael.barrois@polytechnique.org>
Sat, 6 Feb 2010 09:37:44 +0000 (10:37 +0100)
committerRaphaël Barrois <raphael.barrois@polytechnique.org>
Sat, 13 Feb 2010 23:34:01 +0000 (00:34 +0100)
Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
include/directory.enums.inc.php

index 07786b3..5ea6b32 100644 (file)
@@ -59,7 +59,6 @@ class DirEnum
     /** Retrieves all options for a given type
      * @param $type Type of enum for which options are requested
      * @return XorgDbIterator over the results
-     * TODO : Find a way to get either an array, or the adequate PlIterator
      */
     static public function getOptions()
     {
@@ -72,6 +71,21 @@ class DirEnum
         return call_user_func_array(array($obj, 'getOptions'), $args);
     }
 
+    /** Retrieves all options for a given type
+     * @param $type Type of enum for which options are requested
+     * @return Array of the results the results
+     */
+    static public function getOptionsArray()
+    {
+        $args = func_get_args();
+        $type = array_shift($args);
+        if (!array_key_exists($type, self::$enumerations)) {
+            self::init($type);
+        }
+        $obj = self::$enumerations[$type];
+        return call_user_func_array(array($obj, 'getOptionsArray'), $args);
+    }
+
     /** Retrieves all options with number of profiles for autocompletion
      * @param $type Type of enum for which options are requested
      * @param $text Text to autocomplete
@@ -151,6 +165,16 @@ abstract class DirEnumeration
         return $this->options;
     }
 
+    public function getOptionsArray()
+    {
+        $this->_fetchOptions();
+        $options = array();
+        while ($row = $this->options->next()) {
+            $options[$row['id']] = $row['field'];
+        }
+        return $options;
+    }
+
     // {{{ function getIDs
     /** Retrieves possible IDs for given text
      * @param $text Text to search for IDs