Ejemplo n.º 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('ApacheSolrForTypo3\\Solr\\Sorting', $this->configuration->getValueByPathOrDefaultValue('plugin.tx_solr.search.sorting.options.', array()));
     $configuredSortOptions = $sortHelper->getSortOptions();
     $sortParameters = array();
     foreach ($sortOptions as $sortOption) {
         if (isset($configuredSortOptions[$sortOption])) {
             $sortDirection = $this->configuration->getValueByPathOrDefaultValue('plugin.tx_solr.search.sorting.defaultOrder', 'asc');
             if (isset($configuredSortOptions[$sortOption]['fixedOrder'])) {
                 $sortDirection = $configuredSortOptions[$sortOption]['fixedOrder'];
             } elseif (isset($configuredSortOptions[$sortOption]['defaultOrder'])) {
                 $sortDirection = $configuredSortOptions[$sortOption]['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;
                 }
                 $fixedOrder = $this->configuration->getValueByPath('plugin.tx_solr.search.sorting.options.' . $sortOption . '.fixedOrder');
                 if (!is_null($fixedOrder)) {
                     $sortDirection = $fixedOrder;
                 }
                 $sortParameter = $sortOption . ' ' . $sortDirection;
             }
             $sortParameters[] = $sortParameter;
         }
     }
     $sortUrl = $this->queryLinkBuilder->getQueryUrl(array('sort' => implode(', ', $sortParameters)));
     return $sortUrl;
 }
 /**
  * @test
  */
 public function canGetValueByPath()
 {
     $testPath = 'plugin.tx_solr.index.queue.tt_news.fields.content';
     $this->assertSame('SOLR_CONTENT', $this->configuration->getValueByPath($testPath), 'Could not get configuration value by path');
 }