1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
eventmodel.php
См. документацию.
1<?php
2
3namespace Bitrix\Calendar\Access\Model;
4
5use Bitrix\Calendar\Access\AccessibleEvent;
6use Bitrix\Calendar\Core\Event\Event;
7use Bitrix\Calendar\Core\Role\Role;
8use Bitrix\Main\Access\AccessibleItem;
9
11{
12 private static array $cache = [];
13
14 private int $id = 0;
15 private int $ownerId = 0;
16 private int $createdBy = 0;
17 private int $sectionId = 0;
18 private string $sectionType = '';
19 private string $eventType = '';
20 private string $meetingStatus = '';
21 private int $parentEventSectionId = 0;
22 private string $parentEventSectionType = '';
23 private int $parentEventOwnerId = 0;
24 private int $parentEventId = 0;
25 private ?int $eventCategoryId = null;
26 private ?array $attendeeIds = [];
27
28 public static function createFromId(int $itemId = 0): AccessibleItem
29 {
30 if ($itemId <= 0)
31 {
32 return self::createNew();
33 }
34
35 if (!isset(static::$cache[$itemId]))
36 {
37 $model = new self();
38 $model->setId($itemId);
39 static::$cache[$itemId] = $model;
40 }
41
42 return static::$cache[$itemId];
43 }
44
45 public static function createNew(): self
46 {
47 return new self();
48 }
49
50 public static function createFromArray(array $fields): self
51 {
52 if (($fields['ID'] ?? null) && (int)$fields['ID'])
53 {
54 $model = self::createFromId((int)$fields['ID']);
55 }
56 else
57 {
58 $model = self::createNew();
59 }
60
61 if (($fields['OWNER_ID'] ?? null) && (int)$fields['OWNER_ID'])
62 {
63 $model->setOwnerId($fields['OWNER_ID']);
64 }
65
66 if (($fields['CREATED_BY'] ?? null) && (int)$fields['CREATED_BY'])
67 {
68 $model->setCreatedBy($fields['CREATED_BY']);
69 }
70
71 if ($fields['SECTION_ID'] ?? null)
72 {
73 $model->setSectionId((int)$fields['SECTION_ID']);
74 }
75
76 if (($fields['CAL_TYPE'] ?? null) && is_string($fields['CAL_TYPE']))
77 {
78 $model->setSectionType($fields['CAL_TYPE']);
79 }
80
81 if (($fields['EVENT_TYPE'] ?? null) && is_string($fields['EVENT_TYPE']))
82 {
83 $model->setEventType($fields['EVENT_TYPE']);
84 }
85
86 if (($fields['MEETING_STATUS'] ?? null) && is_string($fields['MEETING_STATUS']))
87 {
88 $model->setMeetingStatus($fields['MEETING_STATUS']);
89 }
90
91 if ((int)($fields['PARENT_ID'] ?? null))
92 {
93 $model->setParentEventId((int)$fields['PARENT_ID']);
94 }
95
96 if (
97 (int)($fields['PARENT_ID'] ?? null)
98 && ($fields['ID'] ?? null) !== ($fields['PARENT_ID'] ?? null)
99 )
100 {
101 $parentFields = \CCalendarSect::GetSectionByEventId((int)$fields['PARENT_ID']);
102 if ($parentFields && is_array($parentFields))
103 {
104 $model->setParentEventSectionFields($parentFields);
105 }
106 }
107 elseif ((int)($fields['ID'] ?? null) && ($fields['ID'] ?? null) === ($fields['PARENT_ID'] ?? null))
108 {
109 $model->setParentEventSectionFields($fields);
110 }
111
112 if (!empty($fields['OPTIONS']['CATEGORY_ID']))
113 {
114 $model->setEventCategoryId((int)$fields['OPTIONS']['CATEGORY_ID']);
115 }
116
117 if (
118 !empty($fields['ATTENDEE_LIST'])
119 && $attendees = $fields['ATTENDEE_LIST']
120 )
121 {
122 $model->setAttendeeIds(array_map(fn(array $attendee) => (int)$attendee['id'], $attendees));
123 }
124
125 return $model;
126 }
127
128 public static function createFromObject(Event $event)
129 {
130 if ($event->getId() > 0)
131 {
132 $model = self::createFromId($event->getId());
133 }
134 else
135 {
136 $model = self::createNew();
137 }
138
139 $owner = $event->getOwner();
140 if ($owner instanceof Role)
141 {
142 $model->setOwnerId($owner->getId());
143 }
144
145 $creator = $event->getCreator();
146 if ($creator instanceof Role)
147 {
148 $model->setCreatedBy($creator->getId());
149 }
150
151 $model
152 ->setSectionId($event->getSection()->getId())
153 ->setSectionType($event->getSection()->getType())
154 ->setEventType($event->getSpecialLabel())
155 ->setMeetingStatus($event->getMeetingStatus())
156 ->setEventCategoryId($event->getEventOption()?->getCategoryId())
157 ->setAttendeeIds($event->getAttendeesCollection()?->getAttendeesIdCollection())
158 ;
159
160 $parentFields =\CCalendarSect::GetSectionByEventId($event->getParentId());
161 if ($parentFields && is_array($parentFields))
162 {
163 $model->setParentEventSectionFields($parentFields);
164 }
165
166 return $model;
167 }
168
170 {
171 if (($fields['OWNER_ID'] ?? null) && (int)$fields['OWNER_ID'])
172 {
173 $this->setParentEventOwnerId((int)$fields['OWNER_ID']);
174 }
175
176 if (($fields['SECTION_ID'] ?? null) && (int)$fields['SECTION_ID'])
177 {
178 $this->setParentEventSectionId((int)$fields['SECTION_ID']);
179 }
180
181 if (($fields['CAL_TYPE'] ?? null) && is_string($fields['CAL_TYPE']))
182 {
183 $this->setParentEventSectionType($fields['CAL_TYPE']);
184 }
185
186 return $this;
187 }
188
189 public function setId(int $id): self
190 {
191 $this->id = $id;
192
193 return $this;
194 }
195
196 public function getId(): int
197 {
198 return $this->id;
199 }
200
201 public function setOwnerId(int $ownerId): self
202 {
203 $this->ownerId = $ownerId;
204
205 return $this;
206 }
207
208 public function getOwnerId(): int
209 {
210 return $this->ownerId;
211 }
212
213 public function setCreatedBy(int $createdBy): self
214 {
215 $this->createdBy = $createdBy;
216
217 return $this;
218 }
219
220 public function getCreatedBy(): int
221 {
222 return $this->createdBy;
223 }
224
225 public function setSectionId(int $sectionId): self
226 {
227 $this->sectionId = $sectionId;
228
229 return $this;
230 }
231
232 public function getSectionId(): int
233 {
234 return $this->sectionId;
235 }
236
237 public function setSectionType(string $sectionType): self
238 {
239 $this->sectionType = $sectionType;
240
241 return $this;
242 }
243
244 public function getSectionType(): string
245 {
246 return $this->sectionType;
247 }
248
249 public function setEventType(string $eventType): self
250 {
251 $this->eventType = $eventType;
252
253 return $this;
254 }
255
256 public function getEventType(): string
257 {
258 return $this->eventType;
259 }
260
261 public function setMeetingStatus(string $meetingStatus): self
262 {
263 $this->meetingStatus = $meetingStatus;
264
265 return $this;
266 }
267
268 public function getMeetingStatus(): string
269 {
270 return $this->meetingStatus;
271 }
272
273 public function setParentEventSectionId(int $parentEventSectionId): self
274 {
275 $this->parentEventSectionId = $parentEventSectionId;
276
277 return $this;
278 }
279
280 public function setParentEventId(int $parentEventId): self
281 {
282 $this->parentEventId = $parentEventId;
283
284 return $this;
285 }
286
287 public function getParentEventSectionId(): int
288 {
289 return $this->parentEventSectionId;
290 }
291
292 public function setParentEventSectionType(string $parentEventSectionType): self
293 {
294 $this->parentEventSectionType = $parentEventSectionType;
295
296 return $this;
297 }
298
299 public function getParentEventSectionType(): string
300 {
301 return $this->parentEventSectionType;
302 }
303
304 public function setParentEventOwnerId(int $parentEventOwnerId): self
305 {
306 $this->parentEventOwnerId = $parentEventOwnerId;
307
308 return $this;
309 }
310 public function getParentEventOwnerId(): int
311 {
312 return $this->parentEventOwnerId;
313 }
314
315 public function getParentEventId(): int
316 {
317 return $this->parentEventId;
318 }
319
320 public function setEventCategoryId(?int $eventCategoryId): self
321 {
322 $this->eventCategoryId = $eventCategoryId;
323
324 return $this;
325 }
326
327 public function getEventCategoryId(): ?int
328 {
329 return $this->eventCategoryId;
330 }
331
332 public function setAttendeeIds(?array $attendeeIds): self
333 {
334 $this->attendeeIds = $attendeeIds ?? [];
335
336 return $this;
337 }
338
339 public function hasAttendee(int $userId): bool
340 {
341 return in_array($userId, $this->attendeeIds, true);
342 }
343
344 public function getCreatorId(): int
345 {
346 return $this->createdBy;
347 }
348}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
setEventType(string $eventType)
Определения eventmodel.php:249
static createFromObject(Event $event)
Определения eventmodel.php:128
setOwnerId(int $ownerId)
Определения eventmodel.php:201
setAttendeeIds(?array $attendeeIds)
Определения eventmodel.php:332
setParentEventSectionFields(array $fields)
Определения eventmodel.php:169
setMeetingStatus(string $meetingStatus)
Определения eventmodel.php:261
static createFromArray(array $fields)
Определения eventmodel.php:50
setParentEventOwnerId(int $parentEventOwnerId)
Определения eventmodel.php:304
setParentEventSectionId(int $parentEventSectionId)
Определения eventmodel.php:273
static createFromId(int $itemId=0)
Определения eventmodel.php:28
setSectionType(string $sectionType)
Определения eventmodel.php:237
setEventCategoryId(?int $eventCategoryId)
Определения eventmodel.php:320
setCreatedBy(int $createdBy)
Определения eventmodel.php:213
setSectionId(int $sectionId)
Определения eventmodel.php:225
setParentEventSectionType(string $parentEventSectionType)
Определения eventmodel.php:292
hasAttendee(int $userId)
Определения eventmodel.php:339
setParentEventId(int $parentEventId)
Определения eventmodel.php:280
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$event
Определения prolog_after.php:141
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$fields
Определения yandex_run.php:501