1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
EventOptionService.php
См. документацию.
1<?php
2
4
14
16{
17 private static ?self $instance;
18
19 public static function getInstance(): self
20 {
21 self::$instance ??= new self();
22
23 return self::$instance;
24 }
25
26 public function onEventCreated(int $eventId, CreateEventCommand $createEventCommand, int $threadId): void
27 {
29 $mapperFactory = ServiceLocator::getInstance()->get('calendar.service.mappers.factory');
30 $event = $mapperFactory->getEvent()->getById($eventId);
31 if (!$event)
32 {
33 return;
34 }
35
36 // create event options entity only for open_event
37 if (!$this->isOpenEvent($event))
38 {
39 return;
40 }
41
42 $eventOption = $this->createEventOption(
43 eventId: $event->getId(),
44 categoryId: $createEventCommand->getCategory(),
45 threadId: $threadId,
46 maxAttendees: $createEventCommand->getMaxAttendees(),
47 );
48 $event->setEventOption($eventOption);
49 }
50
51 public function onEventEdited(int $eventId, UpdateEventCommand $updateEventCommand): void
52 {
54 $mapperFactory = ServiceLocator::getInstance()->get('calendar.service.mappers.factory');
55 $event = $mapperFactory->getEvent()->getById($eventId);
56 if (!$event)
57 {
58 return;
59 }
60
61 if (!$this->isOpenEvent($event))
62 {
63 return;
64 }
65
66 if ($updateEventCommand->getMaxAttendees() === null)
67 {
68 return;
69 }
70
71 $eventOption = $event->getEventOption();
72 $eventOption->setOptions(new OptionsDto($updateEventCommand->getMaxAttendees()));
73 $mapperFactory->getEventOption()->update($eventOption);
74 }
75
76 private function createEventOption(
77 int $eventId,
78 int $categoryId,
79 ?int $threadId,
80 ?int $maxAttendees = 0
81 ): EventOption
82 {
84 $mapperFactory = ServiceLocator::getInstance()->get('calendar.service.mappers.factory');
85 $eventOption = (new EventOptionBuilderFromArray([
86 'EVENT_ID' => $eventId,
87 'CATEGORY_ID' => $categoryId,
88 'OPTIONS' => [
89 'max_attendees' => $maxAttendees ?? 0,
90 ],
91 'THREAD_ID' => $threadId
92 ]))->build();
93 $eventOptionFactory = $mapperFactory->getEventOption();
94 $eventOptionFactory->create($eventOption);
95
96 return $eventOption;
97 }
98
99 private function isOpenEvent(Event $event): bool
100 {
101 $section = $event->getSection();
102
103 return $section->getType() === Dictionary::CALENDAR_TYPE['open_event'];
104 }
105
106 private function __construct()
107 {
108 }
109}
$event
Определения prolog_after.php:141