1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
update.php
См. документацию.
1<?php
2
3namespace Bitrix\Calendar\Service\Command\Event;
4
5use Bitrix\Calendar\Access\ActionDictionary;
6use Bitrix\Calendar\Access\Model\EventModel;
7use Bitrix\Calendar\Internals\Exception\LocationBusy;
8use Bitrix\Calendar\Internals\Exception\PermissionDenied;
9use Bitrix\Calendar\Rooms\AccessibilityManager;
10use Bitrix\Calendar\Service\Command\Result;
11use Bitrix\Calendar\Util;
12
13class Update extends Base
14{
15 private bool $canEdit;
16 private bool $canEditAttendees;
17 private bool $canEditLocation;
18
19 public function checkPermissions(): void
20 {
21 $model = $this->getAccessEventModel($this->getId());
22 $controller = $this->getAccessController();
23
24 $this->canEdit = $controller->check(ActionDictionary::ACTION_EVENT_EDIT, $model);
25 $this->canEditAttendees = $controller->check(ActionDictionary::ACTION_EVENT_EDIT_ATTENDEES, $model);
26 $this->canEditLocation = $controller->check(ActionDictionary::ACTION_EVENT_EDIT_LOCATION, $model);
27
28 if (!($this->canEdit || $this->canEditAttendees || $this->canEditLocation))
29 {
30 throw new PermissionDenied();
31 }
32 }
33
34 public function execute(): Result
35 {
36 $params = $this->getInitialParams();
37 $section = $this->getSection();
38
39 $entryFields = [
40 'ID' => $this->getParentEventId(),
41 ];
42
43 if ($this->canEdit)
44 {
45 $meetingHost = $params['meeting_host'] ?? \CCalendar::GetUserId();
46
47 $entryFields = array_merge($entryFields, [
48 'DATE_FROM' => $params['dates']['date_from'],
49 'DATE_TO' => $params['dates']['date_to'],
50 'SKIP_TIME' => $params['dates']['skip_time'],
51 'TZ_FROM' => $params['timezones']['timezone_from'],
52 'TZ_TO' => $params['timezones']['timezone_to'],
53 'NAME' => $params['name'],
54 'DESCRIPTION' => $params['description'],
55 'SECTIONS' => [$this->getSectionId()],
56 'COLOR' => $params['color'],
57 'ACCESSIBILITY' => $params['accessibility'],
58 'IMPORTANCE' => $params['importance'],
59 'PRIVATE_EVENT' => $params['private_event'],
60 'RRULE' => $params['rrule'],
61 'REMIND' => $params['remind'],
62 'SECTION_CAL_TYPE' => $section['CAL_TYPE'],
63 'SECTION_OWNER_ID' => $section['OWNER_ID'],
64 'MEETING_HOST' => $meetingHost,
65 'MEETING' => [
66 'HOST_NAME' => \CCalendar::GetUserName($meetingHost),
67 'NOTIFY' => $params['meeting_notify'] === 'Y',
68 'REINVITE' => $params['meeting_reinvite'] === 'Y',
69 'ALLOW_INVITE' => $params['allow_invite'] === 'Y',
70 'MEETING_CREATOR' => $meetingHost,
71 'HIDE_GUESTS' => $params['hide_guests'] === 'Y',
72 'CHAT_ID' => $params['chat_id'] ?? null,
73 ],
74
75 ]);
76 }
77
78 // Attendees
79 if ($this->canEdit || $this->canEditAttendees)
80 {
81 $entryFields['ATTENDEES_CODES'] = $this->getAttendeeAccessCodes();
82 $entryFields['ATTENDEES'] = \CCalendar::GetDestinationUsers($entryFields['ATTENDEES_CODES']);
83 $entryFields['IS_MEETING'] = $this->isMeeting($entryFields['ATTENDEES_CODES']);
84 $entryFields = $this->excludeAttendees($entryFields);
85 $this->checkBusyAttendies($entryFields);
86 }
87
88 // Location
89 if ($this->canEdit || $this->canEditLocation)
90 {
91 $entryFields['LOCATION'] = $params['location'];
92
93 if (!AccessibilityManager::checkAccessibility($entryFields['LOCATION'], ['fields' => $entryFields]))
94 {
95 throw new LocationBusy();
96 }
97 }
98
99 $newId = \CCalendar::SaveEvent([
100 'arFields' => $entryFields,
101 'UF' => $params['uf_fields'],
102 'silentErrorMode' => false,
103 'recursionEditMode' => $params['rec_edit_mode'],
104 'currentEventDateFrom' => $params['current_date_from'],
105 'sendInvitesToDeclined' => $params['send_invites_again'],
106 'requestUid' => $params['request_uid'],
107 'checkLocationOccupancy' => $params['check_location_occupancy'],
108 'checkPermission' => false,
109 ]);
110
111 $errors = \CCalendar::GetErrors();
112
113 return new Result($newId, $errors);
114 }
115
116 private function getAccessEventModel(int $eventId): EventModel
117 {
118 return \CCalendarEvent::getEventModelForPermissionCheck(
119 eventId: $eventId,
120 userId: $this->getCurrentUserId()
121 );
122 }
123
124 private function getParentEventId(): int
125 {
126 $event = Util::getEventById($this->getId());
127
128 return (int)($event['PARENT_ID'] ?? $this->getId());
129 }
130}
isMeeting(array $accessCodes)
Определения base.php:107
checkBusyAttendies(array $entryFields)
Определения base.php:143
excludeAttendees(array $entryFields)
Определения base.php:116
static getEventById(int $eventId)
Определения util.php:350
$errors
Определения iblock_catalog_edit.php:74
$event
Определения prolog_after.php:141
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799