|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the TYPO3 CMS project. |
|
5
|
|
|
* |
|
6
|
|
|
* It is free software; you can redistribute it and/or modify it under |
|
7
|
|
|
* the terms of the GNU General Public License, either version 2 |
|
8
|
|
|
* of the License, or any later version. |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please read the |
|
11
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
12
|
|
|
* |
|
13
|
|
|
* The TYPO3 project - inspiring people to share! |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
namespace ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets; |
|
17
|
|
|
|
|
18
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSet; |
|
19
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
20
|
|
|
use TYPO3\CMS\Extbase\Object\ObjectManager; |
|
21
|
|
|
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Value object that represent the options facet. |
|
25
|
|
|
* |
|
26
|
|
|
* @author Frans Saris <[email protected]> |
|
27
|
|
|
* @author Timo Hund <[email protected]> |
|
28
|
|
|
*/ |
|
29
|
|
|
abstract class AbstractFacet |
|
30
|
|
|
{ |
|
31
|
|
|
const TYPE_ABSTRACT = 'abstract'; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* String |
|
35
|
|
|
* @var string |
|
36
|
|
|
*/ |
|
37
|
|
|
protected static string $type = self::TYPE_ABSTRACT; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* The resultSet where this facet belongs to. |
|
41
|
|
|
* |
|
42
|
|
|
* @var SearchResultSet |
|
43
|
|
|
*/ |
|
44
|
|
|
protected SearchResultSet $resultSet; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @var string |
|
48
|
|
|
*/ |
|
49
|
|
|
protected string $name; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @var string |
|
53
|
|
|
*/ |
|
54
|
|
|
protected string $field; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @var string |
|
58
|
|
|
*/ |
|
59
|
|
|
protected string $label; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @var array |
|
63
|
|
|
*/ |
|
64
|
|
|
protected array $configuration; |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @var bool |
|
68
|
|
|
*/ |
|
69
|
|
|
protected bool $isAvailable = false; |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @var bool |
|
73
|
|
|
*/ |
|
74
|
|
|
protected bool $isUsed = false; |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @var bool |
|
78
|
|
|
*/ |
|
79
|
|
|
protected bool $allRequirementsMet = true; |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @var ObjectManagerInterface |
|
83
|
|
|
*/ |
|
84
|
|
|
protected ObjectManagerInterface $objectManager; |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* AbstractFacet constructor. |
|
88
|
|
|
* |
|
89
|
|
|
* @param SearchResultSet $resultSet |
|
90
|
|
|
* @param string $name |
|
91
|
|
|
* @param string $field |
|
92
|
|
|
* @param string $label |
|
93
|
|
|
* @param array $configuration Facet configuration passed from typoscript |
|
94
|
|
|
* @param ObjectManager $objectManager |
|
95
|
|
|
*/ |
|
96
|
96 |
|
public function __construct( |
|
97
|
|
|
SearchResultSet $resultSet, |
|
98
|
|
|
string $name, |
|
99
|
|
|
string $field, |
|
100
|
|
|
string $label = '', |
|
101
|
|
|
array $configuration = [], |
|
102
|
|
|
ObjectManagerInterface $objectManager = null |
|
103
|
|
|
) { |
|
104
|
96 |
|
$this->resultSet = $resultSet; |
|
105
|
96 |
|
$this->name = $name; |
|
106
|
96 |
|
$this->field = $field; |
|
107
|
96 |
|
$this->label = $label; |
|
108
|
96 |
|
$this->configuration = $configuration; |
|
109
|
96 |
|
$this->objectManager = $objectManager ?? GeneralUtility::makeInstance(ObjectManager::class); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Get name |
|
114
|
|
|
* |
|
115
|
|
|
* @return string |
|
116
|
|
|
*/ |
|
117
|
61 |
|
public function getName(): string |
|
118
|
|
|
{ |
|
119
|
61 |
|
return $this->name; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Get solr field name |
|
124
|
|
|
* |
|
125
|
|
|
* @return string |
|
126
|
|
|
*/ |
|
127
|
|
|
public function getField(): string |
|
128
|
|
|
{ |
|
129
|
|
|
return $this->field; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* @param string $label |
|
134
|
|
|
*/ |
|
135
|
|
|
public function setLabel(string $label) |
|
136
|
|
|
{ |
|
137
|
|
|
$this->label = $label; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* @return string |
|
142
|
|
|
*/ |
|
143
|
21 |
|
public function getLabel(): string |
|
144
|
|
|
{ |
|
145
|
21 |
|
return $this->label; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* @param bool $isAvailable |
|
150
|
|
|
*/ |
|
151
|
58 |
|
public function setIsAvailable(bool $isAvailable) |
|
152
|
|
|
{ |
|
153
|
58 |
|
$this->isAvailable = $isAvailable; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* @return bool |
|
158
|
|
|
*/ |
|
159
|
20 |
|
public function getIsAvailable(): bool |
|
160
|
|
|
{ |
|
161
|
20 |
|
return $this->isAvailable; |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* @param bool $isUsed |
|
166
|
|
|
*/ |
|
167
|
64 |
|
public function setIsUsed(bool $isUsed) |
|
168
|
|
|
{ |
|
169
|
64 |
|
$this->isUsed = $isUsed; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* @return bool |
|
174
|
|
|
*/ |
|
175
|
34 |
|
public function getIsUsed(): bool |
|
176
|
|
|
{ |
|
177
|
34 |
|
return $this->isUsed; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* @return string |
|
182
|
|
|
*/ |
|
183
|
17 |
|
public function getType(): string |
|
184
|
|
|
{ |
|
185
|
17 |
|
return static::$type; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* @return bool |
|
190
|
|
|
*/ |
|
191
|
20 |
|
public function getAllRequirementsMet(): bool |
|
192
|
|
|
{ |
|
193
|
20 |
|
return $this->allRequirementsMet; |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
/** |
|
197
|
|
|
* @param bool $allRequirementsMet |
|
198
|
|
|
*/ |
|
199
|
43 |
|
public function setAllRequirementsMet(bool $allRequirementsMet) |
|
200
|
|
|
{ |
|
201
|
43 |
|
$this->allRequirementsMet = $allRequirementsMet; |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* @return SearchResultSet |
|
206
|
|
|
*/ |
|
207
|
30 |
|
public function getResultSet(): SearchResultSet |
|
208
|
|
|
{ |
|
209
|
30 |
|
return $this->resultSet; |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
/** |
|
213
|
|
|
* Get configuration |
|
214
|
|
|
* |
|
215
|
|
|
* @return array |
|
216
|
|
|
*/ |
|
217
|
2 |
|
public function getConfiguration(): array |
|
218
|
|
|
{ |
|
219
|
2 |
|
return $this->configuration; |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
/** |
|
223
|
|
|
* Get facet partial name used for rendering the facet |
|
224
|
|
|
* |
|
225
|
|
|
* @return string |
|
226
|
|
|
*/ |
|
227
|
|
|
public function getPartialName(): string |
|
228
|
|
|
{ |
|
229
|
|
|
return 'Default'; |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
/** |
|
233
|
|
|
* @return string |
|
234
|
|
|
*/ |
|
235
|
20 |
|
public function getGroupName(): string |
|
236
|
|
|
{ |
|
237
|
20 |
|
return $this->configuration['groupName'] ?? 'main'; |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
/** |
|
241
|
|
|
* Indicates if this facet should be included in the available facets. When nothing is configured, |
|
242
|
|
|
* the method return TRUE. |
|
243
|
|
|
* |
|
244
|
|
|
* @return bool |
|
245
|
|
|
*/ |
|
246
|
24 |
|
public function getIncludeInAvailableFacets(): bool |
|
247
|
|
|
{ |
|
248
|
24 |
|
return ((int)$this->getFacetSettingOrDefaultValue('includeInAvailableFacets', 1)) === 1; |
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
|
|
/** |
|
252
|
|
|
* Indicates if these facets should be included in the used facets. When nothing is configured, |
|
253
|
|
|
* the methods returns true. |
|
254
|
|
|
* |
|
255
|
|
|
* @return bool |
|
256
|
|
|
*/ |
|
257
|
6 |
|
public function getIncludeInUsedFacets(): bool |
|
258
|
|
|
{ |
|
259
|
6 |
|
return ((int)$this->getFacetSettingOrDefaultValue('includeInUsedFacets', 1)) === 1; |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
|
|
/** |
|
263
|
|
|
* Returns the configured requirements |
|
264
|
|
|
* |
|
265
|
|
|
* @return array |
|
266
|
|
|
*/ |
|
267
|
51 |
|
public function getRequirements(): array |
|
268
|
|
|
{ |
|
269
|
51 |
|
return $this->getFacetSettingOrDefaultValue('requirements.', []); |
|
270
|
|
|
} |
|
271
|
|
|
|
|
272
|
|
|
/** |
|
273
|
|
|
* The implementation of this method should return a "flatten" collection of all items. |
|
274
|
|
|
* |
|
275
|
|
|
* @return AbstractFacetItemCollection |
|
276
|
|
|
*/ |
|
277
|
|
|
abstract public function getAllFacetItems(): AbstractFacetItemCollection; |
|
278
|
|
|
|
|
279
|
|
|
/** |
|
280
|
|
|
* @param string $key |
|
281
|
|
|
* @param mixed $defaultValue |
|
282
|
|
|
* @return mixed |
|
283
|
|
|
*/ |
|
284
|
56 |
|
protected function getFacetSettingOrDefaultValue(string $key, $defaultValue) |
|
285
|
|
|
{ |
|
286
|
56 |
|
if (!isset($this->configuration[$key])) { |
|
287
|
44 |
|
return $defaultValue; |
|
288
|
|
|
} |
|
289
|
|
|
|
|
290
|
17 |
|
return $this->configuration[$key]; |
|
291
|
|
|
} |
|
292
|
|
|
} |
|
293
|
|
|
|