Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Pull Request — master (#715)
by Alexander
07:45
created

SearchController::makeFacetsMenuArray()   D

Complexity

Conditions 18
Paths 75

Size

Total Lines 102
Code Lines 61

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
cc 18
eloc 61
c 4
b 0
f 0
nc 75
nop 1
dl 0
loc 102
rs 4.8666

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * (c) Kitodo. Key to digital objects e.V. <[email protected]>
4
 *
5
 * This file is part of the Kitodo and TYPO3 projects.
6
 *
7
 * @license GNU General Public License version 3 or later.
8
 * For the full copyright and license information, please read the
9
 * LICENSE.txt file that was distributed with this source code.
10
 */
11
12
namespace Kitodo\Dlf\Controller;
13
14
use Kitodo\Dlf\Common\Doc;
15
use Kitodo\Dlf\Common\DocumentList;
16
use Kitodo\Dlf\Common\Helper;
17
use Kitodo\Dlf\Common\Indexer;
18
use Kitodo\Dlf\Common\Solr;
19
use Kitodo\Dlf\Domain\Model\Collection;
20
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
21
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
22
use TYPO3\CMS\Core\Utility\GeneralUtility;
23
use Kitodo\Dlf\Domain\Repository\CollectionRepository;
24
25
class SearchController extends AbstractController
26
{
27
    public $prefixId = 'tx_dlf';
28
    public $extKey = 'dlf';
29
30
    /**
31
     * @var CollectionRepository
32
     */
33
    protected $collectionRepository;
34
35
    /**
36
     * @param CollectionRepository $collectionRepository
37
     */
38
    public function injectCollectionRepository(CollectionRepository $collectionRepository)
39
    {
40
        $this->collectionRepository = $collectionRepository;
41
    }
42
43
    /**
44
     * Search action
45
     */
46
    public function searchAction()
47
    {
48
        $this->extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get($this->extKey);
49
50
        // Build label for result list.
51
        $label = htmlspecialchars(LocalizationUtility::translate('search.search', 'dlf'));
0 ignored issues
show
Bug introduced by
It seems like TYPO3\CMS\Extbase\Utilit...'search.search', 'dlf') can also be of type null; however, parameter $string of htmlspecialchars() 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

51
        $label = htmlspecialchars(/** @scrutinizer ignore-type */ LocalizationUtility::translate('search.search', 'dlf'));
Loading history...
52
        if (!empty($this->requestData['query'])) {
53
            $label .= ' ' . htmlspecialchars(sprintf(LocalizationUtility::translate('search.for', 'dlf'), trim($this->requestData['query'])));
0 ignored issues
show
Bug introduced by
It seems like TYPO3\CMS\Extbase\Utilit...te('search.for', 'dlf') can also be of type null; however, parameter $format of sprintf() 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

53
            $label .= ' ' . htmlspecialchars(sprintf(/** @scrutinizer ignore-type */ LocalizationUtility::translate('search.for', 'dlf'), trim($this->requestData['query'])));
Loading history...
54
        }
55
        // Prepare query parameters.
56
        $params = [];
57
        $matches = [];
58
        // Set search query.
59
        if (
60
            (!empty($this->settings['fulltext']) && !empty($this->requestData['fulltext']))
61
            || preg_match('/fulltext:\((.*)\)/', trim($this->requestData['query']), $matches)
62
        ) {
63
            // If the query already is a fulltext query e.g using the facets
64
            $this->requestData['query'] = empty($matches[1]) ? $this->requestData['query'] : $matches[1];
65
            // Search in fulltext field if applicable. Query must not be empty!
66
            if (!empty($this->requestData['query'])) {
67
                $query = 'fulltext:(' . Solr::escapeQuery(trim($this->requestData['query'])) . ')';
68
            }
69
        } else {
70
            // Retain given search field if valid.
71
            $query = Solr::escapeQueryKeepField(trim($this->requestData['query']), $this->settings['storagePid']);
72
        }
73
        // Add extended search query.
74
        if (
75
            !empty($this->requestData['extQuery'])
76
            && is_array($this->requestData['extQuery'])
77
        ) {
78
            $allowedOperators = ['AND', 'OR', 'NOT'];
79
            $allowedFields = GeneralUtility::trimExplode(',', $this->settings['extendedFields'], true);
80
            $numberOfExtQueries = count($this->requestData['extQuery']);
81
            for ($i = 0; $i < $numberOfExtQueries; $i++) {
82
                if (!empty($this->requestData['extQuery'][$i])) {
83
                    if (
84
                        in_array($this->requestData['extOperator'][$i], $allowedOperators)
85
                        && in_array($this->requestData['extField'][$i], $allowedFields)
86
                    ) {
87
                        if (!empty($query)) {
88
                            $query .= ' ' . $this->requestData['extOperator'][$i] . ' ';
89
                        }
90
                        $query .= Indexer::getIndexFieldName($this->requestData['extField'][$i], $this->settings['storagePid']) . ':(' . Solr::escapeQuery($this->requestData['extQuery'][$i]) . ')';
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $query does not seem to be defined for all execution paths leading up to this point.
Loading history...
91
                    }
92
                }
93
            }
94
        }
95
        // Add filter query for faceting.
96
        if (!empty($this->requestData['fq'])) {
97
            foreach ($this->requestData['fq'] as $filterQuery) {
98
                $params['filterquery'][]['query'] = $filterQuery;
99
            }
100
        }
101
102
        // Add filter query for in-document searching.
103
        if (
104
            $this->settings['searchIn'] == 'document'
105
            || $this->settings['searchIn'] == 'all'
106
        ) {
107
            if (
108
                !empty($this->requestData['id'])
109
                && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($this->requestData['id'])
110
            ) {
111
                // Search in document and all subordinates (valid for up to three levels of hierarchy).
112
                $params['filterquery'][]['query'] = '_query_:"{!join from=uid to=partof}uid:{!join from=uid to=partof}uid:' . $this->requestData['id'] . '"' .
113
                    ' OR {!join from=uid to=partof}uid:' . $this->requestData['id'] .
114
                    ' OR uid:' . $this->requestData['id'];
115
                $label .= ' ' . htmlspecialchars(sprintf(LocalizationUtility::translate('search.in', 'dlf'), Doc::getTitle($this->requestData['id'])));
116
            }
117
        }
118
        // Add filter query for in-collection searching.
119
        if (
120
            $this->settings['searchIn'] == 'collection'
121
            || $this->settings['searchIn'] == 'all'
122
        ) {
123
            if (
124
                !empty($this->requestData['collection'])
125
                && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($this->requestData['collection'])
126
            ) {
127
                $index_name = Helper::getIndexNameFromUid($this->requestData['collection'], 'tx_dlf_collections', $this->settings['storagePid']);
128
                $params['filterquery'][]['query'] = 'collection_faceting:("' . Solr::escapeQuery($index_name) . '")';
129
                $label .= ' ' . sprintf(LocalizationUtility::translate('search.in', 'dlf'), Helper::translate($index_name, 'tx_dlf_collections', $this->settings['storagePid']));
130
            }
131
        }
132
        // Add filter query for collection restrictions.
133
        if ($this->settings['collections']) {
134
            $collIds = explode(',', $this->settings['collections']);
135
            $collIndexNames = [];
136
            foreach ($collIds as $collId) {
137
                $collIndexNames[] = Solr::escapeQuery(Helper::getIndexNameFromUid(intval($collId), 'tx_dlf_collections', $this->settings['storagePid']));
138
            }
139
            // Last value is fake and used for distinction in $this->addCurrentCollection()
140
            $params['filterquery'][]['query'] = 'collection_faceting:("' . implode('" OR "', $collIndexNames) . '" OR "FakeValueForDistinction")';
141
        }
142
        // Set some query parameters.
143
        $params['query'] = !empty($query) ? $query : '*';
144
        $params['start'] = 0;
145
        $params['rows'] = 0;
146
        $params['sort'] = ['score' => 'desc'];
147
        // Instantiate search object.
148
        $solr = Solr::getInstance($this->settings['solrcore']);
149
        if (!$solr->ready) {
150
            $this->logger->error('Apache Solr not available');
151
            $this->redirect('main', 'Search', null);
152
            //return $this->responseFactory->createHtmlResponse($this->view->render());
153
        }
154
        // Set search parameters.
155
        $solr->cPid = $this->settings['storagePid'];
156
        $solr->params = $params;
157
        // Perform search.
158
        $list = $solr->search();
159
        $list->metadata = [
160
            'label' => $label,
161
            'thumbnail' => '',
162
            'searchString' => $this->requestData['query'],
163
            'fulltextSearch' => (!empty($this->requestData['fulltext']) ? '1' : '0'),
164
            'options' => $list->metadata['options']
165
        ];
166
        $list->save();
167
        // Clean output buffer.
168
        ob_end_clean();
169
        $additionalParams = [];
170
        if (!empty($this->requestData['logicalPage'])) {
171
            $additionalParams['logicalPage'] = $this->requestData['logicalPage'];
172
        }
173
        // Jump directly to the page view, if there is only one result and it is configured
174
        if ($list->metadata['options']['numberOfHits'] == 1 && !empty($this->settings['showSingleResult'])) {
175
            $linkConf['parameter'] = $this->settings['targetPidPageView'];
176
            $additionalParams['id'] = $list->current()['uid'];
177
            $additionalParams['highlight_word'] = preg_replace('/\s\s+/', ';', $list->metadata['searchString']);
178
            $additionalParams['page'] = count($list[0]['subparts']) == 1 ? $list[0]['subparts'][0]['page'] : 1;
179
        } else {
180
            // Keep some plugin variables.
181
            $linkConf['parameter'] = $this->settings['targetPid'];
182
            if (!empty($this->requestData['order'])) {
183
                $additionalParams['order'] = $this->requestData['order'];
184
                $additionalParams['asc'] = !empty($this->requestData['asc']) ? '1' : '0';
185
            }
186
        }
187
        $linkConf['forceAbsoluteUrl'] = !empty($this->settings['forceAbsoluteUrl']) ? 1 : 0;
188
        $linkConf['forceAbsoluteUrl.']['scheme'] = !empty($this->settings['forceAbsoluteUrl']) && !empty($this->settings['forceAbsoluteUrlHttps']) ? 'https' : 'http';
189
        $linkConf['additionalParams'] = GeneralUtility::implodeArrayForUrl($this->prefixId, $additionalParams, '', true, false);
190
191
        $this->redirect('main', 'Search', null, null);
192
    }
193
194
    /**
195
     *
196
     * @return mixed
197
     * @throws \TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException
198
     */
199
    public function mainAction()
200
    {
201
        // Quit without doing anything if required variables are not set.
202
        if (empty($this->settings['solrcore'])) {
203
            $this->logger->warning('Incomplete plugin configuration');
204
            return '';
205
        }
206
        if (!isset($this->requestData['query'])
207
            && empty($this->requestData['extQuery'])
208
        ) {
209
            // Extract query and filter from last search.
210
            $list = GeneralUtility::makeInstance(DocumentList::class);
211
            if (!empty($list->metadata['searchString'])) {
212
                if ($list->metadata['options']['source'] == 'search') {
213
                    $search['query'] = $list->metadata['searchString'];
214
                }
215
                $search['params'] = $list->metadata['options']['params'];
216
            }
217
218
            $this->view->assign('QUERY', (!empty($search['query']) ? htmlspecialchars($search['query']) : ''));
219
            $this->view->assign('FULLTEXT_SEARCH', $list->metadata['fulltextSearch']);
220
        } else {
221
            $this->view->assign('QUERY', (!empty($this->requestData['query']) ? htmlspecialchars($this->requestData['query']) : ''));
222
            $this->view->assign('FULLTEXT_SEARCH', $this->requestData['fulltext']);
223
        }
224
225
        $this->view->assign('FACETS_MENU', $this->addFacetsMenu());
226
227
        $this->addEncryptedCoreName();
228
229
        if ($this->settings['searchIn'] == 'collection' || $this->settings['searchIn'] == 'all') {
230
            $this->addCurrentCollection();
231
        }
232
        if ($this->settings['searchIn'] == 'document' || $this->settings['searchIn'] == 'all') {
233
            $this->addCurrentDocument();
234
        }
235
236
        // Get additional fields for extended search.
237
        $this->addExtendedSearch();
238
    }
239
240
    /**
241
     * Adds the current document's UID or parent ID to the search form
242
     *
243
     * @access protected
244
     *
245
     * @return string HTML input fields with current document's UID
246
     */
247
    protected function addCurrentDocument()
248
    {
249
        // Load current list object.
250
        $list = GeneralUtility::makeInstance(DocumentList::class);
251
        // Load current document.
252
        if (
253
            !empty($this->requestData['id'])
254
            && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($this->requestData['id'])
255
        ) {
256
            $this->loadDocument($this->requestData);
257
            // Get document's UID
258
            if ($this->document) {
259
                $this->view->assign('DOCUMENT_ID', $this->document->getUid());
260
            }
261
        } elseif (!empty($list->metadata['options']['params']['filterquery'])) {
262
            // Get document's UID from search metadata.
263
            // The string may be e.g. "{!join from=uid to=partof}uid:{!join from=uid to=partof}uid:2" OR {!join from=uid to=partof}uid:2 OR uid:2"
264
            // or "collection_faceting:("Some Collection Title")"
265
            foreach ($list->metadata['options']['params']['filterquery'] as $facet) {
266
                if (($lastUidPos = strrpos($facet['query'], 'uid:')) !== false) {
267
                    $facetKeyVal = explode(':', substr($facet['query'], $lastUidPos));
268
                    if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($facetKeyVal[1])) {
269
                        $documentId = (int) $facetKeyVal[1];
270
                    }
271
                }
272
            }
273
            if (!empty($documentId)) {
274
                $this->view->assign('DOCUMENT_ID', $documentId);
275
            }
276
        }
277
    }
