Example #1
0
 /**
  * Returns an URL that switches sorting to the given sort option
  *
  * @param array $arguments
  * @return	string
  */
 public function execute(array $arguments = array())
 {
     $sortUrl = '';
     $urlParameters = GeneralUtility::_GP('tx_solr');
     $urlSortParameters = GeneralUtility::trimExplode(',', $urlParameters['sort']);
     $sortOptions = GeneralUtility::trimExplode(',', $arguments[0]);
     $currentSortOption = '';
     $sortHelper = GeneralUtility::makeInstance('Tx_Solr_Sorting', $this->configuration['search.']['sorting.']['options.']);
     $configuredSortOptions = $sortHelper->getSortOptions();
     $sortParameters = array();
     foreach ($sortOptions as $sortOption) {
         if (array_key_exists($sortOption, $configuredSortOptions)) {
             $sortDirection = $this->configuration['search.']['sorting.']['defaultOrder'];
             $sortParameter = $sortOption . ' ' . $sortDirection;
             foreach ($urlSortParameters as $urlSortParameter) {
                 $explodedUrlSortParameter = explode(' ', $urlSortParameter);
                 if ($explodedUrlSortParameter[0] == $sortOption) {
                     list($currentSortOption, $currentSortDirection) = $explodedUrlSortParameter;
                     break;
                 }
             }
             if ($currentSortOption == $sortOption) {
                 switch ($currentSortDirection) {
                     case 'asc':
                         $sortDirection = 'desc';
                         break;
                     case 'desc':
                         $sortDirection = 'asc';
                         break;
                 }
                 if (!empty($this->configuration['search.']['sorting.']['options.'][$sortOption . '.']['fixedOrder'])) {
                     $sortDirection = $this->configuration['search.']['sorting.']['options.'][$sortOption . '.']['fixedOrder'];
                 }
                 $sortParameter = $sortOption . ' ' . $sortDirection;
             }
             $sortParameters[] = $sortParameter;
         }
     }
     $sortUrl = $this->queryLinkBuilder->getQueryUrl(array('sort' => implode(', ', $sortParameters)));
     return $sortUrl;
 }
Example #2
0
 /**
  * Builds the URL to reset all options of a facet - removing all its applied
  * filters from a result set.
  *
  * @return string  Url to remove a facet
  */
 protected function buildResetFacetUrl()
 {
     $resetFacetUrl = '';
     $resultParameters = \TYPO3\CMS\Core\Utility\GeneralUtility::_GPmerged('tx_solr');
     if (is_array($resultParameters['filter'])) {
         // urldecode the array to get the original representation
         $filterParameters = array_values((array) array_map('urldecode', $resultParameters['filter']));
         $filterParameters = array_unique($filterParameters);
         // find and remove all options for this facet
         foreach ($filterParameters as $key => $filter) {
             list($filterName, $filterValue) = explode(':', $filter);
             if ($filterName == $this->facetName) {
                 unset($filterParameters[$key]);
             }
         }
         $filterParameters = array_map('urlencode', $filterParameters);
         $resetFacetUrl = $this->queryLinkBuilder->getQueryUrl(array('filter' => $filterParameters));
     } else {
         $resetFacetUrl = $this->queryLinkBuilder->getQueryUrl();
     }
     return $resetFacetUrl;
 }