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.
Completed
Push — master ( ccdfd2...d635f9 )
by Sebastian
13s queued 11s
created

tx_dlf_listview::getFieldWrap()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
dl 0
loc 9
rs 10
c 1
b 0
f 0
cc 2
nc 2
nop 2
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
/**
13
 * Plugin 'DLF: List View' for the 'dlf' extension.
14
 *
15
 * @author	Sebastian Meyer <[email protected]>
16
 * @author	Henrik Lochmann <[email protected]>
17
 * @author	Frank Ulrich Weber <[email protected]>
18
 * @package	TYPO3
19
 * @subpackage	tx_dlf
20
 * @access	public
21
 */
22
class tx_dlf_listview extends tx_dlf_plugin {
23
24
    public $scriptRelPath = 'plugins/listview/class.tx_dlf_listview.php';
25
26
    /**
27
     * This holds the field wrap of the metadata
28
     *
29
     * @var	array
30
     * @access	private
31
     */
32
    private $fieldwrap = array ();
33
34
    /**
35
     * This holds the list
36
     *
37
     * @var	tx_dlf_list
38
     * @access	protected
39
     */
40
    protected $list;
41
42
    /**
43
     * Array of sorted metadata
44
     *
45
     * @var	array
46
     * @access	protected
47
     */
48
    protected $metadata = array ();
49
50
    /**
51
     * Array of sortable metadata
52
     *
53
     * @var	array
54
     * @access	protected
55
     */
56
    protected $sortables = array ();
57
58
    /**
59
     * Renders the page browser
60
     *
61
     * @access	protected
62
     *
63
     * @return	string		The rendered page browser ready for output
64
     */
65
    protected function getPageBrowser() {
66
67
        // Get overall number of pages.
68
        $maxPages = intval(ceil($this->list->metadata['options']['numberOfToplevelHits'] / $this->conf['limit']));
0 ignored issues
show
Bug Best Practice introduced by
The property $metadata is declared protected in tx_dlf_list. Since you implement __get, consider adding a @property or @property-read.
Loading history...
69
70
        // Return empty pagebrowser if there is just one page.
71
        if ($maxPages < 2) {
72
73
            return '';
74
75
        }
76
77
        // Get separator.
78
        $separator = $this->pi_getLL('separator', ' - ', TRUE);
79
80
        // Add link to previous page.
81
        if ($this->piVars['pointer'] > 0) {
82
83
            $output = $this->pi_linkTP_keepPIvars($this->pi_getLL('prevPage', '&lt;', TRUE), array ('pointer' => $this->piVars['pointer'] - 1), TRUE).$separator;
84
85
        } else {
86
87
            $output = $this->pi_getLL('prevPage', '&lt;', TRUE).$separator;
88
89
        }
90
91
        $i = 0;
92
93
        $skip = NULL;
94
95
        // Add links to pages.
96
        while ($i < $maxPages) {
97
98
            if ($i < 3 || ($i > $this->piVars['pointer'] - 3 && $i < $this->piVars['pointer'] + 3) || $i > $maxPages - 4) {
99
100
                if ($this->piVars['pointer'] != $i) {
101
102
                    $output .= $this->pi_linkTP_keepPIvars(sprintf($this->pi_getLL('page', '%d', TRUE), $i + 1), array ('pointer' => $i), TRUE).$separator;
103
104
                } else {
105
106
                    $output .= sprintf($this->pi_getLL('page', '%d', TRUE), $i + 1).$separator;
107
108
                }
109
110
                $skip = TRUE;
111
112
            } elseif ($skip === TRUE) {
113
114
                $output .= $this->pi_getLL('skip', '...', TRUE).$separator;
115
116
                $skip = FALSE;
117
118
            }
119
120
            $i++;
121
122
        }
123
124
        // Add link to next page.
125
        if ($this->piVars['pointer'] < $maxPages - 1) {
126
127
            $output .= $this->pi_linkTP_keepPIvars($this->pi_getLL('nextPage', '&gt;', TRUE), array ('pointer' => $this->piVars['pointer'] + 1), TRUE);
128
129
        } else {
130
131
            $output .= $this->pi_getLL('nextPage', '&gt;', TRUE);
132
133
        }
134
135
        return $output;
136
137
    }
138
139
    /**
140
     * Renders one entry of the list
141
     *
142
     * @access	protected
143
     *
144
     * @param	integer		$number: The number of the entry
145
     * @param	string		$template: Parsed template subpart
146
     *
147
     * @return	string		The rendered entry ready for output
148
     */
149
    protected function getEntry($number, $template) {
150
151
        $markerArray['###NUMBER###'] = $number + 1;
1 ignored issue
show
Comprehensibility Best Practice introduced by
$markerArray was never initialized. Although not strictly required by PHP, it is generally a good practice to add $markerArray = array(); before regardless.
Loading history...
152
153
        $markerArray['###METADATA###'] = '';
154
155
        $markerArray['###THUMBNAIL###'] = '';
156
157
        $markerArray['###PREVIEW###'] = '';
158
159
        $subpart = '';
160
161
        $imgAlt = '';
162
163
        $noTitle = $this->pi_getLL('noTitle');
164
165
        $metadata = $this->list[$number]['metadata'];
166
167
        foreach ($this->metadata as $index_name => $metaConf) {
168
169
            $parsedValue = '';
170
171
            $fieldwrap = $this->getFieldWrap($index_name, $metaConf['wrap']);
172
173
            do {
174
175
                $value = @array_shift($metadata[$index_name]);
176
177
                // Link title to pageview.
178
                if ($index_name == 'title') {
179
180
                    // Get title of parent document if needed.
181
                    if (empty($value) && $this->conf['getTitle']) {
182
183
                        $superiorTitle = tx_dlf_document::getTitle($this->list[$number]['uid'], TRUE);
184
185
                        if (!empty($superiorTitle)) {
186
187
                            $value = '['.$superiorTitle.']';
188
189
                        }
190
191
                    }
192
193
                    // Set fake title if still not present.
194
                    if (empty($value)) {
195
196
                        $value = $noTitle;
197
198
                    }
199
200
                    $imgAlt = htmlspecialchars($value);
201
202
                    $additionalParams = array (
203
                        'id' => $this->list[$number]['uid'],
204
                        'page' => $this->list[$number]['page']
205
                    );
206
207
                    if (!empty($this->piVars['logicalPage'])) {
208
209
                        $additionalParams['logicalPage'] = $this->piVars['logicalPage'];
210
211
                    }
212
213
                    $conf = array (
214
                        'useCacheHash' => 1,
215
                        'parameter' => $this->conf['targetPid'],
216
                        'additionalParams' => \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl($this->prefixId, $additionalParams, '', TRUE, FALSE)
217
                    );
218
219
                    $value = $this->cObj->typoLink(htmlspecialchars($value), $conf);
220
221
                // Translate name of holding library.
222
                } elseif ($index_name == 'owner' && !empty($value)) {
223
224
                    $value = htmlspecialchars(tx_dlf_helper::translate($value, 'tx_dlf_libraries', $this->conf['pages']));
225
226
                // Translate document type.
227
                } elseif ($index_name == 'type' && !empty($value)) {
228
229
                    $value = htmlspecialchars(tx_dlf_helper::translate($value, 'tx_dlf_structures', $this->conf['pages']));
230
231
                // Translate ISO 639 language code.
232
                } elseif ($index_name == 'language' && !empty($value)) {
233
234
                    $value = htmlspecialchars(tx_dlf_helper::getLanguageName($value));
235
236
                } elseif (!empty($value)) {
237
238
                    $value = htmlspecialchars($value);
239
240
                }
241
242
                $value = $this->cObj->stdWrap($value, $fieldwrap['value.']);
243
244
                if (!empty($value)) {
245
246
                    $parsedValue .= $value;
247
248
                }
249
250
            } while (count($metadata[$index_name]));
251
252
            if (!empty($parsedValue)) {
253
254
                $field = $this->cObj->stdWrap(htmlspecialchars($metaConf['label']), $fieldwrap['key.']);
255
256
                $field .= $parsedValue;
257
258
                $markerArray['###METADATA###'] .= $this->cObj->stdWrap($field, $fieldwrap['all.']);
259
260
            }
261
262
        }
263
264
        // Add thumbnail.
265
        if (!empty($this->list[$number]['thumbnail'])) {
266
267
            $markerArray['###THUMBNAIL###'] = '<img alt="'.$imgAlt.'" src="'.$this->list[$number]['thumbnail'].'" />';
268
269
        }
270
271
        // Add preview.
272
        if (!empty($this->list[$number]['preview'])) {
273
274
            $markerArray['###PREVIEW###'] = $this->list[$number]['preview'];
275
276
        }
277
278
        if (!empty($this->list[$number]['subparts'])) {
279
280
            $subpart = $this->getSubEntries($number, $template);
281
282
        }
283
284
        // basket button
285
        $markerArray['###BASKETBUTTON###'] = '';
286
287
        if (!empty($this->conf['basketButton']) && !empty($this->conf['targetBasket'])) {
288
289
            $additionalParams = array ('id' => $this->list[$number]['uid'], 'startpage' => $this->list[$number]['page'], 'addToBasket' => 'list');
290
291
            $conf = array (
292
                'useCacheHash' => 1,
293
                'parameter' => $this->conf['targetBasket'],
294
                'additionalParams' => \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl($this->prefixId, $additionalParams, '', TRUE, FALSE)
295
            );
296
297
            $link = $this->cObj->typoLink($this->pi_getLL('addBasket', '', TRUE), $conf);
298
299
            $markerArray['###BASKETBUTTON###'] = $link;
300
301
        }
302
303
        return $this->cObj->substituteMarkerArray($this->cObj->substituteSubpart($template['entry'], '###SUBTEMPLATE###', $subpart, TRUE), $markerArray);
304
305
    }
306
307
    /**
308
     * Returns the parsed fieldwrap of a metadata
309
     *
310
     * @access	private
311
     *
312
     * @param	string		$index_name: The index name of a metadata
313
     * @param	string		$wrap: The configured metadata wrap
314
     *
315
     * @return	array		The parsed fieldwrap
316
     */
317
    private function getFieldWrap($index_name, $wrap) {
318
319
        if (isset($this->fieldwrap[$index_name])) {
320
321
            return $this->fieldwrap[$index_name];
322
323
        } else {
324
325
            return $this->fieldwrap[$index_name] = $this->parseTS($wrap);
326
327
        }
328
329
    }
330
331
    /**
332
     * Renders sorting dialog
333
     *
334
     * @access	protected
335
     *
336
     * @return	string		The rendered sorting dialog ready for output
337
     */
338
    protected function getSortingForm() {
339
340
        // Return nothing if there are no sortable metadata fields.
341
        if (!count($this->sortables)) {
342
343
            return '';
344
345
        }
346
347
        // Set class prefix.
348
        $prefix = str_replace('_', '-', get_class($this));
349
350
        // Configure @action URL for form.
351
        $linkConf = array (
352
            'parameter' => $GLOBALS['TSFE']->id
353
        );
354
355
        if (!empty($this->piVars['logicalPage'])) {
356
357
            $linkConf['additionalParams'] = \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl($this->prefixId, array ('logicalPage' => $this->piVars['logicalPage']), '', TRUE, FALSE);
358
359
        }
360
361
        // Build HTML form.
362
        $sorting = '<form action="'.$this->cObj->typoLink_URL($linkConf).'" method="get"><div><input type="hidden" name="id" value="'.$GLOBALS['TSFE']->id.'" />';
363
364
        foreach ($this->piVars as $piVar => $value) {
365
366
            if ($piVar != 'order' && $piVar != 'DATA' && !empty($value)) {
367
368
                $sorting .= '<input type="hidden" name="'.$this->prefixId.'['.$piVar.']" value="'.$value.'" />';
369
370
            }
371
372
        }
373
374
        // Select sort field.
375
        $uniqId = uniqid($prefix.'-');
376
377
        $sorting .= '<label for="'.$uniqId.'">'.$this->pi_getLL('orderBy', '', TRUE).'</label><select id="'.$uniqId.'" name="'.$this->prefixId.'[order]" onchange="javascript:this.form.submit();">';
378
379
        // Add relevance sorting if this is a search result list.
380
        if ($this->list->metadata['options']['source'] == 'search') {
0 ignored issues
show
Bug Best Practice introduced by
The property $metadata is declared protected in tx_dlf_list. Since you implement __get, consider adding a @property or @property-read.
Loading history...
381
382
            $sorting .= '<option value="score"'.(($this->list->metadata['options']['order'] == 'score') ? ' selected="selected"' : '').'>'.$this->pi_getLL('relevance', '', TRUE).'</option>';
383
384
        }
385
386
        foreach ($this->sortables as $index_name => $label) {
387
388
            $sorting .= '<option value="'.$index_name.'"'.(($this->list->metadata['options']['order'] == $index_name) ? ' selected="selected"' : '').'>'.htmlspecialchars($label).'</option>';
389
390
        }
391
392
        $sorting .= '</select>';
393
394
        // Select sort direction.
395
        $uniqId = uniqid($prefix.'-');
396
397
        $sorting .= '<label for="'.$uniqId.'">'.$this->pi_getLL('direction', '', TRUE).'</label><select id="'.$uniqId.'" name="'.$this->prefixId.'[asc]" onchange="javascript:this.form.submit();">';
398
399
        $sorting .= '<option value="1" '.($this->list->metadata['options']['order.asc'] ? ' selected="selected"' : '').'>'.$this->pi_getLL('direction.asc', '', TRUE).'</option>';
400
401
        $sorting .= '<option value="0" '.(!$this->list->metadata['options']['order.asc'] ? ' selected="selected"' : '').'>'.$this->pi_getLL('direction.desc', '', TRUE).'</option>';
402
403
        $sorting .= '</select></div></form>';
404
405
        return $sorting;
406
407
    }
408
409
    /**
410
     * Renders all sub-entries of one entry
411
     *
412
     * @access	protected
413
     *
414
     * @param	integer		$number: The number of the entry
415
     * @param	string		$template: Parsed template subpart
416
     *
417
     * @return	string		The rendered entries ready for output
418
     */
419
    protected function getSubEntries($number, $template) {
420
421
        $content = '';
422
423
        $noTitle = $this->pi_getLL('noTitle');
424
425
        $highlight_word = preg_replace('/\s\s+/', ';', $this->list->metadata['searchString']);
0 ignored issues
show
Bug Best Practice introduced by
The property $metadata is declared protected in tx_dlf_list. Since you implement __get, consider adding a @property or @property-read.
Loading history...
426
427
        foreach ($this->list[$number]['subparts'] as $subpart) {
428
429
            $markerArray['###SUBMETADATA###'] = '';
430
431
            $markerArray['###SUBTHUMBNAIL###'] = '';
432
433
            $markerArray['###SUBPREVIEW###'] = '';
434
435
            $imgAlt = '';
436
437
            foreach ($this->metadata as $index_name => $metaConf) {
438
439
                $parsedValue = '';
440
441
                $fieldwrap = $this->getFieldWrap($index_name, $metaConf['wrap']);
442
443
                do {
444
445
                    $value = @array_shift($subpart['metadata'][$index_name]);
446
447
                    // Link title to pageview.
448
                    if ($index_name == 'title') {
449
450
                        // Get title of parent document if needed.
451
                        if (empty($value) && $this->conf['getTitle']) {
452
453
                            $superiorTitle = tx_dlf_document::getTitle($subpart['uid'], TRUE);
454
455
                            if (!empty($superiorTitle)) {
456
457
                                $value = '['.$superiorTitle.']';
458
459
                            }
460
461
                        }
462
463
                        // Set fake title if still not present.
464
                        if (empty($value)) {
465
466
                            $value = $noTitle;
467
468
                        }
469
470
                        $imgAlt = htmlspecialchars($value);
471
472
                        $additionalParams = array (
473
                            'id' => $subpart['uid'],
474
                            'page' => $subpart['page'],
475
                            'highlight_word' => $highlight_word
476
                        );
477
478
                        if (!empty($this->piVars['logicalPage'])) {
479
480
                            $additionalParams['logicalPage'] = $this->piVars['logicalPage'];
481
482
                        }
483
484
                        $conf = array (
485
                            // we don't want cHash in case of search parameters
486
                            'useCacheHash' => empty($this->list->metadata['searchString']) ? 1 : 0,
487
                            'parameter' => $this->conf['targetPid'],
488
                            'additionalParams' => \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl($this->prefixId, $additionalParams, '', TRUE, FALSE)
489
                        );
490
491
                        $value = $this->cObj->typoLink(htmlspecialchars($value), $conf);
492
493
                    // Translate name of holding library.
494
                    } elseif ($index_name == 'owner' && !empty($value)) {
495
496
                        $value = htmlspecialchars(tx_dlf_helper::translate($value, 'tx_dlf_libraries', $this->conf['pages']));
497
498
                    // Translate document type.
499
                    } elseif ($index_name == 'type' && !empty($value)) {
500
501
                        $_value = $value;
502
503
                        $value = htmlspecialchars(tx_dlf_helper::translate($value, 'tx_dlf_structures', $this->conf['pages']));
504
505
                        // Add page number for single pages.
506
                        if ($_value == 'page') {
507
508
                            $value .= ' '.intval($subpart['page']);
509
510
                        }
511
512
                    // Translate ISO 639 language code.
513
                    } elseif ($index_name == 'language' && !empty($value)) {
514
515
                        $value = htmlspecialchars(tx_dlf_helper::getLanguageName($value));
516
517
                    } elseif (!empty($value)) {
518
519
                        $value = htmlspecialchars($value);
520
521
                    }
522
523
                    $value = $this->cObj->stdWrap($value, $fieldwrap['value.']);
524
525
                    if (!empty($value)) {
526
527
                        $parsedValue .= $value;
528
529
                    }
530
531
                } while (count($subpart['metadata'][$index_name]));
532
533
                if (!empty($parsedValue)) {
534
535
                    $field = $this->cObj->stdWrap(htmlspecialchars($metaConf['label']), $fieldwrap['key.']);
536
537
                    $field .= $parsedValue;
538
539
                    $markerArray['###SUBMETADATA###'] .= $this->cObj->stdWrap($field, $fieldwrap['all.']);
540
541
                }
542
543
            }
544
545
            // Add thumbnail.
546
            if (!empty($subpart['thumbnail'])) {
547
548
                $markerArray['###SUBTHUMBNAIL###'] = '<img alt="'.$imgAlt.'" src="'.$subpart['thumbnail'].'" />';
549
550
            }
551
552
            // Add preview.
553
            if (!empty($subpart['preview'])) {
554
555
                $markerArray['###SUBPREVIEW###'] = $subpart['preview'];
556
557
            }
558
559
            // basket button
560
            $markerArray['###SUBBASKETBUTTON###'] = '';
561
562
            if (!empty($this->conf['basketButton']) && !empty($this->conf['targetBasket'])) {
563
564
                $additionalParams = array ('id' => $this->list[$number]['uid'], 'startpage' => $subpart['page'], 'endpage' => $subpart['page'], 'logId' => $subpart['sid'], 'addToBasket' => 'subentry');
565
566
                $conf = array (
567
                    'useCacheHash' => 1,
568
                    'parameter' => $this->conf['targetBasket'],
569
                    'additionalParams' => \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl($this->prefixId, $additionalParams, '', TRUE, FALSE)
570
                );
571
572
                $link = $this->cObj->typoLink($this->pi_getLL('addBasket', '', TRUE), $conf);
573
574
                $markerArray['###SUBBASKETBUTTON###'] = $link;
575
576
            }
577
578
            $content .= $this->cObj->substituteMarkerArray($template['subentry'], $markerArray);
579
580
        }
581
582
        return $this->cObj->substituteSubpart($this->cObj->getSubpart($this->template, '###SUBTEMPLATE###'), '###SUBENTRY###', $content, TRUE);
583
584
    }
585
586
    /**
587
     * Get metadata configuration from database
588
     *
589
     * @access	protected
590
     *
591
     * @return	void
592
     */
593
    protected function loadConfig() {
594
595
        $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
596
            'tx_dlf_metadata.index_name AS index_name,tx_dlf_metadata.wrap AS wrap,tx_dlf_metadata.is_listed AS is_listed,tx_dlf_metadata.is_sortable AS is_sortable',
597
            'tx_dlf_metadata',
598
            '(tx_dlf_metadata.is_listed=1 OR tx_dlf_metadata.is_sortable=1) AND tx_dlf_metadata.pid='.intval($this->conf['pages']).tx_dlf_helper::whereClause('tx_dlf_metadata'),
599
            '',
600
            'tx_dlf_metadata.sorting ASC',
601
            ''
602
        );
603
604
        while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
605
606
            if ($resArray['is_listed']) {
607
608
                $this->metadata[$resArray['index_name']] = array (
609
                    'wrap' => $resArray['wrap'],
610
                    'label' => tx_dlf_helper::translate($resArray['index_name'], 'tx_dlf_metadata', $this->conf['pages'])
611
                );
612
613
            }
614
615
            if ($resArray['is_sortable']) {
616
617
                $this->sortables[$resArray['index_name']] = tx_dlf_helper::translate($resArray['index_name'], 'tx_dlf_metadata', $this->conf['pages']);
618
619
            }
620
621
        }
