From 469879188dbc7158e5f0c56dd83a8939c2355484 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Thu, 9 Jun 2011 11:12:11 +0200 Subject: [PATCH] Fixes class DE_WithSuboption and uses it for DE_EducationDegrees. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Jacob --- classes/direnum.php | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/classes/direnum.php b/classes/direnum.php index a94c69b..48fc3ba 100644 --- a/classes/direnum.php +++ b/classes/direnum.php @@ -330,37 +330,38 @@ abstract class DE_WithSuboption extends DirEnumeration protected $suboptions = null; - protected function loadOptions() + protected function _fetchSubOptions($subid) { - $opts = XDB::fetchAllAssoc('id', 'SELECT ' . $this->valfield . ' AS field, - ' . $this->optfield . ' AS subid, - ' . $this->idfield . ' AS id - FROM ' . $this->from . ' - ' . $this->join . ' - ' . $this->where . ' - GROUP BY ' . $this->valfield . ' - ORDER BY ' . $this->valfield); - $this->options = array(); - $this->suboptions = array(); - foreach ($opts as $id => $opt) { - $this->options[$id] = $opt['field']; - if (!array_key_exists($opt['subid'], $this->suboptions)) { - $this->suboptions[$opt['subid']] = array(); - } - $this->suboptions[$opt['subid']][$id] = $opt['field']; + if (is_null($this->suboptions)) { + $this->loadSubOptions($subid); } } + protected function loadSubOptions($subid) + { + $where = ($this->where == '') ? '' : $this->where . ' AND '; + $this->suboptions = XDB::fetchAllAssoc('id', 'SELECT ' . $this->valfield . ' AS field, + ' . $this->idfield . ' AS id + FROM ' . $this->from . ' + ' . $this->join . ' + WHERE ' . $where . $this->optfield . ' = ' . $subid . ' + GROUP BY ' . $this->valfield . ' + ORDER BY ' . $this->valfield); + } + public function getOptions($subid = null) { - $this->_fetchOptions(); if ($subid == null) { + $this->_fetchOptions(); return $this->options; - } else if (array_key_exists($subid, $this->suboptions)) { - return $this->suboptions[$subid]; - } else { - return array(); } + + $this->_fetchSubOptions($subid); + if (is_array($this->suboptions)) { + return $this->suboptions; + } + + return array(); } public function getOptionsIter($subid = null) @@ -487,7 +488,7 @@ class DE_EducationSchools extends DirEnumeration // }}} // {{{ class DE_EducationDegrees -class DE_EducationDegrees extends DirEnumeration +class DE_EducationDegrees extends DE_WithSuboption { public $capabilities = self::HAS_OPTIONS; -- 2.1.4