Split the SearchSet into QuickSet and AdvancedSet
[platal.git] / include / ufbuilder.inc.php
index 09dc307..2eacd43 100644 (file)
@@ -166,6 +166,7 @@ class UFB_QuickSearch extends UserFilterBuilder
     {
         $fields = array(
             new UFBF_Quick('quick', 'Recherche rapide'),
+            new UFBF_NotRegistered('nonins', 'Non inscrits'),
         );
         parent::__construct($fields, $envprefix);
     }
@@ -190,7 +191,6 @@ class UFB_AdvancedSearch extends UserFilterBuilder
             new UFBF_AdminArea('region', 'RĂ©gion'),
 
             new UFBF_JobCompany('entreprise', 'Entreprise'),
-            new UFBF_JobSector('sector', 'Poste'),
             new UFBF_JobDescription('jobdescription', 'Fonction'),
             new UFBF_JobCv('cv', 'CV'),
             new UFBF_JobTerms('jobterm', 'Mots-clefs'),
@@ -269,7 +269,7 @@ abstract class UFB_Field
             return false;
         }
 
-        if (!$this->empty) {
+        if (!$this->isEmpty()) {
             $ufc = $this->buildUFC($ufb);
             if ($ufc != null) {
                 $ufb->addCond($ufc);
@@ -521,18 +521,8 @@ class UFBF_Quick extends UFB_Field
             } else {
                 $flags = array('public');
             }
-            if ($ufb->b('with_soundex')) {
-                $soundex = true;
-                $st = array();
-                foreach ($strings as $string) {
-                    $st[] = soundex_fr($string);
-                }
-            } else {
-                $soundex = false;
-                $st = $strings;
-            }
             $exact =$ufb->b('exact');
-            $conds->addChild(new UFC_NameTokens($st, $flags, $soundex, $exact));
+            $conds->addChild(new UFC_NameTokens($strings, $flags, $ufb->b('with_soundex'), $exact));
 
             $ufb->addOrder(new UFO_Score());
         }
@@ -666,6 +656,22 @@ class UFBF_Sex extends UFBF_Enum
 }
 // }}}
 
+// {{{ class UFBF_NotRegistered
+// Simple field for selecting only alive, not registered users (for quick search)
+class UFBF_NotRegistered extends UFBF_Bool
+{
+    protected function buildUFC(UserFilterBuilder &$ufb)
+    {
+        if ($this->val) {
+            return new PFC_And(
+                new PFC_Not(new UFC_Dead()),
+                new PFC_Not(new UFC_Registered())
+            );
+        }
+    }
+}
+// }}}
+
 // {{{ class UFBF_Registered
 class UFBF_Registered extends UFBF_Enum
 {
@@ -778,14 +784,14 @@ class UFBF_Country extends UFBF_Mixed
 // }}}
 
 // {{{ class UFBF_AdminArea
-class UFBF_AdminArea extends UFBF_Mixed
+class UFBF_AdminArea extends UFBF_Index
 {
     protected $direnum = DirEnum::ADMINAREAS;
     protected $onlycurrentfield;
 
-    public function __construct($envfieldtext, $envfieldindex, $formtext = '', $onlycurrentfield = 'only_current')
+    public function __construct($envfield, $formtext = '', $onlycurrentfield = 'only_current')
     {
-        parent::__construct($envfieldtext, $envfieldindex, $formtext);
+        parent::__construct($envfield, $formtext);
         $this->onlycurrentfield = $onlycurrentfield;
     }
 
@@ -833,29 +839,6 @@ class UFBF_JobCompany extends UFBF_Text
 }
 // }}}
 
-// {{{ class UFBF_JobSector
-class UFBF_JobSector extends UFBF_Mixed
-{
-    protected $direnum = DirEnum::SECTORS;
-    private $onlymentorfield;
-
-    public function __construct($envfieldtext, $envfieldindex, $formtext = '', $onlymentorfield = 'only_referent')
-    {
-        parent::__construct($envfieldtext, $envfieldindex, $formtext);
-        $this->onlymentorfield = $onlymentorfield;
-    }
-
-    protected function buildUFC(UserFilterBuilder &$ufb)
-    {
-        if ($ufb->isOn($this->onlymentorfield)) {
-            return new UFC_Mentor_Sectorization($this->val, UserFilter::JOB_SUBSECTOR);
-        } else {
-            return new UFC_Job_Sectorization($this->val, UserFilter::JOB_SUBSUBSECTOR);
-        }
-    }
-}
-// }}}
-
 // {{{ class UFBF_JobTerms
 class UFBF_JobTerms extends UFBF_Index
 {
@@ -955,7 +938,7 @@ class UFBF_Group extends UFBF_Mixed
 // }}}
 
 // {{{ class UFBF_Section
-class UFBF_Section extends UFBF_Index
+class UFBF_Section extends UFBF_Mixed
 {
     protected $direnum = DirEnum::SECTIONS;
 
@@ -1044,6 +1027,11 @@ class UFBF_Networking extends UFBF_Text
         }
     }
 
+    public function isEmpty()
+    {
+        return parent::isEmpty() || $this->nwtype == 0;
+    }
+
     public function buildUFC(UserFilterBuilder &$ufb)
     {
         return new UFC_Networking($this->nwtype, $this->val);
@@ -1081,24 +1069,6 @@ class UFBF_MentorTerm extends UFBF_Index
 }
 // }}}
 
-// {{{ class UFBF_MentorSectorization
-class UFBF_MentorSectorization extends UFBF_Index
-{
-    protected $type;
-
-    public function __construct($envfield, $formtext = '', $type = UFC_Mentor_Sectorization::SECTOR)
-    {
-        parent::__construct($envfield, $formtext);
-        $this->type = $type;
-    }
-
-    protected function buildUFC(UserFilterBuilder &$ufb)
-    {
-        return new UFC_Mentor_Sectorization($this->val, $this->type);
-    }
-}
-// }}}
-
 // {{{ class UFBF_MentorExpertise
 class UFBF_MentorExpertise extends UFBF_Text
 {