622
623
    }
624
625
    /**
626
     * The main method of the PlugIn
627
     *
628
     * @access	public
629
     *
630
     * @param	string		$content: The PlugIn content
631
     * @param	array		$conf: The PlugIn configuration
632
     *
633
     * @return	string		The content that is displayed on the website
634
     */
635
    public function main($content, $conf) {
636
637
        $this->init($conf);
638
639
        // Don't cache the output.
640
        $this->setCache(FALSE);
641
642
        // Load the list.
643
        $this->list = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_dlf_list');
644
645
        $currentEntry = $this->piVars['pointer'] * $this->conf['limit'];
646
        $lastEntry = ($this->piVars['pointer'] + 1) * $this->conf['limit'];
647
648
        // Check if it's a list of database records or Solr documents.
649
        if ((!empty($this->list->metadata['options']['source']) && $this->list->metadata['options']['source'] == 'collection')
650
            && ((!empty($this->piVars['order']) && $this->piVars['order'] != $this->list->metadata['options']['order'])
651
                || (isset($this->piVars['asc']) && $this->piVars['asc'] != $this->list->metadata['options']['order.asc']))) {
652
653
                    // Order list by given field.
654
                    $this->list->sort($this->piVars['order'], (boolean) $this->piVars['asc']);
655
656
                    // Update list's metadata.
657
                    $listMetadata = $this->list->metadata;
658
659
                    $listMetadata['options']['order'] = $this->piVars['order'];
660
661
                    $listMetadata['options']['order.asc'] = (boolean) $this->piVars['asc'];
662
663
                    $this->list->metadata = $listMetadata;
664
665
                    // Save updated list.
666
                    $this->list->save();
667
668
                    // Reset pointer.
669
                    $this->piVars['pointer'] = 0;
670
671
        } elseif (!empty($this->list->metadata['options']['source']) && $this->list->metadata['options']['source'] == 'search') {
672
673
            // Update list's metadata
674
            $listMetadata = $this->list->metadata;
675
676
            // Sort the list if applicable.
677
            if ((!empty($this->piVars['order']) && $this->piVars['order'] != $listMetadata['options']['order'])
678
                || (isset($this->piVars['asc']) && $this->piVars['asc'] != $listMetadata['options']['order.asc'])) {
679
680
                // Update list's metadata.
681
                $listMetadata['options']['params']['sort'] = array ($this->piVars['order']."_sorting" => (boolean) $this->piVars['asc']?'asc':'desc');
682
683
                $listMetadata['options']['order'] = $this->piVars['order'];
684
                $listMetadata['options']['order.asc'] = (boolean) $this->piVars['asc'];
685
686
                // Reset pointer.
687
                $this->piVars['pointer'] = 0;
688
689
            }
690
691
            // Set some query parameters
692
            $listMetadata['options']['params']['start'] = $currentEntry;
693
            $listMetadata['options']['params']['rows'] = $this->conf['limit'];
694
695
            // Search only if the query params have changed.
696
            if ($listMetadata['options']['params'] != $this->list->metadata['options']['params']) {
697
698
                // Instantiate search object.
699
                $solr = tx_dlf_solr::getInstance($this->list->metadata['options']['core']);
700
701
                if (!$solr->ready) {
0 ignored issues
show
Bug Best Practice introduced by
The property $ready is declared protected in tx_dlf_solr. Since you implement __get, consider adding a @property or @property-read.
Loading history...
702
703
                    if (TYPO3_DLOG) {
704
705
                        \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_listview->main('.$content.', [data])] Apache Solr not available', $this->extKey, SYSLOG_SEVERITY_ERROR, $conf);
0 ignored issues
show
Bug introduced by
The constant SYSLOG_SEVERITY_ERROR was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
706
707
                    }
708
709
                    return $content;
710
711
                }
712
713
                // Set search parameters.
714
                $solr->cPid =  $listMetadata['options']['pid'];
0 ignored issues
show
Bug Best Practice introduced by
The property $cPid is declared protected in tx_dlf_solr. Since you implement __set, consider adding a @property or @property-write.
Loading history...
715
                $solr->params = $listMetadata['options']['params'];
0 ignored issues
show
Bug Best Practice introduced by
The property $params is declared protected in tx_dlf_solr. Since you implement __set, consider adding a @property or @property-write.
Loading history...
716
717
                // Perform search.
718
                $this->list = $solr->search();
719
720
            }
721
722
            // Add list description
723
            $listMetadata['description'] = '<p class="tx-dlf-search-numHits">'.htmlspecialchars(sprintf($this->pi_getLL('hits', ''), $this->list->metadata['options']['numberOfHits'], $this->list->metadata['options']['numberOfToplevelHits'])).'</p>';
0 ignored issues
show
Bug Best Practice introduced by
The property $metadata is declared protected in tx_dlf_list. Since you implement __get, consider adding a @property or @property-read.
Loading history...
724
            $this->list->metadata = $listMetadata;
725
726
            // Save updated list.
727
            $this->list->save();
728
729
            $currentEntry = 0;
730
            $lastEntry = $this->conf['limit'];
731
732
        }
