Update modules/search to handle invalid queries
authorRaphaël Barrois <raphael.barrois@polytechnique.org>
Sun, 26 Sep 2010 21:53:22 +0000 (23:53 +0200)
committerRaphaël Barrois <raphael.barrois@polytechnique.org>
Mon, 27 Sep 2010 21:19:19 +0000 (23:19 +0200)
Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
include/userset.inc.php
modules/search.php

index 0612d2f..7ffe768 100644 (file)
@@ -50,6 +50,7 @@ class SearchSet extends ProfileSet
     public  $advanced = false;
     private $score    = null;
     private $quick    = false;
+    private $valid    = true;
 
     public function __construct($quick = false, PlFilterCondition $cond = null)
     {
@@ -74,6 +75,11 @@ class SearchSet extends ProfileSet
         }
     }
 
+    public function isValid()
+    {
+        return $this->valid;
+    }
+
     /** Sets up the conditions for a Quick Search
      * @param $conds Additional conds (as a PFC_And)
      */
@@ -87,6 +93,7 @@ class SearchSet extends ProfileSet
         $ufb = new UFB_QuickSearch();
 
         if (!$ufb->isValid()) {
+            $this->valid = false;
             return;
         }
 
@@ -115,6 +122,7 @@ class SearchSet extends ProfileSet
         $ufb = new UFB_AdvancedSearch();
 
         if (!$ufb->isValid()) {
+            $this->valid = false;
             return;
         }
 
index ba1112f..5d474f5 100644 (file)
@@ -162,19 +162,24 @@ class SearchModule extends PLModule
 
             require_once 'userset.inc.php';
             $view = new SearchSet(false);
-            $view->addMod('minifiche', 'Mini-fiches', true, array('starts_with' => $byletter));
-            $view->addMod('trombi', 'Trombinoscope', false, array('with_promo' => true));
-            // TODO: Reactivate when the new map is completed.
-            // $view->addMod('geoloc', 'Planisphère', false, array('with_annu' => 'search/adv'));
-            $view->apply('search/adv', $page, $model);
-
-            $nb_tot = $view->count();
-            if ($nb_tot > $globals->search->private_max) {
-                $this->form_prepare();
-                $page->trigError('Recherche trop générale.');
-            } else if ($nb_tot == 0) {
+            if (!$view->isValid()) {
                 $this->form_prepare();
-                $page->trigError('Il n\'existe personne correspondant à ces critères dans la base !');
+                $page->trigError('Recherche invalide.');
+            } else {
+                $view->addMod('minifiche', 'Mini-fiches', true, array('starts_with' => $byletter));
+                $view->addMod('trombi', 'Trombinoscope', false, array('with_promo' => true));
+                // TODO: Reactivate when the new map is completed.
+                // $view->addMod('geoloc', 'Planisphère', false, array('with_annu' => 'search/adv'));
+                $view->apply('search/adv', $page, $model);
+
+                $nb_tot = $view->count();
+                if ($nb_tot > $globals->search->private_max) {
+                    $this->form_prepare();
+                    $page->trigError('Recherche trop générale.');
+                } else if ($nb_tot == 0) {
+                    $this->form_prepare();
+                    $page->trigError('Il n\'existe personne correspondant à ces critères dans la base !');
+                }
             }
         }