|
1
|
|
|
<?php |
|
2
|
|
|
namespace ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets; |
|
3
|
|
|
|
|
4
|
|
|
/*************************************************************** |
|
5
|
|
|
* Copyright notice |
|
6
|
|
|
* |
|
7
|
|
|
* (c) 2017- Timo Hund <[email protected]> |
|
8
|
|
|
* All rights reserved |
|
9
|
|
|
* |
|
10
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
|
11
|
|
|
* free software; you can redistribute it and/or modify |
|
12
|
|
|
* it under the terms of the GNU General Public License as published by |
|
13
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
|
14
|
|
|
* (at your option) any later version. |
|
15
|
|
|
* |
|
16
|
|
|
* The GNU General Public License can be found at |
|
17
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
|
18
|
|
|
* |
|
19
|
|
|
* This script is distributed in the hope that it will be useful, |
|
20
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
21
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
22
|
|
|
* GNU General Public License for more details. |
|
23
|
|
|
* |
|
24
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
|
25
|
|
|
***************************************************************/ |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Expression for facet sorting |
|
29
|
|
|
* |
|
30
|
|
|
* @author Timo Hund <[email protected]> |
|
31
|
|
|
* @author Jens Jacobsen <[email protected]> |
|
32
|
|
|
* @package ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets |
|
33
|
|
|
*/ |
|
34
|
|
|
class SortingExpression |
|
35
|
|
|
{ |
|
36
|
|
|
/** |
|
37
|
|
|
* Return expression for facet sorting |
|
38
|
|
|
* |
|
39
|
|
|
* @param string $sorting |
|
40
|
|
|
* @return string |
|
41
|
|
|
*/ |
|
42
|
77 |
|
public function getForFacet($sorting) |
|
43
|
|
|
{ |
|
44
|
77 |
|
$noSortingSet = $sorting !== 0 && $sorting !== FALSE && empty($sorting); |
|
|
|
|
|
|
45
|
77 |
|
$sortingIsCount = $sorting === 'count' || $sorting === 1 || $sorting === '1' || $sorting === TRUE; |
|
|
|
|
|
|
46
|
77 |
|
if ($noSortingSet) { |
|
47
|
42 |
|
return ''; |
|
48
|
65 |
|
} elseif ($sortingIsCount) { |
|
49
|
43 |
|
return 'count'; |
|
50
|
|
|
} else { |
|
51
|
23 |
|
return 'index'; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Return expression for facet sorting combined with direction |
|
57
|
|
|
* |
|
58
|
|
|
* @param string $sorting |
|
59
|
|
|
* @param string $direction |
|
60
|
|
|
* @return string |
|
61
|
|
|
*/ |
|
62
|
24 |
|
public function getForJsonFacet($sorting, $direction) |
|
63
|
|
|
{ |
|
64
|
24 |
|
$expression = $this->getForFacet($sorting); |
|
65
|
24 |
|
$direction = strtolower($direction); |
|
66
|
24 |
|
if (!empty($direction) && in_array($direction, ['asc', 'desc'])) { |
|
67
|
16 |
|
$expression .= ' ' . $direction; |
|
68
|
|
|
} |
|
69
|
24 |
|
return $expression; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|