733
734
        // Load template file.
735
        if (!empty($this->conf['templateFile'])) {
736
737
            $this->template = $this->cObj->getSubpart($this->cObj->fileResource($this->conf['templateFile']), '###TEMPLATE###');
738
739
        } else {
740
741
            $this->template = $this->cObj->getSubpart($this->cObj->fileResource('EXT:dlf/plugins/listview/template.tmpl'), '###TEMPLATE###');
742
743
        }
744
745
        $subpartArray['entry'] = $this->cObj->getSubpart($this->template, '###ENTRY###');
1 ignored issue
show
Comprehensibility Best Practice introduced by
$subpartArray was never initialized. Although not strictly required by PHP, it is generally a good practice to add $subpartArray = array(); before regardless.
Loading history...
746
747
        $subpartArray['subentry'] = $this->cObj->getSubpart($this->template, '###SUBENTRY###');
748
749
        // Set some variable defaults.
750
        if (!empty($this->piVars['pointer']) && (($this->piVars['pointer'] * $this->conf['limit']) + 1) <= $this->list->metadata['options']['numberOfToplevelHits']) {
751
752
            $this->piVars['pointer'] = max(intval($this->piVars['pointer']), 0);
753
754
        } else {
755
756
            $this->piVars['pointer'] = 0;
757
758
        }
