Passed
Push — master ( af9933...6d2375 )
by Torben
04:41 queued 01:21
created

EventDemand::createFromSettings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

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