278
279
280
    /**
281
     * Adds the current collection's UID to the search form
282
     *
283
     * @access protected
284
     *
285
     * @return string HTML input fields with current document's UID and parent ID
286
     */
287
    protected function addCurrentCollection()
288
    {
289
        // Load current collection.
290
        $list = GeneralUtility::makeInstance(DocumentList::class);
291
        if (
292
            !empty($list->metadata['options']['source'])
293
            && $list->metadata['options']['source'] == 'collection'
294
        ) {
295
            $this->view->assign('COLLECTION_ID', $list->metadata['options']['select']);
296
            // Get collection's UID.
297
        } elseif (!empty($list->metadata['options']['params']['filterquery'])) {
298
            // Get collection's UID from search metadata.
299
            foreach ($list->metadata['options']['params']['filterquery'] as $facet) {
300
                $facetKeyVal = explode(':', $facet['query'], 2);
301
                if (
302
                    $facetKeyVal[0] == 'collection_faceting'
303
                    && !strpos($facetKeyVal[1], '" OR "')
304
                ) {
305
                    $collectionId = Helper::getUidFromIndexName(trim($facetKeyVal[1], '(")'), 'tx_dlf_collections');
306
                }
307
            }
308
            $this->view->assign('COLLECTION_ID', $collectionId);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $collectionId does not seem to be defined for all execution paths leading up to this point.
Loading history...
309
        }
310
    }