759
760
        // Load metadata configuration.
761
        $this->loadConfig();
762
763
        for ($currentEntry, $lastEntry; $currentEntry < $lastEntry; $currentEntry++) {
764
765
            if (empty($this->list[$currentEntry])) {
766
767
                break;
768
769
            } else {
770
771
                $content .= $this->getEntry($currentEntry, $subpartArray);
772
773
            }
774
775
        }
776
777
        $markerArray['###LISTTITLE###'] = $this->list->metadata['label'];
1 ignored issue
show
Comprehensibility Best Practice introduced by
$markerArray was never initialized. Although not strictly required by PHP, it is generally a good practice to add $markerArray = array(); before regardless.
Loading history...
778
779
        $markerArray['###LISTDESCRIPTION###'] = $this->list->metadata['description'];
780
781
        if (!empty($this->list->metadata['thumbnail'])) {
782
783
            $markerArray['###LISTTHUMBNAIL###'] = '<img alt="" src="'.$this->list->metadata['thumbnail'].'" />';
784
785
        } else {
786
787
            $markerArray['###LISTTHUMBNAIL###'] = '';
788
789
        }
790
791
        if ($currentEntry) {
792
793
            $currentEntry =  ($this->piVars['pointer'] * $this->conf['limit']) + 1;
794
            $lastEntry = ($this->piVars['pointer'] * $this->conf['limit']) + $this->conf['limit'];
795
796
            $markerArray['###COUNT###'] = htmlspecialchars(sprintf($this->pi_getLL('count'), $currentEntry, $lastEntry < $this->list->metadata['options']['numberOfToplevelHits'] ? $lastEntry : $this->list->metadata['options']['numberOfToplevelHits'], $this->list->metadata['options']['numberOfToplevelHits']));
797
798
        } else {
799
800
            $markerArray['###COUNT###'] = $this->pi_getLL('nohits', '', TRUE);
801
802
        }
803
804
        $markerArray['###PAGEBROWSER###'] = $this->getPageBrowser();
805
806
        $markerArray['###SORTING###'] = $this->getSortingForm();
807
808
        $content = $this->cObj->substituteMarkerArray($this->cObj->substituteSubpart($this->template, '###ENTRY###', $content, TRUE), $markerArray);
809
810
        return $this->pi_wrapInBaseClass($content);
811
812
    }
813
814
}
815