getSearchFacetingShowEmptyFacetsByName()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 14
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
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\Utility\ArrayUtility;
36
use TYPO3\CMS\Core\Utility\GeneralUtility;
37
38
/**
39
 * TypoScript configuration object, used to read all TypoScript configuration.
40
 *
41
 * The TypoScriptConfiguration was introduced in order to be able to replace the old,
42
 * array based configuration with one configuration object.
43
 *
44
 * To read the configuration, you should use
45
 *
46
 * $configuration->getValueByPath
47
 *
48
 * or
49
 *
50
 * $configuration->isValidPath
51
 *
52
 * to check if an configuration path exists.
53
 *
54
 * To ensure Backwards compatibility the TypoScriptConfiguration object implements the
55
 * ArrayAccess interface (offsetGet,offsetExists,offsetUnset and offsetSet)
56
 *
57
 * This was only introduced to be backwards compatible in logTerm only "getValueByPath", "isValidPath" or
58
 * speaking methods for configuration settings should be used!
59
 *
60
 * @author Marc Bastian Heinrichs <[email protected]>
61
 * @author Timo Schmidt <[email protected]>
62
 */
63
class TypoScriptConfiguration
64
{
65
    /**
66
     * @var \ApacheSolrForTypo3\Solr\System\Util\ArrayAccessor|null
67
     */
68
    protected $configurationAccess = null;
69
70
    /**
71
     * Holds the pageId in which context the configuration was parsed
72
     * (normally $GLOBALS['TSFE']->id)
73
     */
74
    protected $contextPageId = 0;
75
76
    /**
77
     * @var ContentObjectService
78
     */
79
    protected $contentObjectService = null;
80
81
    /**
82
     * @param array $configuration
83
     * @param int $contextPageId
84
     * @param ContentObjectService $contentObjectService
85
     */
86 323
    public function __construct(array $configuration, $contextPageId = 0, ContentObjectService $contentObjectService = null)
87
    {
88 323
        $this->configurationAccess = new ArrayAccessor($configuration, '.', true);
89 323
        $this->contextPageId = $contextPageId;
90 323
        $this->contentObjectService = $contentObjectService;
91 323
    }
92
93
    /**
94
     * Checks if a value is 1, '1', 'true'
95
     * @param mixed $value
96
     * @return bool
97
     */
98 269
    protected function getBool($value)
99
    {
100 269
        return filter_var($value, FILTER_VALIDATE_BOOLEAN);
101
    }
102
103
    /**
104
     * This method can be used to only retrieve array keys where the value is not an array.
105
     *
106
     * This can be very handy in the configuration when only keys should ne taken into account
107
     * where the value is not a subconfiguration (typically an typoscript object path).
108
     *
109
     * @param $inputArray
110
     * @return array
111
     */
112 50
    protected function getOnlyArrayKeysWhereValueIsNotAnArray($inputArray)
113
    {
114 50
        $keysWithNonArrayValue = [];
115
116 50
        foreach ($inputArray as $key => $value) {
117 50
            if (is_array($value)) {
118
                // configuration for a content object, skipping
119 44
                continue;
120
            }
121
122 50
            $keysWithNonArrayValue[] = $key;
123
        }
124
125 50
        return $keysWithNonArrayValue;
126
    }
127
128
    /**
129
     * Gets the value from a given TypoScript path.
130
     *
131
     * In the context of an frontend content element the path plugin.tx_solr is
132
     * merged recursive with overrule with the content element specific typoscript
133
     * settings, like plugin.tx_solr_PiResults_Results, and possible flex form settings
134
     * (depends on the solr plugin).
135
     *
136
     * Example: plugin.tx_solr.search.targetPage
137
     * returns $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_solr.']['search.']['targetPage']
138
     *
139
     * @param string $path TypoScript path
140
     * @return mixed The TypoScript object defined by the given path
141
     * @throws InvalidArgumentException
142
     */
143 312
    public function getValueByPath($path)
144
    {
145 312
        if (!is_string($path)) {
0 ignored issues
show
introduced by
The condition is_string($path) is always true.
Loading history...
146
            throw new InvalidArgumentException('Parameter $path is not a string',
147
                1325623321);
148
        }
149 312
        return $this->configurationAccess->get($path);
0 ignored issues
show
Bug introduced by
The method get() does not exist on null. ( Ignorable by Annotation )

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

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

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

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

353
        if (trim(/** @scrutinizer ignore-type */ $result) === '') {
Loading history...
354 39
            return $defaultIfEmpty;
355
        }
356
357 4
        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

357
        return GeneralUtility::trimExplode(',', /** @scrutinizer ignore-type */ $result);
Loading history...
358
    }
359
360
    /**
361
     * Returns an array of all allowedPageTypes.
362
     *
363
     * plugin.tx_solr.index.queue.pages.allowedPageTypes
364
     *
365
     * @param string $configurationName The configuration name of the queue to use.
366
     * @param array $defaultIfEmpty
367
     * @return array
368
     */
369 30
    public function getIndexQueueAllowedPageTypesArrayByConfigurationName($configurationName = 'pages', $defaultIfEmpty = [])
370
    {
371 30
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.allowedPageTypes';
372 30
        $result = $this->getValueByPathOrDefaultValue($path, '');
373 30
        if (trim($result) === '') {
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type array; however, parameter $str 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

373
        if (trim(/** @scrutinizer ignore-type */ $result) === '') {
Loading history...
374
            return $defaultIfEmpty;
375
        }
376
377 30
        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

377
        return GeneralUtility::trimExplode(',', /** @scrutinizer ignore-type */ $result);
Loading history...
378
    }
379
380
    /**
381
     * Returns the configured excludeContentByClass patterns as array.
382
     *
383
     * plugin.tx_solr.index.queue.pages.excludeContentByClass
384
     *
385
     * @param array $defaultIfEmpty
386
     * @return array
387
     */
388 52
    public function getIndexQueuePagesExcludeContentByClassArray($defaultIfEmpty = [])
389
    {
390 52
        $path = 'plugin.tx_solr.index.queue.pages.excludeContentByClass';
391 52
        $result = $this->getValueByPathOrDefaultValue($path, '');
392
393 52
        if (trim($result) === '') {
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type array; however, parameter $str 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

393
        if (trim(/** @scrutinizer ignore-type */ $result) === '') {
Loading history...
394 7
            return $defaultIfEmpty;
395
        }
396
397 45
        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

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

566
        if (trim(/** @scrutinizer ignore-type */ $recursiveUpdateFieldsString) === '') {
Loading history...
567
            return $defaultIfEmpty;
568 26
        }
569 26
        $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

569
        $recursiveUpdateFields = GeneralUtility::trimExplode(',', /** @scrutinizer ignore-type */ $recursiveUpdateFieldsString);
Loading history...
570 26
        // For easier check later on we return an array by combining $recursiveUpdateFields
571 20
        return array_combine($recursiveUpdateFields, $recursiveUpdateFields);
0 ignored issues
show
Bug Best Practice introduced by
The expression return array_combine($re...$recursiveUpdateFields) could also return false which is incompatible with the documented return type array. Did you maybe forget to handle an error condition?

If the returned type also contains false, it is an indicator that maybe an error condition leading to the specific return statement remains unhandled.

Loading history...
572
    }
573 7
574
575 7
    /**
576
     * Retrieves and initialPagesAdditionalWhereClause where clause when configured or an empty string.
577
     *
578
     * plugin.tx_solr.index.queue.<configurationName>.initialPagesAdditionalWhereClause
579
     *
580
     * @param string $configurationName
581
     * @return string
582
     */
583
    public function getInitialPagesAdditionalWhereClause($configurationName)
584
    {
585
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.initialPagesAdditionalWhereClause';
586
        $initialPagesAdditionalWhereClause = $this->getValueByPathOrDefaultValue($path, '');
587 13
588
        if (trim($initialPagesAdditionalWhereClause) === '') {
0 ignored issues
show
Bug introduced by
It seems like $initialPagesAdditionalWhereClause can also be of type array; however, parameter $str 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

588
        if (trim(/** @scrutinizer ignore-type */ $initialPagesAdditionalWhereClause) === '') {
Loading history...
589 13
            return '';
590 13
        }
591
592 13
        return trim($initialPagesAdditionalWhereClause);
593 13
    }
594
595
    /**
596 1
     * Retrieves and additional where clause when configured or an empty string.
597
     *
598
     * plugin.tx_solr.index.queue.<configurationName>.additionalWhereClause
599
     *
600
     * @param string $configurationName
601
     * @return string
602
     */
603
    public function getIndexQueueAdditionalWhereClauseByConfigurationName($configurationName)
604
    {
605
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.additionalWhereClause';
606
        $additionalWhere = $this->getValueByPathOrDefaultValue($path, '');
607 70
608
        if (trim($additionalWhere) === '') {
0 ignored issues
show
Bug introduced by
It seems like $additionalWhere can also be of type array; however, parameter $str 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

608
        if (trim(/** @scrutinizer ignore-type */ $additionalWhere) === '') {
Loading history...
609 70
            return '';
610 70
        }
611
612 70
        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

612
        return ' AND ' . /** @scrutinizer ignore-type */ $additionalWhere;
Loading history...
613 25
    }
614
615
    /**
616 46
     * This method can be used to retrieve all index queue configuration names, where
617
     * a certain table is used. It can be configured with the property "table" or is using the configuration
618
     * key a fallback for the table name.
619
     *
620
     * plugin.tx_solr.index.queue.<configurationName>.
621
     *
622
     * @param string $tableName
623
     * @param array $defaultIfEmpty
624
     * @return array
625
     */
626
    public function getIndexQueueConfigurationNamesByTableName($tableName, $defaultIfEmpty = [])
627
    {
628
        $path = 'plugin.tx_solr.index.queue.';
629
        $configuration = $this->getObjectByPathOrDefault($path, []);
630 1
        $possibleConfigurations = [];
631
632 1
        foreach ($configuration as $configurationName => $indexingEnabled) {
633 1
            $isObject = substr($configurationName, -1) === '.';
634 1
            if ($isObject || !$indexingEnabled) {
635
                continue;
636 1
            }
637 1
638 1
            // when the configuration name equals the tableName we have a fallback
639 1
            $hasTableNameAsConfigurationName = $configurationName == $tableName;
640
            $hasTableAssignedInQueueConfiguration = isset($configuration[$configurationName . '.']['table']) &&
641
                                                    $configuration[$configurationName . '.']['table'] == $tableName;
642
            if ($hasTableNameAsConfigurationName || $hasTableAssignedInQueueConfiguration) {
643 1
                $possibleConfigurations[] = $configurationName;
644 1
            }
645 1
        }
646 1
647 1
        return count($possibleConfigurations) > 0 ? $possibleConfigurations : $defaultIfEmpty;
648
    }
649
650
    /**
651 1
     * This method is used to retrieve the className of a queue initializer for a certain indexing configuration
652
     * of returns the default initializer class, when noting is configured.
653
     *
654
     * plugin.tx_solr.index.queue.<configurationName>.initialization
655
     *
656
     * @param string $configurationName
657
     * @param string $defaultIfEmpty
658
     * @return string
659
     */
660
    public function getIndexQueueInitializerClassByConfigurationName($configurationName, $defaultIfEmpty = Record::class)
661
    {
662
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.initialization';
663
        $className = $this->getValueByPathOrDefaultValue($path, $defaultIfEmpty);
664 7
665
        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...
666 7
    }
667 7
668
    /**
669 7
     * Returns the _LOCAL_LANG configuration from the TypoScript.
670
     *
671
     * plugin.tx_solr._LOCAL_LANG.
672
     *
673
     * @param array $defaultIfEmpty
674
     * @return array
675
     */
676
    public function getLocalLangConfiguration(array $defaultIfEmpty = [])
677
    {
678
        $result = $this->getObjectByPathOrDefault('plugin.tx_solr._LOCAL_LANG.', $defaultIfEmpty);
679
        return $result;
680
    }
681
682
    /**
683
     * When this is enabled the output of the devlog, will be printed as debug output.
684
     *
685
     * @param bool $defaultIfEmpty
686
     * @return bool
687
     */
688
    public function getLoggingDebugOutput($defaultIfEmpty = false)
689
    {
690
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.debugOutput', $defaultIfEmpty);
691
        return $this->getBool($result);
692
    }
693
694
    /**
695
     * Returns if query filters should be written to the log.
696
     *
697
     * plugin.tx_solr.logging.query.filters
698
     *
699
     * @param bool $defaultIfEmpty
700
     * @return bool
701
     */
702
    public function getLoggingQueryFilters($defaultIfEmpty = false)
703
    {
704
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.query.filters', $defaultIfEmpty);
705
        return $this->getBool($result);
706
    }
707
708
    /**
709
     * Returns if the querystring should be logged or not.
710
     *
711
     * plugin.tx_solr.logging.query.queryString
712
     *
713
     * @param bool $defaultIfEmpty
714
     * @return bool
715
     */
716
    public function getLoggingQueryQueryString($defaultIfEmpty = false)
717
    {
718
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.query.queryString', $defaultIfEmpty);
719
        return $this->getBool($result);
720 50
    }
721
722 50
    /**
723 50
     * Returns if the searchWords should be logged or not.
724
     *
725
     * plugin.tx_solr.logging.query.searchWords
726
     *
727
     * @param bool $defaultIfEmpty
728
     * @return bool
729
     */
730
    public function getLoggingQuerySearchWords($defaultIfEmpty = false)
731
    {
732
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.query.searchWords', $defaultIfEmpty);
733
        return $this->getBool($result);
734 120
    }
735
736 120
    /**
737 120
     * Returns if the rawGet requests should be logged or not.
738
     *
739
     * plugin.tx_solr.logging.query.rawGet
740
     *
741
     * @param bool $defaultIfEmpty
742
     * @return bool
743
     */
744
    public function getLoggingQueryRawGet($defaultIfEmpty = false)
745
    {
746
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.query.rawGet', $defaultIfEmpty);
747
        return $this->getBool($result);
748
    }
749
750
    /**
751
     * Returns if the rawPost requests should be logged or not.
752
     *
753
     * plugin.tx_solr.logging.query.rawPost
754
     *
755
     * @param bool $defaultIfEmpty
756
     * @return bool
757
     */
758
    public function getLoggingQueryRawPost($defaultIfEmpty = false)
759
    {
760
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.query.rawPost', $defaultIfEmpty);
761
        return $this->getBool($result);
762 17
    }
763
764 17
    /**
765 17
     * Returns if the rawDelete requests should be logged or not.
766
     *
767
     * plugin.tx_solr.logging.query.rawDelete
768
     *
769
     * @param bool $defaultIfEmpty
770
     * @return bool
771
     */
772
    public function getLoggingQueryRawDelete($defaultIfEmpty = false)
773
    {
774
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.query.rawDelete', $defaultIfEmpty);
775
        return $this->getBool($result);
776
    }
777
778
    /**
779
     * Returns if exceptions should be logged or not.
780
     *
781
     * plugin.tx_solr.logging.exceptions
782
     *
783
     * @param bool $defaultIfEmpty
784
     * @return bool
785
     */
786
    public function getLoggingExceptions($defaultIfEmpty = true)
787
    {
788
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.exceptions', $defaultIfEmpty);
789
        return $this->getBool($result);
790 4
    }
791
792 4
    /**
793 4
     * Returns if indexing operations should be logged or not.
794
     *
795
     * plugin.tx_solr.logging.indexing
796
     *
797
     * @param bool $defaultIfEmpty
798
     * @return bool
799
     */
800
    public function getLoggingIndexing($defaultIfEmpty = false)
801
    {
802
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.indexing', $defaultIfEmpty);
803
        return $this->getBool($result);
804 23
    }
805
806 23
    /**
807 23
     * Returns if indexing queue operations should be logged or not.
808
     *
809
     * plugin.tx_solr.logging.indexing.queue
810
     *
811
     * @param bool $defaultIfEmpty
812
     * @return bool
813
     */
814
    public function getLoggingIndexingQueue($defaultIfEmpty = false)
815
    {
816
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.indexing.queue', $defaultIfEmpty);
817
        return $this->getBool($result);
818 22
    }
819
820 22
    /**
821 22
     * This method can be used to check if the logging during indexing should be done.
822
     * It takes the specific configuration by indexQueueConfiguration into account or is using the
823
     * fallback when the logging is enabled on queue or indexing level.
824
     *
825
     * plugin.tx_solr.logging.indexing.queue.<indexQueueConfiguration>
826
     *
827
     * @param string $indexQueueConfiguration
828
     * @param bool $defaultIfEmpty
829
     * @return bool
830
     */
831
    public function getLoggingIndexingQueueOperationsByConfigurationNameWithFallBack($indexQueueConfiguration, $defaultIfEmpty = false)
832
    {
833
        // when logging is globally enabled we do not need to check the specific configuration
834
        if ($this->getLoggingIndexing()) {
835 23
            return true;
836
        }
837
838 23
        // when the logging for indexing is enabled on queue level we also do not need to check the specific configuration
839 1
        if ($this->getLoggingIndexingQueue()) {
840
            return true;
841
        }
842
843 22
        $path = 'plugin.tx_solr.logging.indexing.queue.' . $indexQueueConfiguration;
844
        $result = $this->getValueByPathOrDefaultValue($path, $defaultIfEmpty);
845
        return $this->getBool($result);
846
    }
847 22
848 22
    /**
849 22
     * Returns if a log message should be written when a page was indexed.
850
     *
851
     * plugin.tx_solr.logging.indexing.pageIndexed
852
     *
853
     * @param bool $defaultIfEmpty
854
     * @return bool
855
     */
856
    public function getLoggingIndexingPageIndexed($defaultIfEmpty = false)
857
    {
858
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.indexing.pageIndexed', $defaultIfEmpty);
859
        return $this->getBool($result);
860 10
    }
861
862 10
    /**
863 10
     * Returns if a log message should be written when the TYPO3 search markers are missing in the page.
864
     *
865
     * plugin.tx_solr.logging.indexing.missingTypo3SearchMarkers
866
     *
867
     * @param bool $defaultIfEmpty
868
     * @return bool
869
     */
870
    public function getLoggingIndexingMissingTypo3SearchMarkers($defaultIfEmpty = true)
871
    {
872
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.indexing.missingTypo3SearchMarkers', $defaultIfEmpty);
873
        return $this->getBool($result);
874 17
    }
875
876 17
    /**
877 17
     * Returns if the initialization of an indexqueue should be logged.
878
     *
879
     * plugin.tx_solr.logging.indexing.indexQueueInitialization
880
     *
881
     * @param bool $defaultIfEmpty
882
     * @return bool
883
     */
884
    public function getLoggingIndexingIndexQueueInitialization($defaultIfEmpty = false)
885
    {
886
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.indexing.indexQueueInitialization', $defaultIfEmpty);
887
        return $this->getBool($result);
888 12
    }
889
890 12
    /**
891 12
     * Indicates if the debug mode is enabled or not.
892
     *
893
     * plugin.tx_solr.enableDebugMode
894
     *
895
     * @param bool $defaultIfEmpty
896
     * @return bool
897
     */
898
    public function getEnabledDebugMode($defaultIfEmpty = false)
899
    {
900
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.enableDebugMode', $defaultIfEmpty);
901
        return $this->getBool($result);
902 39
    }
903
904 39
    /**
905 39
     * Returns true or false if something is configured below plugin.tx_solr.solr.
906
     *
907
     * plugin.tx_solr.solr.
908
     *
909
     * @deprecated Configuring solr connections with TypoScript is deprecated please use the site handling. Will be dropped with EXT:solr 11
910
     * @param boolean $defaultIfEmpty
911
     * @return boolean
912
     */
913
    public function getSolrHasConnectionConfiguration($defaultIfEmpty = false)
914
    {
915
        trigger_error('solr:deprecation: Configuring solr connections with TypoScript is deprecated please use the site handling', E_USER_DEPRECATED);
916 3
917
        $configuration = $this->getObjectByPathOrDefault('plugin.tx_solr.solr.', []);
918 3
        return $configuration !== [] ? true : $defaultIfEmpty;
919 3
    }
920
921
    /**
922
     * Returns the defaultTimeout used for requests to the Solr server
923
     *
924
     * plugin.tx_solr.solr.timeout
925
     *
926
     * @deprecated Configuring solr connections with TypoScript is deprecated please use the site handling. Will be dropped with EXT:solr 11
927
     * @param int $defaultIfEmpty
928
     * @return int
929
     */
930 3
    public function getSolrTimeout($defaultIfEmpty = 0, $scope = 'read')
931
    {
932 3
        trigger_error('solr:deprecation: Configuring solr connections with TypoScript is deprecated please use the site handling', E_USER_DEPRECATED);
933 3
934 3
        $scopePath = 'plugin.tx_solr.solr.' . $scope . '.timeout';
935 3
        $fallbackPath = 'plugin.tx_solr.solr.timeout';
936
        $result = (int)$this->getValueByPathOrDefaultValue($scopePath, -1);
937
        if($result !== -1) {
938
            return $result;
939 3
        }
940
941
        return (int)$this->getValueByPathOrDefaultValue($fallbackPath, $defaultIfEmpty);
942
    }
943
944
    /**
945
     * Returns the scheme used for requests to the Solr server
946
     *
947
     * plugin.tx_solr.solr.scheme
948
     *
949
     * Applies stdWrap on the configured setting
950
     *
951
     * @deprecated Configuring solr connections with TypoScript is deprecated please use the site handling. Will be dropped with EXT:solr 11
952
     * @param string $defaultIfEmpty
953 3
     * @param string $scope read or write, read by default
954
     * @return string
955 3
     */
956 3
    public function getSolrScheme($defaultIfEmpty = 'http', $scope = 'read')
957
    {
958 3
        trigger_error('solr:deprecation: Configuring solr connections with TypoScript is deprecated please use the site handling', E_USER_DEPRECATED);
959
960
        $scopePath = 'plugin.tx_solr.solr.' . $scope . '.scheme';
961
        $fallbackPath = 'plugin.tx_solr.solr.scheme';
962
963
        return $this->getValueByPathWithFallbackOrDefaultValueAndApplyStdWrap($scopePath, $fallbackPath, $defaultIfEmpty);
964
    }
965
966
    /**
967
     * Returns the hostname used for requests to the Solr server
968
     *
969
     * plugin.tx_solr.solr.host
970
     *
971
     * Applies stdWrap on the configured setting
972 6
     *
973
     * @deprecated Configuring solr connections with TypoScript is deprecated please use the site handling. Will be dropped with EXT:solr 11
974 6
     * @param string $defaultIfEmpty
975 6
     * @param string $scope read or write, read by default
976
     * @return string
977 6
     */
978
    public function getSolrHost($defaultIfEmpty = 'localhost', $scope = 'read')
979
    {
980
        trigger_error('solr:deprecation: Configuring solr connections with TypoScript is deprecated please use the site handling', E_USER_DEPRECATED);
981
982
        $scopePath = 'plugin.tx_solr.solr.' . $scope . '.host';
983
        $fallbackPath = 'plugin.tx_solr.solr.host';
984
985
        return $this->getValueByPathWithFallbackOrDefaultValueAndApplyStdWrap($scopePath, $fallbackPath, $defaultIfEmpty);
986
    }
987
988
    /**
989
     * Returns the port used for requests to the Solr server
990
     *
991 3
     * plugin.tx_solr.solr.port
992
     *
993 3
     * Applies stdWrap on the configured setting
994 3
     *
995
     * @deprecated Configuring solr connections with TypoScript is deprecated please use the site handling. Will be dropped with EXT:solr 11
996 3
     * @param int $defaultIfEmpty
997
     * @param string $scope read or write, read by default
998
     * @return int
999
     */
1000
    public function getSolrPort($defaultIfEmpty = 8983, $scope = 'read')
1001
    {
1002
        trigger_error('solr:deprecation: Configuring solr connections with TypoScript is deprecated please use the site handling', E_USER_DEPRECATED);
1003
1004
        $scopePath = 'plugin.tx_solr.solr.' . $scope . '.port';
1005
        $fallbackPath = 'plugin.tx_solr.solr.port';
1006
1007
        return (int)$this->getValueByPathWithFallbackOrDefaultValueAndApplyStdWrap($scopePath, $fallbackPath, $defaultIfEmpty);
1008
    }
1009
1010 6
    /**
1011
     * Returns the path used for requests to the Solr server
1012 6
     *
1013 6
     * plugin.tx_solr.solr.path
1014
     *
1015 6
     * Applies stdWrap on the configured setting
1016
     *
1017 6
     * @deprecated Configuring solr connections with TypoScript is deprecated please use the site handling. Will be dropped with EXT:solr 11
1018 6
     * @param string $defaultIfEmpty
1019
     * @param string $scope read or write, read by default
1020 6
     * @return string
1021
     */
1022
    public function getSolrPath($defaultIfEmpty = '/solr/core_en/', $scope = 'read')
1023
    {
1024
        trigger_error('solr:deprecation: Configuring solr connections with TypoScript is deprecated please use the site handling', E_USER_DEPRECATED);
1025
1026
        $scopePath = 'plugin.tx_solr.solr.' . $scope . '.path';
1027
        $fallbackPath = 'plugin.tx_solr.solr.path';
1028
1029
        $solrPath =  $this->getValueByPathWithFallbackOrDefaultValueAndApplyStdWrap($scopePath, $fallbackPath, $defaultIfEmpty);
1030
1031
        $solrPath = trim($solrPath, '/');
1032
        $solrPath = '/' . $solrPath . '/';
1033
1034 3
        return $solrPath;
1035
    }
1036 3
1037 3
    /**
1038
     * Returns the username used for requests to the Solr server
1039 3
     *
1040
     * plugin.tx_solr.solr.username
1041
     *
1042
     * Applies stdWrap on the configured setting
1043
     *
1044
     * @deprecated Configuring solr connections with TypoScript is deprecated please use the site handling. Will be dropped with EXT:solr 11
1045
     * @param string $defaultIfEmpty
1046
     * @param string $scope read or write, read by default
1047
     * @return string
1048
     */
1049
    public function getSolrUsername($defaultIfEmpty = '', $scope = 'read')
1050
    {
1051
        trigger_error('solr:deprecation: Configuring solr connections with TypoScript is deprecated please use the site handling', E_USER_DEPRECATED);
1052
1053 3
        $scopePath = 'plugin.tx_solr.solr.' . $scope . '.username';
1054
        $fallbackPath = 'plugin.tx_solr.solr.username';
1055 3
1056 3
        return $this->getValueByPathWithFallbackOrDefaultValueAndApplyStdWrap($scopePath, $fallbackPath, $defaultIfEmpty);
1057
    }
1058 3
1059
    /**
1060
     * Returns the password used for requests to the Solr server
1061
     *
1062
     * plugin.tx_solr.solr.password
1063
     *
1064
     * Applies stdWrap on the configured setting
1065
     *
1066
     * @deprecated Configuring solr connections with TypoScript is deprecated please use the site handling. Will be dropped with EXT:solr 11
1067 6
     * @param string $defaultIfEmpty
1068
     * @param string $scope read or write, read by default
1069 6
     * @return string
1070 6
     */
1071
    public function getSolrPassword($defaultIfEmpty = '', $scope = 'read')
1072
    {
1073
        trigger_error('solr:deprecation: Configuring solr connections with TypoScript is deprecated please use the site handling', E_USER_DEPRECATED);
1074 6
1075 6
        $scopePath = 'plugin.tx_solr.solr.' . $scope . '.password';
1076
        $fallbackPath = 'plugin.tx_solr.solr.password';
1077
1078
        return $this->getValueByPathWithFallbackOrDefaultValueAndApplyStdWrap($scopePath, $fallbackPath, $defaultIfEmpty);
1079
    }
1080
1081
    /**
1082
     * @param $path
1083
     * @param $fallbackPath
1084
     * @param $defaultIfBothIsEmpty
1085
     * @return mixed
1086 52
     */
1087
    public function getValueByPathWithFallbackOrDefaultValueAndApplyStdWrap($path, $fallbackPath, $defaultIfBothIsEmpty)
1088 52
    {
1089 52
        $result = (string)$this->getValueByPathOrDefaultValue($path, '');
1090
        if($result !== '') {
1091
            return $this->renderContentElementOfConfigured($path, $result);
1092
        }
1093
1094
        $result = (string)$this->getValueByPathOrDefaultValue($fallbackPath, $defaultIfBothIsEmpty);
1095
        return $this->renderContentElementOfConfigured($fallbackPath, $result);
1096
    }
1097
1098
    /**
1099
     * Retrieves the complete search configuration
1100 39
     *
1101
     * plugin.tx_solr.search.
1102 39
     *
1103 39
     * @param array $defaultIfEmpty
1104
     * @return array
1105
     */
1106
    public function getSearchConfiguration(array $defaultIfEmpty = [])
1107
    {
1108
        $result = $this->getObjectByPathOrDefault('plugin.tx_solr.search.', $defaultIfEmpty);
1109
        return $result;
1110
    }
1111
1112
    /**
1113
     * Indicates if elevation should be used or not
1114 34
     *
1115
     * plugin.tx_solr.search.elevation
1116 34
     *
1117 34
     * @param bool $defaultIfEmpty
1118
     * @return bool
1119
     */
1120
    public function getSearchElevation($defaultIfEmpty = false)
1121
    {
1122
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.elevation', $defaultIfEmpty);
1123
        return $this->getBool($result);
1124
    }
1125
1126
    /**
1127
     * Indicates if elevated results should be marked
1128 34
     *
1129
     * plugin.tx_solr.search.elevation.markElevatedResults
1130 34
     *
1131 34
     * @param bool $defaultIfEmpty
1132
     * @return bool
1133
     */
1134
    public function getSearchElevationMarkElevatedResults($defaultIfEmpty = true)
1135
    {
1136
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.elevation.markElevatedResults', $defaultIfEmpty);
1137
        return $this->getBool($result);
1138
    }
1139
1140
    /**
1141
     * Indicates if elevation should be forced
1142 120
     *
1143
     *plugin.tx_solr.search.elevation.forceElevation
1144 120
     *
1145 120
     * @param bool $defaultIfEmpty
1146
     * @return bool
1147
     */
1148
    public function getSearchElevationForceElevation($defaultIfEmpty = true)
1149
    {
1150
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.elevation.forceElevation', $defaultIfEmpty);
1151
        return $this->getBool($result);
1152
    }
1153
1154
    /**
1155
     * Indicates if collapsing on a certain field should be used to build variants or not.
1156 5
     *
1157
     * plugin.tx_solr.search.variants
1158 5
     *
1159
     * @param bool $defaultIfEmpty
1160
     * @return bool
1161
     */
1162
    public function getSearchVariants($defaultIfEmpty = false)
1163
    {
1164
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.variants', $defaultIfEmpty);
1165
        return $this->getBool($result);
1166
    }
1167
1168
    /**
1169 5
     * Indicates if collapsing on a certain field should be used or not
1170
     *
1171 5
     * plugin.tx_solr.search.variants.variantField
1172 5
     *
1173
     * @param string $defaultIfEmpty
1174
     * @return string
1175
     */
1176
    public function getSearchVariantsField($defaultIfEmpty = 'variantId')
1177
    {
1178
        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...
1179
    }
1180
1181
    /**
1182
     * Indicates if expanding of collapsed items it activated.
1183 5
     *
1184
     * plugin.tx_solr.search.variants.expand
1185 5
     *
1186 5
     * @param bool $defaultIfEmpty
1187
     * @return bool
1188
     */
1189
    public function getSearchVariantsExpand($defaultIfEmpty = false)
1190
    {
1191
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.variants.expand', $defaultIfEmpty);
1192
        return $this->getBool($result);
1193
    }
1194
1195
    /**
1196
     * Retrieves the number of elements that should be expanded.
1197 31
     *
1198
     * plugin.tx_solr.search.variants.limit
1199 31
     *
1200 31
     * @param int $defaultIfEmpty
1201
     * @return int
1202
     */
1203
    public function getSearchVariantsLimit($defaultIfEmpty = 10)
1204
    {
1205
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.variants.limit', $defaultIfEmpty);
1206
        return (int)$result;
1207
    }
1208
1209
    /**
1210
     * Indicates if frequent searches should be show or not.
1211 34
     *
1212
     * plugin.tx_solr.search.frequentSearches
1213 34
     *
1214 34
     * @param bool $defaultIfEmpty
1215
     * @return bool
1216
     */
1217
    public function getSearchFrequentSearches($defaultIfEmpty = false)
1218
    {
1219
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.frequentSearches', $defaultIfEmpty);
1220
        return $this->getBool($result);
1221
    }
1222
1223
    /**
1224
     * Returns the sub configuration of the frequentSearches
1225 34
     *
1226
     * plugin.tx_solr.search.frequentSearches.
1227 34
     *
1228 34
     * @param array $defaultIfEmpty
1229
     * @return array
1230
     */
1231
    public function getSearchFrequentSearchesConfiguration($defaultIfEmpty = [])
1232
    {
1233
        $result = $this->getObjectByPathOrDefault('plugin.tx_solr.search.frequentSearches.', $defaultIfEmpty);
1234
        return $result;
1235
    }
1236
1237
    /**
1238
     * Retrieves the minimum font size that should be used for the frequentSearches.
1239 34
     *
1240
     * plugin.tx_solr.search.frequentSearches.minSize
1241 34
     *
1242 34
     * @param int $defaultIfEmpty
1243
     * @return int
1244
     */
1245
    public function getSearchFrequentSearchesMinSize($defaultIfEmpty = 14)
1246
    {
1247
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.frequentSearches.minSize', $defaultIfEmpty);
1248
        return (int)$result;
1249
    }
1250
1251
    /**
1252
     * Retrieves the maximum font size that should be used for the frequentSearches.
1253 33
     *
1254
     * plugin.tx_solr.search.frequentSearches.minSize
1255 33
     *
1256 33
     * @param int $defaultIfEmpty
1257
     * @return int
1258
     */
1259
    public function getSearchFrequentSearchesMaxSize($defaultIfEmpty = 32)
1260
    {
1261
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.frequentSearches.maxSize', $defaultIfEmpty);
1262
        return (int)$result;
1263
    }
1264
1265
    /**
1266
     * Indicates if frequent searches should be show or not.
1267 122
     *
1268
     * plugin.tx_solr.search.frequentSearches.useLowercaseKeywords
1269 122
     *
1270 122
     * @param bool $defaultIfEmpty
1271
     * @return bool
1272
     */
1273
    public function getSearchFrequentSearchesUseLowercaseKeywords($defaultIfEmpty = false)
1274
    {
1275
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.frequentSearches.useLowercaseKeywords', $defaultIfEmpty);
1276
        return $this->getBool($result);
1277
    }
1278
1279
    /**
1280
     * Returns the configuration if the search should be initialized with an empty query.
1281 122
     *
1282
     * plugin.tx_solr.search.initializeWithEmptyQuery
1283 122
     *
1284 122
     * @param bool $defaultIfEmpty
1285
     * @return bool
1286
     */
1287
    public function getSearchInitializeWithEmptyQuery($defaultIfEmpty = false)
1288
    {
1289
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.initializeWithEmptyQuery', $defaultIfEmpty);
1290
        return $this->getBool($result);
1291
    }
1292
1293
    /**
1294
     * Returns the configured initial query
1295 31
     *
1296
     * plugin.tx_solr.search.initializeWithQuery
1297 31
     *
1298 31
     * @param string $defaultIfEmpty
1299
     * @return string
1300
     */
1301
    public function getSearchInitializeWithQuery($defaultIfEmpty = '')
1302
    {
1303
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.initializeWithQuery', $defaultIfEmpty);
1304
        return (string)$result;
1305
    }
1306
1307
    /**
1308
     * Returns if the last searches should be displayed or not.
1309 35
     *
1310
     * plugin.tx_solr.search.lastSearches
1311 35
     *
1312 35
     * @param bool $defaultIfEmpty
1313
     * @return bool
1314
     */
1315
    public function getSearchLastSearches($defaultIfEmpty = false)
1316
    {
1317
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.lastSearches', $defaultIfEmpty);
1318
        return $this->getBool($result);
1319
    }
1320
1321
    /**
1322
     * Returns the lastSearch mode. "user" for user specific
1323 35
     *
1324
     * plugin.tx_solr.search.lastSearches.mode
1325 35
     *
1326 35
     * @param string $defaultIfEmpty
1327
     * @return string
1328
     */
1329
    public function getSearchLastSearchesMode($defaultIfEmpty = 'user')
1330
    {
1331
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.lastSearches.mode', $defaultIfEmpty);
1332
        return (string)$result;
1333
    }
1334
1335
    /**
1336
     * Returns the lastSearch limit
1337 7
     *
1338
     * plugin.tx_solr.search.lastSearches.limit
1339 7
     *
1340 7
     * @param int $defaultIfEmpty
1341
     * @return int
1342
     */
1343
    public function getSearchLastSearchesLimit($defaultIfEmpty = 10)
1344
    {
1345
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.lastSearches.limit', $defaultIfEmpty);
1346
        return (int)$result;
1347
    }
1348
1349
    /**
1350
     * Indicates if the results of an initial empty query should be shown or not.
1351 5
     *
1352
     * plugin.tx_solr.search.showResultsOfInitialEmptyQuery
1353 5
     *
1354 5
     * @param bool $defaultIfEmpty
1355
     * @return bool
1356
     */
1357
    public function getSearchShowResultsOfInitialEmptyQuery($defaultIfEmpty = false)
1358
    {
1359
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.showResultsOfInitialEmptyQuery', $defaultIfEmpty);
1360
        return $this->getBool($result);
1361
    }
1362
1363
    /**
1364
     * Indicates if the results of an initial search query should be shown.
1365 66
     *
1366
     * plugin.tx_solr.search.showResultsOfInitialQuery
1367 66
     *
1368 66
     * @param bool $defaultIfEmpty
1369
     * @return bool
1370
     */
1371
    public function getSearchShowResultsOfInitialQuery($defaultIfEmpty = false)
1372
    {
1373
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.showResultsOfInitialQuery', $defaultIfEmpty);
1374
        return $this->getBool($result);
1375
    }
1376
1377
    /**
1378
     * Indicates if sorting was enabled or not.
1379 35
     *
1380
     * plugin.tx_solr.search.sorting
1381 35
     *
1382 35
     * @param bool $defaultIfEmpty
1383
     * @return bool
1384
     */
1385
    public function getSearchSorting($defaultIfEmpty = false)
1386
    {
1387
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.sorting', $defaultIfEmpty);
1388
        return $this->getBool($result);
1389
    }
1390
1391
    /**
1392
     * Returns the sorting options configurations.
1393
     *
1394
     * plugin.tx_solr.search.sorting.options.
1395
     *
1396
     * @param array $defaultIfEmpty
1397
     * @return array
1398
     */
1399 38
    public function getSearchSortingOptionsConfiguration($defaultIfEmpty = [])
1400
    {
1401 38
        $result = $this->getObjectByPathOrDefault('plugin.tx_solr.search.sorting.options.', $defaultIfEmpty);
1402 38
        return $result;
1403
    }
1404
1405 38
    /**
1406 2
     * Retrieves the sorting default order for a sort option.
1407
     *
1408
     * plugin.tx_solr.search.sorting.options.<sortOptionName>.defaultOrder
1409
     *
1410 36
     * or
1411 36
     *
1412 36
     * plugin.tx_solr.search.sorting.defaultOrder
1413
     *
1414
     *
1415
     * @param string $sortOptionName
1416
     * @param string $defaultIfEmpty
1417
     * @return string
1418
     */
1419
    public function getSearchSortingDefaultOrderBySortOptionName($sortOptionName = '', $defaultIfEmpty = 'asc')
1420
    {
1421 42
        $sortOrderSpecificPath = 'plugin.tx_solr.search.sorting.options.' . $sortOptionName . '.defaultOrder';
1422
        $specificSortOrder = $this->getValueByPathOrDefaultValue($sortOrderSpecificPath, null);
1423 42
1424
        // if we have a concrete setting, use it
1425 42
        if ($specificSortOrder !== null) {
1426 3
            return mb_strtolower($specificSortOrder);
0 ignored issues
show
Bug introduced by
$specificSortOrder of type array is incompatible with the type string expected by parameter $str 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

1426
            return mb_strtolower(/** @scrutinizer ignore-type */ $specificSortOrder);
Loading history...
1427
        }
1428
1429 39
        // no specific setting, check common setting
1430
        $commonPath = 'plugin.tx_solr.search.sorting.defaultOrder';
1431
        $commonATagParamOrDefaultValue = $this->getValueByPathOrDefaultValue($commonPath, $defaultIfEmpty);
1432
        return mb_strtolower($commonATagParamOrDefaultValue);
1433
    }
1434
1435
    /**
1436
     * Returns the trusted fields configured for the search that do not need to be escaped.
1437
     *
1438
     * @param array $defaultIfEmpty
1439
     * @return array
1440
     */
1441
    public function getSearchTrustedFieldsArray($defaultIfEmpty = ['url'])
1442
    {
1443
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.trustedFields', '');
1444
1445
        if (trim($result) === '') {
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type array; however, parameter $str 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

1445
        if (trim(/** @scrutinizer ignore-type */ $result) === '') {
Loading history...
1446
            return $defaultIfEmpty;
1447
        }
1448
1449
        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

1449
        return GeneralUtility::trimExplode(',', /** @scrutinizer ignore-type */ $result);
Loading history...
1450
    }
1451
1452
    /**
1453
     * Indicates if the plugin arguments should be kept in the search form for a second submission.
1454 117
     *
1455
     * plugin.tx_solr.search.keepExistingParametersForNewSearches
1456 117
     *
1457 117
     * @param bool $defaultIfEmpty
1458
     * @return bool
1459
     */
1460
    public function getSearchKeepExistingParametersForNewSearches($defaultIfEmpty = false)
1461
    {
1462
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.keepExistingParametersForNewSearches', $defaultIfEmpty);
1463
        return $this->getBool($result);
1464
    }
1465
1466
    /**
1467
     * Returns if an empty query is allowed on the query level.
1468 130
     *
1469
     * plugin.tx_solr.search.query.allowEmptyQuery
1470 130
     *
1471 130
     * @param string $defaultIfEmpty
1472
     * @return bool
1473
     */
1474
    public function getSearchQueryAllowEmptyQuery($defaultIfEmpty = '')
1475
    {
1476
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.allowEmptyQuery', $defaultIfEmpty);
1477
        return $this->getBool($result);
1478
    }
1479
1480
    /**
1481 1
     * Returns the filter configuration array
1482
     *
1483 1
     * plugin.tx_solr.search.query.filter.
1484 1
     *
1485
     * @param array $defaultIfEmpty
1486
     * @return array
1487
     */
1488
    public function getSearchQueryFilterConfiguration(array $defaultIfEmpty = [])
1489
    {
1490
        $result = $this->getObjectByPathOrDefault('plugin.tx_solr.search.query.filter.', $defaultIfEmpty);
1491 3
        return $result;
1492
    }
1493 3
1494 3
    /**
1495
     * Can be used to overwrite the filterConfiguration.
1496
     *
1497
     * plugin.tx_solr.search.query.filter.
1498
     *
1499
     * @param array $configuration
1500
     */
1501
    public function setSearchQueryFilterConfiguration(array $configuration)
1502
    {
1503
        $this->configurationAccess->set('plugin.tx_solr.search.query.filter.', $configuration);
1504 120
    }
1505
1506 120
    /**
1507
     * Removes the pageSections filter setting.
1508
     *
1509
     * @return void
1510
     */
1511
    public function removeSearchQueryFilterForPageSections()
1512
    {
1513
        $this->configurationAccess->reset('plugin.tx_solr.search.query.filter.__pageSections');
1514
    }
1515
1516
    /**
1517 120
     * Returns the configured queryFields from TypoScript
1518
     *
1519 120
     * plugin.tx_solr.search.query.queryFields
1520 120
     *
1521
     * @param string $defaultIfEmpty
1522
     * @return string
1523
     */
1524
    public function getSearchQueryQueryFields($defaultIfEmpty = '')
1525
    {
1526
        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...
1527
    }
1528
1529
    /**
1530
     * This method is used to check if a phrase search is enabled or not
1531 2
     *
1532
     * plugin.tx_solr.search.query.phrase = 1
1533 2
     *
1534
     * @param bool $defaultIfEmpty
1535
     * @return bool
1536
     */
1537
    public function getPhraseSearchIsEnabled(bool $defaultIfEmpty = false)
1538
    {
1539
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.phrase', $defaultIfEmpty);
1540
        return $this->getBool($result);
1541
    }
1542
1543
    /**
1544 120
     * Returns the configured phrase fields from TypoScript
1545
     *
1546 120
     * plugin.tx_solr.search.query.phrase.fields
1547 120
     *
1548
     * @param string $defaultIfEmpty
1549
     * @return string
1550
     */
1551
    public function getSearchQueryPhraseFields(string $defaultIfEmpty = '')
1552
    {
1553
        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...
1554
    }
1555
1556
    /**
1557
     * This method is used to check if a bigram phrase search is enabled or not
1558 2
     *
1559
     * plugin.tx_solr.search.query.bigramPhrase = 1
1560 2
     *
1561
     * @param bool $defaultIfEmpty
1562
     * @return bool
1563
     */
1564
    public function getBigramPhraseSearchIsEnabled(bool $defaultIfEmpty = false)
1565
    {
1566
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.bigramPhrase', $defaultIfEmpty);
1567
        return $this->getBool($result);
1568
    }
1569
1570
    /**
1571 120
     * Returns the configured phrase fields from TypoScript
1572
     *
1573 120
     * plugin.tx_solr.search.query.bigramPhrase.fields
1574 120
     *
1575
     * @param string $defaultIfEmpty
1576
     * @return string
1577
     */
1578
    public function getSearchQueryBigramPhraseFields(string $defaultIfEmpty = '')
1579
    {
1580
        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...
1581
    }
1582
1583
    /**
1584
     * This method is used to check if a trigram phrase search is enabled or not
1585 2
     *
1586
     * plugin.tx_solr.search.query.trigramPhrase = 1
1587 2
     *
1588
     * @param bool $defaultIfEmpty
1589
     * @return bool
1590
     */
1591
    public function getTrigramPhraseSearchIsEnabled(bool $defaultIfEmpty = false)
1592
    {
1593
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.trigramPhrase', $defaultIfEmpty);
1594
        return $this->getBool($result);
1595
    }
1596
1597
    /**
1598 122
     * Returns the configured trigram phrase fields from TypoScript
1599
     *
1600 122
     * plugin.tx_solr.search.query.trigramPhrase.fields
1601 122
     *
1602 82
     * @param string $defaultIfEmpty
1603
     * @return string
1604
     */
1605 40
    public function getSearchQueryTrigramPhraseFields(string $defaultIfEmpty = '')
1606
    {
1607
        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...
1608
    }
1609
1610
    /**
1611
     * Returns the configured returnFields as array.
1612
     *
1613
     * plugin.tx_solr.search.query.returnFields
1614
     *
1615
     * @param array $defaultIfEmpty
1616 37
     * @return array
1617
     */
1618 37
    public function getSearchQueryReturnFieldsAsArray($defaultIfEmpty = [])
1619 37
    {
1620
        $returnFields = $this->getValueByPath('plugin.tx_solr.search.query.returnFields');
1621 37
        if (is_null($returnFields)) {
1622
            return $defaultIfEmpty;
1623
        }
1624 37
1625
        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

1625
        return GeneralUtility::trimExplode(',', /** @scrutinizer ignore-type */ $returnFields);
Loading history...
1626
    }
1627
1628
    /**
1629
     * Returns the configured target page for the search.
1630
     * By default the contextPageId will be used
1631
     *
1632
     * plugin.tx_solr.search.targetPage
1633
     *
1634
     * @return int
1635
     */
1636
    public function getSearchTargetPage()
1637
    {
1638
        $targetPage = (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.targetPage', 0);
1639
        if ($targetPage === 0) {
1640
            // when no specific page was configured we use the contextPageId (which is usual $GLOBALS['TSFE']->id)
1641
            $targetPage = $this->contextPageId;
1642
        }
1643
1644
        return $targetPage;
1645
    }
1646
1647
    /**
1648
     * Retrieves the targetPage configuration.
1649
     *
1650 27
     * plugin.tx_solr.search.targetPage.
1651
     *
1652 27
     * @param array $defaultIfEmpty
1653 27
     * @return array
1654
     */
1655
    public function getSearchTargetPageConfiguration(array $defaultIfEmpty = [])
1656
    {
1657
        $result = $this->getObjectByPathOrDefault('plugin.tx_solr.search.targetPage.', $defaultIfEmpty);
1658
        return $result;
1659
    }
1660
1661
    /**
1662
     * Method to check if the site highlighting is enabled. When the siteHighlighting is enabled the
1663
     * sword_list parameter is added to the results link.
1664
     *
1665 120
     * plugin.tx_solr.searcb.results.siteHighlighting
1666
     *
1667 120
     * @param bool $defaultIfEmpty
1668 120
     * @return bool
1669
     */
1670
    public function getSearchResultsSiteHighlighting($defaultIfEmpty = true)
1671
    {
1672
        $isSiteHightlightingEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.siteHighlighting', $defaultIfEmpty);
1673
        return $this->getBool($isSiteHightlightingEnabled);
1674
    }
1675
1676
1677
    /**
1678
     * Can be used to check if the highlighting is enabled
1679 42
     *
1680
     * plugin.tx_solr.search.results.resultsHighlighting
1681 42
     *
1682
     * @param boolean $defaultIfEmpty
1683
     * @return boolean
1684
     */
1685
    public function getSearchResultsHighlighting($defaultIfEmpty = false)
1686
    {
1687
        $isHighlightingEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.resultsHighlighting', $defaultIfEmpty);
1688
        return $this->getBool($isHighlightingEnabled);
1689
    }
1690
1691
    /**
1692
     * Returns the result highlighting fields.
1693
     *
1694
     * plugin.tx_solr.search.results.resultsHighlighting.highlightFields
1695
     *
1696
     * @param string $defaultIfEmpty
1697
     * @return string
1698
     */
1699
    public function getSearchResultsHighlightingFields($defaultIfEmpty = '')
1700
    {
1701
        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...
1702
    }
1703
1704
    /**
1705
     * Returns the result highlighting fields as array.
1706
     *
1707
     * plugin.tx_solr.search.results.resultsHighlighting.highlightFields
1708
     *
1709
     * @param array $defaultIfEmpty
1710
     * @return array
1711 42
     */
1712
    public function getSearchResultsHighlightingFieldsAsArray($defaultIfEmpty = [])
1713 42
    {
1714
        $highlightingFields = $this->getSearchResultsHighlightingFields('');
1715
1716
        if ($highlightingFields === '') {
1717
            return $defaultIfEmpty;
1718
        }
1719
1720
        return GeneralUtility::trimExplode(',', $highlightingFields, true);
1721
    }
1722
1723
    /**
1724 27
     * Returns the fragmentSize for highlighted segments.
1725
     *
1726 27
     * plugin.tx_solr.search.results.resultsHighlighting.fragmentSize
1727
     *
1728
     * @param int $defaultIfEmpty
1729
     * @return int
1730
     */
1731
    public function getSearchResultsHighlightingFragmentSize($defaultIfEmpty = 200)
1732
    {
1733
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.resultsHighlighting.fragmentSize', $defaultIfEmpty);
1734
    }
1735
1736
    /**
1737 36
     * Returns the fragmentSeparator for highlighted segments.
1738
     *
1739 36
     * plugin.tx_solr.search.results.resultsHighlighting.fragmentSeparator
1740
     *
1741
     * @param string $defaultIfEmpty
1742
     * @return string
1743
     */
1744
    public function getSearchResultsHighlightingFragmentSeparator($defaultIfEmpty = '[...]')
1745
    {
1746
        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...
1747
    }
1748
1749
    /**
1750 36
     * Returns the number of results that should be shown per page.
1751
     *
1752 36
     * plugin.tx_solr.search.results.resultsPerPage
1753
     *
1754 36
     * @param int $defaultIfEmpty
1755
     * @return int
1756
     */
1757
    public function getSearchResultsPerPage($defaultIfEmpty = 10)
1758 36
    {
1759
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.resultsPerPage', $defaultIfEmpty);
1760
    }
1761
1762
    /**
1763
     * Returns the available options for the per page switch.
1764
     *
1765
     * plugin.tx_solr.search.results.resultsPerPageSwitchOptions
1766
     *
1767
     * @param array $defaultIfEmpty
1768
     * @return array
1769 42
     */
1770
    public function getSearchResultsPerPageSwitchOptionsAsArray($defaultIfEmpty = [])
1771 42
    {
1772
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.resultsPerPageSwitchOptions', '');
1773
1774
        if (trim($result) === '') {
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type array; however, parameter $str 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

1774
        if (trim(/** @scrutinizer ignore-type */ $result) === '') {
Loading history...
1775
            return $defaultIfEmpty;
1776
        }
1777
1778
        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

1778
        return GeneralUtility::intExplode(',', /** @scrutinizer ignore-type */ $result, true);
Loading history...
1779
    }
1780
1781
    /**
1782 35
     * Returns the configured wrap for the resultHighlighting.
1783
     *
1784 35
     * plugin.tx_solr.search.results.resultsHighlighting.wrap
1785 35
     *
1786
     * @param string $defaultIfEmpty
1787
     * @return string
1788
     */
1789
    public function getSearchResultsHighlightingWrap($defaultIfEmpty = '')
1790
    {
1791
        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...
1792
    }
1793
1794
    /**
1795
     * Indicates if spellchecking is enabled or not.
1796 35
     *
1797
     * plugin.tx_solr.search.spellchecking
1798 35
     *
1799
     * @param bool $defaultIfEmpty
1800
     * @return bool
1801
     */
1802
    public function getSearchSpellchecking($defaultIfEmpty = false)
1803
    {
1804
        $isFacetingEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.spellchecking', $defaultIfEmpty);
1805
        return $this->getBool($isFacetingEnabled);
1806
    }
1807
1808
    /**
1809 38
     * Returns the numberOfSuggestionsToTry that should be used for the spellchecking.
1810
     *
1811 38
     * plugin.tx_solr.search.spellchecking.numberOfSuggestionsToTry
1812 38
     *
1813
     * @param int $defaultIfEmpty
1814
     * @return int
1815
     */
1816
    public function getSearchSpellcheckingNumberOfSuggestionsToTry($defaultIfEmpty = 1)
1817
    {
1818
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.spellchecking.numberOfSuggestionsToTry', $defaultIfEmpty);
1819
    }
1820
1821
    /**
1822
     * Indicates if a second search should be fired from the spellchecking suggestion if no results could be found.
1823 120
     *
1824
     * plugin.tx_solr.search.spellchecking.searchUsingSpellCheckerSuggestion
1825 120
     *
1826 120
     * @param bool $defaultIfEmpty
1827
     * @return bool
1828
     */
1829
    public function getSearchSpellcheckingSearchUsingSpellCheckerSuggestion($defaultIfEmpty = false)
1830
    {
1831
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.spellchecking.searchUsingSpellCheckerSuggestion', $defaultIfEmpty);
1832
        return $this->getBool($result);
1833
    }
1834
1835
    /**
1836
     * Indicates if faceting is enabled or not.
1837
     *
1838
     * plugin.tx_solr.search.faceting
1839
     *
1840
     * @param bool $defaultIfEmpty
1841
     * @return bool
1842
     */
1843
    public function getSearchFaceting($defaultIfEmpty = false)
1844 71
    {
1845
        $isFacetingEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting', $defaultIfEmpty);
1846 71
        return $this->getBool($isFacetingEnabled);
1847 71
    }
1848
1849
    /**
1850 71
     * Retrieves the showEvenWhenEmpty for a facet by facet name. If nothing specific is configured
1851 2
     * the global showEmptyFacets with be returned.
1852
     *
1853
     * plugin.tx_solr.search.faceting.facets.<facetName>.showEvenWhenEmpty
1854
     *
1855 71
     * or
1856 71
     *
1857 71
     * plugin.tx_solr.search.faceting.showEmptyFacets
1858
     *
1859
     *
1860
     * @param string $facetName
1861
     * @param bool $defaultIfEmpty
1862
     * @return bool
1863
     */
1864
    public function getSearchFacetingShowEmptyFacetsByName($facetName = '', $defaultIfEmpty = false)
1865
    {
1866
        $facetSpecificPath = 'plugin.tx_solr.search.faceting.facets.' . $facetName . '.showEvenWhenEmpty';
1867
        $specificShowWhenEmpty = $this->getValueByPathOrDefaultValue($facetSpecificPath, null);
1868
1869
        // if we have a concrete setting, use it
1870
        if ($specificShowWhenEmpty !== null) {
1871
            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...
1872
        }
1873
1874
        // no specific setting, check common setting
1875
        $commonPath = 'plugin.tx_solr.search.faceting.showEmptyFacets';
1876
        $commonIfEmptyOrDefaultValue = $this->getValueByPathOrDefaultValue($commonPath, $defaultIfEmpty);
1877
        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...
1878
    }
1879
1880
    /**
1881 30
     * Returns the wrap for the faceting show all link
1882
     *
1883 30
     * plugin.tx_solr.search.faceting.showAllLink.wrap
1884
     *
1885 30
     * @param string $defaultIfEmpty
1886
     * @return string
1887
     */
1888
    public function getSearchFacetingShowAllLinkWrap($defaultIfEmpty = '')
1889
    {
1890
        return (string)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.showAllLink.wrap', $defaultIfEmpty);
1891
    }
1892
1893
    /**
1894
     * Returns the link url parameters that should be added to a facet.
1895
     *
1896 4
     * plugin.tx_solr.search.faceting.facetLinkUrlParameters
1897
     *
1898 4
     * @param string $defaultIfEmpty
1899 4
     * @return string
1900
     */
1901
    public function getSearchFacetingFacetLinkUrlParameters($defaultIfEmpty = '')
1902
    {
1903
        $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 $str 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

1903
        $linkUrlParameters = trim(/** @scrutinizer ignore-type */ $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.facetLinkUrlParameters', $defaultIfEmpty));
Loading history...
1904
1905
        return $linkUrlParameters;
1906
    }
1907
1908
    /**
1909
     * Returns if the facetLinkUrlsParameters should be included in the reset link.
1910 30
     *
1911
     * plugin.tx_solr.search.faceting.facetLinkUrlParameters.useForFacetResetLinkUrl
1912 30
     *
1913 30
     * @param bool $defaultIfEmpty
1914
     * @return bool
1915
     */
1916
    public function getSearchFacetingFacetLinkUrlParametersUseForFacetResetLinkUrl($defaultIfEmpty = true)
1917 30
    {
1918
        $useForFacetResetLinkUrl = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.facetLinkUrlParameters.useForFacetResetLinkUrl', $defaultIfEmpty);
1919
        return $this->getBool($useForFacetResetLinkUrl);
1920
    }
1921
1922
    /**
1923
     * Returns the link url parameters that should be added to a facet as array.
1924
     *
1925
     * plugin.tx_solr.search.faceting.facetLinkUrlParameters
1926
     *
1927
     * @param array $defaultIfEmpty
1928 46
     * @return array
1929
     */
1930 46
    public function getSearchFacetingFacetLinkUrlParametersAsArray($defaultIfEmpty = [])
1931
    {
1932
        $linkUrlParameters = $this->getSearchFacetingFacetLinkUrlParameters();
1933
        if ($linkUrlParameters === '') {
1934
            return $defaultIfEmpty;
1935
        }
1936
1937
        return GeneralUtility::explodeUrl2Array($linkUrlParameters);
1938
    }
1939
1940
    /**
1941
     * Return the configured minimumCount value for facets.
1942
     *
1943
     * plugin.tx_solr.search.faceting.minimumCount
1944
     *
1945
     * @param int $defaultIfEmpty
1946
     * @return int
1947
     */
1948
    public function getSearchFacetingMinimumCount($defaultIfEmpty = 1)
1949
    {
1950
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.minimumCount', $defaultIfEmpty);
1951
    }
1952
1953
    /**
1954 46
     * Return the configured limit value for facets, used for displaying.
1955
     *
1956 46
     * plugin.tx_solr.search.faceting.limit
1957
     *
1958
     * @param int $defaultIfEmpty
1959
     * @return int
1960
     */
1961
    public function getSearchFacetingLimit($defaultIfEmpty = 10)
1962
    {
1963
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.limit', $defaultIfEmpty);
1964
    }
1965
1966
    /**
1967
     * Return the configured limit value for facets, used for the response.
1968
     *
1969
     * plugin.tx_solr.search.faceting.facetLimit
1970
     *
1971
     * @param int $defaultIfEmpty
1972
     * @return int
1973
     */
1974
    public function getSearchFacetingFacetLimit($defaultIfEmpty = 100)
1975
    {
1976
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.facetLimit', $defaultIfEmpty);
1977
    }
1978
1979
    /**
1980
     * Return the configured faceting sortBy value.
1981 46
     *
1982
     * plugin.tx_solr.search.faceting.sortBy
1983 46
     *
1984
     * @param string $defaultIfEmpty
1985
     * @return string
1986
     */
1987
    public function getSearchFacetingSortBy($defaultIfEmpty = '')
1988
    {
1989
        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...
1990
    }
1991
1992
    /**
1993
     * Returns if a facets should be kept on selection. Global faceting setting
1994
     * can also be configured on facet level by using
1995
     * (plugin.tx_solr.search.faceting.facets.<fieldName>.keepAllOptionsOnSelection)
1996 46
     *
1997
     * plugin.tx_solr.search.faceting.keepAllFacetsOnSelection
1998 46
     *
1999 46
     * @param bool $defaultIfEmpty
2000
     * @return bool
2001
     */
2002
    public function getSearchFacetingKeepAllFacetsOnSelection($defaultIfEmpty = false)
2003
    {
2004
        $keepAllOptionsOnSelection = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.keepAllFacetsOnSelection', $defaultIfEmpty);
2005
        return $this->getBool($keepAllOptionsOnSelection);
2006
    }
2007
2008
    /**
2009
     * Returns if the facet count should be calculated based on the facet selection when
2010
     * plugin.tx_solr.search.faceting.keepAllFacetsOnSelection has been enabled
2011 2
     *
2012
     * plugin.tx_solr.search.faceting.countAllFacetsForSelection
2013 2
     *
2014 2
     * @param bool $defaultIfEmpty
2015
     * @return bool
2016
     */
2017
    public function getSearchFacetingCountAllFacetsForSelection($defaultIfEmpty = false)
2018
    {
2019
        $countAllFacetsForSelection = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.countAllFacetsForSelection', $defaultIfEmpty);
2020
        return $this->getBool($countAllFacetsForSelection);
2021
    }
2022
2023
    /**
2024
     * Returns the configured faceting configuration.
2025 73
     *
2026
     * plugin.tx_solr.search.faceting.facets
2027 73
     *
2028
     * @param array $defaultIfEmpty
2029
     * @return array
2030
     */
2031
    public function getSearchFacetingFacets(array $defaultIfEmpty = [])
2032
    {
2033
        return $this->getObjectByPathOrDefault('plugin.tx_solr.search.faceting.facets.', $defaultIfEmpty);
2034
    }
2035
2036
    /**
2037
     * Returns the configuration of a single facet by facet name.
2038
     *
2039 46
     * plugin.tx_solr.search.faceting.facets.<facetName>
2040
     *
2041 46
     * @param string $facetName
2042
     * @param array $defaultIfEmpty
2043
     * @return array
2044
     */
2045
    public function getSearchFacetingFacetByName($facetName, $defaultIfEmpty = [])
2046
    {
2047
        return $this->getObjectByPathOrDefault('plugin.tx_solr.search.faceting.facets.' . $facetName . '.', $defaultIfEmpty);
2048
    }
2049
2050
    /**
2051
     * Indicates if statistics is enabled or not.
2052 40
     *
2053
     * plugin.tx_solr.statistics
2054 40
     *
2055 40
     * @param bool $defaultIfEmpty
2056
     * @return bool
2057
     */
2058
    public function getStatistics($defaultIfEmpty = false)
2059
    {
2060
        $isStatisticsEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.statistics', $defaultIfEmpty);
2061
        return $this->getBool($isStatisticsEnabled);
2062
    }
2063
2064
    /**
2065
     * Indicates to which length an ip should be anonymized in the statistics
2066 29
     *
2067
     * plugin.tx_solr.statistics.anonymizeIP
2068 29
     *
2069 29
     * @param int $defaultIfEmpty
2070
     * @return int
2071
     */
2072
    public function getStatisticsAnonymizeIP($defaultIfEmpty = 0)
2073
    {
2074
        $anonymizeToLength = $this->getValueByPathOrDefaultValue('plugin.tx_solr.statistics.anonymizeIP', $defaultIfEmpty);
2075
        return (int)$anonymizeToLength;
2076
    }
2077
2078
    /**
2079
     * Indicates if additional debug Data should be added to the statistics
2080 35
     *
2081
     * plugin.tx_solr.statistics.addDebugData
2082 35
     *
2083 35
     * @param bool $defaultIfEmpty
2084
     * @return bool
2085
     */
2086
    public function getStatisticsAddDebugData($defaultIfEmpty = false)
2087
    {
2088
        $statisticsAddDebugDataEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.statistics.addDebugData', $defaultIfEmpty);
2089
        return $this->getBool($statisticsAddDebugDataEnabled);
2090
    }
2091
2092
    /**
2093
     * Indicates if suggestion is enabled or not.
2094
     *
2095
     * plugin.tx_solr.suggest
2096
     *
2097
     * @param bool $defaultIfEmpty
2098
     * @return bool
2099
     */
2100
    public function getSuggest($defaultIfEmpty = false)
2101
    {
2102
        $isSuggestionEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.suggest', $defaultIfEmpty);
2103
        return $this->getBool($isSuggestionEnabled);
2104
    }
2105
2106
    /**
2107
     * Indicates if https should be used for the suggest form.
2108
     *
2109
     * plugin.tx_solr.suggest.forceHttps
2110
     *
2111
     * @param bool $defaultIfEmpty
2112
     * @return bool
2113
     */
2114
    public function getSuggestForceHttps($defaultIfEmpty = false)
2115
    {
2116
        $isHttpsForced = $this->getValueByPathOrDefaultValue('plugin.tx_solr.suggest.forceHttps', $defaultIfEmpty);
2117
        return $this->getBool($isHttpsForced);
2118
    }
2119
2120
    /**
2121
     * Returns the allowed number of suggestions.
2122 1
     *
2123
     * plugin.tx_solr.suggest.numberOfSuggestions
2124 1
     *
2125 1
     * @param int $defaultIfEmpty
2126
     * @return int
2127
     */
2128
    public function getSuggestNumberOfSuggestions($defaultIfEmpty = 10)
2129
    {
2130
        $numberOfSuggestions = $this->getValueByPathOrDefaultValue('plugin.tx_solr.suggest.numberOfSuggestions', $defaultIfEmpty);
2131
        return (int)$numberOfSuggestions;
2132
    }
2133
2134
    /**
2135
     * Indicates if the topResults should be shown or not
2136 1
     *
2137
     * plugin.tx_solr.suggest.showTopResults
2138 1
     *
2139 1
     * @param bool $defaultIfEmpty
2140
     * @return bool
2141
     */
2142
    public function getSuggestShowTopResults($defaultIfEmpty = true)
2143
    {
2144
        $showTopResults = $this->getValueByPathOrDefaultValue('plugin.tx_solr.suggest.showTopResults', $defaultIfEmpty);
2145
        return $this->getBool($showTopResults);
2146
    }
2147
2148
    /**
2149
     * Returns the configured number of top results to show
2150 1
     *
2151
     * plugin.tx_solr.suggest.numberOfTopResults
2152 1
     *
2153 1
     * @param int $defaultIfEmpty
2154
     * @return int
2155
     */
2156
    public function getSuggestNumberOfTopResults($defaultIfEmpty = 5)
2157
    {
2158
        $numberOfTopResults = $this->getValueByPathOrDefaultValue('plugin.tx_solr.suggest.numberOfTopResults', $defaultIfEmpty);
2159
        return (int)$numberOfTopResults;
2160
    }
2161
2162
    /**
2163
     * Returns additional fields for the top results
2164 1
     *
2165
     * plugin.tx_solr.suggest.additionalTopResultsFields
2166 1
     *
2167 1
     * @param array $defaultIfEmpty
2168 1
     * @return array
2169
     */
2170
    public function getSuggestAdditionalTopResultsFields($defaultIfEmpty = [])
2171
    {
2172
        $additionalTopResultsFields = $this->getValueByPathOrDefaultValue('plugin.tx_solr.suggest.additionalTopResultsFields', '');
2173
        if ($additionalTopResultsFields === '') {
2174
            return $defaultIfEmpty;
2175
        }
2176
2177
        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

2177
        return GeneralUtility::trimExplode(',', /** @scrutinizer ignore-type */ $additionalTopResultsFields, true);
Loading history...
2178
    }
2179
2180
    /**
2181
     * Returns the configured template for a specific template fileKey.
2182
     *
2183 42
     * plugin.tx_solr.view.templateFiles.<fileKey>
2184
     *
2185 42
     * @param string $fileKey
2186 42
     * @param string $defaultIfEmpty
2187
     * @return string
2188
     */
2189
    public function getViewTemplateByFileKey($fileKey, $defaultIfEmpty = '')
2190
    {
2191
        $templateFileName = $this->getValueByPathOrDefaultValue('plugin.tx_solr.view.templateFiles.' . $fileKey, $defaultIfEmpty);
2192
        return (string)$templateFileName;
2193
    }
2194
2195
    /**
2196
     * Returns the configured available template files for the flexform.
2197
     *
2198
     * plugin.tx_solr.view.templateFiles.[fileKey].availableTemplates.
2199
     *
2200
     * @param string $fileKey
2201
     * @return array
2202
     */
2203
    public function getAvailableTemplatesByFileKey($fileKey)
2204
    {
2205
        $path = 'plugin.tx_solr.view.templateFiles.' . $fileKey . '.availableTemplates.';
2206
        return (array)$this->getObjectByPathOrDefault($path, []);
2207
    }
2208
2209
    /**
2210
     * Returns the configuration of the crop view helper.
2211
     *
2212
     * plugin.tx_solr.viewHelpers.crop.
2213
     *
2214
     * @param array $defaultIfEmpty
2215
     * @return array
2216
     */
2217
    public function getViewHelpersCropConfiguration(array $defaultIfEmpty = [])
2218
    {
2219
        $cropViewHelperConfiguration = $this->getObjectByPathOrDefault('plugin.tx_solr.viewHelpers.crop.', $defaultIfEmpty);
2220
        return $cropViewHelperConfiguration;
2221
    }
2222
2223
    /**
2224
     * Returns the configuration of the sorting view helper.
2225
     *
2226
     * plugin.tx_solr.viewHelpers.sortIndicator.
2227
     *
2228
     * @param array $defaultIfEmpty
2229
     * @return array
2230
     */
2231
    public function getViewHelpersSortIndicatorConfiguration(array $defaultIfEmpty = [])
2232
    {
2233
        $sortingViewHelperConfiguration = $this->getObjectByPathOrDefault('plugin.tx_solr.viewHelpers.sortIndicator.', $defaultIfEmpty);
2234
        return $sortingViewHelperConfiguration;
2235
    }
2236
2237
    /**
2238
     * Controls whether ext-solr will send commits to solr.
2239
     * Beware: If you disable this, you need to ensure
2240
     * that some other mechanism will commit your changes
2241
     * otherwise they will never be searchable.
2242
     * A good way to achieve this is enabling the solr
2243
     * daemons autoCommit feature.
2244 16
     *
2245
     * plugin.tx_solr.index.enableCommits
2246 16
     *
2247 16
     * @param bool $defaultIfEmpty
2248
     * @return bool
2249
     */
2250
    public function getEnableCommits($defaultIfEmpty = true)
2251
    {
2252
        $enableCommits = $this->getValueByPathOrDefaultValue('plugin.tx_solr.index.enableCommits', $defaultIfEmpty);
2253
        return $this->getBool($enableCommits);
2254
    }
2255
2256
    /**
2257
     * Returns the url namespace that is used for the arguments.
2258 44
     *
2259
     * plugin.tx_solr.view.pluginNamespace
2260 44
     *
2261
     * @param string $defaultIfEmpty
2262
     * @return string
2263
     */
2264
    public function getSearchPluginNamespace($defaultIfEmpty = 'tx_solr')
2265
    {
2266
        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...
2267
    }
2268
2269
    /**
2270
     * Returns true if the global url parameter q, that indicates the query should be used.
2271
     *
2272
     * Should be set to false, when multiple instance on the same page should have their querystring.
2273 30
     *
2274
     * plugin.tx_solr.search.ignoreGlobalQParameter
2275 30
     *
2276 30
     * @param bool $defaultIfEmpty
2277
     * @return bool
2278
     */
2279
    public function getSearchIgnoreGlobalQParameter($defaultIfEmpty = false)
2280
    {
2281
        $enableQParameter = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.ignoreGlobalQParameter', $defaultIfEmpty);
2282
        return $this->getBool($enableQParameter);
2283
2284
    }
2285
2286
    /**
2287
     * Returns the argument names, that should be added to the persistent arguments, as array.
2288 44
     *
2289
     * plugin.tx_solr.search.additionalPersistentArgumentNames
2290 44
     *
2291
     * @param array $defaultIfEmpty
2292 44
     * @return array
2293 43
     */
2294
    public function getSearchAdditionalPersistentArgumentNames($defaultIfEmpty = [])
2295
    {
2296 1
        $additionalPersistentArgumentNames = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.additionalPersistentArgumentNames', '');
2297
2298
        if ($additionalPersistentArgumentNames === '') {
2299
            return $defaultIfEmpty;
2300
        }
2301
2302
        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

2302
        return GeneralUtility::trimExplode(',', /** @scrutinizer ignore-type */ $additionalPersistentArgumentNames, true);
Loading history...
2303
2304
    }
2305
2306
    /**
2307
     * Method to check if grouping was enabled with typoscript.
2308 122
     *
2309
     * plugin.tx_solr.search.grouping
2310 122
     *
2311 122
     * @param bool $defaultIfEmpty
2312
     * @return bool
2313
     */
2314
    public function getSearchGrouping($defaultIfEmpty = false)
2315
    {
2316
        $groupingEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.grouping', $defaultIfEmpty);
2317
        return $this->getBool($groupingEnabled);
2318
    }
2319
2320
    /**
2321
     * Returns the configured numberOfGroups.
2322 1
     *
2323
     * plugin.tx_solr.search.grouping.numberOfGroups
2324 1
     *
2325
     * @param int $defaultIfEmpty
2326
     * @return int
2327
     */
2328
    public function getSearchGroupingNumberOfGroups($defaultIfEmpty = 5)
2329
    {
2330
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.grouping.numberOfGroups', $defaultIfEmpty);
2331
    }
2332
2333
    /**
2334
     * Returns the sortBy configuration for the grouping.
2335 1
     *
2336
     * plugin.tx_solr.search.grouping.sortBy
2337 1
     *
2338
     * @param string $defaultIfEmpty
2339
     * @return string
2340
     */
2341
    public function getSearchGroupingSortBy($defaultIfEmpty = '')
2342
    {
2343
        return (string)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.grouping.sortBy', $defaultIfEmpty);
2344
    }
2345
2346
    /**
2347
     * Returns the highestValue of the numberOfResultsPerGroup configuration that is globally configured and
2348
     * for each group.
2349 3
     *
2350
     * plugin.tx_solr.search.grouping.
2351 3
     *
2352 3
     * @param int $defaultIfEmpty
2353 3
     * @return int
2354 2
     */
2355
    public function getSearchGroupingHighestGroupResultsLimit($defaultIfEmpty = 1)
2356
    {
2357 3
        $groupingConfiguration = $this->getObjectByPathOrDefault('plugin.tx_solr.search.grouping.', []);
2358 3
        $highestLimit = $defaultIfEmpty;
2359 1
        if (!empty($groupingConfiguration['numberOfResultsPerGroup'])) {
2360
            $highestLimit = $groupingConfiguration['numberOfResultsPerGroup'];
2361
        }
2362 2
2363 2
        $configuredGroups = $groupingConfiguration['groups.'];
2364 2
        if (!is_array($configuredGroups)) {
2365
            return $highestLimit;
2366
        }
2367
2368 2
        foreach ($configuredGroups as $groupName => $groupConfiguration) {
2369
            if (!empty($groupConfiguration['numberOfResultsPerGroup']) && $groupConfiguration['numberOfResultsPerGroup'] > $highestLimit) {
2370
                $highestLimit = $groupConfiguration['numberOfResultsPerGroup'];
2371
            }
2372
        }
2373
2374
        return $highestLimit;
2375
    }
2376
2377
    /**
2378
     * Returns the valid numberOfResultsPerGroup value for a group.
2379
     *
2380
     * Returns:
2381
     *
2382
     * plugin.tx_solr.search.grouping.groups.<groupName>.numberOfResultsPerGroup if it is set otherwise
2383
     * plugin.tx_solr.search.grouping.numberOfResultsPerGroup
2384
     *
2385
     * @param string $groupName
2386
     * @param int $defaultIfEmpty
2387
     * @return int
2388
     */
2389
    public function getSearchGroupingResultLimit($groupName, $defaultIfEmpty = 1)
2390
    {
2391
        $specificPath = 'plugin.tx_solr.search.grouping.groups.' . $groupName . 'numberOfResultsPerGroup';
2392
        $specificResultsPerGroup = $this->getValueByPathOrDefaultValue($specificPath, null);
2393
2394
        if ($specificResultsPerGroup !== null) {
2395
            return (int) $specificResultsPerGroup;
2396
        }
2397
2398
        $commonPath = 'plugin.tx_solr.search.grouping.numberOfResultsPerGroup';
2399
        $commonValue = $this->getValueByPathOrDefaultValue($commonPath, null);
2400
        if ($commonValue !== null) {
2401
            return (int) $commonValue;
2402
        }
2403
2404
        return $defaultIfEmpty;
2405
    }
2406
2407
    /**
2408
     * Returns everything that is configured for the groups (plugin.tx_solr.search.grouping.groups.)
2409 1
     *
2410
     * plugin.tx_solr.search.grouping.groups.
2411 1
     *
2412
     * @param array $defaultIfEmpty
2413
     * @return array
2414
     */
2415
    public function getSearchGroupingGroupsConfiguration($defaultIfEmpty = [])
2416
    {
2417
        return $this->getObjectByPathOrDefault('plugin.tx_solr.search.grouping.groups.', $defaultIfEmpty);
2418
    }
2419
2420
    /*
2421 6
     * Applies the stdWrap if it is configured for the path, otherwise the unprocessed value will be returned.
2422
     *
2423 6
     * @param string $valuePath
2424 6
     * @param mixed $value
2425
     * @return mixed
2426 6
     */
2427 4
    protected function renderContentElementOfConfigured($valuePath, $value)
2428
    {
2429
        $configurationPath = $valuePath . '.';
2430 2
        $configuration = $this->getObjectByPath($configurationPath);
2431
2432
        if ($configuration == null) {
2433
            return $value;
2434
        }
2435
        if ($this->contentObjectService === null) {
2436
            $this->contentObjectService = GeneralUtility::makeInstance(ContentObjectService::class);
2437
        }
2438
        return $this->contentObjectService->renderSingleContentObject($value, $configuration);
2439
    }
2440
}
2441