1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Index information |
4
|
|
|
* |
5
|
|
|
* @author Tim Lochmüller |
6
|
|
|
*/ |
7
|
|
|
namespace HDNET\Calendarize\Domain\Model; |
8
|
|
|
|
9
|
|
|
use HDNET\Calendarize\Exception; |
10
|
|
|
use HDNET\Calendarize\Register; |
11
|
|
|
use HDNET\Calendarize\Utility\DateTimeUtility; |
12
|
|
|
use HDNET\Calendarize\Utility\EventUtility; |
13
|
|
|
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Index information |
17
|
|
|
* |
18
|
|
|
* @db |
19
|
|
|
* @smartExclude Workspaces |
20
|
|
|
*/ |
21
|
|
|
class Index extends AbstractModel |
22
|
|
|
{ |
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
|
|
|
* @return AbstractEntity |
107
|
|
|
* @throws Exception |
108
|
|
|
*/ |
109
|
|
|
public function getOriginalObject() |
110
|
|
|
{ |
111
|
|
|
if ($this->originalObject === null) { |
112
|
|
|
$configuration = $this->getConfiguration(); |
113
|
|
|
if ($configuration === null) { |
114
|
|
|
throw new Exception('No valid configuration for the current index: ' . $this->getUniqueRegisterKey(), 123678123); |
115
|
|
|
} |
116
|
|
|
$this->originalObject = EventUtility::getOriginalRecordByConfiguration($configuration, $this->getForeignUid()); |
117
|
|
|
} |
118
|
|
|
return $this->originalObject; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Get the current configuration |
123
|
|
|
* |
124
|
|
|
* @return null|array |
125
|
|
|
*/ |
126
|
|
|
public function getConfiguration() |
127
|
|
|
{ |
128
|
|
|
foreach (Register::getRegister() as $key => $configuration) { |
129
|
|
|
if ($this->getUniqueRegisterKey() == $key) { |
130
|
|
|
return $configuration; |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
return null; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Get the complete start date |
138
|
|
|
* |
139
|
|
|
* @return \DateTime |
140
|
|
|
*/ |
141
|
|
|
public function getStartDateComplete() |
142
|
|
|
{ |
143
|
|
|
$date = $this->getStartDate(); |
144
|
|
|
if (!$this->isAllDay() && $date instanceof \DateTimeInterface) { |
145
|
|
|
$time = DateTimeUtility::normalizeDateTimeSingle($this->getStartTime()); |
146
|
|
|
$date->setTime($time->format('H'), $time->format('i'), 0); |
147
|
|
|
} |
148
|
|
|
return $date; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Get the complete end date |
153
|
|
|
* |
154
|
|
|
* @return \DateTime |
155
|
|
|
*/ |
156
|
|
|
public function getEndDateComplete() |
157
|
|
|
{ |
158
|
|
|
$date = $this->getEndDate(); |
159
|
|
|
if (!$this->isAllDay() && $date instanceof \DateTimeInterface) { |
160
|
|
|
$time = DateTimeUtility::normalizeDateTimeSingle($this->getEndTime()); |
161
|
|
|
$date->setTime($time->format('H'), $time->format('i'), 0); |
162
|
|
|
} |
163
|
|
|
return $date; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Set foreign uid |
168
|
|
|
* |
169
|
|
|
* @param int $foreignUid |
170
|
|
|
*/ |
171
|
|
|
public function setForeignUid($foreignUid) |
172
|
|
|
{ |
173
|
|
|
$this->foreignUid = $foreignUid; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* Get foreign uid |
178
|
|
|
* |
179
|
|
|
* @return int |
180
|
|
|
*/ |
181
|
|
|
public function getForeignUid() |
182
|
|
|
{ |
183
|
|
|
return $this->foreignUid; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Set unique register key |
188
|
|
|
* |
189
|
|
|
* @param string $uniqueRegisterKey |
190
|
|
|
*/ |
191
|
|
|
public function setUniqueRegisterKey($uniqueRegisterKey) |
192
|
|
|
{ |
193
|
|
|
$this->uniqueRegisterKey = $uniqueRegisterKey; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* Get unique register key |
198
|
|
|
* |
199
|
|
|
* @return string |
200
|
|
|
*/ |
201
|
|
|
public function getUniqueRegisterKey() |
202
|
|
|
{ |
203
|
|
|
return $this->uniqueRegisterKey; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* Set foreign table |
208
|
|
|
* |
209
|
|
|
* @param string $foreignTable |
210
|
|
|
*/ |
211
|
|
|
public function setForeignTable($foreignTable) |
212
|
|
|
{ |
213
|
|
|
$this->foreignTable = $foreignTable; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* Get foreign table |
218
|
|
|
* |
219
|
|
|
* @return string |
220
|
|
|
*/ |
221
|
|
|
public function getForeignTable() |
222
|
|
|
{ |
223
|
|
|
return $this->foreignTable; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* Set all day |
228
|
|
|
* |
229
|
|
|
* @param bool $allDay |
230
|
|
|
*/ |
231
|
|
|
public function setAllDay($allDay) |
232
|
|
|
{ |
233
|
|
|
$this->allDay = $allDay; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* Is all day |
238
|
|
|
* |
239
|
|
|
* @return bool |
240
|
|
|
*/ |
241
|
|
|
public function isAllDay() |
242
|
|
|
{ |
243
|
|
|
return (bool)$this->allDay; |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* Set end date |
248
|
|
|
* |
249
|
|
|
* @param \DateTime $endDate |
250
|
|
|
*/ |
251
|
|
|
public function setEndDate($endDate) |
252
|
|
|
{ |
253
|
|
|
$this->endDate = $endDate; |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* Get end date |
258
|
|
|
* |
259
|
|
|
* @return \DateTime |
260
|
|
|
*/ |
261
|
|
|
public function getEndDate() |
262
|
|
|
{ |
263
|
|
|
return $this->endDate; |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* Set end time |
268
|
|
|
* |
269
|
|
|
* @param int $endTime |
270
|
|
|
*/ |
271
|
|
|
public function setEndTime($endTime) |
272
|
|
|
{ |
273
|
|
|
$this->endTime = $endTime; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* Get end time |
278
|
|
|
* |
279
|
|
|
* @return int |
280
|
|
|
*/ |
281
|
|
|
public function getEndTime() |
282
|
|
|
{ |
283
|
|
|
return $this->endTime; |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
/** |
287
|
|
|
* Set start date |
288
|
|
|
* |
289
|
|
|
* @param \DateTime $startDate |
290
|
|
|
*/ |
291
|
|
|
public function setStartDate($startDate) |
292
|
|
|
{ |
293
|
|
|
$this->startDate = $startDate; |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
/** |
297
|
|
|
* Get start date |
298
|
|
|
* |
299
|
|
|
* @return \DateTime |
300
|
|
|
*/ |
301
|
|
|
public function getStartDate() |
302
|
|
|
{ |
303
|
|
|
return $this->startDate; |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* Set start time |
308
|
|
|
* |
309
|
|
|
* @param int $startTime |
310
|
|
|
*/ |
311
|
|
|
public function setStartTime($startTime) |
312
|
|
|
{ |
313
|
|
|
$this->startTime = $startTime; |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
/** |
317
|
|
|
* Get start time |
318
|
|
|
* |
319
|
|
|
* @return int |
320
|
|
|
*/ |
321
|
|
|
public function getStartTime() |
322
|
|
|
{ |
323
|
|
|
return $this->startTime; |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
/** |
327
|
|
|
* Get state |
328
|
|
|
* |
329
|
|
|
* @return string |
330
|
|
|
*/ |
331
|
|
|
public function getState() |
332
|
|
|
{ |
333
|
|
|
return $this->state; |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
/** |
337
|
|
|
* Set state |
338
|
|
|
* |
339
|
|
|
* @param string $state |
340
|
|
|
*/ |
341
|
|
|
public function setState($state) |
342
|
|
|
{ |
343
|
|
|
$this->state = $state; |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
} |
347
|
|
|
|