Example #1
0
 /**
  * Get an array of URL parameters.
  *
  * @return array
  */
 public function getParamArray()
 {
     $params = $this->defaultParams;
     // Build all the URL parameters based on search object settings:
     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] = [$operator];
                         foreach ($current->getQueries() as $inner) {
                             if (!isset($params['lookfor' . $i])) {
                                 $params['lookfor' . $i] = [];
                             }
                             if (!isset($params['type' . $i])) {
                                 $params['type' . $i] = [];
                             }
                             $params['lookfor' . $i][] = $inner->getString();
                             $params['type' . $i][] = $inner->getHandler();
                             if (null !== ($op = $inner->getOperator())) {
                                 $params['op' . $i][] = $op;
                             }
                         }
                     } 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;
             }
         }
     }
     $sort = $this->params->getSort();
     if (!is_null($sort) && $sort != $this->params->getDefaultSort()) {
         $params['sort'] = $sort;
     }
     $limit = $this->params->getLimit();
     if (!is_null($limit) && $limit != $this->options->getDefaultLimit()) {
         $params['limit'] = $limit;
     }
     $view = $this->params->getView();
     if (!is_null($view) && $view != $this->options->getDefaultView()) {
         $params['view'] = $view;
     }
     if ($this->params->getPage() != 1) {
         $params['page'] = $this->params->getPage();
     }
     $filters = $this->params->getFilters();
     if (!empty($filters)) {
         $params['filter'] = [];
         foreach ($filters as $field => $values) {
             foreach ($values as $current) {
                 $params['filter'][] = $field . ':"' . $current . '"';
             }
         }
     }
     $hiddenFilters = $this->params->getHiddenFilters();
     if (!empty($hiddenFilters)) {
         foreach ($hiddenFilters as $field => $values) {
             foreach ($values as $current) {
                 $params['hiddenFilters'][] = $field . ':"' . $current . '"';
             }
         }
     }
     $shards = $this->params->getSelectedShards();
     if (!empty($shards)) {
         sort($shards);
         $defaultShards = $this->options->getDefaultSelectedShards();
         sort($defaultShards);
         if (implode(':::', $shards) != implode(':::', $defaultShards)) {
             $params['shard'] = $shards;
         }
     }
     if ($this->params->hasDefaultsApplied()) {
         $params['dfApplied'] = 1;
     }
     return $params;
 }
Example #2
0
 /**
  * Wrapper around rememberLastSettings() to extract key values from a
  * search Params object.
  *
  * @param \VuFind\Search\Base\Params $params Parameter object
  *
  * @return void
  */
 public function rememberParams(\VuFind\Search\Base\Params $params)
 {
     $settings = ['hiddenFilters' => $params->getHiddenFilters(), 'limit' => $params->getLimit(), 'sort' => $params->getSort(), 'view' => $params->getView()];
     // Special case: RSS view should not be persisted:
     if (strtolower($settings['view']) == 'rss') {
         unset($settings['view']);
     }
     $this->rememberLastSettings($params->getSearchClassId(), $settings);
 }