protected function getSortingLinks() { $sortHelper = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\Sorting', $this->configuration['search.']['sorting.']['options.']); $query = $this->search->getQuery(); $queryLinkBuilder = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\Query\\LinkBuilder', $query); $queryLinkBuilder->setLinkTargetPageId($this->parentPlugin->getLinkTargetPageId()); $sortOptions = array(); $urlParameters = GeneralUtility::_GP('tx_solr'); $urlSortParameters = GeneralUtility::trimExplode(',', $urlParameters['sort']); $configuredSortOptions = $sortHelper->getSortOptions(); foreach ($configuredSortOptions as $sortOptionName => $sortOption) { $sortDirection = $this->configuration['search.']['sorting.']['defaultOrder']; if (!empty($this->configuration['search.']['sorting.']['options.'][$sortOptionName . '.']['defaultOrder'])) { $sortDirection = $this->configuration['search.']['sorting.']['options.'][$sortOptionName . '.']['defaultOrder']; } $sortIndicator = $sortDirection; $currentSortOption = ''; $currentSortDirection = ''; foreach ($urlSortParameters as $urlSortParameter) { $explodedUrlSortParameter = explode(' ', $urlSortParameter); if ($explodedUrlSortParameter[0] == $sortOptionName) { list($currentSortOption, $currentSortDirection) = $explodedUrlSortParameter; break; } } // toggle sorting direction for the current sorting field if ($currentSortOption == $sortOptionName) { switch ($currentSortDirection) { case 'asc': $sortDirection = 'desc'; $sortIndicator = 'asc'; break; case 'desc': $sortDirection = 'asc'; $sortIndicator = 'desc'; break; } } if (!empty($this->configuration['search.']['sorting.']['options.'][$sortOptionName . '.']['fixedOrder'])) { $sortDirection = $this->configuration['search.']['sorting.']['options.'][$sortOptionName . '.']['fixedOrder']; } $sortParameter = $sortOptionName . ' ' . $sortDirection; $temp = array('link' => $queryLinkBuilder->getQueryLink($sortOption['label'], array('sort' => $sortParameter)), 'url' => $queryLinkBuilder->getQueryUrl(array('sort' => $sortParameter)), 'optionName' => $sortOptionName, 'field' => $sortOption['field'], 'label' => $sortOption['label'], 'is_current' => '0', 'direction' => $sortDirection, 'indicator' => $sortIndicator, 'current_direction' => ' '); // set sort indicator for the current sorting field if ($currentSortOption == $sortOptionName) { $temp['selected'] = 'selected="selected"'; $temp['current'] = 'current'; $temp['is_current'] = '1'; $temp['current_direction'] = $sortIndicator; } // special case relevance: just reset the search to normal behavior if ($sortOptionName == 'relevance') { $temp['link'] = $queryLinkBuilder->getQueryLink($sortOption['label'], array('sort' => NULL)); $temp['url'] = $queryLinkBuilder->getQueryUrl(array('sort' => NULL)); unset($temp['direction'], $temp['indicator']); } $sortOptions[] = $temp; } return $sortOptions; }
/** * Creates a link to a given page with a given link text with the current * tx_solr parameters appended to the URL * * @param array Array of arguments, [0] is the link text, [1] is the (optional) page Id to link to (otherwise TSFE->id), [2] are additional URL parameters, [3] use cache, defaults to FALSE * @return string complete anchor tag with URL and link text */ public function execute(array $arguments = array()) { $linkText = $arguments[0]; $pageId = $this->determinePageId(trim($arguments[1])); $additionalUrlParameters = $arguments[2] ? $arguments[2] : ''; $useCache = $arguments[3] ? true : false; $returnOnlyUrl = $arguments[4] ? true : false; // FIXME pass anything not prefixed with tx_solr in $additionalParameters as 4th parameter $additionalUrlParameters = GeneralUtility::explodeUrl2Array($additionalUrlParameters, true); $solrUrlParameters = array(); if (!empty($additionalUrlParameters['tx_solr'])) { $solrUrlParameters = $additionalUrlParameters['tx_solr']; } $linkConfiguration = array('useCacheHash' => $useCache); if ($returnOnlyUrl) { $linkConfiguration['returnLast'] = 'url'; } if ($this->search->hasSearched()) { $query = $this->search->getQuery(); } else { $query = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\Query', ''); } $linkBuilder = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\Query\\LinkBuilder', $query); $linkBuilder->setLinkTargetPageId($pageId); $queryLink = $linkBuilder->getQueryLink($linkText, $solrUrlParameters, $linkConfiguration); return $queryLink; }
/** * Query link with a suggested/corrected query * * @return string Suggestion/spell checked query link */ public function getSuggestionQueryLink() { $suggestions = $this->getSuggestions(); $query = clone $this->search->getQuery(); $query->setKeywords($suggestions['collation']); $queryLinkBuilder = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\Query\\LinkBuilder', $query); $queryLinkBuilder->setLinkTargetPageId($GLOBALS['TSFE']->id); return $queryLinkBuilder->getQueryLink(htmlspecialchars($query->getKeywordsRaw())); }
/** * Constructor. * * @param Facet $facet The facet to render. */ public function __construct(Facet $facet) { $this->search = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\Search'); $this->facet = $facet; $this->facetName = $facet->getName(); $this->solrConfiguration = Util::getSolrConfiguration(); $this->facetConfiguration = $this->solrConfiguration['search.']['faceting.']['facets.'][$this->facetName . '.']; $this->linkTargetPageId = $GLOBALS['TSFE']->id; $this->queryLinkBuilder = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\Query\\LinkBuilder', $this->search->getQuery()); }
/** * Renders facets selected by the user. * * @return string rendered selected facets subpart */ protected function renderUsedFacets() { $template = clone $this->parentPlugin->getTemplate(); $template->workOnSubpart('used_facets'); $query = $this->search->getQuery(); $queryLinkBuilder = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\Query\\LinkBuilder', $this->search->getQuery()); /* @var $queryLinkBuilder LinkBuilder */ $queryLinkBuilder->setLinkTargetPageId($this->parentPlugin->getLinkTargetPageId()); // URL parameters added to facet URLs may not need to be added to the facets reset URL $facetLinkUrlParameters = $this->configuration->getSearchFacetingFacetLinkUrlParametersAsArray(); $useForFacetResetLink = $this->configuration->getSearchFacetingFacetLinkUrlParametersUseForFacetResetLinkUrl(); if (count($facetLinkUrlParameters) > 0 && $useForFacetResetLink) { $addedUrlParameterKeys = array_keys($facetLinkUrlParameters); foreach ($addedUrlParameterKeys as $addedUrlParameterKey) { if (GeneralUtility::isFirstPartOfStr($addedUrlParameterKey, 'tx_solr')) { $addedUrlParameterKey = substr($addedUrlParameterKey, 8, -1); $queryLinkBuilder->addUnwantedUrlParameter($addedUrlParameterKey); } } } $resultParameters = GeneralUtility::_GET('tx_solr'); $filterParameters = array(); if (isset($resultParameters['filter'])) { $filterParameters = (array) array_map('urldecode', $resultParameters['filter']); } $facetsInUse = array(); foreach ($filterParameters as $filter) { // only split by the first ":" to allow the use of colons in the filter value list($filterName, $filterValue) = explode(':', $filter, 2); $facetConfiguration = $this->configuration->getSearchFacetingFacetByName($filterName); // don't render facets that should not be included in used facets if (isset($facetConfiguration['includeInUsedFacets']) && $facetConfiguration['includeInUsedFacets'] == '0') { continue; } $usedFacetRenderer = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\Facet\\UsedFacetRenderer', $filterName, $filterValue, $filter, $this->parentPlugin->getTemplate(), $query); $usedFacetRenderer->setLinkTargetPageId($this->parentPlugin->getLinkTargetPageId()); $facetToRemove = $usedFacetRenderer->render(); $facetsInUse[] = $facetToRemove; } $template->addLoop('facets_in_use', 'remove_facet', $facetsInUse); $template->addVariable('remove_all_facets', array('url' => $queryLinkBuilder->getQueryUrl(array('filter' => array())), 'text' => '###LLL:faceting_removeAllFilters###')); $content = ''; if (count($facetsInUse)) { $content = $template->render(); } return $content; }
/** * Constructor * * @param array $arguments */ public function __construct(array $arguments = array()) { $this->search = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\Search'); $this->configuration = Util::getSolrConfiguration(); $this->queryLinkBuilder = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\Query\\LinkBuilder', $this->search->getQuery()); }
/** * Determines whether filters have been applied to the query or not. * * @return string 1 if filters are applied, 0 if not (for use in templates) */ protected function isFiltered() { $filters = $this->search->getQuery()->getFilters(); $filtered = !empty($filters); return $filtered ? '1' : '0'; }