Passed
Push — main ( f98caf...46400b )
by Torben
71:32 queued 29:51
created

ItemsProcFunc   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 50
rs 10
c 0
b 0
f 0
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getLanguageService() 0 3 1
A getFeuserValues() 0 21 4
A __construct() 0 3 1
A getPaymentMethods() 0 5 2
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\Hooks;
13
14
use DERHANSEN\SfEventMgt\Service\PaymentService;
15
use TYPO3\CMS\Core\Localization\LanguageService;
16
use TYPO3\CMS\Core\Utility\GeneralUtility;
17
18
/**
19
 * Hooks for ItemsProcFunc
20
 */
21
class ItemsProcFunc
22
{
23
    protected PaymentService $paymentService;
24
25
    public function __construct()
26
    {
27
        $this->paymentService = GeneralUtility::makeInstance(PaymentService::class);
28
    }
29
30
    /**
31
     * Itemsproc function for payment method select field
32
     */
33
    public function getPaymentMethods(array &$config): void
34
    {
35
        $paymentMethods = $this->paymentService->getPaymentMethods();
36
        foreach ($paymentMethods as $value => $label) {
37
            $config['items'][] = [$label, $value];
38
        }
39
    }
40
41
    /**
42
     * Itemsproc function for fe_user data select field
43
     */
44
    public function getFeuserValues(array &$config): void
45
    {
46
        $defaultExcludedFields = [
47
            'password',
48
            'usergroup',
49
            'tx_extbase_type',
50
            'disable',
51
            'starttime',
52
            'endtime',
53
            'felogin_forgotHash',
54
            'felogin_redirectPid',
55
            'TSconfig',
56
        ];
57
        $columns = $GLOBALS['TCA']['fe_users']['columns'] ?? [];
58
        foreach ($columns as $columnName => $columnConfig) {
59
            if (($columnConfig['label'] ?? '') === '' || in_array($columnName, $defaultExcludedFields, true)) {
60
                continue;
61
            }
62
63
            $label = $this->getLanguageService()->sL($columnConfig['label']);
64
            $config['items'][] = [$label, $columnName];
65
        }
66
    }
67
68
    protected function getLanguageService(): LanguageService
69
    {
70
        return $GLOBALS['LANG'];
71
    }
72
}
73