1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the TYPO3 CMS project. |
7
|
|
|
* |
8
|
|
|
* It is free software; you can redistribute it and/or modify it under |
9
|
|
|
* the terms of the GNU General Public License, either version 2 |
10
|
|
|
* of the License, or any later version. |
11
|
|
|
* |
12
|
|
|
* For the full copyright and license information, please read the |
13
|
|
|
* LICENSE.txt file that was distributed with this source code. |
14
|
|
|
* |
15
|
|
|
* The TYPO3 project - inspiring people to share! |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
namespace ApacheSolrForTypo3\Solr\Domain\Search; |
19
|
|
|
|
20
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\UrlFacetContainer; |
21
|
|
|
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration; |
22
|
|
|
use ApacheSolrForTypo3\Solr\System\Util\ArrayAccessor; |
23
|
|
|
use TYPO3\CMS\Core\Utility\ArrayUtility; |
24
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* The searchRequest is used to act as an api to the arguments that have been passed |
28
|
|
|
* with GET and POST. |
29
|
|
|
* |
30
|
|
|
* @author Timo Schmidt <[email protected]> |
31
|
|
|
*/ |
32
|
|
|
class SearchRequest |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* The default plugin namespace. |
36
|
|
|
* |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
const DEFAULT_PLUGIN_NAMESPACE = 'tx_solr'; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
protected string $id; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Default namespace overwritten with the configured plugin namespace. |
48
|
|
|
* |
49
|
|
|
* @var string |
50
|
|
|
*/ |
51
|
|
|
protected string $argumentNameSpace = self::DEFAULT_PLUGIN_NAMESPACE; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Arguments that should be kept for sub requests. |
55
|
|
|
* |
56
|
|
|
* Default values, overwritten in the constructor with the namespaced arguments |
57
|
|
|
* |
58
|
|
|
* @var array |
59
|
|
|
*/ |
60
|
|
|
protected array $persistentArgumentsPaths = [ |
61
|
|
|
'tx_solr:q', |
62
|
|
|
'tx_solr:filter', |
63
|
|
|
'tx_solr:sort', |
64
|
|
|
]; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @var bool |
68
|
|
|
*/ |
69
|
|
|
protected bool $stateChanged = false; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @var ArrayAccessor|null |
73
|
|
|
*/ |
74
|
|
|
protected ?ArrayAccessor $argumentsAccessor = null; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* The sys_language_uid that was used in the context where the request was build. |
78
|
|
|
* This could be different from the "L" parameter and not relevant for urls, |
79
|
|
|
* because typolink itself will handle it. |
80
|
|
|
* |
81
|
|
|
* @var int |
82
|
|
|
*/ |
83
|
|
|
protected int $contextSystemLanguageUid = 0; |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* The page_uid that was used in the context where the request was build. |
87
|
|
|
* |
88
|
|
|
* The pageUid is not relevant for the typolink additionalArguments and therefore |
89
|
|
|
* a separate property. |
90
|
|
|
* |
91
|
|
|
* @var int |
92
|
|
|
*/ |
93
|
|
|
protected int $contextPageUid; |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @var TypoScriptConfiguration|null |
97
|
|
|
*/ |
98
|
|
|
protected ?TypoScriptConfiguration $contextTypoScriptConfiguration; |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Container for all active facets inside the URL(TYPO3/FE) |
102
|
|
|
* |
103
|
|
|
* @var UrlFacetContainer|null |
104
|
|
|
*/ |
105
|
|
|
protected ?UrlFacetContainer $activeFacetContainer; |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @var array |
109
|
|
|
*/ |
110
|
|
|
protected array $persistedArguments = []; |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @param array $argumentsArray |
114
|
|
|
* @param int $pageUid |
115
|
|
|
* @param int $sysLanguageUid |
116
|
|
|
* @param TypoScriptConfiguration|null $typoScriptConfiguration |
117
|
104 |
|
*/ |
118
|
|
|
public function __construct( |
119
|
|
|
array $argumentsArray = [], |
120
|
|
|
int $pageUid = 0, |
121
|
|
|
int $sysLanguageUid = 0, |
122
|
|
|
TypoScriptConfiguration $typoScriptConfiguration = null |
123
|
104 |
|
) { |
124
|
104 |
|
$this->stateChanged = true; |
125
|
104 |
|
$this->persistedArguments = $argumentsArray; |
126
|
104 |
|
$this->contextPageUid = $pageUid; |
127
|
104 |
|
$this->contextSystemLanguageUid = $sysLanguageUid; |
128
|
104 |
|
$this->contextTypoScriptConfiguration = $typoScriptConfiguration; |
129
|
|
|
$this->id = spl_object_hash($this); |
130
|
|
|
|
131
|
104 |
|
// overwrite the plugin namespace and the persistentArgumentsPaths |
132
|
54 |
|
if (!is_null($typoScriptConfiguration)) { |
133
|
|
|
$this->argumentNameSpace = $typoScriptConfiguration->getSearchPluginNamespace() ?? self::DEFAULT_PLUGIN_NAMESPACE; |
134
|
|
|
} |
135
|
104 |
|
|
136
|
|
|
$this->persistentArgumentsPaths = [$this->argumentNameSpace . ':q', $this->argumentNameSpace . ':filter', $this->argumentNameSpace . ':sort', $this->argumentNameSpace . ':groupPage']; |
137
|
104 |
|
|
138
|
54 |
|
if (!is_null($typoScriptConfiguration)) { |
139
|
54 |
|
$additionalPersistentArgumentsNames = $typoScriptConfiguration->getSearchAdditionalPersistentArgumentNames(); |
140
|
|
|
foreach ($additionalPersistentArgumentsNames ?? [] as $additionalPersistentArgumentsName) { |
141
|
|
|
$this->persistentArgumentsPaths[] = $this->argumentNameSpace . ':' . $additionalPersistentArgumentsName; |
142
|
54 |
|
} |
143
|
|
|
$this->persistentArgumentsPaths = array_unique($this->persistentArgumentsPaths); |
144
|
|
|
} |
145
|
104 |
|
|
146
|
|
|
$this->reset(); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @return string |
151
|
21 |
|
*/ |
152
|
|
|
public function getId(): string |
153
|
21 |
|
{ |
154
|
|
|
return $this->id; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Can be used do merge arguments into the request arguments |
159
|
|
|
* |
160
|
|
|
* @param array $argumentsToMerge |
161
|
|
|
* @return SearchRequest |
162
|
1 |
|
*/ |
163
|
|
|
public function mergeArguments(array $argumentsToMerge): SearchRequest |
164
|
1 |
|
{ |
165
|
1 |
|
ArrayUtility::mergeRecursiveWithOverrule( |
166
|
1 |
|
$this->persistedArguments, |
167
|
1 |
|
$argumentsToMerge |
168
|
|
|
); |
169
|
1 |
|
|
170
|
|
|
$this->reset(); |
171
|
1 |
|
|
172
|
|
|
return $this; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Helper method to prefix an accessor with the argument's namespace. |
177
|
|
|
* |
178
|
|
|
* @param string $path |
179
|
|
|
* @return string |
180
|
78 |
|
*/ |
181
|
|
|
protected function prefixWithNamespace(string $path): string |
182
|
78 |
|
{ |
183
|
|
|
return $this->argumentNameSpace . ':' . $path; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* @return array |
188
|
2 |
|
*/ |
189
|
|
|
public function getActiveFacetNames(): array |
190
|
2 |
|
{ |
191
|
|
|
return $this->activeFacetContainer->getActiveFacetNames(); |
|
|
|
|
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Returns all facet values for a certain facetName |
196
|
|
|
* @param string $facetName |
197
|
|
|
* @return array |
198
|
18 |
|
*/ |
199
|
|
|
public function getActiveFacetValuesByName(string $facetName): array |
200
|
18 |
|
{ |
201
|
|
|
return $this->activeFacetContainer->getActiveFacetValuesByName($facetName); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* @return array |
206
|
|
|
*/ |
207
|
|
|
public function getActiveFacets(): array |
208
|
|
|
{ |
209
|
|
|
return $this->activeFacetContainer->getActiveFacets(); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* Enable sorting of URL parameters |
214
|
|
|
* @noinspection PhpUnused |
215
|
|
|
*/ |
216
|
|
|
public function sortActiveFacets(): void |
217
|
|
|
{ |
218
|
|
|
$this->activeFacetContainer->enableSort(); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* @return bool |
223
|
23 |
|
*/ |
224
|
|
|
public function isActiveFacetsSorted(): bool |
225
|
23 |
|
{ |
226
|
|
|
return $this->activeFacetContainer->isSorted(); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* @return string |
231
|
|
|
*/ |
232
|
|
|
public function getActiveFacetsUrlParameterStyle(): string |
233
|
|
|
{ |
234
|
|
|
return $this->activeFacetContainer->getParameterStyle(); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* Returns the active count of facets |
239
|
|
|
* |
240
|
|
|
* @return int |
241
|
2 |
|
*/ |
242
|
|
|
public function getActiveFacetCount(): int |
243
|
2 |
|
{ |
244
|
|
|
return $this->activeFacetContainer->count(); |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* @param array $activeFacets |
249
|
|
|
* |
250
|
|
|
* @return SearchRequest |
251
|
|
|
* @noinspection PhpUnused |
252
|
|
|
*/ |
253
|
|
|
protected function setActiveFacets(array $activeFacets = []): SearchRequest |
254
|
|
|
{ |
255
|
|
|
$this->activeFacetContainer->setActiveFacets($activeFacets); |
256
|
|
|
|
257
|
|
|
return $this; |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* Adds a facet value to the request. |
262
|
|
|
* |
263
|
|
|
* @param string $facetName |
264
|
|
|
* @param mixed $facetValue |
265
|
|
|
* |
266
|
|
|
* @return SearchRequest |
267
|
25 |
|
*/ |
268
|
|
|
public function addFacetValue(string $facetName, $facetValue): SearchRequest |
269
|
25 |
|
{ |
270
|
|
|
$this->activeFacetContainer->addFacetValue($facetName, $facetValue); |
271
|
25 |
|
|
272
|
24 |
|
if ($this->activeFacetContainer->hasChanged()) { |
273
|
24 |
|
$this->stateChanged = true; |
274
|
|
|
$this->activeFacetContainer->acknowledgeChange(); |
275
|
|
|
} |
276
|
25 |
|
|
277
|
|
|
return $this; |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* Removes a facet value from the request. |
282
|
|
|
* |
283
|
|
|
* @param string $facetName |
284
|
|
|
* @param mixed $facetValue |
285
|
|
|
* |
286
|
|
|
* @return SearchRequest |
287
|
6 |
|
*/ |
288
|
|
|
public function removeFacetValue(string $facetName, $facetValue): SearchRequest |
289
|
6 |
|
{ |
290
|
6 |
|
$this->activeFacetContainer->removeFacetValue($facetName, $facetValue); |
291
|
6 |
|
if ($this->activeFacetContainer->hasChanged()) { |
292
|
6 |
|
$this->stateChanged = true; |
293
|
|
|
$this->activeFacetContainer->acknowledgeChange(); |
294
|
|
|
} |
295
|
6 |
|
|
296
|
|
|
return $this; |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
/** |
300
|
|
|
* Removes all facet values from the request by a certain facet name |
301
|
|
|
* |
302
|
|
|
* @param string $facetName |
303
|
|
|
* |
304
|
|
|
* @return SearchRequest |
305
|
3 |
|
*/ |
306
|
|
|
public function removeAllFacetValuesByName(string $facetName): SearchRequest |
307
|
3 |
|
{ |
308
|
3 |
|
$this->activeFacetContainer->removeAllFacetValuesByName($facetName); |
309
|
3 |
|
if ($this->activeFacetContainer->hasChanged()) { |
310
|
3 |
|
$this->stateChanged = true; |
311
|
|
|
$this->activeFacetContainer->acknowledgeChange(); |
312
|
3 |
|
} |
313
|
|
|
return $this; |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
/** |
317
|
|
|
* Removes all active facets from the request. |
318
|
|
|
* |
319
|
|
|
* @return SearchRequest |
320
|
6 |
|
*/ |
321
|
|
|
public function removeAllFacets(): SearchRequest |
322
|
6 |
|
{ |
323
|
6 |
|
$this->activeFacetContainer->removeAllFacets(); |
324
|
6 |
|
if ($this->activeFacetContainer->hasChanged()) { |
325
|
6 |
|
$this->stateChanged = true; |
326
|
|
|
$this->activeFacetContainer->acknowledgeChange(); |
327
|
6 |
|
} |
328
|
|
|
return $this; |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
/** |
332
|
|
|
* Check if an active facet has a given value |
333
|
|
|
* |
334
|
|
|
* @param string $facetName |
335
|
|
|
* @param mixed $facetValue |
336
|
|
|
* @return bool |
337
|
2 |
|
*/ |
338
|
|
|
public function getHasFacetValue(string $facetName, $facetValue): bool |
339
|
2 |
|
{ |
340
|
|
|
return $this->activeFacetContainer->hasFacetValue($facetName, $facetValue); |
341
|
|
|
} |
342
|
|
|
|
343
|
|
|
/** |
344
|
|
|
* Returns all sortings in the sorting string e.g. ['title' => 'asc', 'relevance' => 'desc'] |
345
|
44 |
|
* |
346
|
|
|
* @return array |
347
|
44 |
|
*/ |
348
|
44 |
|
public function getSeperatedSortings(): array |
349
|
|
|
{ |
350
|
|
|
$parsedSortings = []; |
351
|
|
|
$explodedSortings = GeneralUtility::trimExplode(',', $this->getSorting()); |
352
|
|
|
|
353
|
|
|
foreach ($explodedSortings as $sorting) { |
354
|
|
|
$sortingSeperated = explode(' ', $sorting); |
355
|
|
|
$parsedSortings[$sortingSeperated[0]] = $sortingSeperated[1]; |
356
|
43 |
|
} |
357
|
|
|
|
358
|
43 |
|
return $parsedSortings; |
359
|
43 |
|
} |
360
|
|
|
|
361
|
|
|
/** |
362
|
|
|
* @return bool |
363
|
|
|
*/ |
364
|
|
|
public function getHasSorting(): bool |
365
|
|
|
{ |
366
|
|
|
$path = $this->prefixWithNamespace('sort'); |
367
|
|
|
return $this->argumentsAccessor->has($path); |
|
|
|
|
368
|
43 |
|
} |
369
|
|
|
|
370
|
43 |
|
/** |
371
|
43 |
|
* Returns the sorting string in the url e.g. title asc. |
372
|
41 |
|
* |
373
|
|
|
* @return string |
374
|
|
|
*/ |
375
|
2 |
|
public function getSorting(): string |
376
|
2 |
|
{ |
377
|
|
|
$path = $this->prefixWithNamespace('sort'); |
378
|
|
|
return $this->argumentsAccessor->get($path, ''); |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
/** |
382
|
|
|
* Helper function to get the sorting configuration name or direction. |
383
|
|
|
* |
384
|
43 |
|
* @param int $index |
385
|
|
|
* @return string |
386
|
43 |
|
*/ |
387
|
|
|
protected function getSortingPart(int $index): ?string |
388
|
|
|
{ |
389
|
|
|
$sorting = $this->getSorting(); |
390
|
|
|
if ($sorting === '') { |
391
|
|
|
return null; |
392
|
|
|
} |
393
|
|
|
|
394
|
42 |
|
$parts = explode(' ', $sorting); |
395
|
|
|
return $parts[$index] ?? null; |
396
|
42 |
|
} |
397
|
|
|
|
398
|
|
|
/** |
399
|
|
|
* Returns the sorting configuration name that is currently used. |
400
|
|
|
* |
401
|
|
|
* @return string |
402
|
1 |
|
*/ |
403
|
|
|
public function getSortingName(): ?string |
404
|
1 |
|
{ |
405
|
1 |
|
return $this->getSortingPart(0); |
406
|
1 |
|
} |
407
|
1 |
|
|
408
|
|
|
/** |
409
|
|
|
* Returns the sorting direction that is currently used. |
410
|
|
|
* |
411
|
|
|
* @return string |
412
|
|
|
*/ |
413
|
|
|
public function getSortingDirection(): string |
414
|
|
|
{ |
415
|
|
|
return mb_strtolower($this->getSortingPart(1) ?? ''); |
416
|
2 |
|
} |
417
|
|
|
|
418
|
2 |
|
/** |
419
|
2 |
|
* @return SearchRequest |
420
|
2 |
|
*/ |
421
|
2 |
|
public function removeSorting(): SearchRequest |
422
|
2 |
|
{ |
423
|
|
|
$path = $this->prefixWithNamespace('sort'); |
424
|
|
|
$this->argumentsAccessor->reset($path); |
425
|
|
|
$this->stateChanged = true; |
426
|
|
|
return $this; |
427
|
|
|
} |
428
|
|
|
|
429
|
|
|
/** |
430
|
|
|
* @param string $sortingName |
431
|
6 |
|
* @param string $direction (asc or desc) |
432
|
|
|
* |
433
|
6 |
|
* @return SearchRequest |
434
|
6 |
|
*/ |
435
|
6 |
|
public function setSorting(string $sortingName, string $direction = 'asc'): SearchRequest |
436
|
|
|
{ |
437
|
6 |
|
$value = $sortingName . ' ' . $direction; |
438
|
4 |
|
$path = $this->prefixWithNamespace('sort'); |
439
|
|
|
$this->argumentsAccessor->set($path, $value); |
440
|
6 |
|
$this->stateChanged = true; |
441
|
|
|
return $this; |
442
|
|
|
} |
443
|
|
|
|
444
|
|
|
/** |
445
|
|
|
* Method to set the paginated page of the search |
446
|
|
|
* |
447
|
|
|
* @param int $page |
448
|
52 |
|
* @return SearchRequest |
449
|
|
|
*/ |
450
|
52 |
|
public function setPage(int $page): SearchRequest |
451
|
52 |
|
{ |
452
|
|
|
$this->stateChanged = true; |
453
|
|
|
$path = $this->prefixWithNamespace('page'); |
454
|
|
|
$this->argumentsAccessor->set($path, $page); |
455
|
|
|
// use initial url by switching back to page 0 |
456
|
|
|
if ($page === 0) { |
457
|
|
|
$this->argumentsAccessor->reset($path); |
458
|
|
|
} |
459
|
23 |
|
return $this; |
460
|
|
|
} |
461
|
23 |
|
|
462
|
23 |
|
/** |
463
|
|
|
* Returns the passed page. |
464
|
23 |
|
* |
465
|
|
|
* @return int|null |
466
|
|
|
*/ |
467
|
|
|
public function getPage(): ?int |
468
|
|
|
{ |
469
|
|
|
$path = $this->prefixWithNamespace('page'); |
470
|
|
|
return $this->argumentsAccessor->get($path); |
471
|
|
|
} |
472
|
|
|
|
473
|
|
|
/** |
474
|
|
|
* Can be used to reset all groupPages. |
475
|
4 |
|
* |
476
|
|
|
* @return SearchRequest |
477
|
4 |
|
*/ |
478
|
4 |
|
public function removeAllGroupItemPages(): SearchRequest |
479
|
4 |
|
{ |
480
|
4 |
|
$path = $this->prefixWithNamespace('groupPage'); |
481
|
4 |
|
$this->argumentsAccessor->reset($path); |
482
|
|
|
|
483
|
|
|
return $this; |
484
|
|
|
} |
485
|
|
|
|
486
|
|
|
/** |
487
|
|
|
* Can be used to paginate within a groupItem. |
488
|
|
|
* |
489
|
|
|
* @param string $groupName e.g. type |
490
|
|
|
* @param string $groupItemValue e.g. pages |
491
|
3 |
|
* @param int $page |
492
|
|
|
* @return SearchRequest |
493
|
3 |
|
*/ |
494
|
3 |
|
public function setGroupItemPage(string $groupName, string $groupItemValue, int $page): SearchRequest |
495
|
3 |
|
{ |
496
|
|
|
$this->stateChanged = true; |
497
|
|
|
$escapedValue = $this->getEscapedGroupItemValue($groupItemValue); |
498
|
|
|
$path = $this->prefixWithNamespace('groupPage:' . $groupName . ':' . $escapedValue); |
499
|
|
|
$this->argumentsAccessor->set($path, $page); |
500
|
|
|
return $this; |
501
|
|
|
} |
502
|
|
|
|
503
|
|
|
/** |
504
|
5 |
|
* Retrieves the current page for this group item. |
505
|
|
|
* |
506
|
5 |
|
* @param string $groupName |
507
|
|
|
* @param string $groupItemValue |
508
|
|
|
* @return int |
509
|
|
|
*/ |
510
|
|
|
public function getGroupItemPage(string $groupName, string $groupItemValue): int |
511
|
|
|
{ |
512
|
|
|
$escapedValue = $this->getEscapedGroupItemValue($groupItemValue); |
513
|
|
|
$path = $this->prefixWithNamespace('groupPage:' . $groupName . ':' . $escapedValue); |
514
|
1 |
|
return max(1, (int)$this->argumentsAccessor->get($path)); |
515
|
|
|
} |
516
|
1 |
|
|
517
|
1 |
|
/** |
518
|
1 |
|
* Removes all non-alphanumeric values from the groupItem value to have a valid array key. |
519
|
1 |
|
* |
520
|
|
|
* @param string $groupItemValue |
521
|
|
|
* @return string |
522
|
|
|
*/ |
523
|
|
|
protected function getEscapedGroupItemValue(string $groupItemValue): string |
524
|
|
|
{ |
525
|
|
|
return preg_replace('/[^A-Za-z0-9]/', '', $groupItemValue); |
526
|
|
|
} |
527
|
|
|
|
528
|
|
|
/** |
529
|
|
|
* Retrieves the highest page of the groups. |
530
|
1 |
|
* |
531
|
|
|
* @return int |
532
|
|
|
*/ |
533
|
|
|
public function getHighestGroupPage(): int |
534
|
|
|
{ |
535
|
|
|
$max = 1; |
536
|
|
|
$path = $this->prefixWithNamespace('groupPage'); |
537
|
|
|
$groupPages = $this->argumentsAccessor->get($path, []); |
538
|
|
|
foreach ($groupPages as $groups) { |
539
|
17 |
|
if (!is_array($groups)) { |
540
|
|
|
continue; |
541
|
17 |
|
} |
542
|
17 |
|
foreach ($groups as $groupItemPage) { |
543
|
17 |
|
if ((int)$groupItemPage > $max) { |
544
|
17 |
|
$max = (int)$groupItemPage; |
545
|
|
|
} |
546
|
|
|
} |
547
|
|
|
} |
548
|
|
|
|
549
|
|
|
return $max; |
550
|
|
|
} |
551
|
|
|
|
552
|
44 |
|
/** |
553
|
|
|
* Method to overwrite the query string. |
554
|
44 |
|
* |
555
|
44 |
|
* @param string $rawQueryString |
556
|
44 |
|
* @return SearchRequest |
557
|
|
|
*/ |
558
|
|
|
public function setRawQueryString(string $rawQueryString = ''): SearchRequest |
559
|
|
|
{ |
560
|
|
|
$this->stateChanged = true; |
561
|
|
|
$path = $this->prefixWithNamespace('q'); |
562
|
|
|
$this->argumentsAccessor->set($path, $rawQueryString); |
563
|
|
|
return $this; |
564
|
|
|
} |
565
|
|
|
|
566
|
43 |
|
/** |
567
|
|
|
* Returns the passed rawQueryString. |
568
|
43 |
|
* |
569
|
43 |
|
* @return string |
570
|
|
|
*/ |
571
|
43 |
|
public function getRawUserQuery(): string |
572
|
3 |
|
{ |
573
|
|
|
$path = $this->prefixWithNamespace('q'); |
574
|
|
|
$query = $this->argumentsAccessor->get($path); |
575
|
40 |
|
return (string)($query ?? ''); |
576
|
2 |
|
} |
577
|
|
|
|
578
|
|
|
/** |
579
|
38 |
|
* Method to check if the query string is an empty string |
580
|
|
|
* (also empty string or whitespaces only are handled as empty). |
581
|
|
|
* |
582
|
|
|
* When no query string is set (null) the method returns false. |
583
|
|
|
* @return bool |
584
|
|
|
*/ |
585
|
|
|
public function getRawUserQueryIsEmptyString(): bool |
586
|
|
|
{ |
587
|
|
|
$path = $this->prefixWithNamespace('q'); |
588
|
49 |
|
$query = $this->argumentsAccessor->get($path); |
589
|
|
|
|
590
|
49 |
|
if ($query === null) { |
591
|
49 |
|
return false; |
592
|
49 |
|
} |
593
|
|
|
|
594
|
|
|
if (trim($query) === '') { |
595
|
|
|
return true; |
596
|
|
|
} |
597
|
|
|
|
598
|
|
|
return false; |
599
|
|
|
} |
600
|
|
|
|
601
|
50 |
|
/** |
602
|
|
|
* This method returns true when no querystring is present at all. |
603
|
50 |
|
* Which means no search by the user was triggered |
604
|
50 |
|
* |
605
|
50 |
|
* @return bool |
606
|
|
|
*/ |
607
|
50 |
|
public function getRawUserQueryIsNull(): bool |
608
|
|
|
{ |
609
|
|
|
$path = $this->prefixWithNamespace('q'); |
610
|
|
|
$query = $this->argumentsAccessor->get($path); |
611
|
|
|
return $query === null; |
612
|
|
|
} |
613
|
1 |
|
|
614
|
|
|
/** |
615
|
1 |
|
* Sets the results per page that are used during search. |
616
|
|
|
* |
617
|
|
|
* @param int $resultsPerPage |
618
|
|
|
* @return SearchRequest |
619
|
|
|
*/ |
620
|
|
|
public function setResultsPerPage(int $resultsPerPage): SearchRequest |
621
|
|
|
{ |
622
|
51 |
|
$path = $this->prefixWithNamespace('resultsPerPage'); |
623
|
|
|
$this->argumentsAccessor->set($path, $resultsPerPage); |
624
|
51 |
|
$this->stateChanged = true; |
625
|
51 |
|
|
626
|
|
|
return $this; |
627
|
|
|
} |
628
|
|
|
|
629
|
|
|
/** |
630
|
|
|
* @return bool |
631
|
|
|
*/ |
632
|
|
|
public function getStateChanged(): bool |
633
|
|
|
{ |
634
|
3 |
|
return $this->stateChanged; |
635
|
|
|
} |
636
|
3 |
|
|
637
|
3 |
|
/** |
638
|
3 |
|
* Returns the passed resultsPerPage value |
639
|
|
|
* @return int |
640
|
3 |
|
*/ |
641
|
|
|
public function getResultsPerPage(): int |
642
|
|
|
{ |
643
|
|
|
$path = $this->prefixWithNamespace('resultsPerPage'); |
644
|
|
|
return (int)$this->argumentsAccessor->get($path); |
645
|
|
|
} |
646
|
|
|
|
647
|
|
|
/** |
648
|
41 |
|
* Allows setting additional filters that are used on time and not transported during the request. |
649
|
|
|
* |
650
|
41 |
|
* @param array $additionalFilters |
651
|
41 |
|
* @return SearchRequest |
652
|
|
|
*/ |
653
|
|
|
public function setAdditionalFilters(array $additionalFilters): SearchRequest |
654
|
|
|
{ |
655
|
|
|
$path = $this->prefixWithNamespace('additionalFilters'); |
656
|
|
|
$this->argumentsAccessor->set($path, $additionalFilters); |
657
|
2 |
|
$this->stateChanged = true; |
658
|
|
|
|
659
|
2 |
|
return $this; |
660
|
|
|
} |
661
|
|
|
|
662
|
|
|
/** |
663
|
|
|
* Retrieves the additional filters that have been set |
664
|
|
|
* |
665
|
2 |
|
* @return array |
666
|
|
|
*/ |
667
|
2 |
|
public function getAdditionalFilters(): array |
668
|
|
|
{ |
669
|
|
|
$path = $this->prefixWithNamespace('additionalFilters'); |
670
|
|
|
return $this->argumentsAccessor->get($path, []); |
671
|
|
|
} |
672
|
|
|
|
673
|
|
|
/** |
674
|
|
|
* @return int |
675
|
54 |
|
*/ |
676
|
|
|
public function getContextSystemLanguageUid(): int |
677
|
54 |
|
{ |
678
|
|
|
return $this->contextSystemLanguageUid; |
679
|
|
|
} |
680
|
|
|
|
681
|
|
|
/** |
682
|
|
|
* @return int |
683
|
|
|
*/ |
684
|
|
|
public function getContextPageUid(): int |
685
|
104 |
|
{ |
686
|
|
|
return $this->contextPageUid; |
687
|
104 |
|
} |
688
|
104 |
|
|
689
|
104 |
|
/** |
690
|
104 |
|
* Get contextTypoScriptConfiguration |
691
|
104 |
|
* |
692
|
104 |
|
* @return TypoScriptConfiguration |
693
|
51 |
|
*/ |
694
|
104 |
|
public function getContextTypoScriptConfiguration(): ?TypoScriptConfiguration |
695
|
104 |
|
{ |
696
|
|
|
return $this->contextTypoScriptConfiguration; |
697
|
|
|
} |
698
|
|
|
|
699
|
104 |
|
/** |
700
|
104 |
|
* Assigns the last known persistedArguments and restores their state. |
701
|
|
|
* |
702
|
|
|
* @return SearchRequest |
703
|
|
|
*/ |
704
|
|
|
public function reset(): SearchRequest |
705
|
104 |
|
{ |
706
|
|
|
$this->argumentsAccessor = new ArrayAccessor($this->persistedArguments); |
707
|
|
|
$this->stateChanged = false; |
708
|
|
|
$this->activeFacetContainer = new UrlFacetContainer( |
709
|
|
|
$this->argumentsAccessor, |
710
|
|
|
$this->argumentNameSpace ?? self::DEFAULT_PLUGIN_NAMESPACE, |
711
|
|
|
$this->contextTypoScriptConfiguration === null ? |
712
|
|
|
UrlFacetContainer::PARAMETER_STYLE_INDEX : |
713
|
|
|
$this->contextTypoScriptConfiguration->getSearchFacetingUrlParameterStyle() |
714
|
39 |
|
); |
715
|
|
|
|
716
|
39 |
|
// If the default of sorting parameter should be true, a modification of this condition is needed. |
717
|
|
|
// If instance of contextTypoScriptConfiguration is not TypoScriptConfiguration the sort should be enabled too |
718
|
|
|
if ($this->contextTypoScriptConfiguration instanceof TypoScriptConfiguration |
719
|
|
|
&& $this->contextTypoScriptConfiguration->getSearchFacetingUrlParameterSort() |
720
|
|
|
) { |
721
|
|
|
$this->activeFacetContainer->enableSort(); |
722
|
|
|
} |
723
|
|
|
|
724
|
|
|
return $this; |
725
|
|
|
} |
726
|
|
|
|
727
|
39 |
|
/** |
728
|
39 |
|
* This can be used to start a new sub request, e.g. for a faceted search. |
729
|
39 |
|
* |
730
|
31 |
|
* @param bool $onlyPersistentArguments |
731
|
|
|
* @return SearchRequest |
732
|
|
|
*/ |
733
|
|
|
public function getCopyForSubRequest(bool $onlyPersistentArguments = true): SearchRequest |
734
|
39 |
|
{ |
735
|
39 |
|
if (!$onlyPersistentArguments) { |
736
|
39 |
|
// create a new request with all data |
737
|
39 |
|
$argumentsArray = $this->argumentsAccessor->getData(); |
738
|
39 |
|
return new SearchRequest( |
739
|
39 |
|
$argumentsArray, |
740
|
|
|
$this->contextPageUid, |
741
|
|
|
$this->contextSystemLanguageUid, |
742
|
|
|
$this->contextTypoScriptConfiguration |
743
|
|
|
); |
744
|
|
|
} |
745
|
|
|
|
746
|
22 |
|
$arguments = new ArrayAccessor(); |
747
|
|
|
foreach ($this->persistentArgumentsPaths as $persistentArgumentPath) { |
748
|
22 |
|
if ($this->argumentsAccessor->has($persistentArgumentPath)) { |
749
|
|
|
$arguments->set($persistentArgumentPath, $this->argumentsAccessor->get($persistentArgumentPath)); |
750
|
|
|
} |
751
|
|
|
} |
752
|
|
|
|
753
|
|
|
return new SearchRequest( |
754
|
43 |
|
$arguments->getData(), |
755
|
|
|
$this->contextPageUid, |
756
|
43 |
|
$this->contextSystemLanguageUid, |
757
|
|
|
$this->contextTypoScriptConfiguration |
758
|
|
|
); |
759
|
|
|
} |
760
|
|
|
|
761
|
|
|
/** |
762
|
|
|
* @return string |
763
|
|
|
* @noinspection PhpUnused |
764
|
17 |
|
*/ |
765
|
|
|
public function getArgumentNamespace(): string |
766
|
17 |
|
{ |
767
|
|
|
return $this->argumentNameSpace; |
768
|
|
|
} |
769
|
|
|
|
770
|
|
|
/** |
771
|
|
|
* @return array |
772
|
|
|
*/ |
773
|
|
|
public function getAsArray(): array |
774
|
|
|
{ |
775
|
|
|
return $this->argumentsAccessor->getData(); |
776
|
|
|
} |
777
|
|
|
|
778
|
|
|
/** |
779
|
|
|
* Returns only the arguments as array. |
780
|
|
|
* |
781
|
|
|
* @return array |
782
|
|
|
*/ |
783
|
|
|
public function getArguments(): array |
784
|
|
|
{ |
785
|
|
|
return $this->argumentsAccessor->get($this->argumentNameSpace) ?? []; |
786
|
|
|
} |
787
|
|
|
} |
788
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.