Completed
Push — master ( a12d02...89c10f )
by Tim
02:20
created

Index   A

Complexity

Total Complexity 35

Size/Duplication

Total Lines 387
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 5

Importance

Changes 0
Metric Value
wmc 35
lcom 3
cbo 5
dl 0
loc 387
rs 9.6
c 0
b 0
f 0

27 Methods

Rating   Name   Duplication   Size   Complexity  
A getOriginalObject() 0 12 3
A getConfiguration() 0 10 3
A getStartDateComplete() 0 9 3
A getEndDateComplete() 0 9 3
A setForeignUid() 0 4 1
A getForeignUid() 0 4 1
A setUniqueRegisterKey() 0 4 1
A getUniqueRegisterKey() 0 4 1
A setForeignTable() 0 4 1
A getForeignTable() 0 4 1
A setAllDay() 0 4 1
A isAllDay() 0 4 1
A setEndDate() 0 4 1
A getEndDate() 0 4 1
A setEndTime() 0 4 1
A getEndTime() 0 4 1
A setStartDate() 0 4 1
A getStartDate() 0 4 1
A setStartTime() 0 4 1
A getStartTime() 0 4 1
A getState() 0 4 1
A setState() 0 4 1
A getSysLanguageUid() 0 4 1
A isOpenEndTime() 0 4 1
A setOpenEndTime() 0 4 1
A getSlug() 0 4 1
A setSlug() 0 4 1
1
<?php
2
3
/**
4
 * Index information.
5
 */
6
declare(strict_types=1);
7
8
namespace HDNET\Calendarize\Domain\Model;
9
10
use HDNET\Autoloader\Annotation\DatabaseField;
11
use HDNET\Autoloader\Annotation\DatabaseTable;
12
use HDNET\Autoloader\Annotation\SmartExclude;
13
use HDNET\Calendarize\Exception\InvalidConfigurationException;
14
use HDNET\Calendarize\Register;
15
use HDNET\Calendarize\Utility\DateTimeUtility;
16
use HDNET\Calendarize\Utility\EventUtility;
17
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
18
19
/**
20
 * Index information.
21
 *
22
 * @DatabaseTable
23
 * @SmartExclude(excludes={"Workspaces"})
24
 */
