|
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 DERHANSEN\SfEventMgt\Utility\PageUtility; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Category demand |
|
18
|
|
|
*/ |
|
19
|
|
|
class CategoryDemand |
|
20
|
|
|
{ |
|
21
|
|
|
public const ORDER_FIELD_ALLOWED = ['title', 'uid', 'sorting']; |
|
22
|
|
|
|
|
23
|
|
|
protected string $storagePage = ''; |
|
24
|
|
|
protected bool $restrictToStoragePage = false; |
|
25
|
|
|
protected string $categories = ''; |
|
26
|
|
|
protected bool $includeSubcategories = false; |
|
27
|
|
|
protected string $orderField = 'uid'; |
|
28
|
|
|
protected string $orderDirection = 'asc'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Sets the storage page |
|
32
|
|
|
* |
|
33
|
|
|
* @param string $storagePage Storagepage |
|
34
|
|
|
*/ |
|
35
|
|
|
public function setStoragePage(string $storagePage): void |
|
36
|
|
|
{ |
|
37
|
|
|
$this->storagePage = $storagePage; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Returns the storage page |
|
42
|
|
|
* |
|
43
|
|
|
* @return string |
|
44
|
|
|
*/ |
|
45
|
|
|
public function getStoragePage(): string |
|
46
|
|
|
{ |
|
47
|
|
|
return $this->storagePage; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Returns restrictToStoragePage |
|
52
|
|
|
* |
|
53
|
|
|
* @return bool |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getRestrictToStoragePage(): bool |
|
56
|
|
|
{ |
|
57
|
|
|
return $this->restrictToStoragePage; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Sets restrictToStoragePage |
|
62
|
|
|
* |
|
63
|
|
|
* @param bool $restrictToStoragePage |
|
64
|
|
|
*/ |
|
65
|
|
|
public function setRestrictToStoragePage(bool $restrictToStoragePage): void |
|
66
|
|
|
{ |
|
67
|
|
|
$this->restrictToStoragePage = $restrictToStoragePage; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Returns the categories |
|
72
|
|
|
* |
|
73
|
|
|
* @return string |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getCategories(): string |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->categories; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Sets the categories |
|
82
|
|
|
* |
|
83
|
|
|
* @param string $categories |
|
84
|
|
|
*/ |
|
85
|
|
|
public function setCategories(string $categories): void |
|
86
|
|
|
{ |
|
87
|
|
|
$this->categories = $categories; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Returns includeSubcategories |
|
92
|
|
|
* |
|
93
|
|
|
* @return bool |
|
94
|
|
|
*/ |
|
95
|
|
|
public function getIncludeSubcategories(): bool |
|
96
|
|
|
{ |
|
97
|
|
|
return $this->includeSubcategories; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Sets includeSubcategories |
|
102
|
|
|
* |
|
103
|
|
|
* @param bool $includeSubcategories |
|
104
|
|
|
*/ |
|
105
|
|
|
public function setIncludeSubcategories(bool $includeSubcategories) |
|
106
|
|
|
{ |
|
107
|
|
|
$this->includeSubcategories = $includeSubcategories; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @return string |
|
112
|
|
|
*/ |
|
113
|
|
|
public function getOrderDirection(): string |
|
114
|
|
|
{ |
|
115
|
|
|
return $this->orderDirection; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* @param string $orderDirection |
|
120
|
|
|
*/ |
|
121
|
|
|
public function setOrderDirection(string $orderDirection): void |
|
122
|
|
|
{ |
|
123
|
|
|
$this->orderDirection = $orderDirection; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* @return string |
|
128
|
|
|
*/ |
|
129
|
|
|
public function getOrderField(): string |
|
130
|
|
|
{ |
|
131
|
|
|
return $this->orderField; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* @param string $orderField |
|
136
|
|
|
*/ |
|
137
|
|
|
public function setOrderField(string $orderField): void |
|
138
|
|
|
{ |
|
139
|
|
|
$this->orderField = $orderField; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* Creates a new CategoryDemand object from the given settings. Respects recursive setting for storage page |
|
144
|
|
|
* and extends all PIDs to children if set. |
|
145
|
|
|
* |
|
146
|
|
|
* @param array $settings |
|
147
|
|
|
* @return CategoryDemand |
|
148
|
|
|
*/ |
|
149
|
|
|
public static function createFromSettings(array $settings = []): CategoryDemand |
|
150
|
|
|
{ |
|
151
|
|
|
$demand = new CategoryDemand(); |
|
152
|
|
|
$demand->setStoragePage( |
|
153
|
|
|
PageUtility::extendPidListByChildren($settings['storagePage'] ?? '', $settings['recursive'] ?? 0) |
|
154
|
|
|
); |
|
155
|
|
|
$demand->setRestrictToStoragePage((bool)($settings['restrictForeignRecordsToStoragePage'] ?? false)); |
|
156
|
|
|
$demand->setCategories($settings['categoryMenu']['categories'] ?? ''); |
|
157
|
|
|
$demand->setIncludeSubcategories((bool)($settings['categoryMenu']['includeSubcategories'] ?? false)); |
|
158
|
|
|
$demand->setOrderField($settings['categoryMenu']['orderField'] ?? 'uid'); |
|
159
|
|
|
$demand->setOrderDirection($settings['categoryMenu']['orderDirection'] ?? 'asc'); |
|
160
|
|
|
return $demand; |
|
161
|
|
|
} |
|
162
|
|
|
} |
|
163
|
|
|
|