Passed
Push — typo3_11 ( 4e402e...fb5d91 )
by Torben
41:22
created

EventDemand::createFromSettings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 21
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 27
rs 9.584
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\Domain\Model\Location;
16
use DERHANSEN\SfEventMgt\Domain\Model\Organisator;
17
use DERHANSEN\SfEventMgt\Domain\Model\Speaker;
18
use DERHANSEN\SfEventMgt\Utility\PageUtility;
19
20
/**
21
 * Event demand
22
 */
23
class EventDemand
24
{
25
    protected string $displayMode = 'all';
26
    protected string $storagePage = '';
27
    protected ?DateTime $currentDateTime = null;
28
    protected string $category = '';
29
    protected bool $includeSubcategories = false;
30
    protected string $categoryConjunction = '';
31
    protected int $topEventRestriction = 0;
32
    protected string $orderField = '';
33
    protected string $orderFieldAllowed = '';
34
    protected string $orderDirection = '';
35
    protected int $queryLimit = 0;
36
    protected string $locationCity = '';
37
    protected string $locationCountry = '';
38
    protected int $year = 0;
39
    protected int $month = 0;
40
    protected int $day = 0;
41
    protected ?SearchDemand $searchDemand = null;
42
    protected bool $ignoreEnableFields = false;
43
    protected string $timeRestrictionLow = '';
44
    protected string $timeRestrictionHigh = '';
45
    protected bool $includeCurrent = false;
46
47
    /**
48
     * Can be an object (if set by code/property mapper) or a string if set by settings array from plugin
49
     *
50
     * @var Location|string|null
51
     */
52
    protected $location = null;
53
54
    /**
55
     * Can be an object (if set by code/property mapper) or a string if set by settings array from plugin
56
     *
57
     * @var Speaker|string|null
58
     */
59
    protected $speaker = null;
60
61
    /**
62
     * Can be an object (if set by code/property mapper) or a string if set by settings array from plugin
63
     *
64
     * @var Organisator|string|null
65
     */
66
    protected $organisator = null;
67
68
    public function getDisplayMode(): string
69
    {
70
        return $this->displayMode;
71
    }
72
73
    public function setDisplayMode(string $displayMode): void
74
    {
75
        $this->displayMode = $displayMode;
76
    }
77
78
    public function getStoragePage(): string
79
    {
80
        return $this->storagePage;
81
    }
82
83
    public function setStoragePage(string $storagePage): void
84
    {
85
        $this->storagePage = $storagePage;
86
    }
87
88
    public function setCurrentDateTime(DateTime $currentDateTime): void
89
    {
90
        $this->currentDateTime = $currentDateTime;
91
    }
92
93
    public function getCurrentDateTime(): DateTime
94
    {
95
        return $this->currentDateTime ?? new \DateTime();
96
    }
97
98
    public function setCategory(string $category): void
99
    {
100
        $this->category = $category;
101
    }
102
103
    public function getCategory(): string
104
    {
105
        return $this->category;
106
    }
107
108
    public function getIncludeSubcategories(): bool
109
    {
110
        return $this->includeSubcategories;
111
    }
112
113
    public function setIncludeSubcategories(bool $includeSubcategories): void
114
    {
115
        $this->includeSubcategories = $includeSubcategories;
116
    }
117
118
    public function getTopEventRestriction(): int
119
    {
120
        return $this->topEventRestriction;
121
    }
122
123
    public function setTopEventRestriction(int $topEventRestriction): void
124
    {
125
        $this->topEventRestriction = $topEventRestriction;
126
    }
127
128
    public function getOrderDirection(): string
129
    {
130
        return $this->orderDirection;
131
    }
132
133
    public function setOrderDirection(string $orderDirection): void
134
    {
135
        $this->orderDirection = $orderDirection;
136
    }
137
138
    public function getOrderField(): string
139
    {
140
        return $this->orderField;
141
    }
142
143
    public function setOrderField(string $orderField): void
144
    {
145
        $this->orderField = $orderField;
146
    }
147
148
    public function getOrderFieldAllowed(): string
149
    {
150
        return $this->orderFieldAllowed;
151
    }
152
153
    public function setOrderFieldAllowed(string $orderFieldAllowed): void
154
    {
155
        $this->orderFieldAllowed = $orderFieldAllowed;
156
    }
157
158
    public function getQueryLimit(): int
159
    {
160
        return $this->queryLimit;
161
    }
162
163
    public function setQueryLimit(int $queryLimit): void
164
    {
165
        $this->queryLimit = $queryLimit;
166
    }
167
168
    public function getLocationCity(): string
169
    {
170
        return $this->locationCity;
171
    }
172
173
    public function setLocationCity(string $locationCity): void
174
    {
175
        $this->locationCity = $locationCity;
176
    }
177
178
    public function getLocationCountry(): string
179
    {
180
        return $this->locationCountry;
181
    }
182
183
    public function setLocationCountry(string $locationCountry): void
184
    {
185
        $this->locationCountry = $locationCountry;
186
    }
187
188
    public function getYear(): int
189
    {
190
        return $this->year;
191
    }
192
193
    public function setYear(int $year): void
194
    {
195
        $this->year = $year;
196
    }
197
198
    public function getMonth(): int
199
    {
200
        return $this->month;
201
    }
202
203
    public function setMonth(int $month): void
204
    {
205
        $this->month = $month;
206
    }
207
208
    public function getDay(): int
209
    {
210
        return $this->day;
211
    }
212
213
    public function setDay(int $day): void
214
    {
215
        $this->day = $day;
216
    }
217
218
    public function getSearchDemand(): ?SearchDemand
219
    {
220
        return $this->searchDemand;
221
    }
222
223
    public function setSearchDemand(?SearchDemand $searchDemand): void
224
    {
225
        $this->searchDemand = $searchDemand;
226
    }
227
228
    public function getCategoryConjunction(): string
229
    {
230
        return $this->categoryConjunction;
231
    }
232
233
    public function setCategoryConjunction(string $categoryConjunction): void
234
    {
235
        $this->categoryConjunction = $categoryConjunction;
236
    }
237
238
    public function getIgnoreEnableFields(): bool
239
    {
240
        return $this->ignoreEnableFields;
241
    }
242
243
    public function setIgnoreEnableFields(bool $ignoreEnableFields): void
244
    {
245
        $this->ignoreEnableFields = $ignoreEnableFields;
246
    }
247
248
    public function getTimeRestrictionLow(): string
249
    {
250
        return $this->timeRestrictionLow;
251
    }
252
253
    public function setTimeRestrictionLow(string $timeRestrictionLow): void
254
    {
255
        $this->timeRestrictionLow = $timeRestrictionLow;
256
    }
257
258
    public function getTimeRestrictionHigh(): string
259
    {
260
        return $this->timeRestrictionHigh;
261
    }
262
263
    public function setTimeRestrictionHigh(string $timeRestrictionHigh): void
264
    {
265
        $this->timeRestrictionHigh = $timeRestrictionHigh;
266
    }
267
268
    public function getIncludeCurrent(): bool
269
    {
270
        return $this->includeCurrent;
271
    }
272
273
    public function setIncludeCurrent(bool $includeCurrent): void
274
    {
275
        $this->includeCurrent = $includeCurrent;
276
    }
277
278
    /**
279
     * @return Location|string|null
280
     */
281
    public function getLocation()
282
    {
283
        return $this->location;
284
    }
285
286
    /**
287
     * @param Location|string|null $location
288
     */
289
    public function setLocation($location): void
290
    {
291
        $this->location = $location;
292
    }
293
294
    /**
295
     * @return Speaker|string|null
296
     */
297
    public function getSpeaker()
298
    {
299
        return $this->speaker;
300
    }
301
302
    /**
303
     * @param Speaker|string|null $speaker
304
     */
305
    public function setSpeaker($speaker): void
306
    {
307
        $this->speaker = $speaker;
308
    }
309
310
    /**
311
     * @return Organisator|string|null
312
     */
313
    public function getOrganisator()
314
    {
315
        return $this->organisator;
316
    }
317
318
    /**
319
     * @param Organisator|string|null $organisator
320
     */
321
    public function setOrganisator($organisator): void
322
    {
323
        $this->organisator = $organisator;
324
    }
325
326
    /**
327
     * Creates a new EventDemand object from the given settings. Respects recursive setting for storage page
328
     * and extends all PIDs to children if set.
329
     *
330
     * @param array $settings
331
     * @return EventDemand
332
     */
333
    public static function createFromSettings(array $settings = []): self
334
    {
335
        $demand = new EventDemand();
336
337
        $demand->setDisplayMode($settings['displayMode'] ?? 'all');
338
        $demand->setStoragePage(
339
            PageUtility::extendPidListByChildren(
340
                (string)($settings['storagePage'] ?? ''),
341
                (int)($settings['recursive'] ?? 0)
342
            )
343
        );
344
        $demand->setCategoryConjunction($settings['categoryConjunction'] ?? '');
345
        $demand->setCategory($settings['category'] ?? '');
346
        $demand->setIncludeSubcategories((bool)($settings['includeSubcategories'] ?? false));
347
        $demand->setTopEventRestriction((int)($settings['topEventRestriction'] ?? 0));
348
        $demand->setOrderField($settings['orderField'] ?? '');
349
        $demand->setOrderFieldAllowed($settings['orderFieldAllowed'] ?? '');
350
        $demand->setOrderDirection($settings['orderDirection'] ?? '');
351
        $demand->setQueryLimit((int)($settings['queryLimit'] ?? 0));
352
        $demand->setTimeRestrictionLow($settings['timeRestrictionLow'] ?? '');
353
        $demand->setTimeRestrictionHigh($settings['timeRestrictionHigh'] ?? '');
354
        $demand->setIncludeCurrent((bool)($settings['includeCurrent'] ?? false));
355
        $demand->setLocation($settings['location']);
356
        $demand->setOrganisator($settings['organisator']);
357
        $demand->setSpeaker($settings['speaker']);
358
359
        return $demand;
360
    }
361
}
362