/** * Constructor. * * @param Tx_Solr_Query $query Solr query * @param string $facetName Facet name * @param Tx_Solr_Facet_FacetOption $facetOption Facet option */ public function __construct(Tx_Solr_Query $query, $facetName, Tx_Solr_Facet_FacetOption $facetOption) { parent::__construct($query); $this->facetName = $facetName; $this->facetConfiguration = $this->solrConfiguration['search.']['faceting.']['facets.'][$this->facetName . '.']; $this->facetOption = $facetOption; if ($this->solrConfiguration['search.']['faceting.']['facetLinkUrlParameters']) { $this->addUrlParameters($this->solrConfiguration['search.']['faceting.']['facetLinkUrlParameters']); } }
/** * 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; }
/** * 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; }