Passed
Pull Request — release-11.2.x (#3557)
by Markus
15:20 queued 12:06
created

getIndexQueueIndexingPriorityByConfigurationName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
namespace ApacheSolrForTypo3\Solr\System\Configuration;
3
4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
 * It is free software; you can redistribute it and/or modify it under
8
 * the terms of the GNU General Public License, either version 2
9
 * of the License, or any later version.
10
 *
11
 * For the full copyright and license information, please read the
12
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
 * The TYPO3 project - inspiring people to share!
15
 */
16
17
use ApacheSolrForTypo3\Solr\IndexQueue\Indexer;
18
use ApacheSolrForTypo3\Solr\IndexQueue\Initializer\Record;
19
use ApacheSolrForTypo3\Solr\System\ContentObject\ContentObjectService;
20
use ApacheSolrForTypo3\Solr\System\Util\ArrayAccessor;
21
use InvalidArgumentException;
22
use TYPO3\CMS\Core\Utility\ArrayUtility;
23
use TYPO3\CMS\Core\Utility\GeneralUtility;
24
25
/**
26
 * TypoScript configuration object, used to read all TypoScript configuration.
27
 *
28
 * The TypoScriptConfiguration was introduced in order to be able to replace the old,
29
 * array based configuration with one configuration object.
30
 *
31
 * To read the configuration, you should use
32
 *
33
 * $configuration->getValueByPath
34
 *
35
 * or
36
 *
37
 * $configuration->isValidPath
38
 *
39
 * to check if an configuration path exists.
40
 *
41
 * To ensure Backwards compatibility the TypoScriptConfiguration object implements the
42
 * ArrayAccess interface (offsetGet,offsetExists,offsetUnset and offsetSet)
43
 *
44
 * This was only introduced to be backwards compatible in logTerm only "getValueByPath", "isValidPath" or
45
 * speaking methods for configuration settings should be used!
46
 *
47
 * @author Marc Bastian Heinrichs <[email protected]>
48
 * @author Timo Schmidt <[email protected]>
49
 * @copyright (c) 2016 Timo Schmidt <[email protected]>
50
 */
51
class TypoScriptConfiguration
52
{
53
    /**
54
     * @var \ApacheSolrForTypo3\Solr\System\Util\ArrayAccessor|null
55
     */
56
    protected $configurationAccess = null;
57
58
    /**
59
     * Holds the pageId in which context the configuration was parsed
60
     * (normally $GLOBALS['TSFE']->id)
61
     */
62
    protected $contextPageId = 0;
63
64
    /**
65
     * @var ContentObjectService
66
     */
67
    protected $contentObjectService = null;
68
69
    /**
70
     * @param array $configuration
71
     * @param int $contextPageId
72
     * @param ContentObjectService $contentObjectService
73
     */
74 329
    public function __construct(array $configuration, $contextPageId = 0, ContentObjectService $contentObjectService = null)
75
    {
76 329
        $this->configurationAccess = new ArrayAccessor($configuration, '.', true);
77 329
        $this->contextPageId = $contextPageId;
78 329
        $this->contentObjectService = $contentObjectService;
79 329
    }
80
81
    /**
82
     * Checks if a value is 1, '1', 'true'
83
     * @param mixed $value
84
     * @return bool
85
     */
86 269
    protected function getBool($value)
87
    {
88 269
        return filter_var($value, FILTER_VALIDATE_BOOLEAN);
89
    }
90
91
    /**
92
     * This method can be used to only retrieve array keys where the value is not an array.
93
     *
94
     * This can be very handy in the configuration when only keys should ne taken into account
95
     * where the value is not a subconfiguration (typically an typoscript object path).
96
     *
97
     * @param $inputArray
98
     * @return array
99
     */
100 39
    protected function getOnlyArrayKeysWhereValueIsNotAnArray($inputArray)
101
    {
102 39
        $keysWithNonArrayValue = [];
103
104 39
        foreach ($inputArray as $key => $value) {
105 12
            if (is_array($value)) {
106
                // configuration for a content object, skipping
107 9
                continue;
108
            }
109
110 12
            $keysWithNonArrayValue[] = $key;
111
        }
112
113 39
        return $keysWithNonArrayValue;
114
    }
115
116
    /**
117
     * Gets the value from a given TypoScript path.
118
     *
119
     * In the context of an frontend content element the path plugin.tx_solr is
120
     * merged recursive with overrule with the content element specific typoscript
121
     * settings, like plugin.tx_solr_PiResults_Results, and possible flex form settings
122
     * (depends on the solr plugin).
123
     *
124
     * Example: plugin.tx_solr.search.targetPage
125
     * returns $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_solr.']['search.']['targetPage']
126
     *
127
     * @param string $path TypoScript path
128
     * @return mixed The TypoScript object defined by the given path
129
     * @throws InvalidArgumentException
130
     */
131 301
    public function getValueByPath($path)
132
    {
133 301
        if (!is_string($path)) {
0 ignored issues
show
introduced by
The condition is_string($path) is always true.
Loading history...
134
            throw new InvalidArgumentException('Parameter $path is not a string',
135
                1325623321);
136
        }
137 301
        return $this->configurationAccess->get($path);
0 ignored issues
show
Bug introduced by
The method get() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

137
        return $this->configurationAccess->/** @scrutinizer ignore-call */ get($path);

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.

Loading history...
138
    }
139
140
    /**
141
     * This method can be used to get  a configuration value by path if it exists or return a
142
     * default value when it does not exist.
143
     *
144
     * @param string $path
145
     * @param mixed $defaultValue
146
     * @return mixed
147
     */
148 298
    public function getValueByPathOrDefaultValue($path, $defaultValue)
149
    {
150 298
        $value = $this->getValueByPath($path);
151 298
        if (is_null($value)) {
152 287
            return $defaultValue;
153
        }
154
155 172
        return $value;
156
    }
157
158
    /**
159
     * Gets the parent TypoScript Object from a given TypoScript path.
160
     *
161
     * In the context of an frontend content element the path plugin.tx_solr is
162
     * merged recursive with overrule with the content element specific typoscript
163
     * settings, like plugin.tx_solr_PiResults_Results, and possible flex form settings
164
     * (depends on the solr plugin).
165
     *
166
     * Example: plugin.tx_solr.index.queue.tt_news.fields.content
167
     * returns $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_solr.']['index.']['queue.']['tt_news.']['fields.']['content.']
168
     * which is a SOLR_CONTENT cObj.
169
     *
170
     * @param string $path TypoScript path
171
     * @return array The TypoScript object defined by the given path
172
     * @throws InvalidArgumentException
173
     */
174 279
    public function getObjectByPath($path)
175
    {
176 279
        if (substr($path, -1) !== '.') {
177 1
            $path = rtrim($path, '.');
178 1
            $path = substr($path, 0, strrpos($path, '.') + 1);
179
        }
180
181 279
        if (!is_string($path)) {
0 ignored issues
show
introduced by
The condition is_string($path) is always true.
Loading history...
182
            throw new InvalidArgumentException('Parameter $path is not a string', 1325627243);
183
        }
184
185 279
        return $this->configurationAccess->get($path);
186
    }
187
188
    /**
189
     * Gets the parent TypoScript Object from a given TypoScript path and if not present return
190
     * the default value
191
     *
192
     * @see getObjectByPath()
193
     * @param string $path
194
     * @param array $defaultValue
195
     * @return array
196
     */
197 278
    public function getObjectByPathOrDefault($path, array $defaultValue)
198
    {
199
        try {
200 278
            $object = $this->getObjectByPath($path);
201
        } catch (\InvalidArgumentException $e) {
202
            return $defaultValue;
203
        }
204
205 278
        if (!is_array($object)) {
0 ignored issues
show
introduced by
The condition is_array($object) is always true.
Loading history...
206 132
            return $defaultValue;
207
        }
208
209 199
        return $object;
210
    }
211
212
    /**
213
     * Checks whether a given TypoScript path is valid.
214
     *
215
     * @param string $path TypoScript path
216
     * @return bool TRUE if the path resolves, FALSE otherwise
217
     */
218
    public function isValidPath($path)
219
    {
220
        $isValidPath = false;
221
222
        $pathValue = $this->getValueByPath($path);
223
        if (!is_null($pathValue)) {
224
            $isValidPath = true;
225
        }
226
227
        return $isValidPath;
228
    }
229
230
    /**
231
     * Merges a configuration with another configuration a
232
     *
233
     * @param array $configurationToMerge
234
     * @param bool $addKeys If set to FALSE, keys that are NOT found in $original will not be set. Thus only existing value can/will be overruled from overrule array.
235
     * @param bool $includeEmptyValues If set, values from $overrule will overrule if they are empty or zero.
236
     * @param bool $enableUnsetFeature If set, special values "__UNSET" can be used in the overrule array in order to unset array keys in the original array.
237
     * @return TypoScriptConfiguration
238
     */
239 7
    public function mergeSolrConfiguration(array $configurationToMerge, $addKeys = true, $includeEmptyValues = true, $enableUnsetFeature = true)
240
    {
241 7
        $data = $this->configurationAccess->getData();
242 7
        ArrayUtility::mergeRecursiveWithOverrule(
243 7
            $data['plugin.']['tx_solr.'],
244 5
            $configurationToMerge,
245 5
            $addKeys,
246 5
            $includeEmptyValues,
247 5
            $enableUnsetFeature
248
        );
249
250 7
        $this->configurationAccess->setData($data);
251
252 7
        return $this;
253
    }
254
255
    /**
256
     * Returns true when ext_solr is enabled
257
     *
258
     * @param boolean $defaultIfEmpty
259
     * @return boolean
260
     */
261
    public function getEnabled($defaultIfEmpty = false)
262
    {
263
        $path = 'plugin.tx_solr.enabled';
264
        $result = $this->getValueByPathOrDefaultValue($path, $defaultIfEmpty);
265
        return $this->getBool($result);
266
    }
267
268
    /**
269
     * Returns the configured additionalFields configured for the indexing.
270
     *
271
     * plugin.tx_solr.index.additionalFields.
272
     *
273
     * @param array $defaultIfEmpty
274
     * @return array
275
     */
276 39
    public function getIndexAdditionalFieldsConfiguration($defaultIfEmpty = [])
277
    {
278 39
        $result = $this->getObjectByPathOrDefault('plugin.tx_solr.index.additionalFields.', $defaultIfEmpty);
279 39
        return $result;
280
    }
281
282
    /**
283
     * Returns all solr fields names where a mapping is configured in index.additionalFields
284
     *
285
     * Returns all keys from
286
     * plugin.tx_solr.index.additionalFields.
287
     *
288
     * @param array $defaultIfEmpty
289
     * @return array
290
     */
291 38
    public function getIndexMappedAdditionalFieldNames($defaultIfEmpty = [])
292
    {
293 38
        $mappingConfiguration = $this->getIndexAdditionalFieldsConfiguration();
294 38
        $mappedFieldNames = $this->getOnlyArrayKeysWhereValueIsNotAnArray($mappingConfiguration);
295 38
        return count($mappedFieldNames) == 0 ? $defaultIfEmpty : $mappedFieldNames;
296
    }
297
298
    /**
299
     * Returns the fieldProcessingInstructions configuration array
300
     *
301
     * plugin.tx_solr.index.fieldProcessingInstructions.
302
     *
303
     * @param array $defaultIfEmpty
304
     * @return array
305
     */
306 57
    public function getIndexFieldProcessingInstructionsConfiguration(array $defaultIfEmpty = [])
307
    {
308 57
        $result = $this->getObjectByPathOrDefault('plugin.tx_solr.index.fieldProcessingInstructions.', $defaultIfEmpty);
309 57
        return $result;
310
    }
311
312
    /**
313
     * Retrieves the indexing configuration array for an indexing queue by configuration name.
314
     *
315
     * plugin.tx_solr.index.queue.<configurationName>.
316
     *
317
     * @param string $configurationName
318
     * @param array $defaultIfEmpty
319
     * @return array
320
     */
321 13
    public function getIndexQueueConfigurationByName($configurationName, array $defaultIfEmpty = [])
322
    {
323 13
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.';
324 13
        $result = $this->getObjectByPathOrDefault($path, $defaultIfEmpty);
325 13
        return $result;
326
    }
327
328
    /**
329
     * Returns an array of all additionalPageIds by index configuration name.
330
     *
331
     * plugin.tx_solr.index.queue.pages.additionalPageIds
332
     *
333
     * @param string $configurationName
334
     * @param array $defaultIfEmpty
335
     * @return array
336
     */
337 61
    public function getIndexQueueAdditionalPageIdsByConfigurationName($configurationName = 'pages', $defaultIfEmpty = [])
338
    {
339 61
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.additionalPageIds';
340 61
        $result = $this->getValueByPathOrDefaultValue($path, '');
341 61
        if (trim($result) === '') {
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type array and null; however, parameter $string of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

341
        if (trim(/** @scrutinizer ignore-type */ $result) === '') {
Loading history...
342 52
            return $defaultIfEmpty;
343
        }
344
345 10
        return GeneralUtility::trimExplode(',', $result);
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type array; however, parameter $string of TYPO3\CMS\Core\Utility\G...lUtility::trimExplode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

345
        return GeneralUtility::trimExplode(',', /** @scrutinizer ignore-type */ $result);
Loading history...
346
    }
347
348
    /**
349
     * Returns an array of all allowedPageTypes.
350
     *
351
     * plugin.tx_solr.index.queue.pages.allowedPageTypes
352
     *
353
     * @param string $configurationName The configuration name of the queue to use.
354
     * @param array $defaultIfEmpty
355
     * @return array
356
     */
357 54
    public function getIndexQueueAllowedPageTypesArrayByConfigurationName($configurationName = 'pages', $defaultIfEmpty = [])
358
    {
359 54
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.allowedPageTypes';
360 54
        $result = $this->getValueByPathOrDefaultValue($path, '');
361 54
        if (trim($result) === '') {
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type array and null; however, parameter $string of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

361
        if (trim(/** @scrutinizer ignore-type */ $result) === '') {
Loading history...
362 2
            return $defaultIfEmpty;
363
        }
364
365 52
        return GeneralUtility::trimExplode(',', $result);
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type array; however, parameter $string of TYPO3\CMS\Core\Utility\G...lUtility::trimExplode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

365
        return GeneralUtility::trimExplode(',', /** @scrutinizer ignore-type */ $result);
Loading history...
366
    }
367
368
    /**
369
     * Returns the configured excludeContentByClass patterns as array.
370
     *
371
     * plugin.tx_solr.index.queue.pages.excludeContentByClass
372
     *
373
     * @param array $defaultIfEmpty
374
     * @return array
375
     */
376 21
    public function getIndexQueuePagesExcludeContentByClassArray($defaultIfEmpty = [])
377
    {
378 21
        $path = 'plugin.tx_solr.index.queue.pages.excludeContentByClass';
379 21
        $result = $this->getValueByPathOrDefaultValue($path, '');
380
381 21
        if (trim($result) === '') {
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type array and null; however, parameter $string of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

381
        if (trim(/** @scrutinizer ignore-type */ $result) === '') {
Loading history...
382 13
            return $defaultIfEmpty;
383
        }
384
385 8
        return GeneralUtility::trimExplode(',', $result);
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type array; however, parameter $string of TYPO3\CMS\Core\Utility\G...lUtility::trimExplode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

385
        return GeneralUtility::trimExplode(',', /** @scrutinizer ignore-type */ $result);
Loading history...
386
    }
387
388
    /**
389
     * Returns the configured database table for an indexing queue configuration or
390
     * the configurationName itself that is used by convention as tableName when no
391
     * other tablename is present.
392
     *
393
     * plugin.tx_solr.index.queue.<configurationName>.table or configurationName
394
     *
395
     * @param string $configurationName
396
     * @return string
397
     */
398 102
    public function getIndexQueueTableNameOrFallbackToConfigurationName($configurationName = '')
399
    {
400 102
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.table';
401 102
        $result = $this->getValueByPathOrDefaultValue($path, $configurationName);
402 102
        return $result;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $result also could return the type array which is incompatible with the documented return type string.
Loading history...
403
    }
404
405
    /**
406
     * Returns the field configuration for a specific index queue.
407
     *
408
     * plugin.tx_solr.index.queue.<configurationName>.fields.
409
     *
410
     * @param string $configurationName
411
     * @param array $defaultIfEmpty
412
     * @return array
413
     */
414 32
    public function getIndexQueueFieldsConfigurationByConfigurationName($configurationName = '', $defaultIfEmpty = [])
415
    {
416 32
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.fields.';
417 32
        $result = $this->getObjectByPathOrDefault($path, $defaultIfEmpty);
418 32
        return $result;
419
    }
420
421
    /**
422
     * Gets an array of tables configured for indexing by the Index Queue. Since the
423
     * record monitor must watch these tables for manipulation.
424
     *
425
     * @return array Array of table names to be watched by the record monitor.
426
     */
427 61
    public function getIndexQueueMonitoredTables()
428
    {
429 61
        $monitoredTables = [];
430
431 61
        $indexingConfigurations = $this->getEnabledIndexQueueConfigurationNames();
432 61
        foreach ($indexingConfigurations as $indexingConfigurationName) {
433 59
            $monitoredTable = $this->getIndexQueueTableNameOrFallbackToConfigurationName($indexingConfigurationName);
434 59
            $monitoredTables[] = $monitoredTable;
435
        }
436
437 61
        return array_values(array_unique($monitoredTables));
438
    }
439
440
    /**
441
     * This method can be used to check if a table is configured to be monitored by the record monitor.
442
     *
443
     * @param string $tableName
444
     * @return bool
445
     */
446 60
    public function getIndexQueueIsMonitoredTable($tableName)
447
    {
448 60
        return in_array($tableName, $this->getIndexQueueMonitoredTables(), true);
449
    }
450
451
    /**
452
     * Returns the configured indexer class that should be used for a certain indexingConfiguration.
453
     * By default "ApacheSolrForTypo3\Solr\IndexQueue\Indexer" will be returned.
454
     *
455
     * plugin.tx_solr.index.queue.<configurationName>.indexer
456
     *
457
     * @param string $configurationName
458
     * @param string $defaultIfEmpty
459
     * @return string
460
     */
461 2
    public function getIndexQueueIndexerByConfigurationName($configurationName, $defaultIfEmpty = Indexer::class)
462
    {
463 2
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.indexer';
464 2
        $result = $this->getValueByPathOrDefaultValue($path, $defaultIfEmpty);
465 2
        return $result;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $result also could return the type array which is incompatible with the documented return type string.
Loading history...
466
    }
467
468
    /**
469
     * Returns the configuration of an indexer for a special indexingConfiguration. By default an empty
470
     * array is returned.
471
     *
472
     * plugin.tx_solr.index.queue.<configurationName>.indexer.
473
     *
474
     * @param string $configurationName
475
     * @param array $defaultIfEmpty
476
     * @return array
477
     */
478 2
    public function getIndexQueueIndexerConfigurationByConfigurationName($configurationName, $defaultIfEmpty = [])
479
    {
480 2
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.indexer.';
481 2
        $result = $this->getObjectByPathOrDefault($path, $defaultIfEmpty);
482 2
        return $result;
483
    }
484
485
    /**
486
     * Returns all solr fields names where a mapping configuration is set for a certain index configuration
487
     *
488
     * Returns all keys from
489
     * plugin.tx_solr.index.queue.<configurationName>.fields.
490
     *
491
     * @param string $configurationName
492
     * @param array $defaultIfEmpty
493
     * @return array
494
     */
495 11
    public function getIndexQueueMappedFieldsByConfigurationName($configurationName = '', $defaultIfEmpty = [])
496
    {
497 11
        $mappingConfiguration = $this->getIndexQueueFieldsConfigurationByConfigurationName($configurationName);
498 11
        $mappedFieldNames = $this->getOnlyArrayKeysWhereValueIsNotAnArray($mappingConfiguration);
499 11
        return count($mappedFieldNames) == 0 ? $defaultIfEmpty : $mappedFieldNames;
500
    }
501
502
    /**
503
     * This method is used to check if an index queue configuration is enabled or not
504
     *
505
     * plugin.tx_solr.index.queue.<configurationName> = 1
506
     *
507
     * @param string $configurationName
508
     * @param bool $defaultIfEmpty
509
     * @return bool
510
     */
511 98
    public function getIndexQueueConfigurationIsEnabled($configurationName, $defaultIfEmpty = false)
512
    {
513 98
        $path = 'plugin.tx_solr.index.queue.' . $configurationName;
514 98
        $result = $this->getValueByPathOrDefaultValue($path, $defaultIfEmpty);
515 98
        return $this->getBool($result);
516
    }
517
518
    /**
519
     * Retrieves an array of enabled index queue configurations.
520
     *
521
     * plugin.tx_solr.index.queue.<configurationName>
522
     *
523
     * @param array $defaultIfEmpty
524
     * @return array
525
     */
526 106
    public function getEnabledIndexQueueConfigurationNames($defaultIfEmpty = [])
527
    {
528 106
        $tablesToIndex = [];
529 106
        $path = 'plugin.tx_solr.index.queue.';
530 106
        $indexQueueConfiguration = $this->getObjectByPathOrDefault($path, []);
531 106
        foreach ($indexQueueConfiguration as $configurationName => $indexingEnabled) {
532 102
            if (substr($configurationName, -1) != '.' && $indexingEnabled) {
533 102
                $tablesToIndex[] = $configurationName;
534
            }
535
        }
536
537 106
        return count($tablesToIndex) == 0 ? $defaultIfEmpty : $tablesToIndex;
538
    }
539
540
    /**
541
     * Retrieves an array of additional fields that will trigger an recursive update of pages
542
     * when some of the fields on that page are modified.
543
     *
544
     * plugin.tx_solr.index.queue.recursiveUpdateFields
545
     *
546
     * @param string $configurationName
547
     * @param array $defaultIfEmpty
548
     * @return array
549
     */
550 40
    public function getIndexQueueConfigurationRecursiveUpdateFields($configurationName, $defaultIfEmpty = [])
551
    {
552 40
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.recursiveUpdateFields';
553 40
        $recursiveUpdateFieldsString = $this->getValueByPathOrDefaultValue($path, '');
554 40
        if (trim($recursiveUpdateFieldsString) === '') {
0 ignored issues
show
Bug introduced by
It seems like $recursiveUpdateFieldsString can also be of type array and null; however, parameter $string of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

554
        if (trim(/** @scrutinizer ignore-type */ $recursiveUpdateFieldsString) === '') {
Loading history...
555 31
            return $defaultIfEmpty;
556
        }
557 10
        $recursiveUpdateFields = GeneralUtility::trimExplode(',', $recursiveUpdateFieldsString);
0 ignored issues
show
Bug introduced by
It seems like $recursiveUpdateFieldsString can also be of type array; however, parameter $string of TYPO3\CMS\Core\Utility\G...lUtility::trimExplode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

557
        $recursiveUpdateFields = GeneralUtility::trimExplode(',', /** @scrutinizer ignore-type */ $recursiveUpdateFieldsString);
Loading history...
558
        // For easier check later on we return an array by combining $recursiveUpdateFields
559 10
        return array_combine($recursiveUpdateFields, $recursiveUpdateFields);
560
    }
561
562
563
    /**
564
     * Retrieves and initialPagesAdditionalWhereClause where clause when configured or an empty string.
565
     *
566
     * plugin.tx_solr.index.queue.<configurationName>.initialPagesAdditionalWhereClause
567
     *
568
     * @param string $configurationName
569
     * @return string
570
     */
571 13
    public function getInitialPagesAdditionalWhereClause($configurationName)
572
    {
573 13
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.initialPagesAdditionalWhereClause';
574 13
        $initialPagesAdditionalWhereClause = $this->getValueByPathOrDefaultValue($path, '');
575
576 13
        if (trim($initialPagesAdditionalWhereClause) === '') {
0 ignored issues
show
Bug introduced by
It seems like $initialPagesAdditionalWhereClause can also be of type array and null; however, parameter $string of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

576
        if (trim(/** @scrutinizer ignore-type */ $initialPagesAdditionalWhereClause) === '') {
Loading history...
577 13
            return '';
578
        }
579
580 1
        return trim($initialPagesAdditionalWhereClause);
581
    }
582
583
    /**
584
     * Retrieves and additional where clause when configured or an empty string.
585
     *
586
     * plugin.tx_solr.index.queue.<configurationName>.additionalWhereClause
587
     *
588
     * @param string $configurationName
589
     * @return string
590
     */
591 99
    public function getIndexQueueAdditionalWhereClauseByConfigurationName($configurationName)
592
    {
593 99
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.additionalWhereClause';
594 99
        $additionalWhere = $this->getValueByPathOrDefaultValue($path, '');
595
596 99
        if (trim($additionalWhere) === '') {
0 ignored issues
show
Bug introduced by
It seems like $additionalWhere can also be of type array and null; however, parameter $string of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

596
        if (trim(/** @scrutinizer ignore-type */ $additionalWhere) === '') {
Loading history...
597 28
            return '';
598
        }
599
600 72
        return ' AND ' . $additionalWhere;
601
    }
602
603
    /**
604
     * This method can be used to retrieve all index queue configuration names, where
605
     * a certain table is used. It can be configured with the property "table" or is using the configuration
606
     * key a fallback for the table name.
607
     *
608
     * plugin.tx_solr.index.queue.<configurationName>.
609
     *
610
     * @param string $tableName
611
     * @param array $defaultIfEmpty
612
     * @return array
613
     */
614 1
    public function getIndexQueueConfigurationNamesByTableName($tableName, $defaultIfEmpty = [])
615
    {
616 1
        $path = 'plugin.tx_solr.index.queue.';
617 1
        $configuration = $this->getObjectByPathOrDefault($path, []);
618 1
        $possibleConfigurations = [];
619
620 1
        foreach ($configuration as $configurationName => $indexingEnabled) {
621 1
            $isObject = substr($configurationName, -1) === '.';
622 1
            if ($isObject || !$indexingEnabled) {
623 1
                continue;
624
            }
625
626
            // when the configuration name equals the tableName we have a fallback
627 1
            $hasTableNameAsConfigurationName = $configurationName == $tableName;
628 1
            $hasTableAssignedInQueueConfiguration = isset($configuration[$configurationName . '.']['table']) &&
629 1
                                                    $configuration[$configurationName . '.']['table'] == $tableName;
630 1
            if ($hasTableNameAsConfigurationName || $hasTableAssignedInQueueConfiguration) {
631 1
                $possibleConfigurations[] = $configurationName;
632
            }
633
        }
634
635 1
        return count($possibleConfigurations) > 0 ? $possibleConfigurations : $defaultIfEmpty;
636
    }
637
638
    /**
639
     * This method is used to retrieve the className of a queue initializer for a certain indexing configuration
640
     * of returns the default initializer class, when noting is configured.
641
     *
642
     * plugin.tx_solr.index.queue.<configurationName>.initialization
643
     *
644
     * @param string $configurationName
645
     * @param string $defaultIfEmpty
646
     * @return string
647
     */
648 7
    public function getIndexQueueInitializerClassByConfigurationName($configurationName, $defaultIfEmpty = Record::class)
649
    {
650 7
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.initialization';
651 7
        $className = $this->getValueByPathOrDefaultValue($path, $defaultIfEmpty);
652
653 7
        return $className;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $className also could return the type array which is incompatible with the documented return type string.
Loading history...
654
    }
655
656
    /**
657
    * Retrieves indexingPriority when configured or 0.
658
    *
659
    * plugin.tx_solr.index.queue.<configurationName>.indexingPriority
660
    *
661
    * @param string $configurationName
662
    * @param int $defaultIfEmpty
663
    * @return int
664
    */
665 85
    public function getIndexQueueIndexingPriorityByConfigurationName(string $configurationName, int $defaultIfEmpty = 0): int
666
    {
667 85
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.indexingPriority';
668 85
        return (int)$this->getValueByPathOrDefaultValue($path, $defaultIfEmpty);
669
    }
670
671
    /**
672
     * Returns the _LOCAL_LANG configuration from the TypoScript.
673
     *
674
     * plugin.tx_solr._LOCAL_LANG.
675
     *
676
     * @param array $defaultIfEmpty
677
     * @return array
678
     */
679
    public function getLocalLangConfiguration(array $defaultIfEmpty = [])
680
    {
681
        $result = $this->getObjectByPathOrDefault('plugin.tx_solr._LOCAL_LANG.', $defaultIfEmpty);
682
        return $result;
683
    }
684
685
    /**
686
     * When this is enabled the output of the devlog, will be printed as debug output.
687
     *
688
     * @param bool $defaultIfEmpty
689
     * @return bool
690
     */
691
    public function getLoggingDebugOutput($defaultIfEmpty = false)
692
    {
693
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.debugOutput', $defaultIfEmpty);
694
        return $this->getBool($result);
695
    }
696
697
    /**
698
     * Returns if query filters should be written to the log.
699
     *
700
     * plugin.tx_solr.logging.query.filters
701
     *
702
     * @param bool $defaultIfEmpty
703
     * @return bool
704
     */
705
    public function getLoggingQueryFilters($defaultIfEmpty = false)
706
    {
707
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.query.filters', $defaultIfEmpty);
708
        return $this->getBool($result);
709
    }
710
711
    /**
712
     * Returns if the querystring should be logged or not.
713
     *
714
     * plugin.tx_solr.logging.query.queryString
715
     *
716
     * @param bool $defaultIfEmpty
717
     * @return bool
718
     */
719 16
    public function getLoggingQueryQueryString($defaultIfEmpty = false)
720
    {
721 16
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.query.queryString', $defaultIfEmpty);
722 16
        return $this->getBool($result);
723
    }
724
725
    /**
726
     * Returns if the searchWords should be logged or not.
727
     *
728
     * plugin.tx_solr.logging.query.searchWords
729
     *
730
     * @param bool $defaultIfEmpty
731
     * @return bool
732
     */
733 91
    public function getLoggingQuerySearchWords($defaultIfEmpty = false)
734
    {
735 91
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.query.searchWords', $defaultIfEmpty);
736 91
        return $this->getBool($result);
737
    }
738
739
    /**
740
     * Returns if the rawGet requests should be logged or not.
741
     *
742
     * plugin.tx_solr.logging.query.rawGet
743
     *
744
     * @param bool $defaultIfEmpty
745
     * @return bool
746
     */
747
    public function getLoggingQueryRawGet($defaultIfEmpty = false)
748
    {
749
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.query.rawGet', $defaultIfEmpty);
750
        return $this->getBool($result);
751
    }
752
753
    /**
754
     * Returns if the rawPost requests should be logged or not.
755
     *
756
     * plugin.tx_solr.logging.query.rawPost
757
     *
758
     * @param bool $defaultIfEmpty
759
     * @return bool
760
     */
761 18
    public function getLoggingQueryRawPost($defaultIfEmpty = false)
762
    {
763 18
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.query.rawPost', $defaultIfEmpty);
764 18
        return $this->getBool($result);
765
    }
766
767
    /**
768
     * Returns if the rawDelete requests should be logged or not.
769
     *
770
     * plugin.tx_solr.logging.query.rawDelete
771
     *
772
     * @param bool $defaultIfEmpty
773
     * @return bool
774
     */
775
    public function getLoggingQueryRawDelete($defaultIfEmpty = false)
776
    {
777
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.query.rawDelete', $defaultIfEmpty);
778
        return $this->getBool($result);
779
    }
780
781
    /**
782
     * Returns if exceptions should be logged or not.
783
     *
784
     * plugin.tx_solr.logging.exceptions
785
     *
786
     * @param bool $defaultIfEmpty
787
     * @return bool
788
     */
789
    public function getLoggingExceptions($defaultIfEmpty = true)
790
    {
791
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.exceptions', $defaultIfEmpty);
792
        return $this->getBool($result);
793
    }
794
795
    /**
796
     * Returns if indexing operations should be logged or not.
797
     *
798
     * plugin.tx_solr.logging.indexing
799
     *
800
     * @param bool $defaultIfEmpty
801
     * @return bool
802
     */
803 23
    public function getLoggingIndexing($defaultIfEmpty = false)
804
    {
805 23
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.indexing', $defaultIfEmpty);
806 23
        return $this->getBool($result);
807
    }
808
809
    /**
810
     * Returns if indexing queue operations should be logged or not.
811
     *
812
     * plugin.tx_solr.logging.indexing.queue
813
     *
814
     * @param bool $defaultIfEmpty
815
     * @return bool
816
     */
817 22
    public function getLoggingIndexingQueue($defaultIfEmpty = false)
818
    {
819 22
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.indexing.queue', $defaultIfEmpty);
820 22
        return $this->getBool($result);
821
    }
822
823
    /**
824
     * This method can be used to check if the logging during indexing should be done.
825
     * It takes the specific configuration by indexQueueConfiguration into account or is using the
826
     * fallback when the logging is enabled on queue or indexing level.
827
     *
828
     * plugin.tx_solr.logging.indexing.queue.<indexQueueConfiguration>
829
     *
830
     * @param string $indexQueueConfiguration
831
     * @param bool $defaultIfEmpty
832
     * @return bool
833
     */
834 23
    public function getLoggingIndexingQueueOperationsByConfigurationNameWithFallBack($indexQueueConfiguration, $defaultIfEmpty = false)
835
    {
836
        // when logging is globally enabled we do not need to check the specific configuration
837 23
        if ($this->getLoggingIndexing()) {
838 1
            return true;
839
        }
840
841
        // when the logging for indexing is enabled on queue level we also do not need to check the specific configuration
842 22
        if ($this->getLoggingIndexingQueue()) {
843
            return true;
844
        }
845
846 22
        $path = 'plugin.tx_solr.logging.indexing.queue.' . $indexQueueConfiguration;
847 22
        $result = $this->getValueByPathOrDefaultValue($path, $defaultIfEmpty);
848 22
        return $this->getBool($result);
849
    }
850
851
    /**
852
     * Returns if a log message should be written when a page was indexed.
853
     *
854
     * plugin.tx_solr.logging.indexing.pageIndexed
855
     *
856
     * @param bool $defaultIfEmpty
857
     * @return bool
858
     */
859 10
    public function getLoggingIndexingPageIndexed($defaultIfEmpty = false)
860
    {
861 10
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.indexing.pageIndexed', $defaultIfEmpty);
862 10
        return $this->getBool($result);
863
    }
864
865
    /**
866
     * Returns if a log message should be written when the TYPO3 search markers are missing in the page.
867
     *
868
     * plugin.tx_solr.logging.indexing.missingTypo3SearchMarkers
869
     *
870
     * @param bool $defaultIfEmpty
871
     * @return bool
872
     */
873 17
    public function getLoggingIndexingMissingTypo3SearchMarkers($defaultIfEmpty = true)
874
    {
875 17
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.indexing.missingTypo3SearchMarkers', $defaultIfEmpty);
876 17
        return $this->getBool($result);
877
    }
878
879
    /**
880
     * Returns if the initialization of an indexqueue should be logged.
881
     *
882
     * plugin.tx_solr.logging.indexing.indexQueueInitialization
883
     *
884
     * @param bool $defaultIfEmpty
885
     * @return bool
886
     */
887 14
    public function getLoggingIndexingIndexQueueInitialization($defaultIfEmpty = false)
888
    {
889 14
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.indexing.indexQueueInitialization', $defaultIfEmpty);
890 14
        return $this->getBool($result);
891
    }
892
893
    /**
894
     * Indicates if the debug mode is enabled or not.
895
     *
896
     * plugin.tx_solr.enableDebugMode
897
     *
898
     * @param bool $defaultIfEmpty
899
     * @return bool
900
     */
901 5
    public function getEnabledDebugMode($defaultIfEmpty = false)
902
    {
903 5
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.enableDebugMode', $defaultIfEmpty);
904 5
        return $this->getBool($result);
905
    }
906
907
    /**
908
     * @param $path
909
     * @param $fallbackPath
910
     * @param $defaultIfBothIsEmpty
911
     * @return mixed
912
     */
913
    public function getValueByPathWithFallbackOrDefaultValueAndApplyStdWrap($path, $fallbackPath, $defaultIfBothIsEmpty)
914
    {
915
        $result = (string)$this->getValueByPathOrDefaultValue($path, '');
916
        if($result !== '') {
917
            return $this->renderContentElementOfConfigured($path, $result);
918
        }
919
920
        $result = (string)$this->getValueByPathOrDefaultValue($fallbackPath, $defaultIfBothIsEmpty);
921
        return $this->renderContentElementOfConfigured($fallbackPath, $result);
922
    }
923
924
    /**
925
     * Retrieves the complete search configuration
926
     *
927
     * plugin.tx_solr.search.
928
     *
929
     * @param array $defaultIfEmpty
930
     * @return array
931
     */
932 18
    public function getSearchConfiguration(array $defaultIfEmpty = [])
933
    {
934 18
        $result = $this->getObjectByPathOrDefault('plugin.tx_solr.search.', $defaultIfEmpty);
935 18
        return $result;
936
    }
937
938
    /**
939
     * Indicates if elevation should be used or not
940
     *
941
     * plugin.tx_solr.search.elevation
942
     *
943
     * @param bool $defaultIfEmpty
944
     * @return bool
945
     */
946 5
    public function getSearchElevation($defaultIfEmpty = false)
947
    {
948 5
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.elevation', $defaultIfEmpty);
949 5
        return $this->getBool($result);
950
    }
951
952
    /**
953
     * Indicates if elevated results should be marked
954
     *
955
     * plugin.tx_solr.search.elevation.markElevatedResults
956
     *
957
     * @param bool $defaultIfEmpty
958
     * @return bool
959
     */
960
    public function getSearchElevationMarkElevatedResults($defaultIfEmpty = true)
961
    {
962
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.elevation.markElevatedResults', $defaultIfEmpty);
963
        return $this->getBool($result);
964
    }
965
966
    /**
967
     * Indicates if elevation should be forced
968
     *
969
     *plugin.tx_solr.search.elevation.forceElevation
970
     *
971
     * @param bool $defaultIfEmpty
972
     * @return bool
973
     */
974
    public function getSearchElevationForceElevation($defaultIfEmpty = true)
975
    {
976
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.elevation.forceElevation', $defaultIfEmpty);
977
        return $this->getBool($result);
978
    }
979
980
    /**
981
     * Indicates if collapsing on a certain field should be used to build variants or not.
982
     *
983
     * plugin.tx_solr.search.variants
984
     *
985
     * @param bool $defaultIfEmpty
986
     * @return bool
987
     */
988 91
    public function getSearchVariants($defaultIfEmpty = false)
989
    {
990 91
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.variants', $defaultIfEmpty);
991 91
        return $this->getBool($result);
992
    }
993
994
    /**
995
     * Indicates if collapsing on a certain field should be used or not
996
     *
997
     * plugin.tx_solr.search.variants.variantField
998
     *
999
     * @param string $defaultIfEmpty
1000
     * @return string
1001
     */
1002 6
    public function getSearchVariantsField($defaultIfEmpty = 'variantId')
1003
    {
1004 6
        return $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.variants.variantField', $defaultIfEmpty);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getValueBy...ield', $defaultIfEmpty) also could return the type array which is incompatible with the documented return type string.
Loading history...
1005
    }
1006
1007
    /**
1008
     * Indicates if expanding of collapsed items it activated.
1009
     *
1010
     * plugin.tx_solr.search.variants.expand
1011
     *
1012
     * @param bool $defaultIfEmpty
1013
     * @return bool
1014
     */
1015 6
    public function getSearchVariantsExpand($defaultIfEmpty = false)
1016
    {
1017 6
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.variants.expand', $defaultIfEmpty);
1018 6
        return $this->getBool($result);
1019
    }
1020
1021
    /**
1022
     * Retrieves the number of elements that should be expanded.
1023
     *
1024
     * plugin.tx_solr.search.variants.limit
1025
     *
1026
     * @param int $defaultIfEmpty
1027
     * @return int
1028
     */
1029 6
    public function getSearchVariantsLimit($defaultIfEmpty = 10)
1030
    {
1031 6
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.variants.limit', $defaultIfEmpty);
1032 6
        return (int)$result;
1033
    }
1034
1035
    /**
1036
     * Indicates if frequent searches should be show or not.
1037
     *
1038
     * plugin.tx_solr.search.frequentSearches
1039
     *
1040
     * @param bool $defaultIfEmpty
1041
     * @return bool
1042
     */
1043
    public function getSearchFrequentSearches($defaultIfEmpty = false)
1044
    {
1045
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.frequentSearches', $defaultIfEmpty);
1046
        return $this->getBool($result);
1047
    }
1048
1049
    /**
1050
     * Returns the sub configuration of the frequentSearches
1051
     *
1052
     * plugin.tx_solr.search.frequentSearches.
1053
     *
1054
     * @param array $defaultIfEmpty
1055
     * @return array
1056
     */
1057
    public function getSearchFrequentSearchesConfiguration($defaultIfEmpty = [])
1058
    {
1059
        $result = $this->getObjectByPathOrDefault('plugin.tx_solr.search.frequentSearches.', $defaultIfEmpty);
1060
        return $result;
1061
    }
1062
1063
    /**
1064
     * Retrieves the minimum font size that should be used for the frequentSearches.
1065
     *
1066
     * plugin.tx_solr.search.frequentSearches.minSize
1067
     *
1068
     * @param int $defaultIfEmpty
1069
     * @return int
1070
     */
1071
    public function getSearchFrequentSearchesMinSize($defaultIfEmpty = 14): int
1072
    {
1073
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.frequentSearches.minSize', $defaultIfEmpty);
1074
        return (int)$result;
1075
    }
1076
1077
    /**
1078
     * Retrieves the maximum font size that should be used for the frequentSearches.
1079
     *
1080
     * plugin.tx_solr.search.frequentSearches.minSize
1081
     *
1082
     * @param int $defaultIfEmpty
1083
     * @return int
1084
     */
1085
    public function getSearchFrequentSearchesMaxSize($defaultIfEmpty = 32): int
1086
    {
1087
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.frequentSearches.maxSize', $defaultIfEmpty);
1088
        return (int)$result;
1089
    }
1090
1091
    /**
1092
     * Indicates if frequent searches should be show or not.
1093
     *
1094
     * plugin.tx_solr.search.frequentSearches.useLowercaseKeywords
1095
     *
1096
     * @param bool $defaultIfEmpty
1097
     * @return bool
1098
     */
1099
    public function getSearchFrequentSearchesUseLowercaseKeywords($defaultIfEmpty = false)
1100
    {
1101
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.frequentSearches.useLowercaseKeywords', $defaultIfEmpty);
1102
        return $this->getBool($result);
1103
    }
1104
1105
    /**
1106
     * Returns the configuration if the search should be initialized with an empty query.
1107
     *
1108
     * plugin.tx_solr.search.initializeWithEmptyQuery
1109
     *
1110
     * @param bool $defaultIfEmpty
1111
     * @return bool
1112
     */
1113 91
    public function getSearchInitializeWithEmptyQuery($defaultIfEmpty = false)
1114
    {
1115 91
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.initializeWithEmptyQuery', $defaultIfEmpty);
1116 91
        return $this->getBool($result);
1117
    }
1118
1119
    /**
1120
     * Returns the configured initial query
1121
     *
1122
     * plugin.tx_solr.search.initializeWithQuery
1123
     *
1124
     * @param string $defaultIfEmpty
1125
     * @return string
1126
     */
1127 91
    public function getSearchInitializeWithQuery($defaultIfEmpty = '')
1128
    {
1129 91
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.initializeWithQuery', $defaultIfEmpty);
1130 91
        return (string)$result;
1131
    }
1132
1133
    /**
1134
     * Returns if the last searches should be displayed or not.
1135
     *
1136
     * plugin.tx_solr.search.lastSearches
1137
     *
1138
     * @param bool $defaultIfEmpty
1139
     * @return bool
1140
     */
1141
    public function getSearchLastSearches($defaultIfEmpty = false)
1142
    {
1143
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.lastSearches', $defaultIfEmpty);
1144
        return $this->getBool($result);
1145
    }
1146
1147
    /**
1148
     * Returns the lastSearch mode. "user" for user specific
1149
     *
1150
     * plugin.tx_solr.search.lastSearches.mode
1151
     *
1152
     * @param string $defaultIfEmpty
1153
     * @return string
1154
     */
1155
    public function getSearchLastSearchesMode($defaultIfEmpty = 'user')
1156
    {
1157
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.lastSearches.mode', $defaultIfEmpty);
1158
        return (string)$result;
1159
    }
1160
1161
    /**
1162
     * Returns the lastSearch limit
1163
     *
1164
     * plugin.tx_solr.search.lastSearches.limit
1165
     *
1166
     * @param int $defaultIfEmpty
1167
     * @return int
1168
     */
1169
    public function getSearchLastSearchesLimit($defaultIfEmpty = 10)
1170
    {
1171
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.lastSearches.limit', $defaultIfEmpty);
1172
        return (int)$result;
1173
    }
1174
1175
    /**
1176
     * Indicates if the results of an initial empty query should be shown or not.
1177
     *
1178
     * plugin.tx_solr.search.showResultsOfInitialEmptyQuery
1179
     *
1180
     * @param bool $defaultIfEmpty
1181
     * @return bool
1182
     */
1183
    public function getSearchShowResultsOfInitialEmptyQuery($defaultIfEmpty = false)
1184
    {
1185
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.showResultsOfInitialEmptyQuery', $defaultIfEmpty);
1186
        return $this->getBool($result);
1187
    }
1188
1189
    /**
1190
     * Indicates if the results of an initial search query should be shown.
1191
     *
1192
     * plugin.tx_solr.search.showResultsOfInitialQuery
1193
     *
1194
     * @param bool $defaultIfEmpty
1195
     * @return bool
1196
     */
1197
    public function getSearchShowResultsOfInitialQuery($defaultIfEmpty = false)
1198
    {
1199
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.showResultsOfInitialQuery', $defaultIfEmpty);
1200
        return $this->getBool($result);
1201
    }
1202
1203
    /**
1204
     * Indicates if sorting was enabled or not.
1205
     *
1206
     * plugin.tx_solr.search.sorting
1207
     *
1208
     * @param bool $defaultIfEmpty
1209
     * @return bool
1210
     */
1211 34
    public function getSearchSorting($defaultIfEmpty = false)
1212
    {
1213 34
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.sorting', $defaultIfEmpty);
1214 34
        return $this->getBool($result);
1215
    }
1216
1217
    /**
1218
     * Returns the sorting options configurations.
1219
     *
1220
     * plugin.tx_solr.search.sorting.options.
1221
     *
1222
     * @param array $defaultIfEmpty
1223
     * @return array
1224
     */
1225 2
    public function getSearchSortingOptionsConfiguration($defaultIfEmpty = [])
1226
    {
1227 2
        $result = $this->getObjectByPathOrDefault('plugin.tx_solr.search.sorting.options.', $defaultIfEmpty);
1228 2
        return $result;
1229
    }
1230
1231
    /**
1232
     * Retrieves the sorting default order for a sort option.
1233
     *
1234
     * plugin.tx_solr.search.sorting.options.<sortOptionName>.defaultOrder
1235
     *
1236
     * or
1237
     *
1238
     * plugin.tx_solr.search.sorting.defaultOrder
1239
     *
1240
     *
1241
     * @param string $sortOptionName
1242
     * @param string $defaultIfEmpty
1243
     * @return string
1244
     */
1245 5
    public function getSearchSortingDefaultOrderBySortOptionName($sortOptionName = '', $defaultIfEmpty = 'asc')
1246
    {
1247 5
        $sortOrderSpecificPath = 'plugin.tx_solr.search.sorting.options.' . $sortOptionName . '.defaultOrder';
1248 5
        $specificSortOrder = $this->getValueByPathOrDefaultValue($sortOrderSpecificPath, null);
1249
1250
        // if we have a concrete setting, use it
1251 5
        if ($specificSortOrder !== null) {
1252 2
            return mb_strtolower($specificSortOrder);
0 ignored issues
show
Bug introduced by
It seems like $specificSortOrder can also be of type array; however, parameter $string of mb_strtolower() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1252
            return mb_strtolower(/** @scrutinizer ignore-type */ $specificSortOrder);
Loading history...
1253
        }
1254
1255
        // no specific setting, check common setting
1256 3
        $commonPath = 'plugin.tx_solr.search.sorting.defaultOrder';
1257 3
        $commonATagParamOrDefaultValue = $this->getValueByPathOrDefaultValue($commonPath, $defaultIfEmpty);
1258 3
        return mb_strtolower($commonATagParamOrDefaultValue);
0 ignored issues
show
Bug introduced by
It seems like $commonATagParamOrDefaultValue can also be of type array and null; however, parameter $string of mb_strtolower() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1258
        return mb_strtolower(/** @scrutinizer ignore-type */ $commonATagParamOrDefaultValue);
Loading history...
1259
    }
1260
1261
    /**
1262
     * Returns the trusted fields configured for the search that do not need to be escaped.
1263
     *
1264
     * @param array $defaultIfEmpty
1265
     * @return array
1266
     */
1267 9
    public function getSearchTrustedFieldsArray($defaultIfEmpty = ['url'])
1268
    {
1269 9
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.trustedFields', '');
1270
1271 9
        if (trim($result) === '') {
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type array and null; however, parameter $string of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1271
        if (trim(/** @scrutinizer ignore-type */ $result) === '') {
Loading history...
1272 3
            return $defaultIfEmpty;
1273
        }
1274
1275 6
        return GeneralUtility::trimExplode(',', $result);
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type array; however, parameter $string of TYPO3\CMS\Core\Utility\G...lUtility::trimExplode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1275
        return GeneralUtility::trimExplode(',', /** @scrutinizer ignore-type */ $result);
Loading history...
1276
    }
1277
1278
    /**
1279
     * Indicates if the plugin arguments should be kept in the search form for a second submission.
1280
     *
1281
     * plugin.tx_solr.search.keepExistingParametersForNewSearches
1282
     *
1283
     * @param bool $defaultIfEmpty
1284
     * @return bool
1285
     */
1286
    public function getSearchKeepExistingParametersForNewSearches($defaultIfEmpty = false)
1287
    {
1288
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.keepExistingParametersForNewSearches', $defaultIfEmpty);
1289
        return $this->getBool($result);
1290
    }
1291
1292
    /**
1293
     * Returns if an empty query is allowed on the query level.
1294
     *
1295
     * plugin.tx_solr.search.query.allowEmptyQuery
1296
     *
1297
     * @param string $defaultIfEmpty
1298
     * @return bool
1299
     */
1300 91
    public function getSearchQueryAllowEmptyQuery($defaultIfEmpty = '')
1301
    {
1302 91
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.allowEmptyQuery', $defaultIfEmpty);
1303 91
        return $this->getBool($result);
1304
    }
1305
1306
    /**
1307
     * Returns the filter configuration array
1308
     *
1309
     * plugin.tx_solr.search.query.filter.
1310
     *
1311
     * @param array $defaultIfEmpty
1312
     * @return array
1313
     */
1314 96
    public function getSearchQueryFilterConfiguration(array $defaultIfEmpty = [])
1315
    {
1316 96
        $result = $this->getObjectByPathOrDefault('plugin.tx_solr.search.query.filter.', $defaultIfEmpty);
1317 96
        return $result;
1318
    }
1319
1320
    /**
1321
     * Can be used to overwrite the filterConfiguration.
1322
     *
1323
     * plugin.tx_solr.search.query.filter.
1324
     *
1325
     * @param array $configuration
1326
     */
1327 1
    public function setSearchQueryFilterConfiguration(array $configuration)
1328
    {
1329 1
        $this->configurationAccess->set('plugin.tx_solr.search.query.filter.', $configuration);
1330 1
    }
1331
1332
    /**
1333
     * Removes the pageSections filter setting.
1334
     *
1335
     * @return void
1336
     */
1337 2
    public function removeSearchQueryFilterForPageSections()
1338
    {
1339 2
        $this->configurationAccess->reset('plugin.tx_solr.search.query.filter.__pageSections');
1340 2
    }
1341
1342
    /**
1343
     * Returns the configured queryFields from TypoScript
1344
     *
1345
     * plugin.tx_solr.search.query.queryFields
1346
     *
1347
     * @param string $defaultIfEmpty
1348
     * @return string
1349
     */
1350 91
    public function getSearchQueryQueryFields($defaultIfEmpty = '')
1351
    {
1352 91
        return $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.queryFields', $defaultIfEmpty);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getValueBy...elds', $defaultIfEmpty) also could return the type array which is incompatible with the documented return type string.
Loading history...
1353
    }
1354
1355
    /**
1356
     * This method is used to check if a phrase search is enabled or not
1357
     *
1358
     * plugin.tx_solr.search.query.phrase = 1
1359
     *
1360
     * @param bool $defaultIfEmpty
1361
     * @return bool
1362
     */
1363 91
    public function getPhraseSearchIsEnabled(bool $defaultIfEmpty = false)
1364
    {
1365 91
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.phrase', $defaultIfEmpty);
1366 91
        return $this->getBool($result);
1367
    }
1368
1369
    /**
1370
     * Returns the configured phrase fields from TypoScript
1371
     *
1372
     * plugin.tx_solr.search.query.phrase.fields
1373
     *
1374
     * @param string $defaultIfEmpty
1375
     * @return string
1376
     */
1377 2
    public function getSearchQueryPhraseFields(string $defaultIfEmpty = '')
1378
    {
1379 2
        return $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.phrase.fields', $defaultIfEmpty);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getValueBy...elds', $defaultIfEmpty) also could return the type array which is incompatible with the documented return type string.
Loading history...
1380
    }
1381
1382
    /**
1383
     * This method is used to check if a bigram phrase search is enabled or not
1384
     *
1385
     * plugin.tx_solr.search.query.bigramPhrase = 1
1386
     *
1387
     * @param bool $defaultIfEmpty
1388
     * @return bool
1389
     */
1390 91
    public function getBigramPhraseSearchIsEnabled(bool $defaultIfEmpty = false)
1391
    {
1392 91
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.bigramPhrase', $defaultIfEmpty);
1393 91
        return $this->getBool($result);
1394
    }
1395
1396
    /**
1397
     * Returns the configured phrase fields from TypoScript
1398
     *
1399
     * plugin.tx_solr.search.query.bigramPhrase.fields
1400
     *
1401
     * @param string $defaultIfEmpty
1402
     * @return string
1403
     */
1404 2
    public function getSearchQueryBigramPhraseFields(string $defaultIfEmpty = '')
1405
    {
1406 2
        return $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.bigramPhrase.fields', $defaultIfEmpty);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getValueBy...elds', $defaultIfEmpty) also could return the type array which is incompatible with the documented return type string.
Loading history...
1407
    }
1408
1409
    /**
1410
     * This method is used to check if a trigram phrase search is enabled or not
1411
     *
1412
     * plugin.tx_solr.search.query.trigramPhrase = 1
1413
     *
1414
     * @param bool $defaultIfEmpty
1415
     * @return bool
1416
     */
1417 91
    public function getTrigramPhraseSearchIsEnabled(bool $defaultIfEmpty = false)
1418
    {
1419 91
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.trigramPhrase', $defaultIfEmpty);
1420 91
        return $this->getBool($result);
1421
    }
1422
1423
    /**
1424
     * Returns the configured trigram phrase fields from TypoScript
1425
     *
1426
     * plugin.tx_solr.search.query.trigramPhrase.fields
1427
     *
1428
     * @param string $defaultIfEmpty
1429
     * @return string
1430
     */
1431 2
    public function getSearchQueryTrigramPhraseFields(string $defaultIfEmpty = '')
1432
    {
1433 2
        return $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.trigramPhrase.fields', $defaultIfEmpty);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getValueBy...elds', $defaultIfEmpty) also could return the type array which is incompatible with the documented return type string.
Loading history...
1434
    }
1435
1436
    /**
1437
     * Returns the configured returnFields as array.
1438
     *
1439
     * plugin.tx_solr.search.query.returnFields
1440
     *
1441
     * @param array $defaultIfEmpty
1442
     * @return array
1443
     */
1444 93
    public function getSearchQueryReturnFieldsAsArray($defaultIfEmpty = [])
1445
    {
1446 93
        $returnFields = $this->getValueByPath('plugin.tx_solr.search.query.returnFields');
1447 93
        if (is_null($returnFields)) {
1448 86
            return $defaultIfEmpty;
1449
        }
1450
1451 7
        return GeneralUtility::trimExplode(',', $returnFields);
0 ignored issues
show
Bug introduced by
It seems like $returnFields can also be of type array; however, parameter $string of TYPO3\CMS\Core\Utility\G...lUtility::trimExplode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1451
        return GeneralUtility::trimExplode(',', /** @scrutinizer ignore-type */ $returnFields);
Loading history...
1452
    }
1453
1454
    /**
1455
     * Returns the configured target page for the search.
1456
     * By default the contextPageId will be used
1457
     *
1458
     * plugin.tx_solr.search.targetPage
1459
     *
1460
     * @return int
1461
     */
1462
    public function getSearchTargetPage()
1463
    {
1464
        $targetPage = (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.targetPage', 0);
1465
        if ($targetPage === 0) {
1466
            // when no specific page was configured we use the contextPageId (which is usual $GLOBALS['TSFE']->id)
1467
            $targetPage = $this->contextPageId;
1468
        }
1469
1470
        return $targetPage;
1471
    }
1472
1473
    /**
1474
     * Retrieves the targetPage configuration.
1475
     *
1476
     * plugin.tx_solr.search.targetPage.
1477
     *
1478
     * @param array $defaultIfEmpty
1479
     * @return array
1480
     */
1481
    public function getSearchTargetPageConfiguration(array $defaultIfEmpty = [])
1482
    {
1483
        $result = $this->getObjectByPathOrDefault('plugin.tx_solr.search.targetPage.', $defaultIfEmpty);
1484
        return $result;
1485
    }
1486
1487
    /**
1488
     * Method to check if the site highlighting is enabled. When the siteHighlighting is enabled the
1489
     * sword_list parameter is added to the results link.
1490
     *
1491
     * plugin.tx_solr.searcb.results.siteHighlighting
1492
     *
1493
     * @param bool $defaultIfEmpty
1494
     * @return bool
1495
     */
1496
    public function getSearchResultsSiteHighlighting($defaultIfEmpty = true)
1497
    {
1498
        $isSiteHightlightingEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.siteHighlighting', $defaultIfEmpty);
1499
        return $this->getBool($isSiteHightlightingEnabled);
1500
    }
1501
1502
1503
    /**
1504
     * Can be used to check if the highlighting is enabled
1505
     *
1506
     * plugin.tx_solr.search.results.resultsHighlighting
1507
     *
1508
     * @param boolean $defaultIfEmpty
1509
     * @return boolean
1510
     */
1511 91
    public function getSearchResultsHighlighting($defaultIfEmpty = false)
1512
    {
1513 91
        $isHighlightingEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.resultsHighlighting', $defaultIfEmpty);
1514 91
        return $this->getBool($isHighlightingEnabled);
1515
    }
1516
1517
    /**
1518
     * Returns the result highlighting fields.
1519
     *
1520
     * plugin.tx_solr.search.results.resultsHighlighting.highlightFields
1521
     *
1522
     * @param string $defaultIfEmpty
1523
     * @return string
1524
     */
1525 8
    public function getSearchResultsHighlightingFields($defaultIfEmpty = '')
1526
    {
1527 8
        return $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.resultsHighlighting.highlightFields', $defaultIfEmpty);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getValueBy...elds', $defaultIfEmpty) also could return the type array which is incompatible with the documented return type string.
Loading history...
1528
    }
1529
1530
    /**
1531
     * Returns the result highlighting fields as array.
1532
     *
1533
     * plugin.tx_solr.search.results.resultsHighlighting.highlightFields
1534
     *
1535
     * @param array $defaultIfEmpty
1536
     * @return array
1537
     */
1538
    public function getSearchResultsHighlightingFieldsAsArray($defaultIfEmpty = [])
1539
    {
1540
        $highlightingFields = $this->getSearchResultsHighlightingFields('');
1541
1542
        if ($highlightingFields === '') {
1543
            return $defaultIfEmpty;
1544
        }
1545
1546
        return GeneralUtility::trimExplode(',', $highlightingFields, true);
1547
    }
1548
1549
    /**
1550
     * Returns the fragmentSize for highlighted segments.
1551
     *
1552
     * plugin.tx_solr.search.results.resultsHighlighting.fragmentSize
1553
     *
1554
     * @param int $defaultIfEmpty
1555
     * @return int
1556
     */
1557 8
    public function getSearchResultsHighlightingFragmentSize($defaultIfEmpty = 200)
1558
    {
1559 8
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.resultsHighlighting.fragmentSize', $defaultIfEmpty);
1560
    }
1561
1562
    /**
1563
     * Returns the fragmentSeparator for highlighted segments.
1564
     *
1565
     * plugin.tx_solr.search.results.resultsHighlighting.fragmentSeparator
1566
     *
1567
     * @param string $defaultIfEmpty
1568
     * @return string
1569
     */
1570
    public function getSearchResultsHighlightingFragmentSeparator($defaultIfEmpty = '[...]')
1571
    {
1572
        return $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.resultsHighlighting.fragmentSeparator', $defaultIfEmpty);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getValueBy...ator', $defaultIfEmpty) also could return the type array which is incompatible with the documented return type string.
Loading history...
1573
    }
1574
1575
    /**
1576
     * Returns the number of results that should be shown per page.
1577
     *
1578
     * plugin.tx_solr.search.results.resultsPerPage
1579
     *
1580
     * @param int $defaultIfEmpty
1581
     * @return int
1582
     */
1583
    public function getSearchResultsPerPage($defaultIfEmpty = 10)
1584
    {
1585
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.resultsPerPage', $defaultIfEmpty);
1586
    }
1587
1588
    /**
1589
     * Returns the available options for the per page switch.
1590
     *
1591
     * plugin.tx_solr.search.results.resultsPerPageSwitchOptions
1592
     *
1593
     * @param array $defaultIfEmpty
1594
     * @return array
1595
     */
1596
    public function getSearchResultsPerPageSwitchOptionsAsArray($defaultIfEmpty = [])
1597
    {
1598
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.resultsPerPageSwitchOptions', '');
1599
1600
        if (trim($result) === '') {
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type array and null; however, parameter $string of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1600
        if (trim(/** @scrutinizer ignore-type */ $result) === '') {
Loading history...
1601
            return $defaultIfEmpty;
1602
        }
1603
1604
        return GeneralUtility::intExplode(',', $result, true);
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type array; however, parameter $string of TYPO3\CMS\Core\Utility\G...alUtility::intExplode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1604
        return GeneralUtility::intExplode(',', /** @scrutinizer ignore-type */ $result, true);
Loading history...
1605
    }
1606
1607
    /**
1608
     * Returns the configured wrap for the resultHighlighting.
1609
     *
1610
     * plugin.tx_solr.search.results.resultsHighlighting.wrap
1611
     *
1612
     * @param string $defaultIfEmpty
1613
     * @return string
1614
     */
1615 8
    public function getSearchResultsHighlightingWrap($defaultIfEmpty = '')
1616
    {
1617 8
        return $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.resultsHighlighting.wrap', $defaultIfEmpty);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getValueBy...wrap', $defaultIfEmpty) also could return the type array which is incompatible with the documented return type string.
Loading history...
1618
    }
1619
1620
    /**
1621
     * Indicates if spellchecking is enabled or not.
1622
     *
1623
     * plugin.tx_solr.search.spellchecking
1624
     *
1625
     * @param bool $defaultIfEmpty
1626
     * @return bool
1627
     */
1628 1
    public function getSearchSpellchecking($defaultIfEmpty = false)
1629
    {
1630 1
        $isFacetingEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.spellchecking', $defaultIfEmpty);
1631 1
        return $this->getBool($isFacetingEnabled);
1632
    }
1633
1634
    /**
1635
     * Returns the numberOfSuggestionsToTry that should be used for the spellchecking.
1636
     *
1637
     * plugin.tx_solr.search.spellchecking.numberOfSuggestionsToTry
1638
     *
1639
     * @param int $defaultIfEmpty
1640
     * @return int
1641
     */
1642 1
    public function getSearchSpellcheckingNumberOfSuggestionsToTry($defaultIfEmpty = 1)
1643
    {
1644 1
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.spellchecking.numberOfSuggestionsToTry', $defaultIfEmpty);
1645
    }
1646
1647
    /**
1648
     * Indicates if a second search should be fired from the spellchecking suggestion if no results could be found.
1649
     *
1650
     * plugin.tx_solr.search.spellchecking.searchUsingSpellCheckerSuggestion
1651
     *
1652
     * @param bool $defaultIfEmpty
1653
     * @return bool
1654
     */
1655 5
    public function getSearchSpellcheckingSearchUsingSpellCheckerSuggestion($defaultIfEmpty = false)
1656
    {
1657 5
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.spellchecking.searchUsingSpellCheckerSuggestion', $defaultIfEmpty);
1658 5
        return $this->getBool($result);
1659
    }
1660
1661
    /**
1662
     * Indicates if faceting is enabled or not.
1663
     *
1664
     * plugin.tx_solr.search.faceting
1665
     *
1666
     * @param bool $defaultIfEmpty
1667
     * @return bool
1668
     */
1669 91
    public function getSearchFaceting($defaultIfEmpty = false)
1670
    {
1671 91
        $isFacetingEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting', $defaultIfEmpty);
1672 91
        return $this->getBool($isFacetingEnabled);
1673
    }
1674
1675
    /**
1676
     * Retrieves the showEvenWhenEmpty for a facet by facet name. If nothing specific is configured
1677
     * the global showEmptyFacets with be returned.
1678
     *
1679
     * plugin.tx_solr.search.faceting.facets.<facetName>.showEvenWhenEmpty
1680
     *
1681
     * or
1682
     *
1683
     * plugin.tx_solr.search.faceting.showEmptyFacets
1684
     *
1685
     *
1686
     * @param string $facetName
1687
     * @param bool $defaultIfEmpty
1688
     * @return bool
1689
     */
1690 37
    public function getSearchFacetingShowEmptyFacetsByName($facetName = '', $defaultIfEmpty = false)
1691
    {
1692 37
        $facetSpecificPath = 'plugin.tx_solr.search.faceting.facets.' . $facetName . '.showEvenWhenEmpty';
1693 37
        $specificShowWhenEmpty = $this->getValueByPathOrDefaultValue($facetSpecificPath, null);
1694
1695
        // if we have a concrete setting, use it
1696 37
        if ($specificShowWhenEmpty !== null) {
1697 2
            return $specificShowWhenEmpty;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $specificShowWhenEmpty also could return the type array which is incompatible with the documented return type boolean.
Loading history...
1698
        }
1699
1700
        // no specific setting, check common setting
1701 37
        $commonPath = 'plugin.tx_solr.search.faceting.showEmptyFacets';
1702 37
        $commonIfEmptyOrDefaultValue = $this->getValueByPathOrDefaultValue($commonPath, $defaultIfEmpty);
1703 37
        return $commonIfEmptyOrDefaultValue;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $commonIfEmptyOrDefaultValue also could return the type array which is incompatible with the documented return type boolean.
Loading history...
1704
    }
1705
1706
    /**
1707
     * Returns the wrap for the faceting show all link
1708
     *
1709
     * plugin.tx_solr.search.faceting.showAllLink.wrap
1710
     *
1711
     * @param string $defaultIfEmpty
1712
     * @return string
1713
     */
1714
    public function getSearchFacetingShowAllLinkWrap($defaultIfEmpty = '')
1715
    {
1716
        return (string)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.showAllLink.wrap', $defaultIfEmpty);
1717
    }
1718
1719
    /**
1720
     * Returns the link url parameters that should be added to a facet.
1721
     *
1722
     * plugin.tx_solr.search.faceting.facetLinkUrlParameters
1723
     *
1724
     * @param string $defaultIfEmpty
1725
     * @return string
1726
     */
1727
    public function getSearchFacetingFacetLinkUrlParameters($defaultIfEmpty = '')
1728
    {
1729
        $linkUrlParameters = trim($this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.facetLinkUrlParameters', $defaultIfEmpty));
0 ignored issues
show
Bug introduced by
It seems like $this->getValueByPathOrD...ters', $defaultIfEmpty) can also be of type array and null; however, parameter $string of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1729
        $linkUrlParameters = trim(/** @scrutinizer ignore-type */ $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.facetLinkUrlParameters', $defaultIfEmpty));
Loading history...
1730
1731
        return $linkUrlParameters;
1732
    }
1733
1734
    /**
1735
     * Returns if the facetLinkUrlsParameters should be included in the reset link.
1736
     *
1737
     * plugin.tx_solr.search.faceting.facetLinkUrlParameters.useForFacetResetLinkUrl
1738
     *
1739
     * @param bool $defaultIfEmpty
1740
     * @return bool
1741
     */
1742
    public function getSearchFacetingFacetLinkUrlParametersUseForFacetResetLinkUrl($defaultIfEmpty = true)
1743
    {
1744
        $useForFacetResetLinkUrl = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.facetLinkUrlParameters.useForFacetResetLinkUrl', $defaultIfEmpty);
1745
        return $this->getBool($useForFacetResetLinkUrl);
1746
    }
1747
1748
    /**
1749
     * Returns the link url parameters that should be added to a facet as array.
1750
     *
1751
     * plugin.tx_solr.search.faceting.facetLinkUrlParameters
1752
     *
1753
     * @param array $defaultIfEmpty
1754
     * @return array
1755
     */
1756
    public function getSearchFacetingFacetLinkUrlParametersAsArray($defaultIfEmpty = [])
1757
    {
1758
        $linkUrlParameters = $this->getSearchFacetingFacetLinkUrlParameters();
1759
        if ($linkUrlParameters === '') {
1760
            return $defaultIfEmpty;
1761
        }
1762
1763
        return GeneralUtility::explodeUrl2Array($linkUrlParameters);
1764
    }
1765
1766
    /**
1767
     * Return the configured minimumCount value for facets.
1768
     *
1769
     * plugin.tx_solr.search.faceting.minimumCount
1770
     *
1771
     * @param int $defaultIfEmpty
1772
     * @return int
1773
     */
1774 15
    public function getSearchFacetingMinimumCount($defaultIfEmpty = 1)
1775
    {
1776 15
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.minimumCount', $defaultIfEmpty);
1777
    }
1778
1779
    /**
1780
     * Return the configured limit value for facets, used for displaying.
1781
     *
1782
     * plugin.tx_solr.search.faceting.limit
1783
     *
1784
     * @param int $defaultIfEmpty
1785
     * @return int
1786
     */
1787
    public function getSearchFacetingLimit($defaultIfEmpty = 10)
1788
    {
1789
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.limit', $defaultIfEmpty);
1790
    }
1791
1792
    /**
1793
     * Return the configured limit value for facets, used for the response.
1794
     *
1795
     * plugin.tx_solr.search.faceting.facetLimit
1796
     *
1797
     * @param int $defaultIfEmpty
1798
     * @return int
1799
     */
1800 15
    public function getSearchFacetingFacetLimit($defaultIfEmpty = 100)
1801
    {
1802 15
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.facetLimit', $defaultIfEmpty);
1803
    }
1804
1805
    /**
1806
     * Return the configured url parameter style value for facets, used for building faceting parameters.
1807
     *
1808
     * plugin.tx_solr.search.faceting.urlParameterStyle
1809
     *
1810
     * @param string $defaultUrlParameterStyle
1811
     * @return string
1812
     */
1813 12
    public function getSearchFacetingUrlParameterStyle(string $defaultUrlParameterStyle = 'index'): string
1814
    {
1815 12
        return (string)$this->getValueByPathOrDefaultValue(
1816 12
            'plugin.tx_solr.search.faceting.urlParameterStyle',
1817
            $defaultUrlParameterStyle
1818
        );
1819
    }
1820
1821
    /**
1822
     * Return the configuration if the URL parameters should be sorted.
1823
     *
1824
     * plugin.tx_solr.search.faceting.urlParameterSort
1825
     *
1826
     * @param bool $defaultUrlParameterSort
1827
     * @return bool
1828
     */
1829 5
    public function getSearchFacetingUrlParameterSort(bool $defaultUrlParameterSort = false): bool
1830
    {
1831 5
        return (bool)$this->getValueByPathOrDefaultValue(
1832 5
            'plugin.tx_solr.search.faceting.urlParameterSort',
1833
            $defaultUrlParameterSort
1834
        );
1835
    }
1836
1837
    /**
1838
     * Return the configured faceting sortBy value.
1839
     *
1840
     * plugin.tx_solr.search.faceting.sortBy
1841
     *
1842
     * @param string $defaultIfEmpty
1843
     * @return string
1844
     */
1845 15
    public function getSearchFacetingSortBy($defaultIfEmpty = '')
1846
    {
1847 15
        return $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.sortBy', $defaultIfEmpty);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getValueBy...rtBy', $defaultIfEmpty) also could return the type array which is incompatible with the documented return type string.
Loading history...
1848
    }
1849
1850
    /**
1851
     * Returns if a facets should be kept on selection. Global faceting setting
1852
     * can also be configured on facet level by using
1853
     * (plugin.tx_solr.search.faceting.facets.<fieldName>.keepAllOptionsOnSelection)
1854
     *
1855
     * plugin.tx_solr.search.faceting.keepAllFacetsOnSelection
1856
     *
1857
     * @param bool $defaultIfEmpty
1858
     * @return bool
1859
     */
1860 15
    public function getSearchFacetingKeepAllFacetsOnSelection($defaultIfEmpty = false)
1861
    {
1862 15
        $keepAllOptionsOnSelection = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.keepAllFacetsOnSelection', $defaultIfEmpty);
1863 15
        return $this->getBool($keepAllOptionsOnSelection);
1864
    }
1865
1866
    /**
1867
     * Returns if the facet count should be calculated based on the facet selection when
1868
     * plugin.tx_solr.search.faceting.keepAllFacetsOnSelection has been enabled
1869
     *
1870
     * plugin.tx_solr.search.faceting.countAllFacetsForSelection
1871
     *
1872
     * @param bool $defaultIfEmpty
1873
     * @return bool
1874
     */
1875 5
    public function getSearchFacetingCountAllFacetsForSelection($defaultIfEmpty = false)
1876
    {
1877 5
        $countAllFacetsForSelection = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.countAllFacetsForSelection', $defaultIfEmpty);
1878 5
        return $this->getBool($countAllFacetsForSelection);
1879
    }
1880
1881
    /**
1882
     * Returns the configured faceting configuration.
1883
     *
1884
     * plugin.tx_solr.search.faceting.facets
1885
     *
1886
     * @param array $defaultIfEmpty
1887
     * @return array
1888
     */
1889 42
    public function getSearchFacetingFacets(array $defaultIfEmpty = [])
1890
    {
1891 42
        return $this->getObjectByPathOrDefault('plugin.tx_solr.search.faceting.facets.', $defaultIfEmpty);
1892
    }
1893
1894
    /**
1895
     * Returns the configuration of a single facet by facet name.
1896
     *
1897
     * plugin.tx_solr.search.faceting.facets.<facetName>
1898
     *
1899
     * @param string $facetName
1900
     * @param array $defaultIfEmpty
1901
     * @return array
1902
     */
1903 15
    public function getSearchFacetingFacetByName($facetName, $defaultIfEmpty = [])
1904
    {
1905 15
        return $this->getObjectByPathOrDefault('plugin.tx_solr.search.faceting.facets.' . $facetName . '.', $defaultIfEmpty);
1906
    }
1907
1908
    /**
1909
     * Indicates if statistics is enabled or not.
1910
     *
1911
     * plugin.tx_solr.statistics
1912
     *
1913
     * @param bool $defaultIfEmpty
1914
     * @return bool
1915
     */
1916 6
    public function getStatistics($defaultIfEmpty = false)
1917
    {
1918 6
        $isStatisticsEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.statistics', $defaultIfEmpty);
1919 6
        return $this->getBool($isStatisticsEnabled);
1920
    }
1921
1922
    /**
1923
     * Indicates to which length an ip should be anonymized in the statistics
1924
     *
1925
     * plugin.tx_solr.statistics.anonymizeIP
1926
     *
1927
     * @param int $defaultIfEmpty
1928
     * @return int
1929
     */
1930
    public function getStatisticsAnonymizeIP($defaultIfEmpty = 0)
1931
    {
1932
        $anonymizeToLength = $this->getValueByPathOrDefaultValue('plugin.tx_solr.statistics.anonymizeIP', $defaultIfEmpty);
1933
        return (int)$anonymizeToLength;
1934
    }
1935
1936
    /**
1937
     * Indicates if additional debug Data should be added to the statistics
1938
     *
1939
     * plugin.tx_solr.statistics.addDebugData
1940
     *
1941
     * @param bool $defaultIfEmpty
1942
     * @return bool
1943
     */
1944 1
    public function getStatisticsAddDebugData($defaultIfEmpty = false)
1945
    {
1946 1
        $statisticsAddDebugDataEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.statistics.addDebugData', $defaultIfEmpty);
1947 1
        return $this->getBool($statisticsAddDebugDataEnabled);
1948
    }
1949
1950
    /**
1951
     * Indicates if suggestion is enabled or not.
1952
     *
1953
     * plugin.tx_solr.suggest
1954
     *
1955
     * @param bool $defaultIfEmpty
1956
     * @return bool
1957
     */
1958
    public function getSuggest($defaultIfEmpty = false)
1959
    {
1960
        $isSuggestionEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.suggest', $defaultIfEmpty);
1961
        return $this->getBool($isSuggestionEnabled);
1962
    }
1963
1964
    /**
1965
     * Indicates if https should be used for the suggest form.
1966
     *
1967
     * plugin.tx_solr.suggest.forceHttps
1968
     *
1969
     * @param bool $defaultIfEmpty
1970
     * @return bool
1971
     */
1972
    public function getSuggestForceHttps($defaultIfEmpty = false)
1973
    {
1974
        $isHttpsForced = $this->getValueByPathOrDefaultValue('plugin.tx_solr.suggest.forceHttps', $defaultIfEmpty);
1975
        return $this->getBool($isHttpsForced);
1976
    }
1977
1978
    /**
1979
     * Returns the allowed number of suggestions.
1980
     *
1981
     * plugin.tx_solr.suggest.numberOfSuggestions
1982
     *
1983
     * @param int $defaultIfEmpty
1984
     * @return int
1985
     */
1986
    public function getSuggestNumberOfSuggestions($defaultIfEmpty = 10)
1987
    {
1988
        $numberOfSuggestions = $this->getValueByPathOrDefaultValue('plugin.tx_solr.suggest.numberOfSuggestions', $defaultIfEmpty);
1989
        return (int)$numberOfSuggestions;
1990
    }
1991
1992
    /**
1993
     * Indicates if the topResults should be shown or not
1994
     *
1995
     * plugin.tx_solr.suggest.showTopResults
1996
     *
1997
     * @param bool $defaultIfEmpty
1998
     * @return bool
1999
     */
2000
    public function getSuggestShowTopResults($defaultIfEmpty = true)
2001
    {
2002
        $showTopResults = $this->getValueByPathOrDefaultValue('plugin.tx_solr.suggest.showTopResults', $defaultIfEmpty);
2003
        return $this->getBool($showTopResults);
2004
    }
2005
2006
    /**
2007
     * Returns the configured number of top results to show
2008
     *
2009
     * plugin.tx_solr.suggest.numberOfTopResults
2010
     *
2011
     * @param int $defaultIfEmpty
2012
     * @return int
2013
     */
2014
    public function getSuggestNumberOfTopResults($defaultIfEmpty = 5)
2015
    {
2016
        $numberOfTopResults = $this->getValueByPathOrDefaultValue('plugin.tx_solr.suggest.numberOfTopResults', $defaultIfEmpty);
2017
        return (int)$numberOfTopResults;
2018
    }
2019
2020
    /**
2021
     * Returns additional fields for the top results
2022
     *
2023
     * plugin.tx_solr.suggest.additionalTopResultsFields
2024
     *
2025
     * @param array $defaultIfEmpty
2026
     * @return array
2027
     */
2028
    public function getSuggestAdditionalTopResultsFields($defaultIfEmpty = [])
2029
    {
2030
        $additionalTopResultsFields = $this->getValueByPathOrDefaultValue('plugin.tx_solr.suggest.additionalTopResultsFields', '');
2031
        if ($additionalTopResultsFields === '') {
2032
            return $defaultIfEmpty;
2033
        }
2034
2035
        return GeneralUtility::trimExplode(',', $additionalTopResultsFields, true);
0 ignored issues
show
Bug introduced by
It seems like $additionalTopResultsFields can also be of type array; however, parameter $string of TYPO3\CMS\Core\Utility\G...lUtility::trimExplode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

2035
        return GeneralUtility::trimExplode(',', /** @scrutinizer ignore-type */ $additionalTopResultsFields, true);
Loading history...
2036
    }
2037
2038
    /**
2039
     * Returns the configured template for a specific template fileKey.
2040
     *
2041
     * plugin.tx_solr.view.templateFiles.<fileKey>
2042
     *
2043
     * @param string $fileKey
2044
     * @param string $defaultIfEmpty
2045
     * @return string
2046
     */
2047
    public function getViewTemplateByFileKey($fileKey, $defaultIfEmpty = '')
2048
    {
2049
        $templateFileName = $this->getValueByPathOrDefaultValue('plugin.tx_solr.view.templateFiles.' . $fileKey, $defaultIfEmpty);
2050
        return (string)$templateFileName;
2051
    }
2052
2053
    /**
2054
     * Returns the configured available template files for the flexform.
2055
     *
2056
     * plugin.tx_solr.view.templateFiles.[fileKey].availableTemplates.
2057
     *
2058
     * @param string $fileKey
2059
     * @return array
2060
     */
2061
    public function getAvailableTemplatesByFileKey($fileKey)
2062
    {
2063
        $path = 'plugin.tx_solr.view.templateFiles.' . $fileKey . '.availableTemplates.';
2064
        return (array)$this->getObjectByPathOrDefault($path, []);
2065
    }
2066
2067
    /**
2068
     * Returns the configuration of the crop view helper.
2069
     *
2070
     * plugin.tx_solr.viewHelpers.crop.
2071
     *
2072
     * @param array $defaultIfEmpty
2073
     * @return array
2074
     */
2075
    public function getViewHelpersCropConfiguration(array $defaultIfEmpty = [])
2076
    {
2077
        $cropViewHelperConfiguration = $this->getObjectByPathOrDefault('plugin.tx_solr.viewHelpers.crop.', $defaultIfEmpty);
2078
        return $cropViewHelperConfiguration;
2079
    }
2080
2081
    /**
2082
     * Returns the configuration of the sorting view helper.
2083
     *
2084
     * plugin.tx_solr.viewHelpers.sortIndicator.
2085
     *
2086
     * @param array $defaultIfEmpty
2087
     * @return array
2088
     */
2089
    public function getViewHelpersSortIndicatorConfiguration(array $defaultIfEmpty = [])
2090
    {
2091
        $sortingViewHelperConfiguration = $this->getObjectByPathOrDefault('plugin.tx_solr.viewHelpers.sortIndicator.', $defaultIfEmpty);
2092
        return $sortingViewHelperConfiguration;
2093
    }
2094
2095
    /**
2096
     * Controls whether ext-solr will send commits to solr.
2097
     * Beware: If you disable this, you need to ensure
2098
     * that some other mechanism will commit your changes
2099
     * otherwise they will never be searchable.
2100
     * A good way to achieve this is enabling the solr
2101
     * daemons autoCommit feature.
2102
     *
2103
     * plugin.tx_solr.index.enableCommits
2104
     *
2105
     * @param bool $defaultIfEmpty
2106
     * @return bool
2107
     */
2108 24
    public function getEnableCommits($defaultIfEmpty = true)
2109
    {
2110 24
        $enableCommits = $this->getValueByPathOrDefaultValue('plugin.tx_solr.index.enableCommits', $defaultIfEmpty);
2111 24
        return $this->getBool($enableCommits);
2112
    }
2113
2114
    /**
2115
     * Returns the url namespace that is used for the arguments.
2116
     *
2117
     * plugin.tx_solr.view.pluginNamespace
2118
     *
2119
     * @param string $defaultIfEmpty
2120
     * @return string
2121
     */
2122 5
    public function getSearchPluginNamespace($defaultIfEmpty = 'tx_solr')
2123
    {
2124 5
        return $this->getValueByPathOrDefaultValue('plugin.tx_solr.view.pluginNamespace', $defaultIfEmpty);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getValueBy...pace', $defaultIfEmpty) also could return the type array which is incompatible with the documented return type string.
Loading history...
2125
    }
2126
2127
    /**
2128
     * Returns true if the global url parameter q, that indicates the query should be used.
2129
     *
2130
     * Should be set to false, when multiple instance on the same page should have their querystring.
2131
     *
2132
     * plugin.tx_solr.search.ignoreGlobalQParameter
2133
     *
2134
     * @param bool $defaultIfEmpty
2135
     * @return bool
2136
     */
2137
    public function getSearchIgnoreGlobalQParameter($defaultIfEmpty = false)
2138
    {
2139
        $enableQParameter = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.ignoreGlobalQParameter', $defaultIfEmpty);
2140
        return $this->getBool($enableQParameter);
2141
2142
    }
2143
2144
    /**
2145
     * Returns the argument names, that should be added to the persistent arguments, as array.
2146
     *
2147
     * plugin.tx_solr.search.additionalPersistentArgumentNames
2148
     *
2149
     * @param array $defaultIfEmpty
2150
     * @return array
2151
     */
2152 7
    public function getSearchAdditionalPersistentArgumentNames($defaultIfEmpty = [])
2153
    {
2154 7
        $additionalPersistentArgumentNames = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.additionalPersistentArgumentNames', '');
2155
2156 7
        if ($additionalPersistentArgumentNames === '') {
2157 6
            return $defaultIfEmpty;
2158
        }
2159
2160 1
        return GeneralUtility::trimExplode(',', $additionalPersistentArgumentNames, true);
0 ignored issues
show
Bug introduced by
It seems like $additionalPersistentArgumentNames can also be of type array; however, parameter $string of TYPO3\CMS\Core\Utility\G...lUtility::trimExplode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

2160
        return GeneralUtility::trimExplode(',', /** @scrutinizer ignore-type */ $additionalPersistentArgumentNames, true);
Loading history...
2161
2162
    }
2163
2164
    /**
2165
     * Method to check if grouping was enabled with typoscript.
2166
     *
2167
     * plugin.tx_solr.search.grouping
2168
     *
2169
     * @param bool $defaultIfEmpty
2170
     * @return bool
2171
     */
2172 93
    public function getSearchGrouping($defaultIfEmpty = false)
2173
    {
2174 93
        $groupingEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.grouping', $defaultIfEmpty);
2175 93
        return $this->getBool($groupingEnabled);
2176
    }
2177
2178
    /**
2179
     * Returns the configured numberOfGroups.
2180
     *
2181
     * plugin.tx_solr.search.grouping.numberOfGroups
2182
     *
2183
     * @param int $defaultIfEmpty
2184
     * @return int
2185
     */
2186 1
    public function getSearchGroupingNumberOfGroups($defaultIfEmpty = 5)
2187
    {
2188 1
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.grouping.numberOfGroups', $defaultIfEmpty);
2189
    }
2190
2191
    /**
2192
     * Returns the sortBy configuration for the grouping.
2193
     *
2194
     * plugin.tx_solr.search.grouping.sortBy
2195
     *
2196
     * @param string $defaultIfEmpty
2197
     * @return string
2198
     */
2199 1
    public function getSearchGroupingSortBy($defaultIfEmpty = '')
2200
    {
2201 1
        return (string)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.grouping.sortBy', $defaultIfEmpty);
2202
    }
2203
2204
    /**
2205
     * Returns the highestValue of the numberOfResultsPerGroup configuration that is globally configured and
2206
     * for each group.
2207
     *
2208
     * plugin.tx_solr.search.grouping.
2209
     *
2210
     * @param int $defaultIfEmpty
2211
     * @return int
2212
     */
2213 3
    public function getSearchGroupingHighestGroupResultsLimit($defaultIfEmpty = 1)
2214
    {
2215 3
        $groupingConfiguration = $this->getObjectByPathOrDefault('plugin.tx_solr.search.grouping.', []);
2216 3
        $highestLimit = $defaultIfEmpty;
2217 3
        if (!empty($groupingConfiguration['numberOfResultsPerGroup'])) {
2218 2
            $highestLimit = $groupingConfiguration['numberOfResultsPerGroup'];
2219
        }
2220
2221 3
        $configuredGroups = $groupingConfiguration['groups.'];
2222 3
        if (!is_array($configuredGroups)) {
2223 1
            return $highestLimit;
2224
        }
2225
2226 2
        foreach ($configuredGroups as $groupName => $groupConfiguration) {
2227 2
            if (!empty($groupConfiguration['numberOfResultsPerGroup']) && $groupConfiguration['numberOfResultsPerGroup'] > $highestLimit) {
2228 1
                $highestLimit = $groupConfiguration['numberOfResultsPerGroup'];
2229
            }
2230
        }
2231
2232 2
        return $highestLimit;
2233
    }
2234
2235
    /**
2236
     * Returns the valid numberOfResultsPerGroup value for a group.
2237
     *
2238
     * Returns:
2239
     *
2240
     * plugin.tx_solr.search.grouping.groups.<groupName>.numberOfResultsPerGroup if it is set otherwise
2241
     * plugin.tx_solr.search.grouping.numberOfResultsPerGroup
2242
     *
2243
     * @param string $groupName
2244
     * @param int $defaultIfEmpty
2245
     * @return int
2246
     */
2247
    public function getSearchGroupingResultLimit($groupName, $defaultIfEmpty = 1)
2248
    {
2249
        $specificPath = 'plugin.tx_solr.search.grouping.groups.' . $groupName . '.numberOfResultsPerGroup';
2250
        $specificResultsPerGroup = $this->getValueByPathOrDefaultValue($specificPath, null);
2251
2252
        if ($specificResultsPerGroup !== null) {
2253
            return (int) $specificResultsPerGroup;
2254
        }
2255
2256
        $commonPath = 'plugin.tx_solr.search.grouping.numberOfResultsPerGroup';
2257
        $commonValue = $this->getValueByPathOrDefaultValue($commonPath, null);
2258
        if ($commonValue !== null) {
2259
            return (int) $commonValue;
2260
        }
2261
2262
        return $defaultIfEmpty;
2263
    }
2264
2265
    /**
2266
     * Returns everything that is configured for the groups (plugin.tx_solr.search.grouping.groups.)
2267
     *
2268
     * plugin.tx_solr.search.grouping.groups.
2269
     *
2270
     * @param array $defaultIfEmpty
2271
     * @return array
2272
     */
2273 1
    public function getSearchGroupingGroupsConfiguration($defaultIfEmpty = [])
2274
    {
2275 1
        return $this->getObjectByPathOrDefault('plugin.tx_solr.search.grouping.groups.', $defaultIfEmpty);
2276
    }
2277
2278
    /*
2279
     * Applies the stdWrap if it is configured for the path, otherwise the unprocessed value will be returned.
2280
     *
2281
     * @param string $valuePath
2282
     * @param mixed $value
2283
     * @return mixed
2284
     */
2285
    protected function renderContentElementOfConfigured($valuePath, $value)
2286
    {
2287
        $configurationPath = $valuePath . '.';
2288
        $configuration = $this->getObjectByPath($configurationPath);
2289
2290
        if ($configuration == null) {
2291
            return $value;
2292
        }
2293
        if ($this->contentObjectService === null) {
2294
            $this->contentObjectService = GeneralUtility::makeInstance(ContentObjectService::class);
2295
        }
2296
        return $this->contentObjectService->renderSingleContentObject($value, $configuration);
2297
    }
2298
}
2299