28 private bool $canEdit;
29 private bool $canEditAttendees;
30 private bool $canEditLocation;
35 $mapperFactory = ServiceLocator::getInstance()->get(
'calendar.service.mappers.factory');
40 $section = $this->getSection($mapperFactory, $command);
41 $event = $this->getEvent($mapperFactory, $command->
getId());
42 $entryFields = $this->convertToArray(
$event, $mapperFactory);
43 $currentFields = $entryFields;
46 $entryFields = ($this->canEdit)
47 ? $this->editBaseFields($entryFields, $command,
$event, $section)
48 : $this->editPersonalFields($entryFields, $command);
51 $entryFields = ($this->canEdit || $this->canEditAttendees)
52 ? $this->editAttendees($entryFields, $command,
$event->getId(), $section)
56 $entryFields = ($this->canEdit || $this->canEditLocation)
57 ? $this->editLocation($entryFields, $command,
$event->getId())
62 $updatedEvent = $mapperFactory->getEvent()->update(
$event, [
63 'checkPermission' =>
false,
65 'silentErrorMode' =>
false,
66 'recursionEditMode' => $this->getRecursionEditMode($command),
71 'userId' => \CCalendar::GetUserId(),
74 if ($updatedEvent ===
null)
79 if ($updatedEvent && $updatedEvent->isMeeting())
81 $this->notifyEventAuthor($mapperFactory, $updatedEvent, $command->
getUserId(), $currentFields);
92 $sectionId =
$event->getSection()->getId();
98 return array_merge($entryFields, [
102 'DT_SKIP_TIME' => $command->
isSkipTime() ?
'Y' :
'N',
107 'SECTIONS' => [$sectionId],
111 'PRIVATE_EVENT' => $command->
isPrivate(),
114 'MEETING_HOST' => $meetingHostId,
117 'HOST_NAME' => \CCalendar::GetUserName($meetingHostId),
121 'MEETING_CREATOR' => $meetingHostId,
130 return array_merge($entryFields, [
139 $attendees = \CCalendar::GetDestinationUsers($attendeeCodes);
140 $isMeeting = $attendeeService->isMeeting($attendeeCodes, $section, $command->
getUserId());
141 $attendeesAndCodes = $attendeeService->excludeAttendees($attendees, $attendeeCodes, $command->
getExcludeUsers());
143 $entryFields[
'ATTENDEES_CODES'] = $attendeesAndCodes[
'codes'];
144 $entryFields[
'ATTENDEES'] = $attendeesAndCodes[
'attendees'];
145 $entryFields[
'IS_MEETING'] = $isMeeting;
147 $additionalExcludeUsers = [];
149 $section->
getType() === Dictionary::CALENDAR_TYPE[
'user']
151 && $section->
getOwner()?->getId() !== (
int)$entryFields[
'MEETING_HOST']
154 $additionalExcludeUsers[] = $section->
getOwner()?->getId();
160 $attendeesToCheck = array_diff($attendeesAndCodes[
'attendees'], [$entryFields[
'MEETING_HOST']]);
161 $attendeeService->checkBusyAttendees($command, $attendeesToCheck, $eventId, $additionalExcludeUsers);
169 $entryFields[
'LOCATION'] = $command->
getLocation();
173 'SKIP_TIME' => $entryFields[
'SKIP_TIME'] ?? ($entryFields[
'DT_SKIP_TIME'] ===
'Y'),
174 'DATE_FROM' => $entryFields[
'DATE_FROM'],
175 'DATE_TO' => $entryFields[
'DATE_TO'],
176 'TZ_FROM' => $entryFields[
'TZ_FROM'],
177 'TZ_TO' => $entryFields[
'TZ_TO'],
179 $isLocationBusy = !AccessibilityManager::checkAccessibility($command->
getLocation(), [
'fields' =>
$params]);
188 private function checkPermissions(
int $eventId,
int $userId):
void
191 $model = $this->getEventAccessModel($eventId,
$userId);
192 $this->canEdit = $controller->check(ActionDictionary::ACTION_EVENT_EDIT, $model);
193 $this->canEditAttendees = $controller->check(ActionDictionary::ACTION_EVENT_EDIT_ATTENDEES, $model);
194 $this->canEditLocation = $controller->check(ActionDictionary::ACTION_EVENT_EDIT_LOCATION, $model);
196 if (!($this->canEdit || $this->canEditAttendees || $this->canEditLocation))
202 private function getEvent(
Factory $factoryMapper,
int $eventId, $isParent =
false):
Event
210 return (
$event->getId() !==
$event->getParentId() && !$isParent)
211 ? $this->getEvent($factoryMapper,
$event->getParentId(),
true)
219 unset($entryFields[
'SECTION_ID']);
220 unset($entryFields[
'RECURRENCE_ID']);
227 return \CCalendarEvent::getEventModelForPermissionCheck(
254 private function notifyEventAuthor(
Factory $mapperFactory,
Event $updatedEvent,
int $userId,
array $currentFields):
void
257 $meetingHostId = $updatedEvent->
getEventHost()?->getId();
260 if (!($isMeeting && $meetingHostId &&
$userId !== $meetingHostId &&
$type ===
'user'))
266 $entryFields = $mapperFactory->
getEvent()->convertToArray($updatedEvent);
267 $entryChanges = \CCalendarEvent::CheckEntryChanges($entryFields, $currentFields);
268 if (empty($entryChanges))
273 $fromTo = \CCalendarEvent::GetEventFromToForUser($entryFields,
$userId);
274 \CCalendarNotify::Send([
275 'mode' =>
'change_notify',
276 'name' => $entryFields[
'NAME'] ??
null,
277 "from" => $fromTo[
'DATE_FROM'] ??
null,
278 "to" => $fromTo[
'DATE_TO'] ??
null,
279 "location" => \CCalendar::GetTextLocation($entryFields[
"LOCATION"] ??
null),
280 "guestId" => $meetingHostId,
281 "eventId" => $updatedEvent->
getId(),
283 "fields" => $entryFields,
284 "isSharing" => $updatedEvent->
getCalendarType() === Dictionary::EVENT_TYPE[
'shared'],
285 "entryChanges" => $entryChanges,
295 $canEditOnlyThis = $this->canEditAttendees && $this->canEditLocation && !$this->canEdit;
297 if ($canEditOnlyThis && in_array($recursionEditMode, [
'next',
'all']))
302 return $recursionEditMode;