X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fdirenum.php;h=e45164c382b2369155cd2a55ed5b55cf47fb5a37;hb=87c297112074d1da4773359b7c9d17d5fab0ff1b;hp=cce7e399234e747e4c9179824c07d753406f96eb;hpb=9d44d2c7a81ca3fda06ef3897d77f6b3005098e2;p=platal.git diff --git a/classes/direnum.php b/classes/direnum.php index cce7e39..e45164c 100644 --- a/classes/direnum.php +++ b/classes/direnum.php @@ -1,6 +1,6 @@ cacheEnabled() && S::has('__DE_' . $type)) { self::$enumerations[$type] = S::v('__DE_' . $type); } else { $cls = "DE_" . ucfirst($type); $obj = new $cls(); self::$enumerations[$type] = $obj; - if ($obj->capabilities & DirEnumeration::SAVE_IN_SESSION) { + if (Platal::globals()->cacheEnabled() + && $obj->capabilities & DirEnumeration::SAVE_IN_SESSION) { S::set('__DE_' . $type, $obj); } } @@ -93,8 +105,10 @@ class DirEnum self::init($type); } $obj = self::$enumerations[$type]; + $args = func_get_args(); + array_shift($args); if ($obj->capabilities & DirEnumeration::HAS_OPTIONS) { - return call_user_func(array($obj, 'getOptionsIter')); + return call_user_func_array(array($obj, 'getOptionsIter'), $args); } else { return PlIteratorUtils::fromArray(array()); } @@ -197,7 +211,9 @@ abstract class DirEnumeration public function getOptionsIter() { - return PlIteratorUtils::fromArray(self::expandArray($this->getOptions()), 1, true); + $options = $this->getOptions(); + $options = self::expandArray($options); + return PlIteratorUtils::fromArray($options, 1, true); } // {{{ function getIDs @@ -233,6 +249,9 @@ abstract class DirEnumeration } // }}} + /** Builds a list of query parts for searching @$text in @$field : + * field LIKE 'text%', field LIKE '% text%', field LIKE '%-text%' + */ private function mkTests($field, $text) { $tests = array(); @@ -276,7 +295,7 @@ abstract class DirEnumeration return XDB::iterator('SELECT ' . $this->valfield . ' AS field' . ($this->ac_distinct ? (', COUNT(DISTINCT ' . $this->ac_unique . ') AS nb') : '') - . ($this->ac_withid ? (', ' . $this->from . '.' . $this->idfield . ' AS id') : '') . ' + . ($this->ac_withid ? (', ' . $this->idfield . ' AS id') : '') . ' FROM ' . $this->from . ' ' . $this->ac_join . ' WHERE ' . $where . ' @@ -341,7 +360,7 @@ abstract class DE_WithSuboption extends DirEnumeration } else if (array_key_exists($subid, $this->suboptions)) { return $this->suboptions[$subid]; } else { - return false; + return array(); } } @@ -425,6 +444,18 @@ class DE_NameTypes extends DirEnumeration } // }}} +// {{{ 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 @@ -456,7 +487,7 @@ class DE_GroupesX extends DirEnumeration protected $from = 'groups'; protected $where = 'WHERE (cat = \'GroupesX\' OR cat = \'Institutions\') AND pub = \'public\''; - protected $ac_join = "INNER JOIN group_members ON (groups.id = memb.asso_id + protected $ac_join = "INNER JOIN group_members ON (groups.id = group_members.asso_id AND (groups.cat = 'GroupesX' OR groups.cat = 'Institutions') AND groups.pub = 'public')"; protected $ac_unique = 'group_members.uid'; @@ -468,6 +499,7 @@ class DE_GroupesX extends DirEnumeration // {{{ class DE_EducationSchools class DE_EducationSchools extends DirEnumeration { + protected $idfield = 'profile_education_enum.id'; protected $valfield = 'profile_education_enum.name'; protected $valfield2 = 'profile_education_enum.abbreviation'; protected $from = 'profile_education_enum'; @@ -502,14 +534,54 @@ class DE_EducationFields extends DirEnumeration } // }}} +// {{{ class DE_CurrentCorps +class DE_CurrentCorps extends DirEnumeration +{ + protected $idfield = 'profile_corps_enum.id'; + protected $valfield = 'profile_corps_enum.name'; + protected $valfield2 = 'profile_corps_enum.abbrev'; + protected $from = 'profile_corps_enum'; + protected $where = 'WHERE profile_corps_enum.still_exists = 1'; + + protected $ac_unique = 'profile_corps.pid'; + protected $ac_join = 'INNER JOIN profile_corps ON (profile_corps.current_corpsid = profile_corps_enum.id)'; +} +// }}} +// +// {{{ class DE_OriginCorps +class DE_OriginCorps extends DirEnumeration +{ + protected $idfield = 'profile_corps_enum.id'; + protected $valfield = 'profile_corps_enum.name'; + protected $valfield2 = 'profile_corps_enum.abbrev'; + protected $from = 'profile_corps_enum'; + + protected $ac_unique = 'profile_corps.pid'; + protected $ac_join = 'INNER JOIN profile_corps ON (profile_corps.original_corpsid = profile_corps_enum.id)'; +} +// }}} + +// {{{ class DE_CorpsRanks +class DE_CorpsRanks extends DirEnumeration +{ + protected $idfield = 'profile_corps_rank_enum.id'; + protected $valfield = 'profile_corps_rank_enum.name'; + protected $valfield2 = 'profile_corps_rank_enum.abbrev'; + protected $from = 'profile_corps_rank_enum'; + + protected $ac_unique = 'profile_corps.pid'; + protected $ac_join = 'INNER JOIN profile_corps ON (profile_corps.rankid = profile_corps_rank_enum.id)'; +} +// }}} + /** GEOLOC */ // {{{ class DE_Nationalities class DE_Nationalities extends DirEnumeration { protected $idfield = 'geoloc_countries.iso_3166_1_a2'; - protected $valfield = 'geoloc_countries.nationalityFR'; - protected $valfield2 = 'geoloc_countries.nationality'; + protected $valfield = 'geoloc_countries.nationality'; + protected $valfield2 = 'geoloc_countries.nationalityEn'; protected $from = 'geoloc_countries'; protected $join = 'INNER JOIN profiles ON (geoloc_countries.iso_3166_1_a2 IN (profiles.nationality1, profiles.nationality2, profiles.nationality3))'; @@ -522,11 +594,11 @@ class DE_Nationalities extends DirEnumeration class DE_Countries extends DirEnumeration { protected $idfield = 'geoloc_countries.iso_3166_1_a2'; - protected $valfield = 'geoloc_countries.countryFR'; - protected $valfield2 = 'geoloc_countries.country'; + protected $valfield = 'geoloc_countries.country'; + protected $valfield2 = 'geoloc_countries.countryEn'; protected $from = 'geoloc_countries'; - protected $ac_join = 'INNER JOIN profile_addresses ON (geoloc_countries.iso_3166_1_a2 = profile_addresses.countryFR'; + protected $ac_join = 'INNER JOIN profile_addresses ON (geoloc_countries.iso_3166_1_a2 = profile_addresses.countryId)'; protected $ac_unique = 'profile_addresses.pid'; } // }}} @@ -544,13 +616,27 @@ class DE_AdminAreas extends DE_WithSuboption } // }}} +// {{{ class DE_SubAdminAreas +class DE_SubAdminAreas extends DE_WithSuboption +{ + protected $idfield = 'geoloc_subadministrativeareas.id'; + protected $optfield = 'geoloc_subadministrativeareas.administrativearea'; + protected $valfield = 'geoloc_subadministrativeareas.name'; + protected $from = 'geoloc_subadministrativeareas'; + + protected $ac_join = 'INNER JOIN profile_addresses ON (profile_addresses.subadministrativeAreaId = geoloc_subadministrativeareas.id)'; + protected $ac_unique = 'profile_addresses.pid'; +} +// }}} + // {{{ class DE_Localities class DE_Localities extends DirEnumeration { + protected $idfield = 'geoloc_localities.id'; protected $valfield = 'geoloc_localities.name'; protected $from = 'geoloc_localities'; - protected $ac_join = 'profile_addresses ON (profile_addresses.localityID = geoloc_localities.id)'; + protected $ac_join = 'INNER JOIN profile_addresses ON (profile_addresses.localityID = geoloc_localities.id)'; protected $ac_unique = 'profile_addresses.pid'; } // }}} @@ -560,6 +646,7 @@ class DE_Localities extends DirEnumeration // {{{ class DE_Companies class DE_Companies extends DirEnumeration { + protected $idfield = 'profile_job_enum.id'; protected $valfield = 'profile_job_enum.name'; protected $valfield2 = 'profile_job_enum.acronym'; protected $from = 'profile_job_enum'; @@ -569,19 +656,8 @@ class DE_Companies extends DirEnumeration } // }}} -// {{{ class DE_Sectors -class DE_Sectors extends DirEnumeration -{ - protected $valfield = 'profile_job_sector_enum.name'; - protected $from = 'profile_job_sector_enum'; - - protected $ac_join = 'INNER JOIN profile_job ON (profile_job_sector_enum.id = profile_job.sectorid)'; - protected $ac_unique = 'profile_job.pid'; -} -// }}} - // {{{ class DE_JobDescription -class DE_JobDescription +class DE_JobDescription extends DirEnumeration { protected $valfield = 'profile_job.description'; protected $from = 'profile_job'; @@ -591,20 +667,80 @@ class DE_JobDescription } // }}} +// {{{ class DE_JobTerms +class DE_JobTerms extends DirEnumeration +{ + // {{{ function getAutoComplete + public function getAutoComplete($text) + { + $tokens = JobTerms::tokenize($text.'%'); + if (count($tokens) == 0) { + return PlIteratorUtils::fromArray(array()); + } + $token_join = JobTerms::token_join_query($tokens, 'e'); + return XDB::iterator('SELECT e.jtid AS id, e.full_name AS field, COUNT(DISTINCT p.pid) AS nb + FROM profile_job_term_enum AS e + INNER JOIN profile_job_term_relation AS r ON (r.jtid_1 = e.jtid) + INNER JOIN profile_job_term AS p ON (r.jtid_2 = p.jtid) + '.$token_join.' + GROUP BY e.jtid + ORDER BY nb DESC, field + LIMIT ' . self::AUTOCOMPLETE_LIMIT); + } + // }}} +} +// }}} + /** NETWORKING */ // {{{ class DE_Networking class DE_Networking extends DirEnumeration { - protected $idfield = 'profile_networking_enum.network_type'; + protected $idfield = 'profile_networking_enum.nwid'; protected $valfield = 'profile_networking_enum.name'; protected $from = 'profile_networking_enum'; - protected $ac_join = 'INNER JOIN profile_networking ON (profile_networking.network_type = profile_networking_enum.network_type'; + protected $ac_join = 'INNER JOIN profile_networking ON (profile_networking.nwid = profile_networking_enum.nwid)'; protected $ac_unique = 'profile_networking.pid'; } // }}} +/** MEDALS + */ +// {{{ class DE_Medals +class DE_Medals extends DirEnumeration +{ + protected $from = 'profile_medal_enum'; + + protected $ac_join = 'INNER JOIN profile_medals ON (profile_medals.mid = profile_medal_enum.id)'; + protected $ac_unique = 'profile_medals.pid'; +} +// }}} + +/** ACCOUNTS + */ +// {{{ class DE_AccountTypes +class DE_AccountTypes extends DirEnumeration +{ + public $capabilities = 0x005; // self::HAS_OPTIONS | self::SAVE_IN_SESSION; + + protected $from = 'account_types'; + protected $valfield = 'perms'; + protected $idfield = 'type'; +} +// }}} + +// {{{ class DE_Skins +class DE_Skins extends DirEnumeration +{ + public $capabilities = 0x005; // self::HAS_OPTIONS | self::SAVE_IN_SESSION; + + protected $from = 'skins'; + protected $valfield = 'name'; + protected $idfield = 'skin_tpl'; +} +// }}} + // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?>