311
312
    /**
313
     * Adds the encrypted Solr core name to the search form
314
     *
315
     * @access protected
316
     *
317
     * @return string HTML input fields with encrypted core name and hash
318
     */
319
    protected function addEncryptedCoreName()
320
    {
321
        // Get core name.
322
        $name = Helper::getIndexNameFromUid($this->settings['solrcore'], 'tx_dlf_solrcores');
323
        // Encrypt core name.
324
        if (!empty($name)) {
325
            $name = Helper::encrypt($name);
326
        }
327
        // Add encrypted fields to search form.
328
        if ($name !== false) {
329
            $this->view->assign('ENCRYPTED_CORE_NAME', $name);
330
        }
331
    }
332
333
    /**
334
     * Adds the facets menu to the search form
335
     *
336
     * @access protected
337
     *
338
     * @return string HTML output of facets menu
339
     */
340
    protected function addFacetsMenu()
341
    {
342
        // Check for typoscript configuration to prevent fatal error.
343
        if (empty($this->settings['facetsConf'])) {
344
            $this->logger->warning('Incomplete plugin configuration');
345
            return '';
346
        }
347
        // Quit without doing anything if no facets are selected.
348
        if (empty($this->settings['facets']) && empty($this->settings['facetCollections'])) {
349
            return '';
350
        }
351
352
        // Get facets from plugin configuration.
353
        $facets = [];
354
        foreach (GeneralUtility::trimExplode(',', $this->settings['facets'], true) as $facet) {
355
            $facets[$facet . '_faceting'] = Helper::translate($facet, 'tx_dlf_metadata', $this->settings['storagePid']);
356
        }
357
358
        $this->view->assign('facetsMenu', $this->makeFacetsMenuArray($facets));
359
    }
