1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
createeventhandler.php
См. документацию.
1<?php
2
3namespace Bitrix\Calendar\Application\Command;
4
5use Bitrix\Calendar\Access\ActionDictionary;
6use Bitrix\Calendar\Access\EventAccessController;
7use Bitrix\Calendar\Access\EventCategoryAccessController;
8use Bitrix\Calendar\Access\Model\EventModel;
9use Bitrix\Calendar\Application\AttendeeService;
10use Bitrix\Calendar\Core\Builders\EventBuilderFromArray;
11use Bitrix\Calendar\Core\Event\Event;
12use Bitrix\Calendar\Core\Event\Tools\Dictionary;
13use Bitrix\Calendar\Core\Mappers\Factory;
14use Bitrix\Calendar\Core\Section\Section;
15use Bitrix\Calendar\Event\Event\AfterCalendarEventCreated;
16use Bitrix\Calendar\Integration\Intranet\UserService;
17use Bitrix\Calendar\Internals\Exception\AttendeeBusy;
18use Bitrix\Calendar\Internals\Exception\EditException;
19use Bitrix\Calendar\Internals\Exception\ExtranetPermissionDenied;
20use Bitrix\Calendar\Internals\Exception\LocationBusy;
21use Bitrix\Calendar\Internals\Exception\PermissionDenied;
22use Bitrix\Calendar\Internals\Exception\SectionNotFound;
23use Bitrix\Calendar\Rooms\AccessibilityManager;
24use Bitrix\Calendar\Util;
25use Bitrix\Main\DI\ServiceLocator;
26
28{
36 public function __invoke(CreateEventCommand $command): Event
37 {
39 $mapperFactory = ServiceLocator::getInstance()->get('calendar.service.mappers.factory');
40 $section = $this->getSection($mapperFactory, $command);
41
42 // check if the current user has access to create event operation
43 $this->checkPermissions($command->getUserId(), $section, $command->getCategory());
44
45 // convert array into domain Event
46 $event = (new EventBuilderFromArray($this->getEventFields($command, $section)))->build();
47 if ($event->isOpenEvent())
48 {
49 $event->setAttendeesCollection(null);
50 $event->setOwner(null);
51 }
52
53 // save Event
54 $createdEvent = $mapperFactory->getEvent()->create($event, [
55 'UF' => $command->getUfFields(),
56 'silentErrorMode' => false,
57 'recursionEditMode' => $command->getRecEditMode(),
58 'currentEventDateFrom' => $command->getCurrentDateFrom(),
59 'sendInvitesToDeclined' => $command->isSendInvitesAgain(),
60 'requestUid' => $command->getRequestUid(),
61 'checkLocationOccupancy' => $command->isCheckLocationOccupancy(),
62 ]);
63
64 if ($createdEvent === null)
65 {
66 throw new EditException();
67 }
68
69 (new AfterCalendarEventCreated($createdEvent->getId(), $command))->emit();
70
71 return $createdEvent;
72 }
73
77 private function checkPermissions(int $userId, Section $section, ?int $categoryId = null): void
78 {
79 $eventAccessController = new EventAccessController($userId);
80 $eventModel = $this->getEventModel($section);
81 $canAdd = $eventAccessController->check(ActionDictionary::ACTION_EVENT_ADD, $eventModel);
82 if (!$canAdd)
83 {
84 throw new PermissionDenied();
85 }
86
87 // check permission for open_event
88 if ($categoryId !== null)
89 {
90 $canPostAtCategory = EventCategoryAccessController::can(
91 $userId,
92 ActionDictionary::ACTION_EVENT_CATEGORY_POST,
93 $categoryId
94 );
95
96 if (!$canPostAtCategory)
97 {
98 throw new PermissionDenied();
99 }
100 }
101
102 if (Util::isCollabUser($userId) && !$section->isCollab())
103 {
104 throw new PermissionDenied();
105 }
106 }
107
112 private function getEventFields(CreateEventCommand $command, Section $section): array
113 {
114 $meetingHostId = $command->getMeetingHost() ? : $command->getUserId();
115
116 $entryFields = [
117 'ID' => 0,
118 'DATE_FROM' => $command->getDateFrom(),
119 'DATE_TO' => $command->getDateTo(),
120 'SKIP_TIME' => $command->isSkipTime(),
121 'DT_SKIP_TIME' => $command->isSkipTime() ? 'Y' : 'N',
122 'TZ_FROM' => $command->getTimeZoneFrom(),
123 'TZ_TO' => $command->getTimeZoneTo(),
124 'NAME' => $command->getName(),
125 'DESCRIPTION' => $command->getDescription(),
126 'SECTIONS' => [$command->getSectionId()],
127 'COLOR' => $command->getColor(),
128 'ACCESSIBILITY' => $command->getAccessibility(),
129 'IMPORTANCE' => $command->getImportance(),
130 'PRIVATE_EVENT' => $command->isPrivate(),
131 'RRULE' => $command->getRrule(),
132 'REMIND' => $command->getRemindList(),
133 'SECTION_CAL_TYPE' => $section->getType(),
134 'SECTION_OWNER_ID' => $section->getOwner()?->getId(),
135 'MEETING_HOST' => $meetingHostId,
136 'OWNER_ID' => $command->getUserId(),
137 'MEETING' => [
138 'HOST_NAME' => \CCalendar::GetUserName($meetingHostId),
139 'NOTIFY' => $command->isMeetingNotify(),
140 'REINVITE' => $command->isMeetingReinvite(),
141 'ALLOW_INVITE' => $command->isAllowInvite(),
142 'MEETING_CREATOR' => $meetingHostId,
143 'HIDE_GUESTS' => $command->isHideGuests(),
144 'CHAT_ID' => $command->getChatId(),
145 ],
146 ];
147
148 // Attendees
149 $attendeeService = new AttendeeService();
150 $attendeeCodes = $attendeeService->getAttendeeAccessCodes($command->getAttendeesEntityList(), $command->getUserId());
151 $attendees = \CCalendar::GetDestinationUsers($attendeeCodes);
152 $isMeeting = $attendeeService->isMeeting($attendeeCodes, $section, $command->getUserId());
153 $attendeesAndCodes = $attendeeService->excludeAttendees($attendees, $attendeeCodes, $command->getExcludeUsers());
154
155 $entryFields['ATTENDEES_CODES'] = $attendeesAndCodes['codes'];
156 $entryFields['ATTENDEES'] = $attendeesAndCodes['attendees'];
157 $entryFields['IS_MEETING'] = $isMeeting;
158
159 $additionalExcludeUsers = [];
160 if (
161 $section->getType() === Dictionary::CALENDAR_TYPE['user']
162 && $section->getOwner()?->getId()
163 && $section->getOwner()?->getId() !== $meetingHostId
164 )
165 {
166 $additionalExcludeUsers[] = $section->getOwner()?->getId();
167 }
168
169 if ($isMeeting && $command->isPlannerFeatureEnabled())
170 {
171 $attendeeService->checkBusyAttendees(
172 command: $command,
173 paramAttendees: $attendeesAndCodes['attendees'],
174 additionalExcludeUsers: $additionalExcludeUsers,
175 );
176 }
177
178 // Location
179 $entryFields['LOCATION'] = $command->getLocation();
180 $isLocationBusy = !AccessibilityManager::checkAccessibility($command->getLocation(), ['fields' => $entryFields]);
181 if ($isLocationBusy)
182 {
183 throw new LocationBusy();
184 }
185
186 return $entryFields;
187 }
188
189 private function getEventModel(Section $section): EventModel
190 {
191 return
192 EventModel::createNew()
193 ->setOwnerId($section->getOwner()?->getId() ?? 0)
194 ->setSectionId($section->getId())
195 ->setSectionType($section->getType() ?? '')
196 ;
197 }
198
203 public function getSection(Factory $mapperFactory, CreateEventCommand $command): Section
204 {
206 $section = $mapperFactory->getSection()->getById($command->getSectionId());
207 if (!$section)
208 {
209 throw new SectionNotFound();
210 }
211
212 if (!in_array($section->getType(), ['user', 'group'], true) && (new UserService())->isNotIntranetUser($command->getUserId()))
213 {
214 throw new ExtranetPermissionDenied();
215 }
216
217 return $section;
218 }
219}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static isCollabUser(int $userId)
Определения util.php:337
</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