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
03:28
created

SearchController::addFacetsMenu()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 6
Bugs 0 Features 0
Metric Value
eloc 9
c 6
b 0
f 0
dl 0
loc 19
rs 9.6111
cc 5
nc 4
nop 0
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\Document;
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
        $requestData = GeneralUtility::_GPmerged('tx_dlf');
49
        unset($requestData['__referrer'], $requestData['__trustedProperties']);
50
51
        $this->extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get($this->extKey);
52
53
        // Build label for result list.
54
        $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

54
        $label = htmlspecialchars(/** @scrutinizer ignore-type */ LocalizationUtility::translate('search.search', 'dlf'));
Loading history...
55
        if (!empty($requestData['query'])) {
56
            $label .= ' ' . htmlspecialchars(sprintf(LocalizationUtility::translate('search.for', 'dlf'), trim($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

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

535
                $entryArray['title'] = sprintf(/** @scrutinizer ignore-type */ LocalizationUtility::translate('search.resetFacet', 'dlf'), $entryArray['title']);
Loading history...
536
            }
537
        } else {
538
            // Facet is not selected, thus add it to filter.
539
            $queryColumn[] = $field . ':("' . Solr::escapeQuery($value) . '")';
540
            $entryArray['ITEM_STATE'] = 'NO';
541
        }
542
        $uri = $this->uriBuilder->reset()
543
            ->setTargetPageUid($GLOBALS['TSFE']->id)
544
            ->setArguments(['tx_dlf' => ['query' => $search['query'], 'fq' => $queryColumn], 'tx_dlf_search' => ['action' => 'search']])
545
            ->setArgumentPrefix('tx_dlf')
546
            ->build();
547
        $entryArray['_OVERRIDE_HREF'] = $uri;
548
549
        return $entryArray;
550
    }
551
552
    /**
553
     * Returns the extended search form and adds the JS files necessary for extended search.
554
     *
555
     * @access protected
556
     *
557
     * @return string The extended search form or an empty string
558
     */
559
    protected function addExtendedSearch()
560
    {
561
        // Quit without doing anything if no fields for extended search are selected.
562
        if (
563
            empty($this->settings['extendedSlotCount'])
564
            || empty($this->settings['extendedFields'])
565
        ) {
566
            return '';
567
        }
568
        // Get operator options.
569
        $operatorOptions = [];
570
        foreach (['AND', 'OR', 'NOT'] as $operator) {
571
            $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

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