示例#1
0
 /**
  * @param string $activeSearchClass The search class ID of the active search
  * @param string $query             The current search query
  * @param string $handler           The current search handler
  * @param string $type              The current search type (basic/advanced)
  * @param string $view              variable to determine which tab config should be used
  *
  * @return array
  */
 public function __invoke($activeSearchClass, $query, $handler, $type = 'basic', $view = 'default')
 {
     $backupConfig = $this->config;
     $this->config = $this->injectViewDependentConfig($view);
     $tabs = parent::__invoke($activeSearchClass, $query, $handler, $type);
     $this->config = $backupConfig;
     return $tabs;
 }
示例#2
0
 /**
  * Determine information about search tabs
  *
  * @param string $activeSearchClass The search class ID of the active search
  * @param string $query             The current search query
  * @param string $handler           The current search handler
  * @param string $type              The current search type (basic/advanced)
  * @param array  $hiddenFilters     The current hidden filters
  * @param array  $savedSearches     Saved search ids from all search tabs
  *
  * @return array
  */
 public function getTabConfig($activeSearchClass, $query, $handler, $type = 'basic', $hiddenFilters = [], $savedSearches = [])
 {
     $this->activeSearchClass = $activeSearchClass;
     $tabs = parent::getTabConfig($activeSearchClass, $query, $handler, $type, $hiddenFilters);
     if ($type == 'advanced') {
         $tabs = array_filter($tabs, function ($tab) {
             return strcasecmp($tab['class'], 'combined') != 0;
         });
     }
     $searchTable = $this->table->get('Search');
     foreach ($tabs as $key => &$tab) {
         // Remove any disabled functions
         if (in_array($tab['class'], ['Combined', 'MetaLib', 'Primo'])) {
             $helper = $this->getView()->plugin($tab['class']);
             if (!$helper->isAvailable()) {
                 unset($tabs[$key]);
                 continue;
             }
         }
         if (isset($tab['url'])) {
             $parts = parse_url($tab['url']);
             $params = [];
             if (isset($parts['query'])) {
                 parse_str($parts['query'], $params);
             }
             // Remove search index specific URL parameters
             $dropParams = [SolrParams::SPATIAL_DATERANGE_FIELD . '_type', 'page', 'set', 'sort'];
             $params = array_diff_key($params, array_flip($dropParams));
             $filterQuery = false;
             $tabId = urlencode($tab['id']);
             if (isset($savedSearches[$tabId])) {
                 $helper = $this->getView()->results->getUrlQuery();
                 $searchId = $savedSearches[$tabId];
                 $searchSettings = $this->getSearchSettings($searchId);
                 $targetClass = $tab['id'];
                 // Make sure that tab url does not contain the
                 // search id for the same tab.
                 if (isset($searchSettings['params'])) {
                     $params = array_merge($params, $searchSettings['params']);
                 }
                 if (isset($params['search'])) {
                     $filtered = [];
                     foreach ($params['search'] as $search) {
                         list($searchClass, $searchId) = explode(':', $search);
                         if ($searchClass !== $targetClass) {
                             $filtered[] = $search;
                         }
                     }
                     if (!empty($filtered)) {
                         $params['search'] = $filtered;
                     } else {
                         unset($params['search']);
                     }
                 }
                 if (isset($searchSettings['filters'])) {
                     $filterQuery .= '&' . $helper->buildQueryString(['filter' => $searchSettings['filters']], false);
                 }
             }
             $url = $parts['path'];
             if (!empty($params)) {
                 $url .= '?' . http_build_query($params);
             }
             if ($filterQuery) {
                 if (strstr($url, '?') === false) {
                     $url .= '?';
                 }
                 $url .= $filterQuery;
             }
             $tab['url'] = $url;
         }
     }
     return count($tabs) > 1 ? $tabs : [];
 }
示例#3
0
 /**
  * Determine information about search tabs
  *
  * @param string $activeSearchClass The search class ID of the active search
  * @param string $query             The current search query
  * @param string $handler           The current search handler
  * @param string $type              The current search type (basic/advanced)
  * @param array  $savedSearches     Saved search ids from all search tabs
  *
  * @return array
  */
 public function __invoke($activeSearchClass, $query, $handler, $type = 'basic', $savedSearches = [])
 {
     $this->activeSearchClass = $activeSearchClass;
     $helper = $this->getView()->results->getUrlQuery();
     $tabs = parent::__invoke($activeSearchClass, $query, $handler, $type);
     $searchTable = $this->table->get('Search');
     foreach ($tabs as &$tab) {
         if (isset($tab['url'])) {
             $parts = parse_url($tab['url']);
             $params = [];
             if (isset($parts['query'])) {
                 parse_str($parts['query'], $params);
             }
             // Remove daterange type from URL
             // (to be added later from a saved search)
             $dropParams = [SolrParams::SPATIAL_DATERANGE_FIELD . '_type'];
             $params = array_diff_key($params, array_flip($dropParams));
             $filterQuery = false;
             $searchClass = $tab['class'];
             if (isset($savedSearches[$searchClass])) {
                 $searchId = $savedSearches[$tab['class']];
                 $searchSettings = $this->getSearchSettings($searchId);
                 $targetClass = $tab['class'];
                 // Make sure that tab url does not contain the
                 // search id for the same tab.
                 if (isset($searchSettings['params'])) {
                     $params = array_merge($params, $searchSettings['params']);
                 }
                 if (isset($params['search'])) {
                     $filtered = [];
                     foreach ($params['search'] as $search) {
                         list($searchClass, $searchId) = explode(':', $search);
                         if ($searchClass !== $targetClass) {
                             $filtered[] = $search;
                         }
                     }
                     if (!empty($filtered)) {
                         $params['search'] = $filtered;
                     } else {
                         unset($params['search']);
                     }
                 }
                 if (isset($searchSettings['filters'])) {
                     $filterQuery .= '&' . $helper->buildQueryString(['filter' => $searchSettings['filters']], false);
                 }
             }
             $url = $parts['path'] . '?' . http_build_query($params);
             if ($filterQuery) {
                 $url .= '&' . $filterQuery;
             }
             $tab['url'] = $url;
         }
     }
     return $tabs;
 }