X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fdirenum.php;h=8a3829db4c1770e9c3cc246fb2c32dd4fd07a888;hb=af56031899164e06d9f08c5591dea06f54cb5243;hp=2f353aed65975b4fd4fddd05459587d992c1806c;hpb=3a2985f931bdbbae9d1c689263a1dc15d9b3b7dc;p=platal.git diff --git a/classes/direnum.php b/classes/direnum.php index 2f353ae..8a3829d 100644 --- a/classes/direnum.php +++ b/classes/direnum.php @@ -29,9 +29,6 @@ class DirEnum * Each of these consts contains the basename of the class (its full name * being DE_$basename). */ - const NAMETYPES = 'nametypes'; - const NAMES = 'names'; - const BINETS = 'binets'; const GROUPESX = 'groupesx'; const SECTIONS = 'sections'; @@ -45,6 +42,7 @@ class DirEnum const CORPSRANKS = 'corpsranks'; const NATIONALITIES = 'nationalities'; + const POSTALCODES = 'postalcodes'; const SUBLOCALITIES = 'sublocalities'; const LOCALITIES = 'localities'; const ADMNISTRATIVEAREAS3 = 'admnistrativeareas3'; @@ -333,37 +331,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) @@ -435,29 +434,6 @@ abstract class DE_WithSuboption extends DirEnumeration } // }}} -// {{{ class DE_NameTypes -// returns 'system' names ('lastname', 'lastname_marital', ...) -class DE_NameTypes extends DirEnumeration -{ - public $capabilities = 0x005; // self::HAS_OPTIONS | self::SAVE_IN_SESSION; - - protected $from = 'profile_name_enum'; - protected $valfield = 'type'; -} -// }}} - -// {{{ class DE_Names -// returns 'system' names ('lastname', 'lastname_marital', ...) -class DE_Names extends DirEnumeration -{ - public $capabilities = 0x005; // self::HAS_OPTIONS | self::SAVE_IN_SESSION; - - protected $from = 'profile_name_enum'; - protected $idfield = 'type'; - protected $valfield = 'name'; -} -// }}} - /** GROUPS */ // {{{ class DE_Binets @@ -501,6 +477,7 @@ class DE_GroupesX extends DirEnumeration // {{{ class DE_EducationSchools class DE_EducationSchools extends DirEnumeration { + protected $ac_beginwith = false; protected $idfield = 'profile_education_enum.id'; protected $valfield = 'profile_education_enum.name'; protected $valfield2 = 'profile_education_enum.abbreviation'; @@ -512,7 +489,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; @@ -595,44 +572,55 @@ class DE_Nationalities extends DirEnumeration // {{{ class DE_AddressesComponents class DE_AddressesComponents extends DirEnumeration { - protected $idfield = 'profile_addresses_components_enum.short_name'; + protected $idfield = 'profile_addresses_components_enum.id'; protected $valfield = 'profile_addresses_components_enum.long_name'; protected $from = 'profile_addresses_components_enum'; protected $ac_join = 'INNER JOIN profile_addresses_components ON (profile_addresses_components.component_id = profile_addresses_components_enum.id)'; protected $ac_unique = 'profile_addresses_components.pid'; - protected $ac_where = 'profile_addresses_components.type = \'home\''; } // }}} // {{{ class DE_AddressesComponents extensions class DE_Countries extends DE_AddressesComponents { protected $where = 'WHERE FIND_IN_SET(\'country\', profile_addresses_components_enum.types)'; + protected $ac_where = 'profile_addresses_components.type = \'home\' AND FIND_IN_SET(\'country\', profile_addresses_components_enum.types)'; } class DE_Admnistrativeareas1 extends DE_AddressesComponents { - protected $where = 'WHERE FIND_IN_SET(\'admnistrativeareas1\', profile_addresses_components_enum.types)'; + protected $where = 'WHERE FIND_IN_SET(\'admnistrative_area_1\', profile_addresses_components_enum.types)'; + protected $ac_where = 'profile_addresses_components.type = \'home\' AND FIND_IN_SET(\'admnistrative_area_1\', profile_addresses_components_enum.types)'; } class DE_Admnistrativeareas2 extends DE_AddressesComponents { - protected $where = 'WHERE FIND_IN_SET(\'admnistrativeareas2\', profile_addresses_components_enum.types)'; + protected $where = 'WHERE FIND_IN_SET(\'admnistrative_area_2\', profile_addresses_components_enum.types)'; + protected $ac_where = 'profile_addresses_components.type = \'home\' AND FIND_IN_SET(\'admnistrative_area_2\', profile_addresses_components_enum.types)'; } class DE_Admnistrativeareas3 extends DE_AddressesComponents { - protected $where = 'WHERE FIND_IN_SET(\'admnistrativeareas3\', profile_addresses_components_enum.types)'; + protected $where = 'WHERE FIND_IN_SET(\'admnistrative_area_3\', profile_addresses_components_enum.types)'; + protected $ac_where = 'profile_addresses_components.type = \'home\' AND FIND_IN_SET(\'admnistrative_area_3\', profile_addresses_components_enum.types)'; } class DE_Localities extends DE_AddressesComponents { - protected $where = 'WHERE FIND_IN_SET(\'localities\', profile_addresses_components_enum.types)'; + protected $where = 'WHERE FIND_IN_SET(\'locality\', profile_addresses_components_enum.types)'; + protected $ac_where = 'profile_addresses_components.type = \'home\' AND FIND_IN_SET(\'locality\', profile_addresses_components_enum.types)'; } class DE_Sublocalities extends DE_AddressesComponents { - protected $where = 'WHERE FIND_IN_SET(\'sublocalities\', profile_addresses_components_enum.types)'; + protected $where = 'WHERE FIND_IN_SET(\'sublocality\', profile_addresses_components_enum.types)'; + protected $ac_where = 'profile_addresses_components.type = \'home\' AND FIND_IN_SET(\'sublocality\', profile_addresses_components_enum.types)'; +} + +class DE_Postalcodes extends DE_AddressesComponents +{ + protected $where = 'WHERE FIND_IN_SET(\'postal_code\', profile_addresses_components_enum.types)'; + protected $ac_where = 'profile_addresses_components.type = \'home\' AND FIND_IN_SET(\'postal_code\', profile_addresses_components_enum.types)'; } // }}}