Fix bug in DirEnum for DE with "suboptions" (degree for a given school, ...)
authorRaphaël Barrois <raphael.barrois@polytechnique.org>
Wed, 17 Feb 2010 22:54:31 +0000 (23:54 +0100)
committerRaphaël Barrois <raphael.barrois@polytechnique.org>
Wed, 17 Feb 2010 22:54:31 +0000 (23:54 +0100)
Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
include/directory.enums.inc.php

index d2c816c..37c1d20 100644 (file)
@@ -337,21 +337,23 @@ class DE_EducationDegrees extends DirEnumeration
                         LEFT JOIN profile_education_degree AS ped ON (pee.id = ped.eduid)
                         LEFT JOIN profile_education_degree_enum AS pede ON (ped.degreeid = pede.id)
                          ORDER BY pede.degree');
+        $options = array();
         foreach($res->fetchAllRow() as $row) {
             list($eduid, $degreeid, $name) = $row;
-            $this->options[$degreeid] = array('id' => $degreeid, 'field' => $name);
+            $options[$degreeid] = array('id' => $degreeid, 'field' => $name);
             if (!array_key_exists($eduid, $this->suboptions)) {
                 $this->suboptions[$eduid] = array();
             }
             $this->suboptions[$eduid][] = array('id' => $degreeid, 'field' => $name);
         }
+        $this->options = PlIteratorUtils::fromArray($options, 1, true);
     }
 
     public function getOptions($eduid = null)
     {
         $this->_fetchOptions();
         if ($eduid == null) {
-            return PlIteratorUtils::fromArray($this->options, 1, true);
+            return $this->options;
         }
         if (array_key_exists($eduid, $this->suboptions)) {
             return PlIteratorUtils::fromArray($this->suboptions[$eduid], 1, true);
@@ -360,6 +362,16 @@ class DE_EducationDegrees extends DirEnumeration
         }
     }
 
+    public function getOptionsArray($eduid = null)
+    {
+        $it = $this->getOptions($eduid);
+        $options = array();
+        while ($row = $it->next()) {
+            $options[$row['id']] = $row['field'];
+        }
+        return $options;
+    }
+
     public function getIDs($text, $mode, $eduid = null)
     {
         if ($eduid == null) {
@@ -427,14 +439,16 @@ class DE_AdminAreas extends DirEnumeration
                              FROM geoloc_administrativeareas
                          GROUP BY name
                          ORDER BY name');
+        $options = array();
         foreach($res->fetchAllRow() as $row) {
             list($id, $field, $country) = $row;
-            $this->options[] = array('id' => $id, 'field' => $field);
+            $options[$id] = array('id' => $id, 'field' => $field);
             if (!array_key_exists($country, $this->suboptions)) {
                 $this->suboptions[$country] = array();
             }
             $this->suboptions[$country][] = array('id' => $id, 'field' => $field);
         }
+        $this->options = PlIteratorUtils::fromArray($options, 1, true);
     }
 
     public function getOptions($country = null)
@@ -442,7 +456,7 @@ class DE_AdminAreas extends DirEnumeration
         $this->_fetchOptions();
 
         if ($country == null) {
-            return PlIteratorUtils::fromArray($this->options, 1, true);
+            return $this->options;
         }
         if (array_key_exists($country, $this->suboptions)) {
             return PlIteratorUtils::fromArray($this->suboptions[$country], 1, true);
@@ -451,6 +465,16 @@ class DE_AdminAreas extends DirEnumeration
         }
     }
 
+    public function getOptionsArray($country = null)
+    {
+        $it = $this->getOptions($eduid);
+        $options = array();
+        while ($row = $it->next()) {
+            $options[$row['id']] = $row['field'];
+        }
+        return $options;
+    }
+
     public function getIDs($text, $mode, $country = null)
     {
         if ($country == null) {