Completed
Push — master ( 36bbbe...f30a93 )
by Tim
02:07
created

Index::getSysLanguageUid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * Index information.
5
 */
6
declare(strict_types=1);
7
8
namespace HDNET\Calendarize\Domain\Model;
9
10
use HDNET\Calendarize\Exception;
11
use HDNET\Calendarize\Register;
12
use HDNET\Calendarize\Utility\DateTimeUtility;
13
use HDNET\Calendarize\Utility\EventUtility;
14
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
15
16
/**
17
 * Index information.
18
 *
19
 * @db
20
 * @smartExclude Workspaces
21
 */
22
class Index extends AbstractModel
23
{
24
    /**
25
     * The unique register key of the used table/model configuration.
26
     *
27
     * @var string
28
     * @db varchar(150) DEFAULT '' NOT NULL
29
     */
30
    protected $uniqueRegisterKey;
31
32
    /**
33
     * TableName.
34
     *
35
     * @var string
36
     * @db varchar(150) DEFAULT '' NOT NULL
37
     */
38
    protected $foreignTable;
39
40
    /**
41
     * The Id of the foreign element.
42
     *
43
     * @var int
44
     * @db
45
     */
46
    protected $foreignUid;
47
48
    /**
49
     * Start date.
50
     *
51
     * @var \DateTime
52
     * @db
53
     */
54
    protected $startDate;
55
56
    /**
57
     * End date.
58
     *
59
     * @var \DateTime
60
     * @db
61
     */
62
    protected $endDate;
63
64
    /**
65
     * Start time.
66
     *
67
     * @var int
68
     * @db
69
     */
70
    protected $startTime;
71
72
    /**
73
     * End time.
74
     *
75
     * @var int
76
     * @db
77
     */
78
    protected $endTime;
79
80
    /**
81
     * AllDay.
82
     *
83
     * @var bool
84
     * @db
85
     */
86
    protected $allDay;
87
88
    /**
89
     * State.
90
     *
91
     * @var string
92
     * @db
93
     */
94
    protected $state;
95
96
    /**
97
     * The original object.
98
     *
99
     * @var AbstractEntity
100
     */
101
    protected $originalObject;
102
103
    /**
104
     * Get the original record for the current index.
105
     *
106
     * @throws Exception
107
     *
108
     * @return AbstractEntity
109
     */
110
    public function getOriginalObject()
111
    {
112
        if (null === $this->originalObject) {
113
            $configuration = $this->getConfiguration();
114
            if (empty($configuration)) {
115
                throw new Exception('No valid configuration for the current index: ' . $this->getUniqueRegisterKey(), 123678123);
116
            }
117
            $this->originalObject = EventUtility::getOriginalRecordByConfiguration($configuration, (int) $this->getForeignUid());
118
        }
119
120
        return $this->originalObject;
121
    }
122
123
    /**
124
     * Get the current configuration.
125
     *
126
     * @return array
127
     */
128
    public function getConfiguration(): array
129
    {
130
        foreach (Register::getRegister() as $key => $configuration) {
131
            if ($this->getUniqueRegisterKey() === $key) {
132
                return $configuration;
133
            }
134
        }
135
136
        return [];
137
    }
138
139
    /**
140
     * Get the complete start date.
141
     *
142
     * @return \DateTime
143
     */
144
    public function getStartDateComplete()
145
    {
146
        $date = $this->getStartDate();
147
        if (!$this->isAllDay() && $date instanceof \DateTimeInterface) {
148
            $time = DateTimeUtility::normalizeDateTimeSingle($this->getStartTime());
149
150
            return \DateTime::createFromFormat('Y-m-d H:i', $date->format('Y-m-d') . ' ' . $time->format('H:i'));
0 ignored issues
show
Comprehensibility Best Practice introduced by
The expression \DateTime::createFromFor... $time->format('H:i')); of type DateTime|false adds false to the return on line 150 which is incompatible with the return type documented by HDNET\Calendarize\Domain...x::getStartDateComplete of type DateTime. It seems like you forgot to handle an error condition.
Loading history...
151
        }
152
153
        return $date;
154
    }
155
156
    /**
157
     * Get the complete end date.
158
     *
159
     * @return \DateTime
160
     */
161
    public function getEndDateComplete()
