Passed
Push — typo3_11 ( e1aa8b...4cf35f )
by Torben
05:35
created

UserRegistrationDemand::createFromSettings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 1
dl 0
loc 14
rs 9.9666
c 0
b 0
f 0
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\Domain\Model\Dto;
13
14
use DateTime;
15
use DERHANSEN\SfEventMgt\Utility\PageUtility;
16
use TYPO3\CMS\Extbase\Domain\Model\FrontendUser;
17
18
/**
19
 * UserRegistrationDemand
20
 */
21
class UserRegistrationDemand
22
{
23
    protected string $displayMode = 'all';
24
    protected string $storagePage = '';
25
    protected string $orderField = '';
26
    protected string $orderDirection = '';
27
    protected ?DateTime $currentDateTime = null;
28
    protected ?FrontendUser $user = null;
29
30
    public function getDisplayMode(): string
31
    {
32
        return $this->displayMode;
33
    }
34
35
    public function setDisplayMode(string $displayMode): void
36
    {
37
        $this->displayMode = $displayMode;
38
    }
39
40
    public function getStoragePage(): string
41
    {
42
        return $this->storagePage;
43
    }
44
45
    public function setStoragePage(string $storagePage): void
46
    {
47
        $this->storagePage = $storagePage;
48
    }
49
50
    public function getOrderField(): string
51
    {
52
        return $this->orderField;
53
    }
54
55
    public function setOrderField(string $orderField): void
56
    {
57
        $this->orderField = $orderField;
58
    }
59
60
    public function getOrderDirection(): string
61
    {
62
        return $this->orderDirection;
63
    }
64
65
    public function setOrderDirection(string $orderDirection): void
66
    {
67
        $this->orderDirection = $orderDirection;
68
    }
69
70
    public function setCurrentDateTime(DateTime $currentDateTime): void
71
    {
72
        $this->currentDateTime = $currentDateTime;
73
    }
74
75
    public function getCurrentDateTime(): DateTime
76
    {
77
        if ($this->currentDateTime != null) {
78
            return $this->currentDateTime;
79
        }
80
81
        return new \DateTime();
82
    }
83
84
    public function getUser(): ?FrontendUser
85
    {
86
        return $this->user;
87
    }
88
89
    public function setUser(?FrontendUser $user): void
90
    {
91
        $this->user = $user;
92
    }
93
94
    /**
95
     * Creates a new UserRegistrationDemand object from the given settings. Respects recursive setting for storage page
96
     * and extends all PIDs to children if set.
97
     *
98
     * @param array $settings
99
     * @return UserRegistrationDemand
100
     */
101
    public static function createFromSettings(array $settings = []): self
102
    {
103
        $demand = new UserRegistrationDemand();
104
        $demand->setDisplayMode($settings['userRegistration']['displayMode'] ?? 'all');
105
        $demand->setStoragePage(
106
            PageUtility::extendPidListByChildren(
107
                (string)($settings['userRegistration']['storagePage'] ?? ''),
108
                (int)($settings['userRegistration']['recursive'] ?? 0)
109
            )
110
        );
111
        $demand->setOrderField($settings['userRegistration']['orderField'] ?? '');
112
        $demand->setOrderDirection($settings['userRegistration']['orderDirection'] ?? '');
113
114
        return $demand;
115
    }
116
}
117