/** * The main entry point of this class * It will return the complete sorting HTML * * @return string HTML */ public function renderSorting() { // show sorting: // if show Sorting is activated in FlexForm // if a value to sortBy is set in FlexForm (title, relevance, sortdate, what ever...) // if there are any entries in current search results if ($this->conf['showSortInFrontend'] && !empty($this->conf['sortByVisitor']) && $this->pObj->numberOfResults) { // loop all allowed orderings foreach ($this->sortBy as $field) { // we can't sort by score if there is no sword given if ($this->pObj->sword != '' || $field != 'score') { $sortByDir = $this->getDefaultSortingDirection($field); if (TYPO3_VERSION_INTEGER >= 7000000) { $dbOrdering = TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(' ', $this->db->getOrdering()); } else { $dbOrdering = t3lib_div::trimExplode(' ', $this->db->getOrdering()); } /* if ordering direction is the same change it * * Explaintation: * No ordering is active. Default Ordering by db is "sortdate desc". * Default ordering by current field is also "sortdate desc". * So...if you click the link for sortdate it will sort the results by "sortdate desc" again * To prevent this we change the default ordering here */ if ($field == $dbOrdering[0] && $sortByDir == $dbOrdering[1]) { $sortByDir = $this->changeOrdering($sortByDir); } $markerArray['###FIELDNAME###'] = $field; $markerArray['###URL###'] = $this->generateSortingLink($field, $sortByDir); $markerArray['###CLASS###'] = $this->getClassNameForUpDownArrow($field, $dbOrdering); $links .= $this->cObj->substituteMarkerArray($this->subpartArray['###SORT_LINK###'], $markerArray); } } $content = $this->cObj->substituteSubpart($this->subpartArray['###ORDERNAVIGATION###'], '###SORT_LINK###', $links); $content = $this->cObj->substituteMarker($content, '###LABEL_SORT###', $this->pObj->pi_getLL('label_sort')); return $content; } else { return ''; } }
/** * Test ordering if a searchword was given * - show sorting in FE is allowed * - admin presorts are uninteresting * - FE-User is allowed to choose between sortdate,tstamp and title * - allowed piVars are given * * @test */ public function checkOrderingWithSearchwordAndUserCanSortWithAllowedPiVars() { $this->pObj->sword = 'Hallo'; $this->pObj->conf = array('sortWithoutSearchword' => 'tstamp asc', 'showSortInFrontend' => true, 'sortByVisitor' => 'sortdate,tstamp,title', 'sortByAdmin' => 'sortdate desc'); $this->pObj->piVars = array('orderByField' => 'title', 'orderByDir' => 'asc'); $this->pObj->piVars = $this->div->cleanPiVars($this->pObj->piVars); $db = new tx_kesearch_db($this->pObj); $this->assertEquals('title asc', $db->getOrdering()); }