From e39e72a6a6ece28f003efdad6328118ea6beb804 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Barrois?= Date: Mon, 1 Feb 2010 16:16:17 +0100 Subject: [PATCH] Add class DirEnum, to access all enumerations used in the site MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Raphaël Barrois --- include/directory.enums.inc.php | 209 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 209 insertions(+) create mode 100644 include/directory.enums.inc.php diff --git a/include/directory.enums.inc.php b/include/directory.enums.inc.php new file mode 100644 index 0000000..013e0d7 --- /dev/null +++ b/include/directory.enums.inc.php @@ -0,0 +1,209 @@ + optionTxt + */ + protected $options; + + protected $idfield = 'id'; + protected $valfield = 'text'; + protected $from; + protected $where = ''; + + public function __construct() { + $this->loadOptions(); + } + + public function getOptions() + { + return $this->options; + } + + /** The function used to load options + */ + protected function loadOptions() + { + $this->options = XDB::iterator('SELECT ' . $this->valfield . ' AS field, + ' . $this->idfield . ' AS id + FROM ' . $this->from . ' + ' . $this->where . ' + GROUP BY ' . $this->valfield . ' + ORDER BY ' . $this->valfield); + } +} + +class DE_Binets extends DirEnumeration +{ + protected $from = 'binets_def'; +} +class DE_Sections extends DirEnumeration +{ + protected $from = 'sections'; +} +class DE_Schools extends DirEnumeration +{ + protected $valfield = 'name'; + protected $from = 'profile_education_enum'; +} +class DE_Degrees extends DirEnumeration +{ + protected $suboptions = array(); + + protected function loadOptions() + { + $res = XDB::query('SELECT ped.eduid, ped.degreeid, pede.degree + FROM profile_education_enum AS pee + 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'); + foreach($res->fetchAllRow() as $row) { + list($eduid, $degreeid, $name) = $row; + $this->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); + } + } + + public function getOptions($eduid = null) + { + if ($eduid == null) { + return PlIteratorUtils::fromArray($this->options, 1, true); + } + if (array_key_exists($eduid, $this->suboptions)) { + return PlIteratorUtils::fromArray($this->suboptions[$eduid], 1, true); + } else { + return array(); + } + } +} +class DE_Nationalities extends DirEnumeration +{ + protected $idfield = 'iso_3166_1_a2'; + protected $valfield = 'nationalityFR'; + protected $from = 'geoloc_countries AS gc'; + protected $where = 'INNER JOIN profiles AS p ON (gc.iso_3166_1_a2 IN (p.nationality1, p.nationality2, p.nationality3))'; +} +class DE_Countries extends DirEnumeration +{ + protected $idfield = 'iso_3166_1_a2'; + protected $valfield = 'countryFR'; + protected $from = 'geoloc_countries'; +} +class DE_AdminAreas extends DirEnumeration +{ + protected $suboptions = array(); + + protected function loadOptions() + { + $res = XDB::query('SELECT id, name AS field, country + FROM geoloc_administrativeareas + GROUP BY name + ORDER BY name'); + foreach($res->fetchAllRow() as $row) { + list($id, $field, $country) = $row; + $this->options[] = array('id' => $id, 'field' => $field); + if (!array_key_exists($country, $this->suboptions)) { + $this->suboptions[$country] = array(); + } + $this->suboptions[$country][] = array('id' => $id, 'field' => $field); + } + } + + public function getOptions($country = null) + { + if ($country == null) { + return PlIteratorUtils::fromArray($this->options, 1, true); + } + if (array_key_exists($country, $this->suboptions)) { + return PlIteratorUtils::fromArray($this->suboptions[$country], 1, true); + } else { + return array(); + } + } +} +class DE_GroupesX extends DirEnumeration +{ + protected $valfield = 'nom'; + protected $from = '#groupex#.asso'; + protected $where = 'WHERE (cat = \'GroupesX\' OR cat = \'Institutions\') AND pub = \'public\''; +} +class DE_Sectors extends DirEnumeration +{ + protected $valfield = 'name'; + protected $from = 'profile_job_sector_enum'; +} +class DE_Networking extends DirEnumeration +{ + protected $idfield = 'network_type'; + protected $valfield = 'name'; + protected $from = 'profile_networking_enum'; +} +?> -- 2.1.4