162
    {
163
        $date = $this->getEndDate();
164
        if (!$this->isAllDay() && $date instanceof \DateTimeInterface) {
165
            $time = DateTimeUtility::normalizeDateTimeSingle($this->getEndTime());
166
167
            return \DateTime::createFromFormat('Y-m-d H:i', $date->format('Y-m-d') . ' ' . $time->format('H:i'));
0 ignored issues
show
Comprehensibility Best Practice introduced by
The expression \DateTime::createFromFor... $time->format('H:i')); of type DateTime|false adds false to the return on line 167 which is incompatible with the return type documented by HDNET\Calendarize\Domain...dex::getEndDateComplete of type DateTime. It seems like you forgot to handle an error condition.
Loading history...
168
        }
169
170
        return $date;
171
    }
172
173
    /**
174
     * Set foreign uid.
175
     *
176
     * @param int $foreignUid
177
     */
178
    public function setForeignUid($foreignUid)
179
    {
180
        $this->foreignUid = $foreignUid;
181
    }
182
183
    /**
184
     * Get foreign uid.
185
     *
186
     * @return int
187
     */
188
    public function getForeignUid()
189
    {
190
        return $this->foreignUid;
191
    }
192
193
    /**
194
     * Set unique register key.
195
     *
196
     * @param string $uniqueRegisterKey
197
     */
198
    public function setUniqueRegisterKey($uniqueRegisterKey)
199
    {
200
        $this->uniqueRegisterKey = $uniqueRegisterKey;
201
    }
202
203
    /**
204
     * Get unique register key.
205
     *
206
     * @return string
207
     */
208
    public function getUniqueRegisterKey()
209
    {
210
        return $this->uniqueRegisterKey;
211
    }
212
213
    /**
214
     * Set foreign table.
215
     *
216
     * @param string $foreignTable
217
     */
218
    public function setForeignTable($foreignTable)
219
    {
220
        $this->foreignTable = $foreignTable;
221
    }
222
223
    /**
224
     * Get foreign table.
225
     *
226
     * @return string
227
     */
228
    public function getForeignTable()
229
    {
230
        return $this->foreignTable;
231
    }
232
233
    /**
234
     * Set all day.
235
     *
236
     * @param bool $allDay
237
     */
238
    public function setAllDay($allDay)
239
    {
240
        $this->allDay = $allDay;
241
    }
242
243
    /**
244
     * Is all day.
245
     *
246
     * @return bool
247
     */
248
    public function isAllDay()
249
    {
250
        return (bool) $this->allDay;
251
    }
252
253
    /**
254
     * Set end date.
255
     *
256
     * @param \DateTime $endDate
257
     */
258
    public function setEndDate($endDate)
259
    {
260
        $this->endDate = $endDate;
261
    }
262
263
    /**
264
     * Get end date.
265
     *
266
     * @return \DateTime
267
     */
268
    public function getEndDate()
269
    {
270
        return $this->endDate;
271
    }
272
273
    /**
274
     * Set end time.
275
     *
276
     * @param int $endTime
277
     */
278
    public function setEndTime($endTime)
279
    {
280
        $this->endTime = $endTime;
281
    }
282
283
    /**
284
     * Get end time.
285
     *
286
     * @return int
287
     */
288
    public function getEndTime()
289
    {
290
        return $this->endTime;
291
    }
292
293
    /**
294
     * Set start date.
295
     *
296
     * @param \DateTime $startDate
297
     */
298
    public function setStartDate($startDate)
299
    {
300
        $this->startDate = $startDate;
301
    }
302
303
    /**
304
     * Get start date.
305
     *
306
     * @return \DateTime
307
     */
308
    public function getStartDate()
309
    {
310
        return $this->startDate;
311
    }
312
313
    /**
314
     * Set start time.
315
     *
316
     * @param int $startTime
317
     */
318
    public function setStartTime($startTime)
319
    {
320
        $this->startTime = $startTime;
321
    }
322
323
    /**
324
     * Get start time.
325
     *
326
     * @return int
327
     */
328
    public function getStartTime()
329
    {
330
        return $this->startTime;
331
    }
332
333
    /**
334
     * Get state.
335
     *
336
     * @return string
337
     */
338
    public function getState()
339
    {
340
        return $this->state;
341
    }
342
343
    /**
344
     * Set state.
345
     *
346
     * @param string $state
347
     */
348
    public function setState($state)
349
    {
350
        $this->state = $state;
351
    }
352
353
    /**
354
     * Get sys language uid.
355
     *
356
     * @return int
357
     */
358
    public function getSysLanguageUid()
359
    {
360
        return (int) $this->_languageUid;
361
    }
362
}
363