From 459e6f8179a60e4ed026e3feb2e92d1c5b0df479 Mon Sep 17 00:00:00 2001 From: Pascal Corpet Date: Mon, 30 Aug 2010 00:12:13 +0200 Subject: [PATCH] Fixes referent search (include jobterms) --- classes/userfilter.php | 30 ++++++++++ include/ufbuilder.inc.php | 17 ++++-- modules/profile.php | 2 +- modules/search.php | 33 ++++++++++- templates/include/field.select.tpl | 2 + templates/search/referent.tpl | 111 +++++++++++++++++++++++++++---------- 6 files changed, 158 insertions(+), 37 deletions(-) diff --git a/classes/userfilter.php b/classes/userfilter.php index 6e29146..07a67a4 100644 --- a/classes/userfilter.php +++ b/classes/userfilter.php @@ -1216,6 +1216,27 @@ class UFC_Mentor_Country implements UserFilterCondition } // }}} +// {{{ class UFC_Mentor_Terms +/** Filters users based on the job terms they used in mentoring. + * @param $val The ID of the job term, or an array of such IDs + */ +class UFC_Mentor_Terms implements UserFilterCondition +{ + private $val; + + public function __construct($val) + { + $this->val = $val; + } + + public function buildCondition(PlFilter &$uf) + { + $sub = $uf->addMentorFilter(UserFilter::MENTOR_TERM); + return $sub . '.jtid_1 = ' . XDB::escape($this->val); + } +} +// }}} + // {{{ class UFC_Mentor_Sectorization /** Filters users based on mentoring (sub|)sector * @param $sector ID of (sub)sector @@ -2655,9 +2676,11 @@ class UserFilter extends PlFilter */ private $pms = array(); + private $mjtr = false; const MENTOR_EXPERTISE = 1; const MENTOR_COUNTRY = 2; const MENTOR_SECTOR = 3; + const MENTOR_TERM = 4; public function addMentorFilter($type) { @@ -2672,6 +2695,10 @@ class UserFilter extends PlFilter case self::MENTOR_SECTOR: $this->pms['pms'] = 'profile_mentor_sector'; return 'pms'; + case self::MENTOR_TERM: + $this->pms['pmt'] = 'profile_mentor_term'; + $this->mjtr = true; + return 'mjtr'; default: Platal::page()->killError("Undefined mentor filter."); } @@ -2683,6 +2710,9 @@ class UserFilter extends PlFilter foreach ($this->pms as $sub => $tab) { $joins[$sub] = PlSqlJoin::left($tab, '$ME.pid = $PID'); } + if ($this->mjtr) { + $joins['mjtr'] = PlSqlJoin::left('profile_job_term_relation', '$ME.jtid_2 = pmt.jtid'); + } return $joins; } diff --git a/include/ufbuilder.inc.php b/include/ufbuilder.inc.php index 819fd91..9689155 100644 --- a/include/ufbuilder.inc.php +++ b/include/ufbuilder.inc.php @@ -207,9 +207,8 @@ class UFB_MentorSearch extends UserFilterBuilder public function __construct($envprefix = '') { $fields = array( - new UFBF_MentorCountry('pays_sel'), - new UFBF_MentorSectorization('sector', '', UFC_Mentor_Sectorization::SECTOR), - new UFBF_MentorSectorization('subSector', '', UFC_Mentor_Sectorization::SUBSECTOR), + new UFBF_MentorCountry('country'), + new UFBF_MentorTerm('jobterm', 'jobtermText'), new UFBF_MentorExpertise('expertise'), ); parent::__construct($fields, $envprefix); @@ -1039,7 +1038,7 @@ class UFBF_Networking extends UFBF_Text // }}} // {{{ class UFBF_MentorCountry -class UFBF_MentorCountry extends UFBF_Index +class UFBF_MentorCountry extends UFBF_Text { protected function buildUFC(UserFilterBuilder &$ufb) { @@ -1048,6 +1047,16 @@ class UFBF_MentorCountry extends UFBF_Index } // }}} +// {{{ class UFBF_Mentorterm +class UFBF_MentorTerm extends UFBF_Index +{ + protected function buildUFC(UserFilterBuilder &$ufb) + { + return new UFC_Mentor_Terms($this->val); + } +} +// }}} + // {{{ class UFBF_MentorSectorization class UFBF_MentorSectorization extends UFBF_Index { diff --git a/modules/profile.php b/modules/profile.php index 1527e85..e1004c9 100644 --- a/modules/profile.php +++ b/modules/profile.php @@ -654,7 +654,7 @@ class ProfileModule extends PLModule $joins = JobTerms::token_join_query($tokens, 'e'); if ($type == 'mentor') { $count = ', COUNT(DISTINCT pid) AS nb'; - $countjoin = ' LEFT JOIN profile_job_term_relation AS r ON(r.jtid_1 = e.jtid) LEFT JOIN profile_mentor_term AS m ON(r.jtid_2 = m.jtid)'; + $countjoin = ' INNER JOIN profile_job_term_relation AS r ON(r.jtid_1 = e.jtid) INNER JOIN profile_mentor_term AS m ON(r.jtid_2 = m.jtid)'; $countorder = 'nb DESC, '; } else { $count = $countjoin = $countorder = ''; diff --git a/modules/search.php b/modules/search.php index 190ee3b..2ed9e65 100644 --- a/modules/search.php +++ b/modules/search.php @@ -32,6 +32,7 @@ class SearchModule extends PLModule 'jobs' => $this->make_hook('referent', AUTH_COOKIE), 'emploi' => $this->make_hook('referent', AUTH_COOKIE), 'referent/search' => $this->make_hook('referent', AUTH_COOKIE), + 'search/referent/countries' => $this->make_hook('referent_countries', AUTH_COOKIE), ); } @@ -337,6 +338,8 @@ class SearchModule extends PLModule function handler_referent(&$page, $action = null, $subaction = null) { + global $globals; + $wp = new PlWikiPage('Docs.Emploi'); $wp->buildCache(); @@ -357,14 +360,40 @@ class SearchModule extends PLModule $set = new ProfileSet($ufc); $set->addMod('mentor', 'Référents'); $set->apply('referent/search', $page, $action, $subaction); - if ($set->count() > 100) { - $page->assign('recherche_trop_large', true); + $nb_tot = $set->count(); + if ($nb_tot > $globals->search->private_max) { + $this->form_prepare(); + $page->trigError('Recherche trop générale.'); + $page->assign('plset_count', 0); + } else if ($nb_tot == 0) { + $this->form_prepare(); + $page->trigError('Il n\'existe personne correspondant à ces critères dans la base.'); } } $page->changeTpl('search/referent.tpl'); } + /** + * Builds a select field to choose among countries that referents + * know about. Only referents linked to term (jtid) are displayed. + * @param $jtid id of job term to restrict referents + */ + function handler_referent_countries(&$page, $jtid = null) + { + pl_content_headers("text/xml"); + $page->changeTpl('include/field.select.tpl', NO_SKIN); + $page->assign('name', 'country'); + $it = XDB::iterator("SELECT gc.iso_3166_1_a2 AS id, gc.countryFR AS field + FROM geoloc_countries AS gc + INNER JOIN profile_mentor_country AS mp ON (mp.country = gc.iso_3166_1_a2) + INNER JOIN profile_mentor_term AS mt ON (mt.pid = mp.pid) + INNER JOIN profile_job_term_relation AS jtr ON (jtr.jtid_2 = mt.jtid) + WHERE jtr.jtid_1 = {?} + GROUP BY iso_3166_1_a2 + ORDER BY countryFR", $jtid); + $page->assign('list', $it); + } } // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: diff --git a/templates/include/field.select.tpl b/templates/include/field.select.tpl index a079ab4..2757bff 100644 --- a/templates/include/field.select.tpl +++ b/templates/include/field.select.tpl @@ -25,9 +25,11 @@ {/if} {if t($with_text_value)} diff --git a/templates/search/referent.tpl b/templates/search/referent.tpl index 0da1170..ab57b71 100644 --- a/templates/search/referent.tpl +++ b/templates/search/referent.tpl @@ -42,48 +42,79 @@ var baseurl = platal_baseurl + "referent/"; {literal} var Ajax2 = new AjaxEngine(); -function setSector(sector) +/** Hides or display tree of all job terms */ +function toggleJobTermsTree() { - if (sector == '') { - document.getElementById('scat').style.display = 'none'; - document.getElementById('country').style.display = 'none'; - document.getElementById('keywords').style.display = 'none'; - document.getElementById('search_referent').disabled = 'disabled'; - } else { - Ajax.update_html('ssect_chg', baseurl + 'ssect/' + sector); - Ajax2.update_html('country_chg', baseurl + 'country/' + sector); - document.getElementById('scat').style.display = ''; - document.getElementById('country').style.display = ''; - document.getElementById('keywords').style.display = ''; - document.getElementById('search_referent').disabled = ''; + $('#mentoring_terms').closest('tr').toggle(); + return false; +} + +/** Function called by autocomplete when a term is selected */ +function selectJobTerm(li) +{ + if (li.extra[1] < 0) { + return; } + chooseJobTermInTree(null,li.extra[1],li.selectValue); } -function setSSectors() +/** Prepares display for a jobterm in select's dropdown + * @param row the returned row from ajax : text, nb, id + */ +function displayJobTerm(row) { - var sect = document.getElementById('sect_field').value; - var ssect = document.getElementById('ssect_field').value; - Ajax2.update_html('country_chg', baseurl + 'country/' + sect + '/' + ssect); + if (row[1] < 0) { + return '... précise ta recherche ... <\/em>'; + } + return row[0]+' ('+row[1]+' camarade'+((row[1] > 1)?'s':'')+')'; } -function toggleJobTermsTree() +/** Function called by job terms tree when an item is clicked */ +function chooseJobTermInTree(treeid, jtid, full_name) { - $('#mentoring_terms').closest('tr').toggle(); - return false; + $('#jobtermText').val(full_name); + $('#mentoring_terms').closest('tr').hide(); + updateJobTerm(jtid, $('#country_chg select').val()); +} + +/** Changes job term and proposes the different countries linked */ +function updateJobTerm(jtid, country) +{ + $('#jobterm').val(jtid); + $('#country_chg').closest('tr').show(); + $('#keywords').show(); + $('#country_chg').load(platal_baseurl + 'search/referent/countries/' + jtid, function(response, status, xhr) { + if (country) { + if (status != "error") { + $('#country_chg select').val(country); + } + } + }); +} + +/** Function called when validating form */ +function validateSearchForm(f) +{ + if (!f.jobterm.value) { + alert('Il faut choisir un mot clef avant de lancer la recherche.'); + $('#jobtermText').val('').focus(); + return false; + } + return true; } {/literal} //]]> -
- + +
@@ -92,24 +123,44 @@ function toggleJobTermsTree()
+ + + + + + + +
Mot-clef : - - + + {icon name=table title="Tous les mots-clefs"}
- +
{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} -- 2.1.4