|
1
|
|
|
<?php |
|
2
|
|
|
namespace ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder; |
|
3
|
|
|
|
|
4
|
|
|
/*************************************************************** |
|
5
|
|
|
* Copyright notice |
|
6
|
|
|
* |
|
7
|
|
|
* (c) 2017 <[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 3 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
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* The Sorting ParameterProvider is responsible to build the solr query parameters |
|
31
|
|
|
* that are needed for the sorting. |
|
32
|
|
|
* |
|
33
|
|
|
* @package ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder |
|
34
|
|
|
*/ |
|
35
|
|
|
class Sorting extends AbstractDeactivatable |
|
36
|
|
|
{ |
|
37
|
|
|
const SORT_ASC = 'ASC'; |
|
38
|
|
|
const SORT_DESC = 'DESC'; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var string |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $fieldName = ''; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var string |
|
47
|
|
|
*/ |
|
48
|
|
|
protected $direction = self::SORT_ASC; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Debug constructor. |
|
52
|
|
|
* |
|
53
|
|
|
* @param bool $isEnabled |
|
54
|
|
|
* @param string $fieldName |
|
55
|
|
|
* @param string $direction |
|
56
|
|
|
*/ |
|
57
|
7 |
|
public function __construct($isEnabled = false, $fieldName = '', $direction = self::SORT_ASC) |
|
58
|
|
|
{ |
|
59
|
7 |
|
$this->isEnabled = $isEnabled; |
|
60
|
7 |
|
$this->setFieldName($fieldName); |
|
61
|
7 |
|
$this->setDirection($direction); |
|
62
|
7 |
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @return Sorting |
|
66
|
|
|
*/ |
|
67
|
|
|
public static function getEmpty() |
|
68
|
|
|
{ |
|
69
|
|
|
return new Sorting(false); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @return string |
|
74
|
|
|
*/ |
|
75
|
7 |
|
public function getFieldName(): string |
|
76
|
|
|
{ |
|
77
|
7 |
|
return $this->fieldName; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @param string $fieldName |
|
82
|
|
|
*/ |
|
83
|
7 |
|
public function setFieldName(string $fieldName) |
|
84
|
|
|
{ |
|
85
|
7 |
|
$this->fieldName = $fieldName; |
|
86
|
7 |
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @return string |
|
90
|
|
|
*/ |
|
91
|
7 |
|
public function getDirection(): string |
|
92
|
|
|
{ |
|
93
|
7 |
|
return $this->direction; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @param string $direction |
|
98
|
|
|
*/ |
|
99
|
7 |
|
public function setDirection(string $direction) |
|
100
|
|
|
{ |
|
101
|
7 |
|
$this->direction = $direction; |
|
102
|
7 |
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Parses a sorting representation "<fieldName> <direction>" |
|
106
|
|
|
* @param string $sortingString |
|
107
|
|
|
* @return Sorting |
|
108
|
|
|
*/ |
|
109
|
7 |
|
public static function fromString($sortingString) |
|
110
|
|
|
{ |
|
111
|
7 |
|
$parts = GeneralUtility::trimExplode(' ', $sortingString); |
|
112
|
7 |
|
return new Sorting(true, $parts[0], $parts[1]); |
|
113
|
|
|
} |
|
114
|
|
|
} |