Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
eventmodel.php
1<?php
2
4
9
11{
12 private static array $cache = [];
13
14 private int $id = 0;
15 private int $ownerId = 0;
16 private int $sectionId = 0;
17 private string $sectionType = '';
18 private string $eventType = '';
19 private string $meetingStatus = '';
20 private int $parentEventSectionId = 0;
21 private string $parentEventSectionType = '';
22 private int $parentEventOwnerId = 0;
23 private int $parentEventId = 0;
24
25 public static function createFromId(int $itemId = 0): AccessibleItem
26 {
27 if ($itemId <= 0)
28 {
29 return self::createNew();
30 }
31
32 if (!isset(static::$cache[$itemId]))
33 {
34 $model = new self();
35 $model->setId($itemId);
36 static::$cache[$itemId] = $model;
37 }
38
39 return static::$cache[$itemId];
40 }
41
42 public static function createNew(): self
43 {
44 return new self();
45 }
46
47 public static function createFromArray(array $fields): self
48 {
49 if (($fields['ID'] ?? null) && (int)$fields['ID'])
50 {
51 $model = self::createFromId((int)$fields['ID']);
52 }
53 else
54 {
55 $model = self::createNew();
56 }
57
58 if (($fields['OWNER_ID'] ?? null) && (int)$fields['OWNER_ID'])
59 {
60 $model->setOwnerId($fields['OWNER_ID']);
61 }
62
63 if ($fields['SECTION_ID'] ?? null)
64 {
65 $model->setSectionId((int)$fields['SECTION_ID']);
66 }
67
68 if (($fields['CAL_TYPE'] ?? null) && is_string($fields['CAL_TYPE']))
69 {
70 $model->setSectionType($fields['CAL_TYPE']);
71 }
72
73 if (($fields['EVENT_TYPE'] ?? null) && is_string($fields['EVENT_TYPE']))
74 {
75 $model->setEventType($fields['EVENT_TYPE']);
76 }
77
78 if (($fields['MEETING_STATUS'] ?? null) && is_string($fields['MEETING_STATUS']))
79 {
80 $model->setMeetingStatus($fields['MEETING_STATUS']);
81 }
82
83 if ((int)($fields['PARENT_ID'] ?? null))
84 {
85 $model->setParentEventId((int)$fields['PARENT_ID']);
86 }
87
88 if (
89 (int)($fields['PARENT_ID'] ?? null)
90 && ($fields['ID'] ?? null) !== ($fields['PARENT_ID'] ?? null)
91 )
92 {
93 $parentFields = \CCalendarSect::GetSectionByEventId((int)$fields['PARENT_ID']);
94 if ($parentFields && is_array($parentFields))
95 {
96 $model->setParentEventSectionFields($parentFields);
97 }
98 }
99 elseif ((int)($fields['ID'] ?? null) && ($fields['ID'] ?? null) === ($fields['PARENT_ID'] ?? null))
100 {
101 $model->setParentEventSectionFields($fields);
102 }
103
104 return $model;
105 }
106
107 public static function createFromObject(Event $event)
108 {
109 if ($event->getId() > 0)
110 {
111 $model = self::createFromId($event->getId());
112 }
113 else
114 {
115 $model = self::createNew();
116 }
117
118 $owner = $event->getOwner();
119 if ($owner instanceof Role)
120 {
121 $model->setOwnerId($owner->getId());
122 }
123
124 $model
125 ->setSectionId($event->getSection()->getId())
126 ->setSectionType($event->getSection()->getType())
127 ->setEventType($event->getSpecialLabel())
128 ->setMeetingStatus($event->getMeetingStatus())
129 ;
130
131 $parentFields =\CCalendarSect::GetSectionByEventId($event->getParentId());
132 if ($parentFields && is_array($parentFields))
133 {
134 $model->setParentEventSectionFields($parentFields);
135 }
136
137 return $model;
138 }
139
140 public function setParentEventSectionFields(array $fields): self
141 {
142 if (($fields['OWNER_ID'] ?? null) && (int)$fields['OWNER_ID'])
143 {
144 $this->setParentEventOwnerId((int)$fields['OWNER_ID']);
145 }
146
147 if (($fields['SECTION_ID'] ?? null) && (int)$fields['SECTION_ID'])
148 {
149 $this->setParentEventSectionId((int)$fields['SECTION_ID']);
150 }
151
152 if (($fields['CAL_TYPE'] ?? null) && is_string($fields['CAL_TYPE']))
153 {
154 $this->setParentEventSectionType($fields['CAL_TYPE']);
155 }
156
157 return $this;
158 }
159
160 public function setId(int $id): self
161 {
162 $this->id = $id;
163
164 return $this;
165 }
166
167 public function getId(): int
168 {
169 return $this->id;
170 }
171
172 public function setOwnerId(int $ownerId): self
173 {
174 $this->ownerId = $ownerId;
175
176 return $this;
177 }
178
179 public function getOwnerId(): int
180 {
181 return $this->ownerId;
182 }
183
184 public function setSectionId(int $sectionId): self
185 {
186 $this->sectionId = $sectionId;
187
188 return $this;
189 }
190
191 public function getSectionId(): int
192 {
193 return $this->sectionId;
194 }
195
196 public function setSectionType(string $sectionType): self
197 {
198 $this->sectionType = $sectionType;
199
200 return $this;
201 }
202
203 public function getSectionType(): string
204 {
205 return $this->sectionType;
206 }
207
208 public function setEventType(string $eventType): self
209 {
210 $this->eventType = $eventType;
211
212 return $this;
213 }
214
215 public function getEventType(): string
216 {
217 return $this->eventType;
218 }
219
220 public function setMeetingStatus(string $meetingStatus): self
221 {
222 $this->meetingStatus = $meetingStatus;
223
224 return $this;
225 }
226
227 public function getMeetingStatus(): string
228 {
229 return $this->meetingStatus;
230 }
231
232 public function setParentEventSectionId(int $parentEventSectionId): self
233 {
234 $this->parentEventSectionId = $parentEventSectionId;
235
236 return $this;
237 }
238
239 public function setParentEventId(int $parentEventId): self
240 {
241 $this->parentEventId = $parentEventId;
242
243 return $this;
244 }
245
246 public function getParentEventSectionId(): int
247 {
248 return $this->parentEventSectionId;
249 }
250
251 public function setParentEventSectionType(string $parentEventSectionType): self
252 {
253 $this->parentEventSectionType = $parentEventSectionType;
254
255 return $this;
256 }
257
258 public function getParentEventSectionType(): string
259 {
260 return $this->parentEventSectionType;
261 }
262
263 public function setParentEventOwnerId(int $parentEventOwnerId): self
264 {
265 $this->parentEventOwnerId = $parentEventOwnerId;
266
267 return $this;
268 }
269 public function getParentEventOwnerId(): int
270 {
271 return $this->parentEventOwnerId;
272 }
273
274 public function getParentEventId(): int
275 {
276 return $this->parentEventId;
277 }
278}
setMeetingStatus(string $meetingStatus)
static createFromArray(array $fields)
setParentEventOwnerId(int $parentEventOwnerId)
setParentEventSectionId(int $parentEventSectionId)
setParentEventSectionType(string $parentEventSectionType)