360
361
    /**
362
     * This builds a menu array for HMENU
363
     *
364
     * @access public
365
     *
366
     * @param string $content: The PlugIn content
367
     * @param array $conf: The PlugIn configuration
368
     *
369
     * @return array HMENU array
370
     */
371
    public function makeFacetsMenuArray($facets)
372
    {
373
        $menuArray = [];
374
        // Set default value for facet search.
375
        $search = [
376
            'query' => '*',
377
            'params' => [
378
                'component' => [
379
                    'facetset' => [
380
                        'facet' => []
381
                    ]
382
                ]
383
            ]
384
        ];
385
        // Extract query and filter from last search.
386
        $list = GeneralUtility::makeInstance(DocumentList::class);
387
        if (!empty($list->metadata['options']['source'])) {
388
            if ($list->metadata['options']['source'] == 'search') {
389
                $search['query'] = $list->metadata['options']['select'];
390
            }
391
            $search['params'] = $list->metadata['options']['params'];
392
        }
393
        // Get applicable facets.
394
        $solr = Solr::getInstance($this->settings['solrcore']);
395
        if (!$solr->ready) {
396
            $this->logger->error('Apache Solr not available');
397
            return [];
398
        }
399
        // Set needed parameters for facet search.
400
        if (empty($search['params']['filterquery'])) {
401
            $search['params']['filterquery'] = [];
402
        }
403
404
        foreach (array_keys($facets) as $field) {
405
            $search['params']['component']['facetset']['facet'][] = [
406
                'type' => 'field',
407
                'key' => $field,
408
                'field' => $field,
409
                'limit' => $this->settings['limitFacets'],
410
                'sort' => isset($this->settings['sortingFacets']) ? $this->settings['sortingFacets'] : 'count'
411
            ];
412
        }
413
414
        // Set additional query parameters.
415
        $search['params']['start'] = 0;
416
        $search['params']['rows'] = 0;
417
        // Set query.
418
        $search['params']['query'] = $search['query'];
419
        // Perform search.
420
        $selectQuery = $solr->service->createSelect($search['params']);
421
        $results = $solr->service->select($selectQuery);
422
        $facet = $results->getFacetSet();
423
424
        $facetCollectionArray = [];
425
426
        // replace everything expect numbers and comma
427
        $facetCollections = preg_replace('/[^0-9,]/', '', $this->settings['facetCollections']);
428
429
        if (!empty($facetCollections)) {
430
            $collections = $this->collectionRepository->findCollectionsBySettings(['collections' => $facetCollections]);
431
432
            /** @var Collection $collection */
433
            foreach ($collections as $collection) {
434
                $facetCollectionArray[] = $collection->getIndexName();
435
            }
436
        }
437
438
        // Process results.
439
        if ($facet) {
440
            foreach ($facet as $field => $values) {
441
                $entryArray = [];
442
                $entryArray['title'] = htmlspecialchars($facets[$field]);
443
                $entryArray['count'] = 0;
444
                $entryArray['_OVERRIDE_HREF'] = '';
445
                $entryArray['doNotLinkIt'] = 1;
446
                $entryArray['ITEM_STATE'] = 'NO';
447
                // Count number of facet values.
448
                $i = 0;
449
                foreach ($values as $value => $count) {
450
                    if ($count > 0) {
451
                        // check if facet collection configuration exists
452
                        if (!empty($this->settings['facetCollections'])) {
453
                            if ($field == "collection_faceting" && !in_array($value, $facetCollectionArray)) {
454
                                continue;
455
                            }
456
                        }
457
                        $entryArray['count']++;
458
                        if ($entryArray['ITEM_STATE'] == 'NO') {
459
                            $entryArray['ITEM_STATE'] = 'IFSUB';
460
                        }
461
                        $entryArray['_SUB_MENU'][] = $this->getFacetsMenuEntry($field, $value, $count, $search, $entryArray['ITEM_STATE']);
462
                        if (++$i == $this->settings['limit']) {
463
                            break;
464
                        }
465
                    } else {
466
                        break;
467
                    }
468
                }
469
                $menuArray[] = $entryArray;
470
            }
471
        }
472
        return $menuArray;
473
    }
