From: Raphaël Barrois Date: Sat, 6 Feb 2010 09:37:44 +0000 (+0100) Subject: Implement DirEnum::getOptionsArray() X-Git-Tag: xorg/1.0.0~332^2~245 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=a137e4074691a4123b2e703d6d4e52a4c06aceab;p=platal.git Implement DirEnum::getOptionsArray() Signed-off-by: Raphaël Barrois --- diff --git a/include/directory.enums.inc.php b/include/directory.enums.inc.php index 07786b3..5ea6b32 100644 --- a/include/directory.enums.inc.php +++ b/include/directory.enums.inc.php @@ -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