Passed
Push — typo3_11 ( 7f497e...38eed7 )
by Torben
04:08
created

PieventPreviewRenderer::setCategorySettings()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 13
c 1
b 0
f 0
nc 5
nop 2
dl 0
loc 19
rs 9.8333
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Extension "sf_event_mgt" for TYPO3 CMS.
7
 *
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 DERHANSEN\SfEventMgt\Preview;
13
14
use TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem;
15
use TYPO3\CMS\Core\Utility\GeneralUtility;
16
17
class PieventPreviewRenderer extends AbstractPluginPreviewRenderer
18
{
19
    /**
20
     * Renders the content of the plugin preview.
21
     *
22
     * @param GridColumnItem $item
23
     * @return string
24
     */
25
    public function renderPageModulePreviewContent(GridColumnItem $item): string
26
    {
27
        $data = [];
28
        $record = $item->getRecord();
29
        $flexFormData = GeneralUtility::xml2array($record['pi_flexform']);
30
31
        $action = htmlspecialchars($this->getLanguageService()->sL(self::LLPATH . 'flexforms_general.mode')) . ': ';
32
        $action .= $this->getSwitchableControllerActionTitle($flexFormData);
33
34
        $this->setPluginPidConfig($data, $flexFormData, 'listPid', 'additional');
35
        $this->setPluginPidConfig($data, $flexFormData, 'detailPid', 'additional');
36
        $this->setPluginPidConfig($data, $flexFormData, 'registrationPid', 'additional');
37
        $this->setPluginPidConfig($data, $flexFormData, 'paymentPid', 'additional');
38
39
        $this->setStoragePage($data, $flexFormData, 'settings.storagePage');
40
41
        $this->setOrderSettings($data, $flexFormData, 'settings.orderField', 'settings.orderDirection');
42
        $this->setOverrideDemandSettings($data, $flexFormData);
43
44
        if ($this->showFieldsForListViewOnly($flexFormData)) {
45
            $this->setCategoryConjuction($data, $flexFormData);
46
            $this->setCategorySettings($data, $flexFormData);
47
        }
48
49
        return $this->renderAsTable($data, $action);
50
    }
51
52
    /**
53
     * Returns, if fields, that are only visible for list view, should be shown
54
     *
55
     * @param array $flexFormData
56
     * @return bool
57
     */
58
    protected function showFieldsForListViewOnly(array $flexFormData): bool
59
    {
60
        $actions = $this->getFlexFormFieldValue($flexFormData, 'switchableControllerActions');
61
        switch ($actions) {
62
            case 'Event->list':
63
            case 'Event->search':
64
            case 'Event->calendar':
65
                $result = true;
66
                break;
67
            default:
68
                $result = false;
69
        }
70
71
        return $result;
72
    }
73
74
    /**
75
     * Sets category conjunction if a category is selected
76
     */
77
    protected function setCategoryConjuction(array &$data, array $flexFormData): void
78
    {
79
        // If not category is selected, we do not need to display the category mode
80
        $categories = $this->getFlexFormFieldValue($flexFormData, 'settings.category');
81
        if ($categories === null || $categories === '') {
82
            return;
83
        }
84
85
        $categoryConjunction = strtolower($this->getFlexFormFieldValue($flexFormData, 'settings.categoryConjunction'));
0 ignored issues
show
Bug introduced by
It seems like $this->getFlexFormFieldV...s.categoryConjunction') can also be of type null; however, parameter $string of strtolower() 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

85
        $categoryConjunction = strtolower(/** @scrutinizer ignore-type */ $this->getFlexFormFieldValue($flexFormData, 'settings.categoryConjunction'));
Loading history...
86
        switch ($categoryConjunction) {
87
            case 'or':
88
            case 'and':
89
            case 'notor':
90
            case 'notand':
91
                $text = htmlspecialchars($this->getLanguageService()->sL(
92
                    self::LLPATH . 'flexforms_general.categoryConjunction.' . $categoryConjunction
93
                ));
94
                break;
95
            default:
96
                $text = htmlspecialchars($this->getLanguageService()->sL(
97
                    self::LLPATH . 'flexforms_general.categoryConjunction.ignore'
98
                ));
99
                $text .= ' <span class="label label-warning">' . htmlspecialchars($this->getLanguageService()->sL(self::LLPATH . 'flexforms_general.possibleMisconfiguration')) . '</span>';
100
        }
101
102
        $data[] = [
103
            'title' => $this->getLanguageService()->sL(self::LLPATH . 'flexforms_general.categoryConjunction'),
104
            'value' => $text,
105
        ];
106
    }
107
108
    /**
109
     * Get category settings
110
     */
111
    protected function setCategorySettings(array &$data, array $flexFormData): void
112
    {
113
        $categories = GeneralUtility::intExplode(',', $this->getFlexFormFieldValue($flexFormData, 'settings.category'), true);
114
        if (count($categories) > 0) {
115
            $categoriesOut = [];
116
            foreach ($categories as $id) {
117
                $categoriesOut[] = $this->getRecordData($id, 'sys_category');
118
            }
119
120
            $data[] = [
121
                'title' => $this->getLanguageService()->sL(self::LLPATH . 'flexforms_general.category'),
122
                'value' => implode(', ', $categoriesOut),
123
            ];
124
125
            $includeSubcategories = $this->getFlexFormFieldValue($flexFormData, 'settings.includeSubcategories');
126
            if ((int)$includeSubcategories === 1) {
127
                $data[] = [
128
                    'title' => $this->getLanguageService()->sL(self::LLPATH . 'flexforms_general.includeSubcategories'),
129
                    'value' => '<i class="fa fa-check"></i>',
130
                ];
131
            }
132
        }
133
    }
134
}
135