Split the SearchSet into QuickSet and AdvancedSet
authorRaphaël Barrois <raphael.barrois@polytechnique.org>
Tue, 28 Dec 2010 15:37:17 +0000 (16:37 +0100)
committerRaphaël Barrois <raphael.barrois@polytechnique.org>
Wed, 29 Dec 2010 17:55:03 +0000 (18:55 +0100)
Also move the 'not registered' field for quicksearch into the UFB_Quick.

Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
include/ufbuilder.inc.php
include/userset.inc.php
modules/carnet.php
modules/gadgets.php
modules/search.php

index a28a10a..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);
     }
@@ -655,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
 {
index c648005..d2e1823 100644 (file)
@@ -45,21 +45,15 @@ class ProfileSet extends PlSet
     }
 }
 
+require_once "ufbuilder.inc.php";
+
 class SearchSet extends ProfileSet
 {
-    public  $advanced = false;
-    private $score    = null;
-    private $quick    = false;
-    private $valid    = true;
+    protected $score    = null;
+    protected $valid    = true;
 
-    public function __construct($quick = false, PlFilterCondition $cond = null)
+    public function __construct(UserFilterBuilder &$ufb, PlFilterCondition $cond = null)
     {
-        if (isset($no_search)) {
-            return;
-        }
-
-        $this->quick = $quick;
-
         if (is_null($cond)) {
             $conds = new PFC_And();
         } else if ($cond instanceof PFC_And) {
@@ -68,30 +62,6 @@ class SearchSet extends ProfileSet
             $conds = new PFC_And($cond);
         }
 
-        if ($quick) {
-            $this->getQuick($conds);
-        } else {
-            $this->getAdvanced($conds);
-        }
-    }
-
-    public function isValid()
-    {
-        return $this->valid;
-    }
-
-    /** Sets up the conditions for a Quick Search
-     * @param $conds Additional conds (as a PFC_And)
-     */
-    private function getQuick($conds)
-    {
-        if (!S::logged()) {
-            Env::kill('with_soundex');
-        }
-
-        require_once 'ufbuilder.inc.php';
-        $ufb = new UFB_QuickSearch();
-
         if (!$ufb->isValid()) {
             $this->valid = false;
             return;
@@ -102,36 +72,12 @@ class SearchSet extends ProfileSet
 
         $orders = $ufb->getOrders();
 
-        if (S::logged() && Env::has('nonins')) {
-            $conds = new PFC_And($conds,
-                new PFC_Not(new UFC_Dead()),
-                new PFC_Not(new UFC_Registered())
-            );
-        }
-
         parent::__construct($conds, $orders);
     }
 
-    /** Sets up the conditions for an Advanced Search
-     * @param $conds Additional conds (as a PFC_And)
-     */
-    private function getAdvanced($conds)
+    public function isValid()
     {
-        $this->advanced = true;
-        require_once 'ufbuilder.inc.php';
-        $ufb = new UFB_AdvancedSearch();
-
-        if (!$ufb->isValid()) {
-            $this->valid = false;
-            return;
-        }
-
-        $ufc = $ufb->getUFC();
-        $conds->addChild($ufc);
-
-        $orders = $ufb->getOrders();
-
-        parent::__construct($conds, $orders);
+        return $this->valid;
     }
 
     /** Add a "rechercher=Chercher" field to the query to simulate the POST
@@ -153,6 +99,28 @@ class SearchSet extends ProfileSet
     }
 }
 
+// Specialized SearchSet for quick search.
+class QuickSearchSet extends SearchSet
+{
+    public function __construct(PlFilterCondition $cond = null)
+    {
+        if (!S::logged()) {
+            Env::kill('with_soundex');
+        }
+
+        parent::__construct(new UFB_QuickSearch(), $cond);
+    }
+}
+
+// Specialized SearchSet for advanced search.
+class AdvancedSearchSet extends SearchSet
+{
+    public function __construct(PlFilterCondition $cond = null)
+    {
+        parent::__construct(new UFB_AdvancedSearch(), $cond);
+    }
+}
+
 /** Simple set based on an array of User objects
  */
 class ArraySet extends ProfileSet
index 9454062..ba5e1df 100644 (file)
@@ -316,7 +316,7 @@ class CarnetModule extends PLModule
         }
         if ($search && trim(Env::v('quick'))) {
             $base = 'carnet/contacts/search';
-            $view = new SearchSet(true, new UFC_Contact($user));
+            $view = new QuickSearchSet(new UFC_Contact($user));
         } else {
             $base = 'carnet/contacts';
             $view = new ProfileSet(new UFC_Contact($user));
index b8700de..d3bbe8b 100644 (file)
@@ -74,7 +74,7 @@ class GadgetsModule extends PLModule
             global $globals;
             require_once 'userset.inc.php';
 
-            $view = new SearchSet(true);
+            $view = new QuickSearchSet();
             $view->addMod('gadget', 'Gadget', true);
             $view->apply(null, $page);
 
index 14383b4..21d9870 100644 (file)
@@ -120,7 +120,7 @@ class SearchModule extends PLModule
             $page->assign('formulaire', 0);
 
             require_once 'userset.inc.php';
-            $view = new SearchSet(true);
+            $view = new QuickSearchSet();
             $view->addMod('minifiche', 'Mini-fiches', true, array('with_score' => true, 'starts_with' => $byletter));
             if (S::logged() && !Env::i('nonins')) {
                 $view->addMod('trombi', 'Trombinoscope', false, array('with_promo' => true, 'with_score' => true));
@@ -169,7 +169,7 @@ class SearchModule extends PLModule
             }
 
             require_once 'userset.inc.php';
-            $view = new SearchSet(false);
+            $view = new AdvancedSearchSet();
             if (!$view->isValid()) {
                 $this->form_prepare();
                 $page->trigError('Recherche invalide.');