}
// }}}
+// {{{ 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
*/
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)
{
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.");
}
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;
}
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);
// }}}
// {{{ class UFBF_MentorCountry
-class UFBF_MentorCountry extends UFBF_Index
+class UFBF_MentorCountry extends UFBF_Text
{
protected function buildUFC(UserFilterBuilder &$ufb)
{
}
// }}}
+// {{{ 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
{
$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 = '';
'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),
);
}
function handler_referent(&$page, $action = null, $subaction = null)
{
+ global $globals;
+
$wp = new PlWikiPage('Docs.Emploi');
$wp->buildCache();
$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:
{/if}
<select name="{$name}"{if t($onchange)} onchange="{$onchange}"{/if}{if t($id)} id="{$id}"{/if}>
<option value=""> - </option>
+ {if $list}
{iterate from=$list item='option'}
<option value="{$option.id}">{$option.field|htmlspecialchars}</option>
{/iterate}
+ {/if}
</select>
{if t($with_text_value)}
<input type="hidden" value="" name="{$name}Txt" />
{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 '<em>... 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}
//]]></script>
-<form action="{$smarty.server.REQUEST_URI}" method="get">
- <table cellpadding="0" cellspacing="0" summary="Formulaire de recherche de referents" class="bicol">
+<form action="{$smarty.server.REQUEST_URI}" method="get" onsubmit="return validateSearchForm(this)">
+ <table cellpadding="0" cellspacing="0" summary="Formulaire de recherche de référents" class="bicol">
<tr class="impair">
<td class="titre">
Mot-clef :
</td>
<td>
- <input type="text" name="jobterm_text" id="term_search" size="32"/>
- <input type="hidden" name="jobterm" />
+ <input type="text" name="jobtermText" id="jobtermText" size="32" value="{$smarty.request.jobtermText}"/>
+ <input type="hidden" name="jobterm" id="jobterm" value="{$smarty.request.jobterm}"/>
<a id="jobTermsTreeToggle" href="#">{icon name=table title="Tous les mots-clefs"}</a>
</td>
</tr>
<div id="mentoring_terms"></div>
</td>
</tr>
+ <tr class="pair" style="display:none">
+ <td class="titre">
+ Pays bien connus du référent :
+ </td>
+ <td id="country_chg">
+ </td>
+ </tr>
+ <tr class="impair" style="display:none" id="keywords">
+ <td class="titre">
+ Expertise (recherche texte) :
+ </td>
+ <td>
+ <input type="text" value="{$smarty.request.expertise}" size="30" name="expertise" />
+ </td>
+ </tr>
</table>
<div class="center" style="margin-top: 1em;">
- <input id="search_referent" type="submit" value="Chercher" name="Chercher" />
+ <input id="search_referent" type="submit" value="Chercher" />
</div>
</form>
<script type="text/javascript">
{literal}
$(function() {
- createJobTermsTree('#mentoring_terms', 'profile/ajax/tree/jobterms/mentors', 'mentor', 'searchForJobTerm');
- $("#term_search").autocomplete(baseurl + "autocomplete",
+ createJobTermsTree('#mentoring_terms', 'profile/ajax/tree/jobterms/mentors', 'mentor', 'chooseJobTermInTree');
+ $("#jobtermText").autocomplete(baseurl + "autocomplete",
{
"selectOnly":1,
- "matchSubset":0,
- "width":$("#term_search").width()
+ "width":$("#jobtermText").width()*2,
+ "onItemSelect" : selectJobTerm,
+ "formatItem" : displayJobTerm,
+ "matchSubset" : false
});
$('#jobTermsTreeToggle').click(toggleJobTermsTree);
-});
{/literal}
+ {if $smarty.request.jobterm}
+ updateJobTerm("{$smarty.request.jobterm}", "{$smarty.request.country}");
+ {/if}
+{rdelim});
</script>
{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}