Adds search on corps (Closes #911).
authorStéphane Jacob <sj@m4x.org>
Fri, 15 Apr 2011 09:17:45 +0000 (11:17 +0200)
committerStéphane Jacob <sj@m4x.org>
Fri, 15 Apr 2011 09:17:45 +0000 (11:17 +0200)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
ChangeLog
classes/direnum.php
classes/userfilter.php
classes/userfilter/conditions.inc.php
include/ufbuilder.inc.php
modules/search.php
templates/search/adv.form.tpl

index 26a5846..0516778 100644 (file)
--- 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:
index 5ed7807..e45164c 100644 (file)
@@ -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
index c67213d..7b0fdb5 100644 (file)
@@ -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';
         }
     }
index c213de6..c689f0b 100644 (file)
@@ -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');
index fdd8c6f..13cb8fc 100644 (file)
@@ -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
 {
index cd80aeb..b9ae916 100644 (file)
@@ -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();
index d8fc26f..ee04684 100644 (file)
@@ -516,6 +516,36 @@ function cleanForm(f) {
       </td>
     </tr>
     <tr>
+      <td>Corps d'origine</td>
+      <td>
+        <select name="origin_corps">
+        {foreach from=$origin_corps_list key=id item=corps}
+          <option value="{$id}" {if $smarty.request.origin_corps eq $id}selected="selected"{/if}>{$corps}</option>
+        {/foreach}
+        </select>
+      </td>
+    </tr>
+    <tr>
+      <td>Corps actuel</td>
+      <td>
+        <select name="current_corps">
+        {foreach from=$current_corps_list key=id item=corps}
+          <option value="{$id}" {if $smarty.request.current_corps eq $id}selected="selected"{/if}>{$corps}</option>
+        {/foreach}
+        </select>
+      </td>
+    </tr>
+    <tr>
+      <td>Grade</td>
+      <td>
+        <select name="corps_rank">
+        {foreach from=$corps_rank_list key=id item=corps}
+          <option value="{$id}" {if $smarty.request.corps_rank eq $id}selected="selected"{/if}>{$corps}</option>
+        {/foreach}
+        </select>
+      </td>
+    </tr>
+    <tr>
       <td>Commentaire contient</td>
       <td><input type="text" name="free" size="32" value="{$smarty.request.free}" /></td>
     </tr>