25
class Index extends AbstractModel
26
{
27
    /**
28
     * The unique register key of the used table/model configuration.
29
     *
30
     * @var string
31
     * @DatabaseField(sql="varchar(150) DEFAULT '' NOT NULL")
32
     */
33
    protected $uniqueRegisterKey;
34
35
    /**
36
     * TableName.
37
     *
38
     * @var string
39
     * @DatabaseField(sql="varchar(150) DEFAULT '' NOT NULL")
40
     */
41
    protected $foreignTable;
42
43
    /**
44
     * The Id of the foreign element.
45
     *
46
     * @var int
47
     * @DatabaseField("int")
48
     */
49
    protected $foreignUid;
50
51
    /**
52
     * Start date.
53
     *
54
     * @var \DateTime|null
55
     * @DatabaseField(sql="date default NULL")
56
     */
57
    protected $startDate;
58
59
    /**
60
     * End date.
61
     *
62
     * @var \DateTime|null
63
     * @DatabaseField(sql="date default NULL")
64
     */
65
    protected $endDate;
66
67
    /**
68
     * Start time.
69
     *
70
     * @var int
71
     * @DatabaseField("int")
72
     */
73
    protected $startTime;
74
75
    /**
76
     * End time.
77
     *
78
     * @var int
79
     * @DatabaseField("int")
80
     */
81
    protected $endTime;
82
83
    /**
84
     * AllDay.
85
     *
86
     * @var bool
87
     * @DatabaseField("bool")
88
     */
89
    protected $allDay;
90
91
    /**
92
     * OpenEndTime.
93
     *
94
     * @var bool
95
     * @DatabaseField("bool")
96
     */
97
    protected $openEndTime;
98
99
    /**
100
     * State.
101
     *
102
     * @var string
103
     * @DatabaseField("string")
104
     */
105
    protected $state;
106
107
    /**
108
     * The original object.
109
     *
110
     * @var AbstractEntity
111
     */
112
    protected $originalObject;
113
114
    /**
115
     * Slug.
116
     *
117
     * @var string
118
     * @DatabaseField("string")
119
     */
120
    protected $slug = '';
121
122
    /**
123
     * Get the original record for the current index.
124
     *
125
     * @return AbstractEntity
126
     *
127
     * @throws InvalidConfigurationException
128
     */
129
    public function getOriginalObject()
130
    {
131
        if (null === $this->originalObject) {
132
            $configuration = $this->getConfiguration();
133
            if (empty($configuration)) {
134
                throw new InvalidConfigurationException('No valid configuration for the current index: ' . $this->getUniqueRegisterKey(), 123678123);
135
            }
136
            $this->originalObject = EventUtility::getOriginalRecordByConfiguration($configuration, (int)$this->getForeignUid());
137
        }
138
139
        return $this->originalObject;
140
    }
141
142
    /**
143
     * Get the current configuration.
144
     *
145
     * @return array
146
     */
147
    public function getConfiguration(): array
148
    {
149
        foreach (Register::getRegister() as $key => $configuration) {
150
            if ($this->getUniqueRegisterKey() === $key) {
151
                return $configuration;
152
            }
153
        }
154
155
        return [];
156
    }
157
158
    /**
159
     * Get the complete start date.
160
     *
161
     * @return \DateTime|null
162
     */
163
    public function getStartDateComplete(): ?\DateTime
164
    {
165
        $date = $this->getStartDate();
166
        if (!$this->isAllDay() && $date instanceof \DateTimeInterface) {
167
            return DateTimeUtility::setSecondsOfDateTime($date, $this->getStartTime());
168
        }
169
170
        return $date;
171
    }
172
173
    /**
174
     * Get the complete end date.
175
     *
176
     * @return \DateTime|null
177
     */
178
    public function getEndDateComplete(): ?\DateTime
179
    {
180
        $date = $this->getEndDate();
181
        if (!$this->isAllDay() && $date instanceof \DateTimeInterface) {
182
            return DateTimeUtility::setSecondsOfDateTime($date, $this->getEndTime());
183
        }
184
185
        return $date;
186
    }
187
188
    /**
189
     * Set foreign uid.
190
     *
191
     * @param int $foreignUid
192
     */
193
    public function setForeignUid($foreignUid)
194
    {
195
        $this->foreignUid = $foreignUid;
196
    }
197
198
    /**
199
     * Get foreign uid.
200
     *
201
     * @return int
202
     */
203
    public function getForeignUid()
204
    {
205
        return $this->foreignUid;
206
    }
207
208
    /**
209
     * Set unique register key.
210
     *
211
     * @param string $uniqueRegisterKey
212
     */
213
    public function setUniqueRegisterKey($uniqueRegisterKey)
214
    {
215
        $this->uniqueRegisterKey = $uniqueRegisterKey;
216
    }
217
218
    /**
219
     * Get unique register key.
220
     *
221
     * @return string
222
     */
223
    public function getUniqueRegisterKey()
224
    {
225
        return $this->uniqueRegisterKey;
226
    }
227
228
    /**
229
     * Set foreign table.
230
     *
231
     * @param string $foreignTable
232
     */
233
    public function setForeignTable($foreignTable)
234
    {
235
        $this->foreignTable = $foreignTable;
236
    }
237
238
    /**
239
     * Get foreign table.
240
     *
241
     * @return string
242
     */
243
    public function getForeignTable()
244
    {
245
        return $this->foreignTable;
246
    }
247
248
    /**
249
     * Set all day.
250
     *
251
     * @param bool $allDay
252
     */
253
    public function setAllDay($allDay)
254
    {
255
        $this->allDay = $allDay;
256
    }
257
258
    /**
259
     * Is all day.
260
     *
261
     * @return bool
262
     */
263
    public function isAllDay()
264
    {
265
        return (bool)$this->allDay;
266
    }
267
268
    /**
269
     * Set end date.
270
     *
271
     * @param \DateTime|null $endDate
272
     */
273
    public function setEndDate(?\DateTime $endDate): void
274
    {
275
        $this->endDate = DateTimeUtility::fixDateTimeForDb($endDate);
276
    }
277
278
    /**
279
     * Get end date.
280
     *
281
     * @return \DateTime|null
282
     */
283
    public function getEndDate(): ?\DateTime
284
    {
285
        return DateTimeUtility::fixDateTimeForExtbase($this->endDate);
286
    }
287
288
    /**
289
     * Set end time.
290
     *
291
     * @param int $endTime
292
     */
293
    public function setEndTime($endTime)
294
    {
295
        $this->endTime = $endTime;
296
    }
297
298
    /**
299
     * Get end time.
300
     *
301
     * @return int
302
     */
303
    public function getEndTime()
304
    {
305
        return $this->endTime;
306
    }
307
308
    /**
309
     * Set start date.
310
     *
311
     * @param \DateTime|null $startDate
312
     */
313
    public function setStartDate(?\DateTime $startDate): void
314
    {
315
        $this->startDate = DateTimeUtility::fixDateTimeForDb($startDate);
316
    }
317
318
    /**
319
     * Get start date.
320
     *
321
     * @return \DateTime|null
322
     */
323
    public function getStartDate(): ?\DateTime
324
    {
325
        return DateTimeUtility::fixDateTimeForExtbase($this->startDate);
326
    }
327
328
    /**
329
     * Set start time.
330
     *
331
     * @param int $startTime
332
     */
333
    public function setStartTime($startTime)
334
    {
335
        $this->startTime = $startTime;
336
    }
337
338
    /**
339
     * Get start time.
340
     *
341
     * @return int
342
     */
343
    public function getStartTime()
344
    {
345
        return $this->startTime;
346
    }
347
348
    /**
349
     * Get state.
350
     *
351
     * @return string
352
     */
353
    public function getState()
354
    {
355
        return $this->state;
356
    }
357
358
    /**
359
     * Set state.
360
     *
361
     * @param string $state
362
     */
363
    public function setState($state)
364
    {
365
        $this->state = $state;
366
    }
367
368
    /**
369
     * Get sys language uid.
370
     *
371
     * @return int
372
     */
373
    public function getSysLanguageUid()
374
    {
375
        return (int)$this->_languageUid;
376
    }
377
378
    /**
379
     * @return bool
380
     */
381
    public function isOpenEndTime()
382
    {
383
        return $this->openEndTime;
384
    }
385
386
    /**
387
     * @param bool $openEndTime
388
     */
389
    public function setOpenEndTime($openEndTime)
390
    {
391
        $this->openEndTime = $openEndTime;
392
    }
393
394
    /**
395
     * @return string
396
     */
397
    public function getSlug(): string
398
    {
399
        return $this->slug;
400
    }
401
402
    /**
403
     * @param string $slug
404
     */
405
    public function setSlug(string $slug): void
406
    {
407
        $this->slug = $slug;
408
    }
409
410
411
}
412