474
475
    /**
476
     * Creates an array for a HMENU entry of a facet value.
477
     *
478
     * @access protected
479
     *
480
     * @param string $field: The facet's index_name
481
     * @param string $value: The facet's value
482
     * @param int $count: Number of hits for this facet
483
     * @param array $search: The parameters of the current search query
484
     * @param string &$state: The state of the parent item
485
     *
486
     * @return array The array for the facet's menu entry
487
     */
488
    protected function getFacetsMenuEntry($field, $value, $count, $search, &$state)
489
    {
490
        $entryArray = [];
491
        // Translate value.
492
        if ($field == 'owner_faceting') {
493
            // Translate name of holding library.
494
            $entryArray['title'] = htmlspecialchars(Helper::translate($value, 'tx_dlf_libraries', $this->settings['storagePid']));
495
        } elseif ($field == 'type_faceting') {
496
            // Translate document type.
497
            $entryArray['title'] = htmlspecialchars(Helper::translate($value, 'tx_dlf_structures', $this->settings['storagePid']));
498
        } elseif ($field == 'collection_faceting') {
499
            // Translate name of collection.
500
            $entryArray['title'] = htmlspecialchars(Helper::translate($value, 'tx_dlf_collections', $this->settings['storagePid']));
501
        } elseif ($field == 'language_faceting') {
502
            // Translate ISO 639 language code.
503
            $entryArray['title'] = htmlspecialchars(Helper::getLanguageName($value));
504
        } else {
505
            $entryArray['title'] = htmlspecialchars($value);
506
        }
507
        $entryArray['count'] = $count;
508
        $entryArray['doNotLinkIt'] = 0;
509
        // Check if facet is already selected.
510
        $queryColumn = array_column($search['params']['filterquery'], 'query');
511
        $index = array_search($field . ':("' . Solr::escapeQuery($value) . '")', $queryColumn);
512
        if ($index !== false) {
513
            // Facet is selected, thus remove it from filter.
514
            unset($queryColumn[$index]);
515
            $queryColumn = array_values($queryColumn);
516
            $entryArray['ITEM_STATE'] = 'CUR';
517
            $state = 'ACTIFSUB';
518
            //Reset facets
519
            if ($this->settings['resetFacets']) {
520
                //remove ($count) for selected facet in template
521
                $entryArray['count'] = false;
522
                //build link to delete selected facet
523
                $uri = $this->uriBuilder->reset()
524
                    ->setTargetPageUid($GLOBALS['TSFE']->id)
525
                    ->setArguments(['tx_dlf' => ['query' => $search['query'], 'fq' => $queryColumn], 'tx_dlf_search' => ['action' => 'search']])
526
                    ->setAddQueryString(true)
527
                    ->build();
528
                $entryArray['_OVERRIDE_HREF'] = $uri;
529
                $entryArray['title'] = sprintf(LocalizationUtility::translate('search.resetFacet', 'dlf'), $entryArray['title']);
0 ignored issues
show
Bug introduced by
It seems like TYPO3\CMS\Extbase\Utilit...rch.resetFacet', 'dlf') can also be of type null; however, parameter $format of sprintf() 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

529
                $entryArray['title'] = sprintf(/** @scrutinizer ignore-type */ LocalizationUtility::translate('search.resetFacet', 'dlf'), $entryArray['title']);
Loading history...
530
            }
531
        } else {
532
            // Facet is not selected, thus add it to filter.
533
            $queryColumn[] = $field . ':("' . Solr::escapeQuery($value) . '")';
534
            $entryArray['ITEM_STATE'] = 'NO';
535
        }
536
        $uri = $this->uriBuilder->reset()
537
            ->setTargetPageUid($GLOBALS['TSFE']->id)
538
            ->setArguments(['tx_dlf' => ['query' => $search['query'], 'fq' => $queryColumn], 'tx_dlf_search' => ['action' => 'search']])
539
            ->setArgumentPrefix('tx_dlf')
540
            ->build();
541
        $entryArray['_OVERRIDE_HREF'] = $uri;
542
543
        return $entryArray;
544
    }
