From 8e72025345ea4c1e7cedb5c0a68a6d474aca298a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Barrois?= Date: Thu, 4 Feb 2010 23:44:21 +0100 Subject: [PATCH] Switch search and UserSet to new UserFilter system MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Raphaël Barrois --- include/userset.inc.php | 280 ++++++++++++++++++++++++++---------------------- modules/search.php | 275 ++++++++--------------------------------------- 2 files changed, 196 insertions(+), 359 deletions(-) diff --git a/include/userset.inc.php b/include/userset.inc.php index a7fe264..56dac4b 100644 --- a/include/userset.inc.php +++ b/include/userset.inc.php @@ -21,99 +21,101 @@ class UserSet extends PlSet { - private $cond; - - public function __construct($cond = null) + public function __construct(PlFilterCondition &$cond, $orders) { - $this->cond = new UFC_And(); - if (!is_null($cond) && ($cond instanceof UserFilterCondition)) { - $this->cond->addChild($cond); - } + parent::__construct($cond, $orders); } - public function &get($fields, $joins, $where, $groupby, $order, $limitcount = null, $limitfrom = null) + protected function buildFilter(PlFilterCondition &$cond, $orders) { - $uf = new UserFilter($this->cond); - $users = $uf->getUsers($limitcount, $limitfrom); - $this->count = $uf->getTotalCount(); - return $users; + return new UserFilter($cond, $orders); } } class SearchSet extends UserSet { public $advanced = false; - private $score = null; - private $order = null; - private $quick = false; + private $score = null; + private $conds = null; + private $orders = null; + private $quick = false; - public function __construct($quick = false, $no_search = false, $join = '', $where = '') + public function __construct($quick = false, $no_search = false, PlFilterCondition $cond = null) { Platal::load('search', 'search.inc.php'); + if ($no_search) { return; } $this->quick = $quick; + + if (is_null($cond)) { + $this->conds = new PFC_And(); + } else if ($cond instanceof PFC_And) { + $this->conds = $cond; + } else { + $this->conds = new PFC_And($cond); + } + if ($quick) { - $this->getQuick($join, $where); + $this->getQuick(); } else { - $this->getAdvanced($join, $where); + $this->getAdvanced(); } } - private function getQuick($join, $where) + private function getQuick() { - Platal::load('search', 'search.inc.php'); - global $globals; if (!S::logged()) { Env::kill('with_soundex'); } - $qSearch = new QuickSearch('quick'); - $fields = new SFieldGroup(true, array($qSearch)); - if ($qSearch->isEmpty()) { - new ThrowError('Aucun critère de recherche n\'est spécifié.'); - } - $this->score = $qSearch->get_score_statement(); - $pwhere = $fields->get_where_statement(); - if (trim($pwhere)) { - if (trim($where)) { - $where .= ' AND '; - } - $where .= $pwhere; + + require_once 'ufbuilder.inc.php'; + $ufb = new UFB_QuickSearch(); + + if (!$ufb->isValid()) { + return; } + + $this->conds->addChild($ufb->getUFC()); + + $orders = $ufb->getOrders(); + $orders[] = new UFO_Promo(UserFilter::DISPLAY, true); + $orders[] = new UFO_Promo(UserFilter::DN_SORT); + if (S::logged() && Env::has('nonins')) { - if (trim($where)) { - $where .= ' AND '; - } - $where .= 'u.perms="pending" AND u.deces=0'; + $this->conds = new PFC_And($this->conds, + new UFC_Not(new UFC_Dead()), + new UFC_Registered() + ); } - parent::__construct($join . ' ' . $fields->get_select_statement(), $where); - $this->order = implode(',',array_filter(array($fields->get_order_statement(), - 'u.promo DESC, NomSortKey, prenom'))); + parent::__construct($this->conds, $orders); } - private function getAdvanced($join, $where) + private function getAdvanced() { - global $globals; $this->advanced = true; - $fields = new SFieldGroup(true, advancedSearchFromInput()); - if ($fields->too_large()) { - new ThrowError('Recherche trop générale.'); + require_once 'ufbuilder.inc.php'; + $ufb = new UFB_AdvancedSearch(); + + if (!$ufb->isValid()) { + return; } - parent::__construct(@$join . ' ' . $fields->get_select_statement(), - @$where . ' ' . $fields->get_where_statement()); - $this->order = implode(',',array_filter(array($fields->get_order_statement(), - 'promo DESC, NomSortKey, prenom'))); + + $this->conds->addChild($ufb->getUFC()); } - public function &get($fields, $joins, $where, $groupby, $order, $limitcount = null, $limitfrom = null) + public function &get(PlLimit $limit = null) { - if ($this->score) { - $fields .= ', ' . $this->score; + $uf = $this->buildFilter($this->conds, $this->orders); + if (is_null($limit)) { + $limit = new PlLimit(20, 0); } - return parent::get($fields, $joins, $where, $groupby, $order, $limitcount, $limitfrom); + $it = $uf->getProfiles($limit); + $this->count = $uf->getTotalCount(); + return $it; } } @@ -121,22 +123,13 @@ class ArraySet extends UserSet { public function __construct(array $users) { - $where = $this->getUids($users); - if ($where) { - $where = "u.hruid IN ($where)"; + $hruids = User::getBulkHruid($users, array('User', '_silent_user_callback')); + if (is_null($hruids) || count($hruids) == 0) { + $cond = new PFC_False(); } else { - $where = " 0 "; + $cond = new UFC_Hruid($hruids); } - parent::__construct('', $where); - } - - private function getUids(array $users) - { - $users = User::getBulkHruid($users, array('User', '_silent_user_callback')); - if (is_null($users)) { - return ''; - } - return '\'' . implode('\', \'', $users) . '\''; + parent::__construct($cond); } } @@ -148,22 +141,60 @@ class MinificheView extends MultipageView global $globals; $this->entriesPerPage = $globals->search->per_page; if (@$params['with_score']) { - $this->addSortKey('score', array('-score', '-date', '-d.promo', 'sort_name'), 'pertinence'); + $this->addSort(new PlViewOrder('score', array( + new UFO_Score(true), + new UFO_ProfileUpdate(true), + new UFO_Promo(UserFilter::DISPLAY, true), + new UFO_Name(UserFilter::DN_SORT), + ), 'pertinence')); } - $this->addSortKey('name', array('sort_name'), 'nom'); - $this->addSortKey('promo', array('-d.promo', 'sort_name'), 'promotion'); - $this->addSortKey('date_mod', array('-date', '-d.promo', 'sort_name'), 'dernière modification'); + $this->addSort(new PlViewOrder( + 'name', + array(new UFO_Name(UserFilter::DN_SORT)), + 'nom')); + $this->addSort(new PlViewOrder('promo', array( + new UFO_Promo(UserFilter::DISPLAY, true), + new UFO_Name(UserFilter::DN_SORT), + ), 'promotion')); + $this->addSort(new PlViewOrder('date_mod', array( + new UFO_ProfileUpdate(true), + new UFO_Promo(UserFilter::DISPLAY, true), + new UFO_Name(UserFilter::DN_SORT), + ), 'dernière modification')); parent::__construct($set, $data, $params); } - public function bounds() + protected function getBoundValue($obj) { + if ($obj instanceof Profile) { + switch ($this->bound_field) { + case 'name': + $name = $obj->name('%l'); + return strtoupper($name[0]); + case 'promo': + return $obj->promo(); + default: + return null; + } + } return null; } - public function fields() + public function bounds() { - return null; + $order = Env::v('order', $this->defaultkey); + $show_bounds = 0; + if (($order == "name") || ($order == "-name")) { + $this->bound_field = "name"; + $show_bounds = 1; + } elseif (($order == "promo") || ($order == "-promo")) { + $this->bound_field = "promo"; + $show_bounds = -1; + } + if ($order{0} == '-') { + $show_bounds = -$show_bounds; + } + return $show_bounds; } public function templateName() @@ -177,23 +208,34 @@ class MentorView extends MultipageView public function __construct(PlSet &$set, $data, array $params) { $this->entriesPerPage = 10; - $this->addSortKey('rand', array('RAND(' . S::i('uid') . ')'), 'aléatoirement'); - $this->addSortKey('name', array('sort_name'), 'nom'); - $this->addSortKey('promo', array('-d.promo', 'sort_name'), 'promotion'); - $this->addSortKey('date_mod', array('-date', '-d.promo', 'sort_name'), 'dernière modification'); + $this->addSort(new PlViewOrder('rand', array(new PFO_Random(S::i('uid'))), 'aléatoirement')); + $this->addSort(new PlViewOrder('name', array(new UFO_Name(UserFilter::DN_SORT)), 'nom')); + $this->addSort(new PlViewOrder('promo', array( + new UFO_Promo(UserFilter::DISPLAY, true), + new UFO_Name(UserFilter::DN_SORT), + ), 'promotion')); + $this->addSort(new PlViewOrder('date_mod', array( + new UFO_ProfileUpdate(true), + new UFO_Promo(UserFilter::DISPLAY, true), + new UFO_Name(UserFilter::DN_SORT), + ), 'dernière modification')); parent::__construct($set, $data, $params); } - public function fields() - { - return "m.uid, d.promo, u.hruid, - m.expertise, mp.country, ms.sectorid, ms.subsectorid, - d.directory_name, d.sort_name"; - } - - public function joins() + protected function getBoundValue($obj) { - return "INNER JOIN profile_display AS d ON (d.pid = u.user_id)"; + if ($obj instanceof Profile) { + switch ($this->bound_field) { + case 'name': + $name = $obj->name('%l'); + return strtoupper($name[0]); + case 'promo': + return $obj->promo(); + default: + return null; + } + } + return null; } public function bounds() @@ -224,24 +266,36 @@ class TrombiView extends MultipageView public function __construct(PlSet &$set, $data, array $params) { $this->entriesPerPage = 24; - $this->order = explode(',', Env::v('order', 'sort_name')); if (@$params['with_score']) { - $this->addSortKey('score', array('-score', '-watch_last', '-d.promo', 'sort_name'), 'pertinence'); + $this->addSort(new PlViewOrder('score', array( + new UFO_Score(true), + new UFO_ProfileUpdate(true), + new UFO_Promo(UserFilter::DISPLAY, true), + new UFO_Name(UserFilter::DN_SORT), + ), 'pertinence')); } - $this->addSortKey('name', array('sort_name'), 'nom'); - $this->addSortKey('promo', array('-d.promo', 'sort_name'), 'promotion'); + $this->addSort(new PlViewOrder('name', array(new UFO_Name(UserFilter::DN_SORT)), 'nom')); + $this->addSort(new PlViewOrder('promo', array( + new UFO_Promo(UserFilter::DISPLAY, true), + new UFO_Name(UserFilter::DN_SORT), + ), 'promotion')); parent::__construct($set, $data, $params); } - public function fields() - { - return "u.user_id, d.directory_name, d.sort_name, u.promo, d.promo, u.hruid "; - } - - public function joins() + protected function getBoundValue($obj) { - return "INNER JOIN photo AS p ON (p.uid = u.user_id) - INNER JOIN profile_display AS d ON (d.pid = u.user_id)"; + if ($obj instanceof Profile) { + switch ($this->bound_field) { + case 'name': + $name = $obj->name('%l'); + return strtoupper($name[0]); + case 'promo': + return $obj->promo(); + default: + return null; + } + } + return null; } public function bounds() @@ -283,35 +337,9 @@ class GadgetView implements PlView $this->set =& $set; } - public function fields() - { - return "u.user_id AS id, u.*," . - "u.perms != 'pending' AS inscrit, - u.perms != 'pending' AS wasinscrit, - u.deces != 0 AS dcd, u.deces, - FIND_IN_SET('femme', u.flags) AS sexe, - " // adr.city, gr.name AS region - . "gc.iso_3166_1_a2, gc.countryFR AS countrytxt" . - (S::logged() ? ", c.contact AS contact" : ''); - } - - public function joins() - { - return "LEFT JOIN profile_addresses AS adr ON (u.user_id = adr.pid AND - FIND_IN_SET('current', adr.flags)" - . (S::logged() ? "" : "AND adr.pub = 'public'") . ") - LEFT JOIN geoloc_countries AS gc ON (adr.countryId = gc.iso_3166_1_a2) - LEFT JOIN geoloc_administrativeareas AS gr ON (adr.countryId = gr.country - AND adr.administrativeAreaId = gr.id) - " . (S::logged() ? - "LEFT JOIN contacts AS c ON (c.contact = u.user_id - AND c.uid = " . S::v('uid') . ")" : ""); - } - public function apply(PlPage &$page) { - $page->assign_by_ref('set', - $this->set->get($this->fields(), $this->joins(), null, null, null, 5, 0)); + $page->assign_by_ref('set', $this->set->get(new PlLimit(5, 0))); } public function args() diff --git a/modules/search.php b/modules/search.php index b2b0d78..bc32293 100644 --- a/modules/search.php +++ b/modules/search.php @@ -43,32 +43,6 @@ class SearchModule extends PLModule Platal::page()->assign('formulaire',1); } - function get_diplomas($school = null) - { - if (is_null($school) && Env::has('school')) { - $school = Env::i('school'); - } - - if ((!is_null($school)) && ($school != '')) { - $sql = 'SELECT degreeid - FROM profile_education_degree - WHERE eduid=' . $school; - } else { - $sql = 'SELECT id - FROM profile_education_degree_enum - ORDER BY id'; - } - - $res = XDB::query($sql); - Platal::page()->assign('choix_diplomas', $res->fetchColumn()); - - $sql = 'SELECT degree - FROM profile_education_degree_enum - ORDER BY id'; - $res = XDB::query($sql); - Platal::page()->assign('name_diplomas', $res->fetchColumn()); - } - function handler_quick(&$page, $action = null, $subaction = null) { global $globals; @@ -164,36 +138,9 @@ class SearchModule extends PLModule if (!Env::has('rechercher') && $action != 'geoloc') { $this->form_prepare(); } else { - $textFields = array( - 'country' => array('field' => 'iso_3166_1_a2', 'table' => 'geoloc_countries', 'text' => 'countryFR', - 'exact' => false), - 'fonction' => array('field' => 'id', 'table' => 'fonctions_def', 'text' => 'fonction_fr', 'exact' => true), - 'secteur' => array('field' => 'id', 'table' => 'profile_job_sector_enum', 'text' => 'name', 'exact' => false), - 'nationalite' => array('field' => 'iso_3166_1_a2', 'table' => 'geoloc_countries', - 'text' => 'nationalityFR', 'exact' => 'false'), - 'binet' => array('field' => 'id', 'table' => 'binets_def', 'text' => 'text', 'exact' => false), - 'networking_type' => array('field' => 'network_type', 'table' => 'profile_networking_enum', - 'text' => 'name', 'exact' => false), - 'groupex' => array('field' => 'id', 'table' => '#groupex#.asso', - 'text' => "(cat = 'GroupesX' OR cat = 'Institutions') AND pub = 'public' AND nom", - 'exact' => false), - 'section' => array('field' => 'id', 'table' => 'sections', 'text' => 'text', 'exact' => false), - 'school' => array('field' => 'id', 'table' => 'profile_education_enum', 'text' => 'name', 'exact' => false), - 'city' => array('table' => 'geoloc_localities', 'text' => 'name', 'exact' => false) - ); if (!Env::has('page')) { S::logger()->log('search', 'adv=' . var_export($_GET, true)); } - foreach ($textFields as $field=>&$query) { - if (!Env::v($field) && Env::v($field . 'Txt')) { - $res = XDB::query("SELECT {$query['field']} - FROM {$query['table']} - WHERE {$query['text']} " . ($query['exact'] ? " = {?}" : - " LIKE CONCAT('%', {?}, '%')"), - Env::v($field . 'Txt')); - $_REQUEST[$field] = $res->fetchOneCell(); - } - } require_once 'userset.inc.php'; $view = new SearchSet(false, $action == 'geoloc' && substr($subaction, -3) == 'swf'); @@ -248,142 +195,27 @@ class SearchModule extends PLModule die(); } - // default search - $unique = 'pid'; - $db = 'profiles'; - $realid = false; - $beginwith = true; - $field2 = false; - $qsearch = str_replace(array('%', '_'), '', $q); - $distinct = true; - - switch ($type) { - case 'binetTxt': - $db = 'binets_def INNER JOIN - binets_ins ON(binets_def.id = binets_ins.binet_id)'; - $field = 'binets_def.text'; - if (strlen($q) > 2) - $beginwith = false; - $realid = 'binets_def.id'; - break; - case 'networking_typeTxt': - $db = 'profile_networking_enum INNER JOIN - profile_networking ON(profile_networking.network_type = profile_networking_enum.network_type)'; - $field = 'profile_networking_enum.name'; - $unique = 'uid'; - $realid = 'profile_networking_enum.network_type'; - break; - case 'city': - $db = 'geoloc_localities INNER JOIN - profile_addresses ON (geoloc_localities.id = profile_addresses.localityId)'; - $unique = 'uid'; - $field ='geoloc_localities.name'; - break; - case 'countryTxt': - $db = 'geoloc_countries INNER JOIN - profile_addresses ON (geoloc_countries.iso_3166_1_a2 = profile_addresses.countryId)'; - $unique = 'pid'; - $field = 'geoloc_countries.countryFR'; - $realid = 'geoloc_countries.iso_3166_1_a2'; - break; - case 'entreprise': - $db = 'profile_job_enum INNER JOIN - profile_job ON (profile_job.jobid = profile_job_enum.id)'; - $field = 'profile_job_enum.name'; - $unique = 'profile_job.uid'; - break; - case 'fonctionTxt': - $db = 'fonctions_def INNER JOIN - profile_job ON (profile_job.fonctionid = fonctions_def.id)'; - $field = 'fonction_fr'; - $unique = 'uid'; - $realid = 'fonctions_def.id'; - $beginwith = false; - break; - case 'groupexTxt': - $db = "#groupex#.asso AS a INNER JOIN - #groupex#.membres AS m ON(a.id = m.asso_id - AND (a.cat = 'GroupesX' OR a.cat = 'Institutions') - AND a.pub = 'public')"; - $field='a.nom'; - $field2 = 'a.diminutif'; - if (strlen($q) > 2) - $beginwith = false; - $realid = 'a.id'; - $unique = 'm.uid'; - break; - case 'nationaliteTxt': - $db = 'geoloc_countries INNER JOIN - profile ON (geoloc_countries.a2 IN (profile.nationality1, profile.nationality2, profile.nationality3))'; - $field = 'geoloc_countries.nationalityFR'; - $realid = 'geoloc_countries.iso_3166_1_a2'; - break; - case 'description': - $db = 'profile_job'; - $field = 'description'; - $unique = 'uid'; - break; - case 'schoolTxt': - $db = 'profile_education_enum INNER JOIN - profile_education ON (profile_education_enum.id = profile_education.eduid)'; - $field = 'profile_education_enum.name'; - $unique = 'uid'; - $realid = 'profile_education_enum.id'; - if (strlen($q) > 2) - $beginwith = false; - break; - case 'secteurTxt': - $db = 'profile_job_sector_enum INNER JOIN - profile_job ON (profile_job.sectorid = profile_job_sector_enum.id)'; - $field = 'profile_job_sector_enum.name'; - $realid = 'profile_job_sector_enum.id'; - $unique = 'uid'; - $beginwith = false; - break; - case 'subSubSector': - $db = 'profile_job_subsubsector_enum'; - $field = 'name'; - $beginwith = false; - $unique = 'name'; - $distinct = false; - break; - case 'sectionTxt': - $db = 'sections AS acs - INNER JOIN profiles AS acp ON (acp.section = acs.id)'; - $field = 'acs.text'; - $realid = 'acs.id'; - $beginwith = false; - break; - default: exit(); + require_once 'directory.enums.inc.php'; + $enums = array( + 'binetTxt' => DirEnum::BINETS, + 'groupexTxt' => DirEnum::GROUPESX, + 'sectionTxt' => DirEnum::SECTIONS, + 'networking_typeTxt' => DirEnum::NETWORKS, + 'city' => DirEnum::LOCALITIES, + 'countryTxt' => DirEnum::COUNTRIES, + 'entreprise' => DirEnum::COMPANIES, + 'secteurTxt' => DirEnum::SECTORS, + 'description' => DirEnum::JOBDESCRIPTION, + 'nationaliteTxt' => DirEnum::NATIONALITIES, + 'schoolTxt' => DirEnum::SCHOOLS, + ); + if (!array_key_exists($enums, $type)) { + exit(); } - function make_field_test($fields, $beginwith) { - $tests = array(); - $tests[] = $fields . ' LIKE CONCAT({?}, \'%\')'; - if (!$beginwith) { - $tests[] = $fields . ' LIKE CONCAT(\'% \', {?}, \'%\')'; - $tests[] = $fields . ' LIKE CONCAT(\'%-\', {?}, \'%\')'; - } - return '(' . implode(' OR ', $tests) . ')'; - } - $field_select = $field; - $field_t = make_field_test($field, $beginwith); - if ($field2) { - $field2_t = make_field_test($field2, $beginwith); - $field_select = 'IF(' . $field_t . ', ' . $field . ', ' . $field2. ')'; - } - $list = XDB::iterator('SELECT ' . $field_select . ' AS field' - . ($distinct ? (', COUNT(DISTINCT ' . $unique . ') AS nb') : '') - . ($realid ? (', ' . $realid . ' AS id') : '') . ' - FROM ' . $db . ' - WHERE ' . $field_t . - ($field2 ? (' OR ' . $field2_t) : '') . ' - GROUP BY ' . $field_select . ' - ORDER BY ' . ($distinct ? 'nb DESC' : $field_select) . ' - LIMIT 11', - $qsearch, $qsearch, $qsearch, $qsearch, $qsearch, $qsearch, $qsearch, $qsearch, - $qsearch, $qsearch, $qsearch, $qsearch, $qsearch, $qsearch, $qsearch, $qsearch); + $enum = $enums[$type]; + $list = DirEnum::getAutoComplete($enum, $q); $nbResults = 0; $res = ""; while ($result = $list->next()) { @@ -411,84 +243,61 @@ class SearchModule extends PLModule function handler_list(&$page, $type = null, $idVal = null) { // Give the list of all values possible of type and builds a select input for it - $field = 'text'; - $id = 'id'; - $where = ''; + $ids = null; + require_once 'directory.enums.inc.php'; switch ($type) { - case 'binet': - $db = 'binets_def'; + case 'binet': + $ids = DirEnum::getOptions(DirEnum::BINETS); break; case 'networking_type': - $db = 'profile_networking_enum'; - $field = 'name'; - $id = 'network_type'; + $ids = DirEnum::getOptions(DirEnum::NETWORKS); break; case 'country': - $db = 'geoloc_countries'; - $field = 'countryFR'; - $id = 'iso_3166_1_a2'; + $ids = DirEnum::getOptions(DirEnum::COUNTRIES); $page->assign('onchange', 'changeCountry(this.value)'); break; - case 'fonction': - $db = 'fonctions_def'; - $field = 'fonction_fr'; - break; case 'diploma': - pl_content_headers("text/xml"); - $this->get_diplomas(); - $page->changeTpl('search/adv.grade.form.tpl', NO_SKIN); - return; + if (Env::has('school') && Env::i('school') != 0) { + $ids = DirEnum::getOptions(DirEnum::DEGREES, Env::i('school')); + } else { + $ids = DirEnum::getOptions(DirEnum::DEGREES); + } + break; case 'groupex': - $db = '#groupex#.asso'; - $where = " WHERE (cat = 'GroupesX' OR cat = 'Institutions') AND pub = 'public'"; - $field = 'nom'; + $ids = DirEnum::getOptions(DirEnum::GROUPESX); break; case 'nationalite': - $db = 'geoloc_countries INNER JOIN - profiles AS acp ON (acgp.a2 IN (acp.nationality1, acp.nationality2, acp.nationality3))'; - $field = 'nationalityFR'; - $id = 'iso_3166_1_a2'; + $ids = DirEnum::getOptions(DirEnum::NATIONALITIES); break; - case 'region': - $db = 'geoloc_administrativeareas'; - $field = 'name'; - $id = 'id'; - if (isset($_REQUEST['country'])) { - $where .= ' WHERE country = "' . $_REQUEST['country'] . '"'; + case 'region': + if ($isset($_REQUEST['country'])) { + $ids = DirEnum::getOptions(DirEnum::ADMINAREAS, $_REQUEST['country']); + } else { + $ids = DirEnum::getOptions(DirEnum::ADMINAREAS); } break; case 'school': - $db = 'profile_education_enum'; - $field = 'name'; - $id = 'id'; + $ids = DirEnum::getOptions(DirEnum::SCHOOLS); $page->assign('onchange', 'changeSchool(this.value)'); break; case 'section': - $db = 'sections'; + $ids = DirEnum::getOptions(DirEnum::SECTIONS); break; case 'secteur': - $db = 'profile_job_sector_enum INNER JOIN - profile_job ON (profile_job.sectorid = profile_job_sector_enum.id)'; - $field = 'profile_job_sector_enum.name'; - $id = 'profile_job_sector_enum.id'; + $ids = DirEnum::getOptions(DirEnum::SECTORS); break; default: exit(); } if (isset($idVal)) { pl_content_headers("text/plain"); - $result = XDB::query('SELECT '.$field.' AS field FROM '.$db.' WHERE '.$id.' = {?} LIMIT 1',$idVal); - echo $result->fetchOneCell(); + echo $ids[$idVal]; exit(); } pl_content_headers("text/xml"); $page->changeTpl('include/field.select.tpl', NO_SKIN); $page->assign('name', $type); - $page->assign('list', XDB::iterator('SELECT '.$field.' AS field, - '.$id.' AS id - FROM '.$db.$where.' - GROUP BY '.$field.' - ORDER BY '.$field)); + $page->assign('list', $ids); $page->assign('with_text_value', true); $page->assign('onchange', "document.forms.recherche.{$type}Txt.value = this.options[this.selectedIndex].text"); } -- 2.1.4