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

renderPageModulePreviewContent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 11
rs 10
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 PiuserregPreviewRenderer extends AbstractPluginPreviewRenderer
18
{
19
    public function renderPageModulePreviewContent(GridColumnItem $item): string
20
    {
21
        $data = [];
22
        $record = $item->getRecord();
23
        $flexFormData = GeneralUtility::xml2array($record['pi_flexform']);
24
25
        $this->setPluginPidConfig($data, $flexFormData, 'registrationPid', 'sDEF');
26
        $this->setStoragePage($data, $flexFormData, 'settings.userRegistration.storagePage');
27
        $this->setOrderSettings($data, $flexFormData, 'settings.userRegistration.orderField', 'settings.userRegistration.orderDirection');
28
29
        return $this->renderAsTable($data);
30
    }
31
32
    /**
33
     * Returns, if fields, that are only visible for list view, should be shown
34
     *
35
     * @param array $flexFormData
36
     * @return bool
37
     */
38
    protected function showFieldsForListViewOnly(array $flexFormData): bool
39
    {
40
        $actions = $this->getFlexFormFieldValue($flexFormData, 'switchableControllerActions');
41
        switch ($actions) {
42
            case 'Event->list':
43
            case 'Event->search':
44
            case 'Event->calendar':
45
                $result = true;
46
                break;
47
            default:
48
                $result = false;
49
        }
50
51
        return $result;
52
    }
53
54
    /**
55
     * Sets category conjunction if a category is selected
56
     */
57
    public function setCategoryConjuction(array &$data, array $flexFormData): void
58
    {
59
        // If not category is selected, we do not need to display the category mode
60
        $categories = $this->getFlexFormFieldValue($flexFormData, 'settings.category');
61
        if ($categories === null || $categories === '') {
62
            return;
63
        }
64
65
        $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

65
        $categoryConjunction = strtolower(/** @scrutinizer ignore-type */ $this->getFlexFormFieldValue($flexFormData, 'settings.categoryConjunction'));
Loading history...
66
        switch ($categoryConjunction) {
67
            case 'or':
68
            case 'and':
69
            case 'notor':
70
            case 'notand':
71
                $text = htmlspecialchars($this->getLanguageService()->sL(
72
                    self::LLPATH . 'flexforms_general.categoryConjunction.' . $categoryConjunction
73
                ));
74
                break;
75
            default:
76
                $text = htmlspecialchars($this->getLanguageService()->sL(
77
                    self::LLPATH . 'flexforms_general.categoryConjunction.ignore'
78
                ));
79
                $text .= ' <span class="label label-warning">' . htmlspecialchars($this->getLanguageService()->sL(self::LLPATH . 'flexforms_general.possibleMisconfiguration')) . '</span>';
80
        }
81
82
        $data[] = [
83
            'title' => $this->getLanguageService()->sL(self::LLPATH . 'flexforms_general.categoryConjunction'),
84
            'value' => $text,
85
        ];
86
    }
87
88
    /**
89
     * Get category settings
90
     */
91
    public function setCategorySettings(array &$data, array $flexFormData): void
92
    {
93
        $categories = GeneralUtility::intExplode(',', $this->getFlexFormFieldValue($flexFormData, 'settings.category'), true);
94
        if (count($categories) > 0) {
95
            $categoriesOut = [];
96
            foreach ($categories as $id) {
97
                $categoriesOut[] = $this->getRecordData($id, 'sys_category');
98
            }
99
100
            $data[] = [
101
                'title' => $this->getLanguageService()->sL(self::LLPATH . 'flexforms_general.category'),
102
                'value' => implode(', ', $categoriesOut),
103
            ];
104
105
            $includeSubcategories = $this->getFlexFormFieldValue($flexFormData, 'settings.includeSubcategories');
106
            if ((int)$includeSubcategories === 1) {
107
                $data[] = [
108
                    'title' => $this->getLanguageService()->sL(self::LLPATH . 'flexforms_general.includeSubcategories'),
109
                    'value' => '<i class="fa fa-check"></i>',
110
                ];
111
            }
112
        }
113
    }
114
}
115