545
546
    /**
547
     * Returns the extended search form and adds the JS files necessary for extended search.
548
     *
549
     * @access protected
550
     *
551
     * @return string The extended search form or an empty string
552
     */
553
    protected function addExtendedSearch()
554
    {
555
        // Quit without doing anything if no fields for extended search are selected.
556
        if (
557
            empty($this->settings['extendedSlotCount'])
558
            || empty($this->settings['extendedFields'])
559
        ) {
560
            return '';
561
        }
562
        // Get operator options.
563
        $operatorOptions = [];
564
        foreach (['AND', 'OR', 'NOT'] as $operator) {
565
            $operatorOptions[$operator] = htmlspecialchars(LocalizationUtility::translate('search.' . $operator, 'dlf'));
0 ignored issues
show
Bug introduced by
It seems like TYPO3\CMS\Extbase\Utilit...h.' . $operator, 'dlf') can also be of type null; however, parameter $string of htmlspecialchars() 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

565
            $operatorOptions[$operator] = htmlspecialchars(/** @scrutinizer ignore-type */ LocalizationUtility::translate('search.' . $operator, 'dlf'));
Loading history...
566
        }
567
        // Get field selector options.
568
        $fieldSelectorOptions = [];
569
        $searchFields = GeneralUtility::trimExplode(',', $this->settings['extendedFields'], true);
570
        foreach ($searchFields as $searchField) {
571
            $fieldSelectorOptions[$searchField] = Helper::translate($searchField, 'tx_dlf_metadata', $this->settings['storagePid']);
572
        }
573
        $slotCountArray = [];
574
        for ($i = 0; $i < $this->settings['extendedSlotCount']; $i++) {
575
            $slotCountArray[] = $i;
576
        }
577
578
        $this->view->assign('extendedSlotCount', $slotCountArray);
579
        $this->view->assign('extendedFields', $this->settings['extendedFields']);
580
        $this->view->assign('operators', $operatorOptions);
581
        $this->view->assign('searchFields', $fieldSelectorOptions);
582
    }
583
}
584