From 00f25ab1d2a20a4faef657d0981b6638924d596a Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Fri, 15 Apr 2011 11:17:45 +0200 Subject: [PATCH] Adds search on corps (Closes #911). MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Jacob --- ChangeLog | 1 + classes/direnum.php | 21 +++++++++++++++--- classes/userfilter.php | 4 ++-- classes/userfilter/conditions.inc.php | 25 +++++++++++++++++----- include/ufbuilder.inc.php | 40 +++++++++++++++++++++++++++++++++++ modules/search.php | 12 +++++++++++ templates/search/adv.form.tpl | 30 ++++++++++++++++++++++++++ 7 files changed, 123 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 26a5846..0516778 100644 --- a/ChangeLog +++ b/ChangeLog @@ -11,6 +11,7 @@ Bug/Wish: - #1445: Add job entry year -JAC * Search: + - #911: Adds search on corps -JAC - #990: Adds search on broken redirections -JAC * XnetList: diff --git a/classes/direnum.php b/classes/direnum.php index 5ed7807..e45164c 100644 --- a/classes/direnum.php +++ b/classes/direnum.php @@ -40,7 +40,8 @@ class DirEnum const EDUDEGREES = 'educationdegrees'; const EDUFIELDS = 'educationfields'; - const CORPS = 'corps'; + const CURRENTCORPS = 'currentcorps'; + const ORIGINCORPS = 'origincorps'; const CORPSRANKS = 'corpsranks'; const NATIONALITIES = 'nationalities'; @@ -533,18 +534,32 @@ class DE_EducationFields extends DirEnumeration } // }}} -// {{{ class DE_Corps -class DE_Corps 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 diff --git a/classes/userfilter.php b/classes/userfilter.php index c67213d..7b0fdb5 100644 --- a/classes/userfilter.php +++ b/classes/userfilter.php @@ -1046,10 +1046,10 @@ class UserFilter extends PlFilter $this->requireProfiles(); $this->pc = true; if ($type == UFC_Corps::CURRENT) { - $pce['pcec'] = 'current_corpsid'; + $this->pce['pcec'] = 'current_corpsid'; return 'pcec'; } else if ($type == UFC_Corps::ORIGIN) { - $pce['pceo'] = 'original_corpsid'; + $this->pce['pceo'] = 'original_corpsid'; return 'pceo'; } } diff --git a/classes/userfilter/conditions.inc.php b/classes/userfilter/conditions.inc.php index c213de6..c689f0b 100644 --- a/classes/userfilter/conditions.inc.php +++ b/classes/userfilter/conditions.inc.php @@ -1198,11 +1198,13 @@ class UFC_Corps extends UserFilterCondition const ORIGIN = 2; private $corps; + private $id; private $type; - public function __construct($corps, $type = self::CURRENT) + public function __construct($corps, $id = null, $type = self::CURRENT) { $this->corps = $corps; + $this->id = $id; $this->type = $type; } @@ -1214,8 +1216,14 @@ class UFC_Corps extends UserFilterCondition * pcec for profile_corps_enum - current */ $sub = $uf->addCorpsFilter($this->type); - $cond = $sub . '.abbreviation = ' . $corps; - $cond .= ' AND ' . $uf->getVisibilityCondition($sub . '.corps_pub'); + if (is_null($this->id)) { + $cond = $sub . '.abbreviation = ' . $this->corps; + } else { + $cond = $sub . '.id = ' . $this->id; + } + // XXX(x2006barrois): find a way to get rid of that hardcoded + // reference to 'pc'. + $cond .= ' AND ' . $uf->getVisibilityCondition('pc.corps_pub'); return $cond; } } @@ -1227,9 +1235,12 @@ class UFC_Corps extends UserFilterCondition class UFC_Corps_Rank extends UserFilterCondition { private $rank; - public function __construct($rank) + private $id; + + public function __construct($rank, $id = null) { $this->rank = $rank; + $this->id = $id; } public function buildCondition(PlFilter $uf) @@ -1239,7 +1250,11 @@ class UFC_Corps_Rank extends UserFilterCondition * pcr for profile_corps_rank */ $sub = $uf->addCorpsRankFilter(); - $cond = $sub . '.abbreviation = ' . $rank; + if (is_null($this->id)) { + $cond = $sub . '.abbreviation = ' . $this->rank; + } else { + $cond = $sub . '.id = ' . $this->id; + } // XXX(x2006barrois): find a way to get rid of that hardcoded // reference to 'pc'. $cond .= ' AND ' . $uf->getVisibilityCondition('pc.corps_pub'); diff --git a/include/ufbuilder.inc.php b/include/ufbuilder.inc.php index fdd8c6f..13cb8fc 100644 --- a/include/ufbuilder.inc.php +++ b/include/ufbuilder.inc.php @@ -357,6 +357,10 @@ class UFB_AdvancedSearch extends UserFilterBuilder new UFBF_JobCv('cv', 'CV'), new UFBF_JobTerms('jobterm', 'Mots-clefs'), + new UFBF_OriginCorps('origin_corps', 'Corps d\'origine'), + new UFBF_CurrentCorps('current_corps', 'Corps actuel'), + new UFBF_CorpsRank('corps_rank', 'Grade'), + new UFBF_Nationality('nationaliteTxt', 'nationalite', 'Nationalité'), new UFBF_Binet('binetTxt', 'binet', 'Binet'), new UFBF_Group('groupexTxt', 'groupex', 'Groupe X'), @@ -1331,6 +1335,42 @@ class UFBF_EducationField extends UFBF_Mixed } // }}} +// {{{ class UFBF_OriginCorps +class UFBF_OriginCorps extends UFBF_Index +{ + protected $direnum = DirEnum::ORIGINCORPS; + + protected function buildUFC(UserFilterBuilder $ufb) + { + return new UFC_Corps(null, $this->val, UFC_Corps::ORIGIN); + } +} +// }}} + +// {{{ class UFBF_CurrentCorps +class UFBF_CurrentCorps extends UFBF_Index +{ + protected $direnum = DirEnum::CURRENTCORPS; + + protected function buildUFC(UserFilterBuilder $ufb) + { + return new UFC_Corps(null, $this->val, UFC_Corps::CURRENT); + } +} +// }}} + +// {{{ class UFBF_CorpsRank +class UFBF_CorpsRank extends UFBF_Index +{ + protected $direnum = DirEnum::CORPSRANKS; + + protected function buildUFC(UserFilterBuilder $ufb) + { + return new UFC_Corps_Rank(null, $this->val); + } +} +// }}} + // {{{ class UFBF_Comment class UFBF_Comment extends UFBF_Text { diff --git a/modules/search.php b/modules/search.php index cd80aeb..b9ae916 100644 --- a/modules/search.php +++ b/modules/search.php @@ -156,6 +156,18 @@ class SearchModule extends PLModule $networks[0] = '-'; ksort($networks); $page->assign('networking_types', $networks); + $origin_corps_list = DirEnum::getOptions(DirEnum::CURRENTCORPS); + $current_corps_list = DirEnum::getOptions(DirEnum::ORIGINCORPS); + $corps_rank_list = DirEnum::getOptions(DirEnum::CORPSRANKS); + $origin_corps_list[0] = '-'; + $current_corps_list[0] = '-'; + $corps_rank_list[0] = '-'; + ksort($origin_corps_list); + ksort($current_corps_list); + ksort($corps_rank_list); + $page->assign('origin_corps_list', $origin_corps_list); + $page->assign('current_corps_list', $current_corps_list); + $page->assign('corps_rank_list', $corps_rank_list); if (!Env::has('rechercher') && $model != 'geoloc') { $this->form_prepare(); diff --git a/templates/search/adv.form.tpl b/templates/search/adv.form.tpl index d8fc26f..ee04684 100644 --- a/templates/search/adv.form.tpl +++ b/templates/search/adv.form.tpl @@ -516,6 +516,36 @@ function cleanForm(f) { + Corps d'origine + + + + + + Corps actuel + + + + + + Grade + + + + + Commentaire contient -- 2.1.4