Passed
Pull Request — master (#2809)
by
unknown
34:29
created

TypoScriptConfiguration::getUnifiedArray()   A

Complexity

Conditions 6
Paths 4

Size

Total Lines 28
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 13
c 0
b 0
f 0
dl 0
loc 28
ccs 6
cts 6
cp 1
rs 9.2222
cc 6
nc 4
nop 0
crap 6
1
<?php
2
namespace ApacheSolrForTypo3\Solr\System\Configuration;
3
4
/***************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2016 Timo Schmidt <[email protected]>
8
 *  All rights reserved
9
 *
10
 *  This script is part of the TYPO3 project. The TYPO3 project is
11
 *  free software; you can redistribute it and/or modify
12
 *  it under the terms of the GNU General Public License as published by
13
 *  the Free Software Foundation; either version 3 of the License, or
14
 *  (at your option) any later version.
15
 *
16
 *  The GNU General Public License can be found at
17
 *  http://www.gnu.org/copyleft/gpl.html.
18
 *  A copy is found in the textfile GPL.txt and important notices to the license
19
 *  from the author is found in LICENSE.txt distributed with these scripts.
20
 *
21
 *
22
 *  This script is distributed in the hope that it will be useful,
23
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
24
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
 *  GNU General Public License for more details.
26
 *
27
 *  This copyright notice MUST APPEAR in all copies of the script!
28
 ***************************************************************/
29
30
use ApacheSolrForTypo3\Solr\IndexQueue\Indexer;
31
use ApacheSolrForTypo3\Solr\IndexQueue\Initializer\Record;
32
use ApacheSolrForTypo3\Solr\System\ContentObject\ContentObjectService;
33
use ApacheSolrForTypo3\Solr\System\Util\ArrayAccessor;
34
use InvalidArgumentException;
35
use TYPO3\CMS\Core\TypoScript\TypoScriptService;
36
use TYPO3\CMS\Core\Utility\ArrayUtility;
37
use TYPO3\CMS\Core\Utility\GeneralUtility;
38
39
/**
40
 * TypoScript configuration object, used to read all TypoScript configuration.
41
 *
42
 * The TypoScriptConfiguration was introduced in order to be able to replace the old,
43
 * array based configuration with one configuration object.
44
 *
45
 * To read the configuration, you should use
46
 *
47
 * $configuration->getValueByPath
48
 *
49
 * or
50
 *
51
 * $configuration->isValidPath
52
 *
53
 * to check if an configuration path exists.
54
 *
55
 * To ensure Backwards compatibility the TypoScriptConfiguration object implements the
56
 * ArrayAccess interface (offsetGet,offsetExists,offsetUnset and offsetSet)
57
 *
58
 * This was only introduced to be backwards compatible in logTerm only "getValueByPath", "isValidPath" or
59
 * speaking methods for configuration settings should be used!
60
 *
61
 * @author Marc Bastian Heinrichs <[email protected]>
62
 * @author Timo Schmidt <[email protected]>
63
 */
64
class TypoScriptConfiguration implements UnifyConfigurationInterface
65
{
66
    /**
67
     * @var ArrayAccessor|null
68
     */
69
    protected $configurationAccess = null;
70
71
    /**
72
     * Holds the pageId in which context the configuration was parsed
73
     * (normally $GLOBALS['TSFE']->id)
74
     */
75
    protected $contextPageId = 0;
76
77
    /**
78
     * @var ContentObjectService
79
     */
80
    protected $contentObjectService = null;
81
82
    /**
83
     * @param array $configuration
84
     * @param int $contextPageId
85
     * @param ContentObjectService $contentObjectService
86 295
     */
87
    public function __construct(
88 295
        array $configuration,
89 295
        int $contextPageId = 0,
90 295
        ContentObjectService $contentObjectService = null
91 295
    ) {
92
        $this->configurationAccess = new ArrayAccessor($configuration, '.', true);
93
        $this->contextPageId = $contextPageId;
94
        $this->contentObjectService = $contentObjectService;
95
    }
96
97
    /**
98 236
     * {@inheritDoc}
99
     */
100 236
    public function load(): UnifyConfigurationInterface
101
    {
102
        if (!empty($configuration)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $configuration seems to never exist and therefore empty should always be true.
Loading history...
103
            return $this;
104
        }
105
        // TODO: Load configuration if empty
106
107
        return $this;
108
    }
109
110
    /**
111
     * {@inheritDoc}
112 32
     */
113
    public function getUnifiedArray(): array
114 32
    {
115
        $pluginData = $this->configurationAccess->get('plugin.tx_solr.');
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

115
        /** @scrutinizer ignore-call */ 
116
        $pluginData = $this->configurationAccess->get('plugin.tx_solr.');

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...
116 32
117 12
        if ($pluginData === null) {
118
            return [];
119 9
        }
120
        /*
121
         * Remove dots and make the array clean
122 12
         * Important: if a node can enabled and has sub nodes, the node value is located within _typoScriptNodeValue
123
         */
124
        $typoScriptService = new TypoScriptService();
125 32
        $pluginData = $typoScriptService->convertTypoScriptArrayToPlainArray($pluginData);
126
127
        // Change keys for Solr connection
128
        // TODO: This should not be done if the site configuration is in use
129
        if (isset($pluginData['solr'])) {
130
            if (!isset($pluginData['connection'])) {
131
                $pluginData['connection'] = [];
132
            }
133
            foreach (['read', 'write'] as $type) {
134
                if (isset($pluginData['solr'][$type])) {
135
                    $pluginData['connection'][$type] = $pluginData['solr'][$type];
136
                    unset($pluginData['solr'][$type]);
137
                }
138
            }
139
        }
140
        return $pluginData;
141
    }
142
143 270
    /**
144
     * Checks if a value is 1, '1', 'true'
145 270
     * @param mixed $value
146
     * @return bool
147
     */
148
    protected function getBool($value)
149 270
    {
150
        return filter_var($value, FILTER_VALIDATE_BOOLEAN);
151
    }
152
153
    /**
154
     * This method can be used to only retrieve array keys where the value is not an array.
155
     *
156
     * This can be very handy in the configuration when only keys should ne taken into account
157
     * where the value is not a subconfiguration (typically an typoscript object path).
158
     *
159
     * @param $inputArray
160 267
     * @return array
161
     */
162 267
    protected function getOnlyArrayKeysWhereValueIsNotAnArray($inputArray)
163 267
    {
164 254
        $keysWithNonArrayValue = [];
165
166
        foreach ($inputArray as $key => $value) {
167 148
            if (is_array($value)) {
168
                // configuration for a content object, skipping
169
                continue;
170
            }
171
172
            $keysWithNonArrayValue[] = $key;
173
        }
174
175
        return $keysWithNonArrayValue;
176
    }
177
178
    /**
179
     * Gets the value from a given TypoScript path.
180
     *
181
     * In the context of an frontend content element the path plugin.tx_solr is
182
     * merged recursive with overrule with the content element specific typoscript
183
     * settings, like plugin.tx_solr_PiResults_Results, and possible flex form settings
184
     * (depends on the solr plugin).
185
     *
186 251
     * Example: plugin.tx_solr.search.targetPage
187
     * returns $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_solr.']['search.']['targetPage']
188 251
     *
189 1
     * @param string $path TypoScript path
190 1
     * @return mixed The TypoScript object defined by the given path
191
     * @throws InvalidArgumentException
192
     */
193 251
    public function getValueByPath($path)
194
    {
195
        if (!is_string($path)) {
0 ignored issues
show
introduced by
The condition is_string($path) is always true.
Loading history...
196
            throw new InvalidArgumentException('Parameter $path is not a string',
197 251
                1325623321);
198
        }
199
        return $this->configurationAccess->get($path);
200
    }
201
202
    /**
203
     * This method can be used to get  a configuration value by path if it exists or return a
204
     * default value when it does not exist.
205
     *
206
     * @param string $path
207
     * @param mixed $defaultValue
208
     * @return mixed
209 250
     */
210
    public function getValueByPathOrDefaultValue($path, $defaultValue)
211
    {
212 250
        $value = $this->getValueByPath($path);
213
        if (is_null($value)) {
214
            return $defaultValue;
215
        }
216
217 250
        return $value;
218 121
    }
219
220
    /**
221 174
     * Gets the parent TypoScript Object from a given TypoScript path.
222
     *
223
     * In the context of an frontend content element the path plugin.tx_solr is
224
     * merged recursive with overrule with the content element specific typoscript
225
     * settings, like plugin.tx_solr_PiResults_Results, and possible flex form settings
226
     * (depends on the solr plugin).
227
     *
228
     * Example: plugin.tx_solr.index.queue.tt_news.fields.content
229
     * returns $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_solr.']['index.']['queue.']['tt_news.']['fields.']['content.']
230
     * which is a SOLR_CONTENT cObj.
231
     *
232
     * @param string $path TypoScript path
233
     * @return array The TypoScript object defined by the given path
234
     * @throws InvalidArgumentException
235
     */
236
    public function getObjectByPath($path)
237
    {
238
        if (substr($path, -1) !== '.') {
239
            $path = rtrim($path, '.');
240
            $path = substr($path, 0, strrpos($path, '.') + 1);
241
        }
242
243
        if (!is_string($path)) {
0 ignored issues
show
introduced by
The condition is_string($path) is always true.
Loading history...
244
            throw new InvalidArgumentException('Parameter $path is not a string', 1325627243);
245
        }
246
247
        return $this->configurationAccess->get($path);
248
    }
249
250
    /**
251 6
     * Gets the parent TypoScript Object from a given TypoScript path and if not present return
252
     * the default value
253 6
     *
254 6
     * @see getObjectByPath
255 6
     * @param string $path
256 6
     * @param array $defaultValue
257 6
     * @return array
258 6
     */
259 6
    public function getObjectByPathOrDefault($path, array $defaultValue)
260
    {
261
        try {
262 6
            $object = $this->getObjectByPath($path);
263
        } catch (\InvalidArgumentException $e) {
264 6
            return $defaultValue;
265
        }
266
267
        if (!is_array($object)) {
0 ignored issues
show
introduced by
The condition is_array($object) is always true.
Loading history...
268
            return $defaultValue;
269
        }
270
271
        return $object;
272
    }
273
274
    /**
275
     * Checks whether a given TypoScript path is valid.
276
     *
277
     * @param string $path TypoScript path
278
     * @return bool TRUE if the path resolves, FALSE otherwise
279
     */
280
    public function isValidPath($path)
281
    {
282
        $isValidPath = false;
283
284
        $pathValue = $this->getValueByPath($path);
285
        if (!is_null($pathValue)) {
286
            $isValidPath = true;
287
        }
288 32
289
        return $isValidPath;
290 32
    }
291 32
292
    /**
293
     * Merges a configuration with another configuration a
294
     *
295
     * @param array $configurationToMerge
296
     * @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.
297
     * @param bool $includeEmptyValues If set, values from $overrule will overrule if they are empty or zero.
298
     * @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.
299
     * @return TypoScriptConfiguration
300
     */
301
    public function mergeSolrConfiguration(array $configurationToMerge, $addKeys = true, $includeEmptyValues = true, $enableUnsetFeature = true)
302
    {
303 31
        $data = $this->configurationAccess->getData();
304
        ArrayUtility::mergeRecursiveWithOverrule(
305 31
            $data['plugin.']['tx_solr.'],
306 31
            $configurationToMerge,
307 31
            $addKeys,
308
            $includeEmptyValues,
309
            $enableUnsetFeature
310
        );
311
312
        $this->configurationAccess->setData($data);
313
314
        return $this;
315
    }
316
317
    /**
318 49
     * Returns true when ext_solr is enabled
319
     *
320 49
     * @param boolean $defaultIfEmpty
321 49
     * @return boolean
322
     */
323
    public function getEnabled($defaultIfEmpty = false)
324
    {
325
        $path = 'plugin.tx_solr.enabled';
326
        $result = $this->getValueByPathOrDefaultValue($path, $defaultIfEmpty);
327
        return $this->getBool($result);
328
    }
329
330
    /**
331
     * Returns the configured additionalFields configured for the indexing.
332
     *
333 7
     * plugin.tx_solr.index.additionalFields.
334
     *
335 7
     * @param array $defaultIfEmpty
336 7
     * @return array
337 7
     */
338
    public function getIndexAdditionalFieldsConfiguration($defaultIfEmpty = [])
339
    {
340
        $result = $this->getObjectByPathOrDefault('plugin.tx_solr.index.additionalFields.', $defaultIfEmpty);
341
        return $result;
342
    }
343
344
    /**
345
     * Returns all solr fields names where a mapping is configured in index.additionalFields
346
     *
347
     * Returns all keys from
348
     * plugin.tx_solr.index.additionalFields.
349 44
     *
350
     * @param array $defaultIfEmpty
351 44
     * @return array
352 44
     */
353 44
    public function getIndexMappedAdditionalFieldNames($defaultIfEmpty = [])
354 38
    {
355
        $mappingConfiguration = $this->getIndexAdditionalFieldsConfiguration();
356
        $mappedFieldNames = $this->getOnlyArrayKeysWhereValueIsNotAnArray($mappingConfiguration);
357 7
        return count($mappedFieldNames) == 0 ? $defaultIfEmpty : $mappedFieldNames;
358
    }
359
360
    /**
361
     * Returns the fieldProcessingInstructions configuration array
362
     *
363
     * plugin.tx_solr.index.fieldProcessingInstructions.
364
     *
365
     * @param array $defaultIfEmpty
366
     * @return array
367
     */
368
    public function getIndexFieldProcessingInstructionsConfiguration(array $defaultIfEmpty = [])
369 32
    {
370
        $result = $this->getObjectByPathOrDefault('plugin.tx_solr.index.fieldProcessingInstructions.', $defaultIfEmpty);
371 32
        return $result;
372 32
    }
373 32
374
    /**
375
     * Retrieves the indexing configuration array for an indexing queue by configuration name.
376
     *
377 32
     * plugin.tx_solr.index.queue.<configurationName>.
378
     *
379
     * @param string $configurationName
380
     * @param array $defaultIfEmpty
381
     * @return array
382
     */
383
    public function getIndexQueueConfigurationByName($configurationName, array $defaultIfEmpty = [])
384
    {
385
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.';
386
        $result = $this->getObjectByPathOrDefault($path, $defaultIfEmpty);
387
        return $result;
388 14
    }
389
390 14
    /**
391 14
     * Returns an array of all additionalPageIds by index configuration name.
392
     *
393 14
     * plugin.tx_solr.index.queue.pages.additionalPageIds
394 7
     *
395
     * @param string $configurationName
396
     * @param array $defaultIfEmpty
397 7
     * @return array
398
     */
399
    public function getIndexQueueAdditionalPageIdsByConfigurationName($configurationName = 'pages', $defaultIfEmpty = [])
400
    {
401
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.additionalPageIds';
402
        $result = $this->getValueByPathOrDefaultValue($path, '');
403
        if (trim($result) === '') {
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type array; 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

403
        if (trim(/** @scrutinizer ignore-type */ $result) === '') {
Loading history...
404
            return $defaultIfEmpty;
405
        }
406
407
        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

407
        return GeneralUtility::trimExplode(',', /** @scrutinizer ignore-type */ $result);
Loading history...
408
    }
409
410 79
    /**
411
     * Returns an array of all allowedPageTypes.
412 79
     *
413 79
     * plugin.tx_solr.index.queue.pages.allowedPageTypes
414 79
     *
415
     * @param string $configurationName The configuration name of the queue to use.
416
     * @param array $defaultIfEmpty
417
     * @return array
418
     */
419
    public function getIndexQueueAllowedPageTypesArrayByConfigurationName($configurationName = 'pages', $defaultIfEmpty = [])
420
    {
421
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.allowedPageTypes';
422
        $result = $this->getValueByPathOrDefaultValue($path, '');
423
        if (trim($result) === '') {
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type array; 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

423
        if (trim(/** @scrutinizer ignore-type */ $result) === '') {
Loading history...
424
            return $defaultIfEmpty;
425
        }
426 31
427
        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

427
        return GeneralUtility::trimExplode(',', /** @scrutinizer ignore-type */ $result);
Loading history...
428 31
    }
429 31
430 31
    /**
431
     * Returns the configured excludeContentByClass patterns as array.
432
     *
433
     * plugin.tx_solr.index.queue.pages.excludeContentByClass
434
     *
435
     * @param array $defaultIfEmpty
436
     * @return array
437
     */
438
    public function getIndexQueuePagesExcludeContentByClassArray($defaultIfEmpty = [])
439 39
    {
440
        $path = 'plugin.tx_solr.index.queue.pages.excludeContentByClass';
441 39
        $result = $this->getValueByPathOrDefaultValue($path, '');
442
443 39
        if (trim($result) === '') {
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type array; 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

443
        if (trim(/** @scrutinizer ignore-type */ $result) === '') {
Loading history...
444 39
            return $defaultIfEmpty;
445 39
        }
446 39
447
        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

447
        return GeneralUtility::trimExplode(',', /** @scrutinizer ignore-type */ $result);
Loading history...
448
    }
449 39
450
    /**
451
     * Returns the configured database table for an indexing queue configuration or
452
     * the configurationName itself that is used by convention as tableName when no
453
     * other tablename is present.
454
     *
455
     * plugin.tx_solr.index.queue.<configurationName>.table or configurationName
456
     *
457
     * @param string $configurationName
458 38
     * @return string
459
     */
460 38
    public function getIndexQueueTableNameOrFallbackToConfigurationName($configurationName = '')
461
    {
462
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.table';
463
        $result = $this->getValueByPathOrDefaultValue($path, $configurationName);
464
        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...
465
    }
466
467
    /**
468
     * Returns the field configuration for a specific index queue.
469
     *
470
     * plugin.tx_solr.index.queue.<configurationName>.fields.
471
     *
472
     * @param string $configurationName
473 2
     * @param array $defaultIfEmpty
474
     * @return array
475 2
     */
476 2
    public function getIndexQueueFieldsConfigurationByConfigurationName($configurationName = '', $defaultIfEmpty = [])
477 2
    {
478
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.fields.';
479
        $result = $this->getObjectByPathOrDefault($path, $defaultIfEmpty);
480
        return $result;
481
    }
482
483
    /**
484
     * Gets an array of tables configured for indexing by the Index Queue. Since the
485
     * record monitor must watch these tables for manipulation.
486
     *
487
     * @return array Array of table names to be watched by the record monitor.
488
     */
489
    public function getIndexQueueMonitoredTables()
490 2
    {
491
        $monitoredTables = [];
492 2
493 2
        $indexingConfigurations = $this->getEnabledIndexQueueConfigurationNames();
494 2
        foreach ($indexingConfigurations as $indexingConfigurationName) {
495
            $monitoredTable = $this->getIndexQueueTableNameOrFallbackToConfigurationName($indexingConfigurationName);
496
            $monitoredTables[] = $monitoredTable;
497
        }
498
499
        return array_values(array_unique($monitoredTables));
500
    }
501
502
    /**
503
     * This method can be used to check if a table is configured to be monitored by the record monitor.
504
     *
505
     * @param string $tableName
506
     * @return bool
507 11
     */
508
    public function getIndexQueueIsMonitoredTable($tableName)
509 11
    {
510 11
        return in_array($tableName, $this->getIndexQueueMonitoredTables(), true);
511 11
    }
512
513
    /**
514
     * Returns the configured indexer class that should be used for a certain indexingConfiguration.
515
     * By default "ApacheSolrForTypo3\Solr\IndexQueue\Indexer" will be returned.
516
     *
517
     * plugin.tx_solr.index.queue.<configurationName>.indexer
518
     *
519
     * @param string $configurationName
520
     * @param string $defaultIfEmpty
521
     * @return string
522
     */
523 73
    public function getIndexQueueIndexerByConfigurationName($configurationName, $defaultIfEmpty = Indexer::class)
524
    {
525 73
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.indexer';
526 73
        $result = $this->getValueByPathOrDefaultValue($path, $defaultIfEmpty);
527 73
        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...
528
    }
529
530
    /**
531
     * Returns the configuration of an indexer for a special indexingConfiguration. By default an empty
532
     * array is returned.
533
     *
534
     * plugin.tx_solr.index.queue.<configurationName>.indexer.
535
     *
536
     * @param string $configurationName
537
     * @param array $defaultIfEmpty
538 80
     * @return array
539
     */
540 80
    public function getIndexQueueIndexerConfigurationByConfigurationName($configurationName, $defaultIfEmpty = [])
541 80
    {
542 80
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.indexer.';
543 80
        $result = $this->getObjectByPathOrDefault($path, $defaultIfEmpty);
544 79
        return $result;
545 79
    }
546
547
    /**
548
     * Returns all solr fields names where a mapping configuration is set for a certain index configuration
549 80
     *
550
     * Returns all keys from
551
     * plugin.tx_solr.index.queue.<configurationName>.fields.
552
     *
553
     * @param string $configurationName
554
     * @param array $defaultIfEmpty
555
     * @return array
556
     */
557
    public function getIndexQueueMappedFieldsByConfigurationName($configurationName = '', $defaultIfEmpty = [])
558
    {
559
        $mappingConfiguration = $this->getIndexQueueFieldsConfigurationByConfigurationName($configurationName);
560
        $mappedFieldNames = $this->getOnlyArrayKeysWhereValueIsNotAnArray($mappingConfiguration);
561
        return count($mappedFieldNames) == 0 ? $defaultIfEmpty : $mappedFieldNames;
562 27
    }
563
564 27
    /**
565 27
     * This method is used to check if an index queue configuration is enabled or not
566 27
     *
567 21
     * plugin.tx_solr.index.queue.<configurationName> = 1
568
     *
569 7
     * @param string $configurationName
570
     * @param bool $defaultIfEmpty
571 7
     * @return bool
572
     */
573
    public function getIndexQueueConfigurationIsEnabled($configurationName, $defaultIfEmpty = false)
574
    {
575
        $path = 'plugin.tx_solr.index.queue.' . $configurationName;
576
        $result = $this->getValueByPathOrDefaultValue($path, $defaultIfEmpty);
577
        return $this->getBool($result);
578
    }
579
580
    /**
581
     * Retrieves an array of enabled index queue configurations.
582
     *
583 13
     * plugin.tx_solr.index.queue.<configurationName>
584
     *
585 13
     * @param array $defaultIfEmpty
586 13
     * @return array
587
     */
588 13
    public function getEnabledIndexQueueConfigurationNames($defaultIfEmpty = [])
589 13
    {
590
        $tablesToIndex = [];
591
        $path = 'plugin.tx_solr.index.queue.';
592 1
        $indexQueueConfiguration = $this->getObjectByPathOrDefault($path, []);
593
        foreach ($indexQueueConfiguration as $configurationName => $indexingEnabled) {
594
            if (substr($configurationName, -1) != '.' && $indexingEnabled) {
595
                $tablesToIndex[] = $configurationName;
596
            }
597
        }
598
599
        return count($tablesToIndex) == 0 ? $defaultIfEmpty : $tablesToIndex;
600
    }
601
602
    /**
603 76
     * Retrieves an array of additional fields that will trigger an recursive update of pages
604
     * when some of the fields on that page are modified.
605 76
     *
606 76
     * plugin.tx_solr.index.queue.recursiveUpdateFields
607
     *
608 76
     * @param string $configurationName
609 27
     * @param array $defaultIfEmpty
610
     * @return array
611
     */
612 51
    public function getIndexQueueConfigurationRecursiveUpdateFields($configurationName, $defaultIfEmpty = [])
613
    {
614
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.recursiveUpdateFields';
615
        $recursiveUpdateFieldsString = $this->getValueByPathOrDefaultValue($path, '');
616
        if (trim($recursiveUpdateFieldsString) === '') {
0 ignored issues
show
Bug introduced by
It seems like $recursiveUpdateFieldsString can also be of type array; 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

616
        if (trim(/** @scrutinizer ignore-type */ $recursiveUpdateFieldsString) === '') {
Loading history...
617
            return $defaultIfEmpty;
618
        }
619
        $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

619
        $recursiveUpdateFields = GeneralUtility::trimExplode(',', /** @scrutinizer ignore-type */ $recursiveUpdateFieldsString);
Loading history...
620
        // For easier check later on we return an array by combining $recursiveUpdateFields
621
        return array_combine($recursiveUpdateFields, $recursiveUpdateFields);
622
    }
623
624
625
    /**
626 1
     * Retrieves and initialPagesAdditionalWhereClause where clause when configured or an empty string.
627
     *
628 1
     * plugin.tx_solr.index.queue.<configurationName>.initialPagesAdditionalWhereClause
629 1
     *
630 1
     * @param string $configurationName
631
     * @return string
632 1
     */
633 1
    public function getInitialPagesAdditionalWhereClause($configurationName)
634 1
    {
635 1
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.initialPagesAdditionalWhereClause';
636
        $initialPagesAdditionalWhereClause = $this->getValueByPathOrDefaultValue($path, '');
637
638
        if (trim($initialPagesAdditionalWhereClause) === '') {
0 ignored issues
show
Bug introduced by
It seems like $initialPagesAdditionalWhereClause can also be of type array; 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

638
        if (trim(/** @scrutinizer ignore-type */ $initialPagesAdditionalWhereClause) === '') {
Loading history...
639 1
            return '';
640 1
        }
641 1
642 1
        return trim($initialPagesAdditionalWhereClause);
643 1
    }
644
645
    /**
646
     * Retrieves and additional where clause when configured or an empty string.
647 1
     *
648
     * plugin.tx_solr.index.queue.<configurationName>.additionalWhereClause
649
     *
650
     * @param string $configurationName
651
     * @return string
652
     */
653
    public function getIndexQueueAdditionalWhereClauseByConfigurationName($configurationName)
654
    {
655
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.additionalWhereClause';
656
        $additionalWhere = $this->getValueByPathOrDefaultValue($path, '');
657
658
        if (trim($additionalWhere) === '') {
0 ignored issues
show
Bug introduced by
It seems like $additionalWhere can also be of type array; 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

658
        if (trim(/** @scrutinizer ignore-type */ $additionalWhere) === '') {
Loading history...
659
            return '';
660 7
        }
661
662 7
        return ' AND ' . $additionalWhere;
0 ignored issues
show
Bug introduced by
Are you sure $additionalWhere of type array|string can be used in concatenation? ( Ignorable by Annotation )

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

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

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

1299
            return mb_strtolower(/** @scrutinizer ignore-type */ $specificSortOrder);
Loading history...
1300 90
        }
1301
1302
        // no specific setting, check common setting
1303
        $commonPath = 'plugin.tx_solr.search.sorting.defaultOrder';
1304
        $commonATagParamOrDefaultValue = $this->getValueByPathOrDefaultValue($commonPath, $defaultIfEmpty);
1305
        return mb_strtolower($commonATagParamOrDefaultValue);
1306
    }
1307
1308
    /**
1309
     * Returns the trusted fields configured for the search that do not need to be escaped.
1310
     *
1311 95
     * @param array $defaultIfEmpty
1312
     * @return array
1313 95
     */
1314 95
    public function getSearchTrustedFieldsArray($defaultIfEmpty = ['url'])
1315
    {
1316
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.trustedFields', '');
1317
1318
        if (trim($result) === '') {
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type array; 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

1318
        if (trim(/** @scrutinizer ignore-type */ $result) === '') {
Loading history...
1319
            return $defaultIfEmpty;
1320
        }
1321
1322
        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

1322
        return GeneralUtility::trimExplode(',', /** @scrutinizer ignore-type */ $result);
Loading history...
1323
    }
1324 1
1325
    /**
1326 1
     * Indicates if the plugin arguments should be kept in the search form for a second submission.
1327 1
     *
1328
     * plugin.tx_solr.search.keepExistingParametersForNewSearches
1329
     *
1330
     * @param bool $defaultIfEmpty
1331
     * @return bool
1332
     */
1333
    public function getSearchKeepExistingParametersForNewSearches($defaultIfEmpty = false)
1334 2
    {
1335
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.keepExistingParametersForNewSearches', $defaultIfEmpty);
1336 2
        return $this->getBool($result);
1337 2
    }
1338
1339
    /**
1340
     * Returns if an empty query is allowed on the query level.
1341
     *
1342
     * plugin.tx_solr.search.query.allowEmptyQuery
1343
     *
1344
     * @param string $defaultIfEmpty
1345
     * @return bool
1346
     */
1347 90
    public function getSearchQueryAllowEmptyQuery($defaultIfEmpty = '')
1348
    {
1349 90
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.allowEmptyQuery', $defaultIfEmpty);
1350
        return $this->getBool($result);
1351
    }
1352
1353
    /**
1354
     * Returns the filter configuration array
1355
     *
1356
     * plugin.tx_solr.search.query.filter.
1357
     *
1358
     * @param array $defaultIfEmpty
1359
     * @return array
1360 90
     */
1361
    public function getSearchQueryFilterConfiguration(array $defaultIfEmpty = [])
1362 90
    {
1363 90
        $result = $this->getObjectByPathOrDefault('plugin.tx_solr.search.query.filter.', $defaultIfEmpty);
1364
        return $result;
1365
    }
1366
1367
    /**
1368
     * Can be used to overwrite the filterConfiguration.
1369
     *
1370
     * plugin.tx_solr.search.query.filter.
1371
     *
1372
     * @param array $configuration
1373
     */
1374 2
    public function setSearchQueryFilterConfiguration(array $configuration)
1375
    {
1376 2
        $this->configurationAccess->set('plugin.tx_solr.search.query.filter.', $configuration);
1377
    }
1378
1379
    /**
1380
     * Removes the pageSections filter setting.
1381
     *
1382
     * @return void
1383
     */
1384
    public function removeSearchQueryFilterForPageSections()
1385
    {
1386
        $this->configurationAccess->reset('plugin.tx_solr.search.query.filter.__pageSections');
1387 90
    }
1388
1389 90
    /**
1390 90
     * Returns the configured queryFields from TypoScript
1391
     *
1392
     * plugin.tx_solr.search.query.queryFields
1393
     *
1394
     * @param string $defaultIfEmpty
1395
     * @return string
1396
     */
1397
    public function getSearchQueryQueryFields($defaultIfEmpty = '')
1398
    {
1399
        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...
1400
    }
1401 2
1402
    /**
1403 2
     * This method is used to check if a phrase search is enabled or not
1404
     *
1405
     * plugin.tx_solr.search.query.phrase = 1
1406
     *
1407
     * @param bool $defaultIfEmpty
1408
     * @return bool
1409
     */
1410
    public function getPhraseSearchIsEnabled(bool $defaultIfEmpty = false)
1411
    {
1412
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.phrase', $defaultIfEmpty);
1413
        return $this->getBool($result);
1414 90
    }
1415
1416 90
    /**
1417 90
     * Returns the configured phrase fields from TypoScript
1418
     *
1419
     * plugin.tx_solr.search.query.phrase.fields
1420
     *
1421
     * @param string $defaultIfEmpty
1422
     * @return string
1423
     */
1424
    public function getSearchQueryPhraseFields(string $defaultIfEmpty = '')
1425
    {
1426
        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...
1427
    }
1428 2
1429
    /**
1430 2
     * This method is used to check if a bigram phrase search is enabled or not
1431
     *
1432
     * plugin.tx_solr.search.query.bigramPhrase = 1
1433
     *
1434
     * @param bool $defaultIfEmpty
1435
     * @return bool
1436
     */
1437
    public function getBigramPhraseSearchIsEnabled(bool $defaultIfEmpty = false)
1438
    {
1439
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.bigramPhrase', $defaultIfEmpty);
1440
        return $this->getBool($result);
1441 92
    }
1442
1443 92
    /**
1444 92
     * Returns the configured phrase fields from TypoScript
1445 86
     *
1446
     * plugin.tx_solr.search.query.bigramPhrase.fields
1447
     *
1448 6
     * @param string $defaultIfEmpty
1449
     * @return string
1450
     */
1451
    public function getSearchQueryBigramPhraseFields(string $defaultIfEmpty = '')
1452
    {
1453
        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...
1454
    }
1455
1456
    /**
1457
     * This method is used to check if a trigram phrase search is enabled or not
1458
     *
1459
     * plugin.tx_solr.search.query.trigramPhrase = 1
1460
     *
1461
     * @param bool $defaultIfEmpty
1462
     * @return bool
1463
     */
1464
    public function getTrigramPhraseSearchIsEnabled(bool $defaultIfEmpty = false)
1465
    {
1466
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.trigramPhrase', $defaultIfEmpty);
1467
        return $this->getBool($result);
1468
    }
1469
1470
    /**
1471
     * Returns the configured trigram phrase fields from TypoScript
1472
     *
1473
     * plugin.tx_solr.search.query.trigramPhrase.fields
1474
     *
1475
     * @param string $defaultIfEmpty
1476
     * @return string
1477
     */
1478
    public function getSearchQueryTrigramPhraseFields(string $defaultIfEmpty = '')
1479
    {
1480
        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...
1481
    }
1482
1483
    /**
1484
     * Returns the configured returnFields as array.
1485
     *
1486
     * plugin.tx_solr.search.query.returnFields
1487
     *
1488
     * @param array $defaultIfEmpty
1489
     * @return array
1490
     */
1491
    public function getSearchQueryReturnFieldsAsArray($defaultIfEmpty = [])
1492
    {
1493
        $returnFields = $this->getValueByPath('plugin.tx_solr.search.query.returnFields');
1494
        if (is_null($returnFields)) {
1495
            return $defaultIfEmpty;
1496
        }
1497
1498
        return GeneralUtility::trimExplode(',', $returnFields);
0 ignored issues
show
Bug introduced by
$returnFields of type array is incompatible with the type string expected by parameter $string of TYPO3\CMS\Core\Utility\G...lUtility::trimExplode(). ( Ignorable by Annotation )

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

1498
        return GeneralUtility::trimExplode(',', /** @scrutinizer ignore-type */ $returnFields);
Loading history...
1499
    }
1500
1501
    /**
1502
     * Returns the configured target page for the search.
1503
     * By default the contextPageId will be used
1504
     *
1505
     * plugin.tx_solr.search.targetPage
1506
     *
1507
     * @return int
1508 90
     */
1509
    public function getSearchTargetPage()
1510 90
    {
1511 90
        $targetPage = (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.targetPage', 0);
1512
        if ($targetPage === 0) {
1513
            // when no specific page was configured we use the contextPageId (which is usual $GLOBALS['TSFE']->id)
1514
            $targetPage = $this->contextPageId;
1515
        }
1516
1517
        return $targetPage;
1518
    }
1519
1520
    /**
1521
     * Retrieves the targetPage configuration.
1522 7
     *
1523
     * plugin.tx_solr.search.targetPage.
1524 7
     *
1525
     * @param array $defaultIfEmpty
1526
     * @return array
1527
     */
1528
    public function getSearchTargetPageConfiguration(array $defaultIfEmpty = [])
1529
    {
1530
        $result = $this->getObjectByPathOrDefault('plugin.tx_solr.search.targetPage.', $defaultIfEmpty);
1531
        return $result;
1532
    }
1533
1534
    /**
1535
     * Method to check if the site highlighting is enabled. When the siteHighlighting is enabled the
1536
     * sword_list parameter is added to the results link.
1537
     *
1538
     * plugin.tx_solr.searcb.results.siteHighlighting
1539
     *
1540
     * @param bool $defaultIfEmpty
1541
     * @return bool
1542
     */
1543
    public function getSearchResultsSiteHighlighting($defaultIfEmpty = true)
1544
    {
1545
        $isSiteHightlightingEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.siteHighlighting', $defaultIfEmpty);
1546
        return $this->getBool($isSiteHightlightingEnabled);
1547
    }
1548
1549
1550
    /**
1551
     * Can be used to check if the highlighting is enabled
1552
     *
1553
     * plugin.tx_solr.search.results.resultsHighlighting
1554 7
     *
1555
     * @param boolean $defaultIfEmpty
1556 7
     * @return boolean
1557
     */
1558
    public function getSearchResultsHighlighting($defaultIfEmpty = false)
1559
    {
1560
        $isHighlightingEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.resultsHighlighting', $defaultIfEmpty);
1561
        return $this->getBool($isHighlightingEnabled);
1562
    }
1563
1564
    /**
1565
     * Returns the result highlighting fields.
1566
     *
1567
     * plugin.tx_solr.search.results.resultsHighlighting.highlightFields
1568
     *
1569
     * @param string $defaultIfEmpty
1570
     * @return string
1571
     */
1572
    public function getSearchResultsHighlightingFields($defaultIfEmpty = '')
1573
    {
1574
        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...
1575
    }
1576
1577
    /**
1578
     * Returns the result highlighting fields as array.
1579
     *
1580
     * plugin.tx_solr.search.results.resultsHighlighting.highlightFields
1581
     *
1582
     * @param array $defaultIfEmpty
1583
     * @return array
1584
     */
1585
    public function getSearchResultsHighlightingFieldsAsArray($defaultIfEmpty = [])
1586
    {
1587
        $highlightingFields = $this->getSearchResultsHighlightingFields('');
1588
1589
        if ($highlightingFields === '') {
1590
            return $defaultIfEmpty;
1591
        }
1592
1593
        return GeneralUtility::trimExplode(',', $highlightingFields, true);
1594
    }
1595
1596
    /**
1597
     * Returns the fragmentSize for highlighted segments.
1598
     *
1599
     * plugin.tx_solr.search.results.resultsHighlighting.fragmentSize
1600
     *
1601
     * @param int $defaultIfEmpty
1602
     * @return int
1603
     */
1604
    public function getSearchResultsHighlightingFragmentSize($defaultIfEmpty = 200)
1605
    {
1606
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.resultsHighlighting.fragmentSize', $defaultIfEmpty);
1607
    }
1608
1609
    /**
1610
     * Returns the fragmentSeparator for highlighted segments.
1611
     *
1612 7
     * plugin.tx_solr.search.results.resultsHighlighting.fragmentSeparator
1613
     *
1614 7
     * @param string $defaultIfEmpty
1615
     * @return string
1616
     */
1617
    public function getSearchResultsHighlightingFragmentSeparator($defaultIfEmpty = '[...]')
1618
    {
1619
        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...
1620
    }
1621
1622
    /**
1623
     * Returns the number of results that should be shown per page.
1624
     *
1625 1
     * plugin.tx_solr.search.results.resultsPerPage
1626
     *
1627 1
     * @param int $defaultIfEmpty
1628 1
     * @return int
1629
     */
1630
    public function getSearchResultsPerPage($defaultIfEmpty = 10)
1631
    {
1632
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.resultsPerPage', $defaultIfEmpty);
1633
    }
1634
1635
    /**
1636
     * Returns the available options for the per page switch.
1637
     *
1638
     * plugin.tx_solr.search.results.resultsPerPageSwitchOptions
1639 1
     *
1640
     * @param array $defaultIfEmpty
1641 1
     * @return array
1642
     */
1643
    public function getSearchResultsPerPageSwitchOptionsAsArray($defaultIfEmpty = [])
1644
    {
1645
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.resultsPerPageSwitchOptions', '');
1646
1647
        if (trim($result) === '') {
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type array; 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

1647
        if (trim(/** @scrutinizer ignore-type */ $result) === '') {
Loading history...
1648
            return $defaultIfEmpty;
1649
        }
1650
1651
        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

1651
        return GeneralUtility::intExplode(',', /** @scrutinizer ignore-type */ $result, true);
Loading history...
1652 4
    }
1653
1654 4
    /**
1655 4
     * Returns the configured wrap for the resultHighlighting.
1656
     *
1657
     * plugin.tx_solr.search.results.resultsHighlighting.wrap
1658
     *
1659
     * @param string $defaultIfEmpty
1660
     * @return string
1661
     */
1662
    public function getSearchResultsHighlightingWrap($defaultIfEmpty = '')
1663
    {
1664
        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...
1665
    }
1666 90
1667
    /**
1668 90
     * Indicates if spellchecking is enabled or not.
1669 90
     *
1670
     * plugin.tx_solr.search.spellchecking
1671
     *
1672
     * @param bool $defaultIfEmpty
1673
     * @return bool
1674
     */
1675
    public function getSearchSpellchecking($defaultIfEmpty = false)
1676
    {
1677
        $isFacetingEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.spellchecking', $defaultIfEmpty);
1678
        return $this->getBool($isFacetingEnabled);
1679
    }
1680
1681
    /**
1682
     * Returns the numberOfSuggestionsToTry that should be used for the spellchecking.
1683
     *
1684
     * plugin.tx_solr.search.spellchecking.numberOfSuggestionsToTry
1685
     *
1686
     * @param int $defaultIfEmpty
1687 37
     * @return int
1688
     */
1689 37
    public function getSearchSpellcheckingNumberOfSuggestionsToTry($defaultIfEmpty = 1)
1690 37
    {
1691
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.spellchecking.numberOfSuggestionsToTry', $defaultIfEmpty);
1692
    }
1693 37
1694 2
    /**
1695
     * Indicates if a second search should be fired from the spellchecking suggestion if no results could be found.
1696
     *
1697
     * plugin.tx_solr.search.spellchecking.searchUsingSpellCheckerSuggestion
1698 37
     *
1699 37
     * @param bool $defaultIfEmpty
1700 37
     * @return bool
1701
     */
1702
    public function getSearchSpellcheckingSearchUsingSpellCheckerSuggestion($defaultIfEmpty = false)
1703
    {
1704
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.spellchecking.searchUsingSpellCheckerSuggestion', $defaultIfEmpty);
1705
        return $this->getBool($result);
1706
    }
1707
1708
    /**
1709
     * Indicates if faceting is enabled or not.
1710
     *
1711
     * plugin.tx_solr.search.faceting
1712
     *
1713
     * @param bool $defaultIfEmpty
1714
     * @return bool
1715
     */
1716
    public function getSearchFaceting($defaultIfEmpty = false)
1717
    {
1718
        $isFacetingEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting', $defaultIfEmpty);
1719
        return $this->getBool($isFacetingEnabled);
1720
    }
1721
1722
    /**
1723
     * Retrieves the showEvenWhenEmpty for a facet by facet name. If nothing specific is configured
1724
     * the global showEmptyFacets with be returned.
1725
     *
1726
     * plugin.tx_solr.search.faceting.facets.<facetName>.showEvenWhenEmpty
1727
     *
1728
     * or
1729
     *
1730
     * plugin.tx_solr.search.faceting.showEmptyFacets
1731
     *
1732
     *
1733
     * @param string $facetName
1734
     * @param bool $defaultIfEmpty
1735
     * @return bool
1736
     */
1737
    public function getSearchFacetingShowEmptyFacetsByName($facetName = '', $defaultIfEmpty = false)
1738
    {
1739
        $facetSpecificPath = 'plugin.tx_solr.search.faceting.facets.' . $facetName . '.showEvenWhenEmpty';
1740
        $specificShowWhenEmpty = $this->getValueByPathOrDefaultValue($facetSpecificPath, null);
1741
1742
        // if we have a concrete setting, use it
1743
        if ($specificShowWhenEmpty !== null) {
1744
            return $specificShowWhenEmpty;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $specificShowWhenEmpty returns the type array which is incompatible with the documented return type boolean.
Loading history...
1745
        }
1746
1747
        // no specific setting, check common setting
1748
        $commonPath = 'plugin.tx_solr.search.faceting.showEmptyFacets';
1749
        $commonIfEmptyOrDefaultValue = $this->getValueByPathOrDefaultValue($commonPath, $defaultIfEmpty);
1750
        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...
1751
    }
1752
1753
    /**
1754
     * Returns the wrap for the faceting show all link
1755
     *
1756
     * plugin.tx_solr.search.faceting.showAllLink.wrap
1757
     *
1758
     * @param string $defaultIfEmpty
1759
     * @return string
1760
     */
1761
    public function getSearchFacetingShowAllLinkWrap($defaultIfEmpty = '')
1762
    {
1763
        return (string)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.showAllLink.wrap', $defaultIfEmpty);
1764
    }
1765
1766
    /**
1767
     * Returns the link url parameters that should be added to a facet.
1768
     *
1769
     * plugin.tx_solr.search.faceting.facetLinkUrlParameters
1770
     *
1771 15
     * @param string $defaultIfEmpty
1772
     * @return string
1773 15
     */
1774
    public function getSearchFacetingFacetLinkUrlParameters($defaultIfEmpty = '')
1775
    {
1776
        $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; 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

1776
        $linkUrlParameters = trim(/** @scrutinizer ignore-type */ $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.facetLinkUrlParameters', $defaultIfEmpty));
Loading history...
1777
1778
        return $linkUrlParameters;
1779
    }
1780
1781
    /**
1782
     * Returns if the facetLinkUrlsParameters should be included in the reset link.
1783
     *
1784
     * plugin.tx_solr.search.faceting.facetLinkUrlParameters.useForFacetResetLinkUrl
1785
     *
1786
     * @param bool $defaultIfEmpty
1787
     * @return bool
1788
     */
1789
    public function getSearchFacetingFacetLinkUrlParametersUseForFacetResetLinkUrl($defaultIfEmpty = true)
1790
    {
1791
        $useForFacetResetLinkUrl = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.facetLinkUrlParameters.useForFacetResetLinkUrl', $defaultIfEmpty);
1792
        return $this->getBool($useForFacetResetLinkUrl);
1793
    }
1794
1795
    /**
1796
     * Returns the link url parameters that should be added to a facet as array.
1797 15
     *
1798
     * plugin.tx_solr.search.faceting.facetLinkUrlParameters
1799 15
     *
1800
     * @param array $defaultIfEmpty
1801
     * @return array
1802
     */
1803
    public function getSearchFacetingFacetLinkUrlParametersAsArray($defaultIfEmpty = [])
1804
    {
1805
        $linkUrlParameters = $this->getSearchFacetingFacetLinkUrlParameters();
1806
        if ($linkUrlParameters === '') {
1807
            return $defaultIfEmpty;
1808
        }
1809
1810 15
        return GeneralUtility::explodeUrl2Array($linkUrlParameters);
1811
    }
1812 15
1813
    /**
1814
     * Return the configured minimumCount value for facets.
1815
     *
1816
     * plugin.tx_solr.search.faceting.minimumCount
1817
     *
1818
     * @param int $defaultIfEmpty
1819
     * @return int
1820
     */
1821
    public function getSearchFacetingMinimumCount($defaultIfEmpty = 1)
1822
    {
1823
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.minimumCount', $defaultIfEmpty);
1824
    }
1825 15
1826
    /**
1827 15
     * Return the configured limit value for facets, used for displaying.
1828 15
     *
1829
     * plugin.tx_solr.search.faceting.limit
1830
     *
1831
     * @param int $defaultIfEmpty
1832
     * @return int
1833
     */
1834
    public function getSearchFacetingLimit($defaultIfEmpty = 10)
1835
    {
1836
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.limit', $defaultIfEmpty);
1837
    }
1838
1839
    /**
1840 5
     * Return the configured limit value for facets, used for the response.
1841
     *
1842 5
     * plugin.tx_solr.search.faceting.facetLimit
1843 5
     *
1844
     * @param int $defaultIfEmpty
1845
     * @return int
1846
     */
1847
    public function getSearchFacetingFacetLimit($defaultIfEmpty = 100)
1848
    {
1849
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.facetLimit', $defaultIfEmpty);
1850
    }
1851
1852
    /**
1853
     * Return the configured faceting sortBy value.
1854 42
     *
1855
     * plugin.tx_solr.search.faceting.sortBy
1856 42
     *
1857
     * @param string $defaultIfEmpty
1858
     * @return string
1859
     */
1860
    public function getSearchFacetingSortBy($defaultIfEmpty = '')
1861
    {
1862
        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...
1863
    }
1864
1865
    /**
1866
     * Returns if a facets should be kept on selection. Global faceting setting
1867
     * can also be configured on facet level by using
1868 15
     * (plugin.tx_solr.search.faceting.facets.<fieldName>.keepAllOptionsOnSelection)
1869
     *
1870 15
     * plugin.tx_solr.search.faceting.keepAllFacetsOnSelection
1871
     *
1872
     * @param bool $defaultIfEmpty
1873
     * @return bool
1874
     */
1875
    public function getSearchFacetingKeepAllFacetsOnSelection($defaultIfEmpty = false)
1876
    {
1877
        $keepAllOptionsOnSelection = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.keepAllFacetsOnSelection', $defaultIfEmpty);
1878
        return $this->getBool($keepAllOptionsOnSelection);
1879
    }
1880
1881 5
    /**
1882
     * Returns if the facet count should be calculated based on the facet selection when
1883 5
     * plugin.tx_solr.search.faceting.keepAllFacetsOnSelection has been enabled
1884 5
     *
1885
     * plugin.tx_solr.search.faceting.countAllFacetsForSelection
1886
     *
1887
     * @param bool $defaultIfEmpty
1888
     * @return bool
1889
     */
1890
    public function getSearchFacetingCountAllFacetsForSelection($defaultIfEmpty = false)
1891
    {
1892
        $countAllFacetsForSelection = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.countAllFacetsForSelection', $defaultIfEmpty);
1893
        return $this->getBool($countAllFacetsForSelection);
1894
    }
1895
1896
    /**
1897
     * Returns the configured faceting configuration.
1898
     *
1899
     * plugin.tx_solr.search.faceting.facets
1900
     *
1901
     * @param array $defaultIfEmpty
1902
     * @return array
1903
     */
1904
    public function getSearchFacetingFacets(array $defaultIfEmpty = [])
1905
    {
1906
        return $this->getObjectByPathOrDefault('plugin.tx_solr.search.faceting.facets.', $defaultIfEmpty);
1907
    }
1908
1909 1
    /**
1910
     * Returns the configuration of a single facet by facet name.
1911 1
     *
1912 1
     * plugin.tx_solr.search.faceting.facets.<facetName>
1913
     *
1914
     * @param string $facetName
1915
     * @param array $defaultIfEmpty
1916
     * @return array
1917
     */
1918
    public function getSearchFacetingFacetByName($facetName, $defaultIfEmpty = [])
1919
    {
1920
        return $this->getObjectByPathOrDefault('plugin.tx_solr.search.faceting.facets.' . $facetName . '.', $defaultIfEmpty);
1921
    }
1922
1923
    /**
1924
     * Indicates if statistics is enabled or not.
1925
     *
1926
     * plugin.tx_solr.statistics
1927
     *
1928
     * @param bool $defaultIfEmpty
1929
     * @return bool
1930
     */
1931
    public function getStatistics($defaultIfEmpty = false)
1932
    {
1933
        $isStatisticsEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.statistics', $defaultIfEmpty);
1934
        return $this->getBool($isStatisticsEnabled);
1935
    }
1936
1937
    /**
1938
     * Indicates to which length an ip should be anonymized in the statistics
1939
     *
1940
     * plugin.tx_solr.statistics.anonymizeIP
1941
     *
1942
     * @param int $defaultIfEmpty
1943
     * @return int
1944
     */
1945
    public function getStatisticsAnonymizeIP($defaultIfEmpty = 0)
1946
    {
1947
        $anonymizeToLength = $this->getValueByPathOrDefaultValue('plugin.tx_solr.statistics.anonymizeIP', $defaultIfEmpty);
1948
        return (int)$anonymizeToLength;
1949
    }
1950
1951
    /**
1952
     * Indicates if additional debug Data should be added to the statistics
1953
     *
1954
     * plugin.tx_solr.statistics.addDebugData
1955
     *
1956
     * @param bool $defaultIfEmpty
1957
     * @return bool
1958
     */
1959
    public function getStatisticsAddDebugData($defaultIfEmpty = false)
1960
    {
1961
        $statisticsAddDebugDataEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.statistics.addDebugData', $defaultIfEmpty);
1962
        return $this->getBool($statisticsAddDebugDataEnabled);
1963
    }
1964
1965
    /**
1966
     * Indicates if suggestion is enabled or not.
1967
     *
1968
     * plugin.tx_solr.suggest
1969
     *
1970
     * @param bool $defaultIfEmpty
1971
     * @return bool
1972
     */
1973
    public function getSuggest($defaultIfEmpty = false)
1974
    {
1975
        $isSuggestionEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.suggest', $defaultIfEmpty);
1976
        return $this->getBool($isSuggestionEnabled);
1977
    }
1978
1979
    /**
1980
     * Indicates if https should be used for the suggest form.
1981
     *
1982
     * plugin.tx_solr.suggest.forceHttps
1983
     *
1984
     * @param bool $defaultIfEmpty
1985
     * @return bool
1986
     */
1987
    public function getSuggestForceHttps($defaultIfEmpty = false)
1988
    {
1989
        $isHttpsForced = $this->getValueByPathOrDefaultValue('plugin.tx_solr.suggest.forceHttps', $defaultIfEmpty);
1990
        return $this->getBool($isHttpsForced);
1991
    }
1992
1993
    /**
1994
     * Returns the allowed number of suggestions.
1995
     *
1996
     * plugin.tx_solr.suggest.numberOfSuggestions
1997
     *
1998
     * @param int $defaultIfEmpty
1999
     * @return int
2000
     */
2001
    public function getSuggestNumberOfSuggestions($defaultIfEmpty = 10)
2002
    {
2003
        $numberOfSuggestions = $this->getValueByPathOrDefaultValue('plugin.tx_solr.suggest.numberOfSuggestions', $defaultIfEmpty);
2004
        return (int)$numberOfSuggestions;
2005
    }
2006
2007
    /**
2008
     * Indicates if the topResults should be shown or not
2009
     *
2010
     * plugin.tx_solr.suggest.showTopResults
2011
     *
2012
     * @param bool $defaultIfEmpty
2013
     * @return bool
2014
     */
2015
    public function getSuggestShowTopResults($defaultIfEmpty = true)
2016
    {
2017
        $showTopResults = $this->getValueByPathOrDefaultValue('plugin.tx_solr.suggest.showTopResults', $defaultIfEmpty);
2018
        return $this->getBool($showTopResults);
2019
    }
2020
2021
    /**
2022
     * Returns the configured number of top results to show
2023
     *
2024
     * plugin.tx_solr.suggest.numberOfTopResults
2025
     *
2026
     * @param int $defaultIfEmpty
2027
     * @return int
2028
     */
2029
    public function getSuggestNumberOfTopResults($defaultIfEmpty = 5)
2030
    {
2031
        $numberOfTopResults = $this->getValueByPathOrDefaultValue('plugin.tx_solr.suggest.numberOfTopResults', $defaultIfEmpty);
2032
        return (int)$numberOfTopResults;
2033
    }
2034
2035
    /**
2036
     * Returns additional fields for the top results
2037
     *
2038
     * plugin.tx_solr.suggest.additionalTopResultsFields
2039
     *
2040
     * @param array $defaultIfEmpty
2041
     * @return array
2042
     */
2043
    public function getSuggestAdditionalTopResultsFields($defaultIfEmpty = [])
2044
    {
2045
        $additionalTopResultsFields = $this->getValueByPathOrDefaultValue('plugin.tx_solr.suggest.additionalTopResultsFields', '');
2046
        if ($additionalTopResultsFields === '') {
2047
            return $defaultIfEmpty;
2048
        }
2049
2050
        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

2050
        return GeneralUtility::trimExplode(',', /** @scrutinizer ignore-type */ $additionalTopResultsFields, true);
Loading history...
2051
    }
2052
2053
    /**
2054
     * Returns the configured template for a specific template fileKey.
2055
     *
2056
     * plugin.tx_solr.view.templateFiles.<fileKey>
2057
     *
2058
     * @param string $fileKey
2059
     * @param string $defaultIfEmpty
2060
     * @return string
2061
     */
2062
    public function getViewTemplateByFileKey($fileKey, $defaultIfEmpty = '')
2063
    {
2064
        $templateFileName = $this->getValueByPathOrDefaultValue('plugin.tx_solr.view.templateFiles.' . $fileKey, $defaultIfEmpty);
2065
        return (string)$templateFileName;
2066
    }
2067
2068
    /**
2069
     * Returns the configured available template files for the flexform.
2070
     *
2071
     * plugin.tx_solr.view.templateFiles.[fileKey].availableTemplates.
2072
     *
2073 14
     * @param string $fileKey
2074
     * @return array
2075 14
     */
2076 14
    public function getAvailableTemplatesByFileKey($fileKey)
2077
    {
2078
        $path = 'plugin.tx_solr.view.templateFiles.' . $fileKey . '.availableTemplates.';
2079
        return (array)$this->getObjectByPathOrDefault($path, []);
2080
    }
2081
2082
    /**
2083
     * Returns the configuration of the crop view helper.
2084
     *
2085
     * plugin.tx_solr.viewHelpers.crop.
2086
     *
2087 4
     * @param array $defaultIfEmpty
2088
     * @return array
2089 4
     */
2090
    public function getViewHelpersCropConfiguration(array $defaultIfEmpty = [])
2091
    {
2092
        $cropViewHelperConfiguration = $this->getObjectByPathOrDefault('plugin.tx_solr.viewHelpers.crop.', $defaultIfEmpty);
2093
        return $cropViewHelperConfiguration;
2094
    }
2095
2096
    /**
2097
     * Returns the configuration of the sorting view helper.
2098
     *
2099
     * plugin.tx_solr.viewHelpers.sortIndicator.
2100
     *
2101
     * @param array $defaultIfEmpty
2102
     * @return array
2103
     */
2104
    public function getViewHelpersSortIndicatorConfiguration(array $defaultIfEmpty = [])
2105
    {
2106
        $sortingViewHelperConfiguration = $this->getObjectByPathOrDefault('plugin.tx_solr.viewHelpers.sortIndicator.', $defaultIfEmpty);
2107
        return $sortingViewHelperConfiguration;
2108
    }
2109
2110
    /**
2111
     * Controls whether ext-solr will send commits to solr.
2112
     * Beware: If you disable this, you need to ensure
2113
     * that some other mechanism will commit your changes
2114
     * otherwise they will never be searchable.
2115
     * A good way to achieve this is enabling the solr
2116
     * daemons autoCommit feature.
2117 6
     *
2118
     * plugin.tx_solr.index.enableCommits
2119 6
     *
2120
     * @param bool $defaultIfEmpty
2121 6
     * @return bool
2122 5
     */
2123
    public function getEnableCommits($defaultIfEmpty = true)
2124
    {
2125 1
        $enableCommits = $this->getValueByPathOrDefaultValue('plugin.tx_solr.index.enableCommits', $defaultIfEmpty);
2126
        return $this->getBool($enableCommits);
2127
    }
2128
2129
    /**
2130
     * Returns the url namespace that is used for the arguments.
2131
     *
2132
     * plugin.tx_solr.view.pluginNamespace
2133
     *
2134
     * @param string $defaultIfEmpty
2135
     * @return string
2136
     */
2137 92
    public function getSearchPluginNamespace($defaultIfEmpty = 'tx_solr')
2138
    {
2139 92
        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...
2140 92
    }
2141
2142
    /**
2143
     * Returns true if the global url parameter q, that indicates the query should be used.
2144
     *
2145
     * Should be set to false, when multiple instance on the same page should have their querystring.
2146
     *
2147
     * plugin.tx_solr.search.ignoreGlobalQParameter
2148
     *
2149
     * @param bool $defaultIfEmpty
2150
     * @return bool
2151 1
     */
2152
    public function getSearchIgnoreGlobalQParameter($defaultIfEmpty = false)
2153 1
    {
2154
        $enableQParameter = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.ignoreGlobalQParameter', $defaultIfEmpty);
2155
        return $this->getBool($enableQParameter);
2156
2157
    }
2158
2159
    /**
2160
     * Returns the argument names, that should be added to the persistent arguments, as array.
2161
     *
2162
     * plugin.tx_solr.search.additionalPersistentArgumentNames
2163
     *
2164 1
     * @param array $defaultIfEmpty
2165
     * @return array
2166 1
     */
2167
    public function getSearchAdditionalPersistentArgumentNames($defaultIfEmpty = [])
2168
    {
2169
        $additionalPersistentArgumentNames = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.additionalPersistentArgumentNames', '');
2170
2171
        if ($additionalPersistentArgumentNames === '') {
2172
            return $defaultIfEmpty;
2173
        }
2174
2175
        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

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