From fdaa361ee734eb41af09166015340a5944def4ec Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Mon, 19 Aug 2013 13:42:38 -0400
Subject: [PATCH] Added mechanism to suppress lookfor parameter in special
 searches (reserves/new items). Resolves VUFIND-873; thanks to David Lacy for
 reporting the problem.

---
 .../VuFind/Controller/SearchController.php    |  2 +
 .../src/VuFind/Search/UrlQueryHelper.php      | 79 ++++++++++++-------
 2 files changed, 52 insertions(+), 29 deletions(-)

diff --git a/module/VuFind/src/VuFind/Controller/SearchController.php b/module/VuFind/src/VuFind/Controller/SearchController.php
index b9a0757d97a..9020debe7f2 100644
--- a/module/VuFind/src/VuFind/Controller/SearchController.php
+++ b/module/VuFind/src/VuFind/Controller/SearchController.php
@@ -417,6 +417,7 @@ class SearchController extends AbstractSearch
             $url = $view->results->getUrlQuery();
             $url->setDefaultParameter('range', $range);
             $url->setDefaultParameter('department', $dept);
+            $url->setSuppressQuery(true);
         }
 
         return $view;
@@ -522,6 +523,7 @@ class SearchController extends AbstractSearch
         $url->setDefaultParameter('course', $course);
         $url->setDefaultParameter('inst', $inst);
         $url->setDefaultParameter('dept', $dept);
+        $url->setSuppressQuery(true);
         return $view;
     }
 
diff --git a/module/VuFind/src/VuFind/Search/UrlQueryHelper.php b/module/VuFind/src/VuFind/Search/UrlQueryHelper.php
index 5355194ed4f..cda68e076ae 100644
--- a/module/VuFind/src/VuFind/Search/UrlQueryHelper.php
+++ b/module/VuFind/src/VuFind/Search/UrlQueryHelper.php
@@ -67,6 +67,13 @@ class UrlQueryHelper
      */
     protected $defaultParams = array();
 
+    /**
+     * Should we suppress the standard query parameter?
+     *
+     * @var bool
+     */
+    protected $suppressQuery = false;
+
     /**
      * Constructor
      *
@@ -103,6 +110,18 @@ class UrlQueryHelper
         $this->defaultParams[$name] = $value;
     }
 
+    /**
+     * Control query suppression
+     *
+     * @param bool $suppress Should we suppress queries?
+     *
+     * @return void
+     */
+    public function setSuppressQuery($suppress)
+    {
+        $this->suppressQuery = $suppress;
+    }
+
     /**
      * Get an array of URL parameters.
      *
@@ -113,40 +132,42 @@ class UrlQueryHelper
         $params = $this->defaultParams;
 
         // Build all the URL parameters based on search object settings:
-        if ($this->params->getSearchType() == 'advanced') {
-            $query = $this->params->getQuery();
-            if ($query instanceof QueryGroup) {
-                $params['join'] = $query->getOperator();
-                foreach ($query->getQueries() as $i => $current) {
-                    if ($current instanceof QueryGroup) {
-                        $operator = $current->isNegated()
-                            ? 'NOT' : $current->getOperator();
-                        $params['bool' . $i] = array($operator);
-                        foreach ($current->getQueries() as $inner) {
-                            if (!isset($params['lookfor' . $i])) {
-                                $params['lookfor' . $i] = array();
+        if (!$this->suppressQuery) {
+            if ($this->params->getSearchType() == 'advanced') {
+                $query = $this->params->getQuery();
+                if ($query instanceof QueryGroup) {
+                    $params['join'] = $query->getOperator();
+                    foreach ($query->getQueries() as $i => $current) {
+                        if ($current instanceof QueryGroup) {
+                            $operator = $current->isNegated()
+                                ? 'NOT' : $current->getOperator();
+                            $params['bool' . $i] = array($operator);
+                            foreach ($current->getQueries() as $inner) {
+                                if (!isset($params['lookfor' . $i])) {
+                                    $params['lookfor' . $i] = array();
+                                }
+                                if (!isset($params['type' . $i])) {
+                                    $params['type' . $i] = array();
+                                }
+                                $params['lookfor'.$i][] = $inner->getString();
+                                $params['type' . $i][] = $inner->getHandler();
                             }
-                            if (!isset($params['type' . $i])) {
-                                $params['type' . $i] = array();
-                            }
-                            $params['lookfor'.$i][] = $inner->getString();
-                            $params['type' . $i][] = $inner->getHandler();
+                        } else {
+                            throw new \Exception('Unexpected Query object.');
                         }
-                    } else {
-                        throw new \Exception('Unexpected Query object.');
                     }
+                } else {
+                    throw new \Exception('Unexpected Query object.');
                 }
             } else {
-                throw new \Exception('Unexpected Query object.');
-            }
-        } else {
-            $search = $this->params->getDisplayQuery();
-            if (!empty($search)) {
-                $params[$this->basicSearchParam] = $search;
-            }
-            $type = $this->params->getSearchHandler();
-            if (!empty($type)) {
-                $params['type'] = $type;
+                $search = $this->params->getDisplayQuery();
+                if (!empty($search)) {
+                    $params[$this->basicSearchParam] = $search;
+                }
+                $type = $this->params->getSearchHandler();
+                if (!empty($type)) {
+                    $params['type'] = $type;
+                }
             }
         }
         $sort = $this->params->getSort();
-- 
GitLab