1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
base.php
См. документацию.
1<?php
2
3namespace Bitrix\Calendar\Service\Command\Event;
4
5use Bitrix\Calendar\Access\EventAccessController;
6use Bitrix\Calendar\Core\Managers\Accessibility;
7use Bitrix\Calendar\Integration\Intranet\UserService;
8use Bitrix\Calendar\Internals\Exception\AttendeeBusy;
9use Bitrix\Calendar\Internals\Exception\ExtranetPermissionDenied;
10use Bitrix\Calendar\Internals\Exception\SectionNotFound;
11use Bitrix\Calendar\Service\Command\Result;
12use Bitrix\Calendar\Service\SectionRepository;
13use Bitrix\Calendar\UserSettings;
14use Bitrix\Calendar\Util;
15
16abstract class Base
17{
18 private int $currentUserId;
19 private int $sectionId;
20 private SectionRepository $sectionRepository;
21 private UserService $intranetUserService;
22 private array $initialParams;
23 private array $section = [];
24 private EventAccessController $eventAccessController;
25
26 public function __construct(array $params)
27 {
28 $this->initialParams = $params;
29 $this->currentUserId = $this->initialParams['user_id'];
30 $this->sectionId = $this->initialParams['section_id'];
31 $this->eventAccessController = new EventAccessController($this->currentUserId);
32 }
33
35 {
36 return $this->eventAccessController;
37 }
38
39 public function getSectionId(): int
40 {
41 return $this->sectionId;
42 }
43
44 public function getCurrentUserId(): int
45 {
46 return $this->currentUserId;
47 }
48
49 public function getSection(): array
50 {
51 if (!empty($this->section))
52 {
53 return $this->section;
54 }
55
56 $section = $this->sectionRepository->getSectionById($this->sectionId);
57 if (!$section)
58 {
59 throw new SectionNotFound();
60 }
61
62 if (!in_array($section['CAL_TYPE'], ['user', 'group'], true) && $this->intranetUserService->isNotIntranetUser($this->getCurrentUserId()))
63 {
64 throw new ExtranetPermissionDenied();
65 }
66
67 $this->section = $section;
68
69 return $this->section;
70 }
71
72 public function getId(): ?int
73 {
74 return $this->initialParams['id'] ?? null;
75 }
76
77 public function getInitialParams(): array
78 {
79 return $this->initialParams;
80 }
81
82 public function setSectionRepository(SectionRepository $sectionRepository): self
83 {
84 $this->sectionRepository = $sectionRepository;
85 return $this;
86 }
87
88 public function setIntranetUserService(UserService $intranetUserService): self
89 {
90 $this->intranetUserService = $intranetUserService;
91 return $this;
92 }
93
94 abstract public function checkPermissions(): void;
95 abstract public function execute(): Result;
96
97 protected function getAttendeeAccessCodes(): array
98 {
99 $codes = [];
100 if (isset($this->initialParams['attendees_entity_list']) && is_array($this->initialParams['attendees_entity_list']))
101 {
102 $codes = Util::convertEntitiesToCodes($this->initialParams['attendees_entity_list']);
103 }
104 return \CCalendarEvent::handleAccessCodes($codes, ['userId' => $this->getCurrentUserId()]);
105 }
106
107 protected function isMeeting(array $accessCodes): bool
108 {
109 $section = $this->getSection();
110 $calType = $section['SECTION_CAL_TYPE'] ?? '';
111
112 return $accessCodes !== ['U'.$this->getCurrentUserId()]
113 || in_array($calType, ['group', 'company_calendar'], true);
114 }
115
116 protected function excludeAttendees(array $entryFields): array
117 {
118 $excludeUsers = $this->getExcludeUsers($entryFields);
119 if (!empty($excludeUsers))
120 {
121 $entryFields['ATTENDEES_CODES'] = [];
122 $entryFields['ATTENDEES'] = array_diff($entryFields['ATTENDEES'], $excludeUsers);
123 foreach($entryFields['ATTENDEES'] as $attendee)
124 {
125 $entryFields['ATTENDEES_CODES'][] = 'U'. (int)$attendee;
126 }
127 }
128
129 return $entryFields;
130 }
131
132 protected function getExcludeUsers(array $entryFields): array
133 {
134 $excludeUsers = [];
135 if ($this->initialParams['exclude_users'] && !empty($entryFields['ATTENDEES']))
136 {
137 $excludeUsers = explode(',', $this->initialParams['exclude_users']);
138 }
139
140 return $excludeUsers;
141 }
142
143 protected function checkBusyAttendies(array $entryFields): void
144 {
145 $isMeeting = $entryFields['IS_MEETING'] ?? false;
146 if ($isMeeting && $this->initialParams['is_planner_feature_enabled'])
147 {
148 $attendees = [];
149 if ($this->initialParams['check_current_users_accessibility'])
150 {
151 $attendees = $entryFields['ATTENDEES'];
152 }
153 else if (is_array($this->initialParams['new_attendees_list']))
154 {
155 $attendees = array_diff($this->initialParams['new_attendees_list'], $this->getExcludeUsers($entryFields));
156 }
157
158 $timezoneName = \CCalendar::GetUserTimezoneName(\CCalendar::GetUserId());
159 $timezoneOffset = Util::getTimezoneOffsetUTC($timezoneName);
160 $timestampFrom = \CCalendar::TimestampUTC($this->initialParams['dates']['date_from']) - $timezoneOffset;
161 $timestampTo = \CCalendar::TimestampUTC($this->initialParams['dates']['date_to']) - $timezoneOffset;
162 if ($this->initialParams['dates']['skip_time'])
163 {
164 $timestampTo += \CCalendar::GetDayLen();
165 }
166 $busyUsers = $this->getBusyUsersIds($attendees, $this->initialParams['id'], $timestampFrom, $timestampTo);
167 if (!empty($busyUsers))
168 {
169 $busyUsersList = \CCalendarEvent::getUsersDetails($busyUsers);
170 $busyUserName = current($busyUsersList)['DISPLAY_NAME'];
171 $attendeeBusyException = (new AttendeeBusy())
172 ->setBusyUsersList($busyUsersList)
173 ->setAttendeeName($busyUserName);
174
175 throw $attendeeBusyException;
176 }
177 }
178 }
179
180 private function getBusyUsersIds(array $attendees, int $curEventId, int $fromTs, int $toTs): array
181 {
182 $usersToCheck = $this->getUsersToCheck($attendees);
183 if (empty($usersToCheck))
184 {
185 return [];
186 }
187
188 return (new Accessibility())
189 ->setSkipEventId($curEventId)
190 ->getBusyUsersIds($usersToCheck, $fromTs, $toTs);
191 }
192
193 private function getUsersToCheck(array $attendees): array
194 {
195 $usersToCheck = [];
196 foreach ($attendees as $attId)
197 {
198 if ((int)$attId !== \CCalendar::GetUserId())
199 {
200 $userSettings = UserSettings::get((int)$attId);
201 if ($userSettings && $userSettings['denyBusyInvitation'])
202 {
203 $usersToCheck[] = (int)$attId;
204 }
205 }
206 }
207 return $usersToCheck;
208 }
209}
setSectionRepository(SectionRepository $sectionRepository)
Определения base.php:82
isMeeting(array $accessCodes)
Определения base.php:107
__construct(array $params)
Определения base.php:26
setIntranetUserService(UserService $intranetUserService)
Определения base.php:88
getExcludeUsers(array $entryFields)
Определения base.php:132
checkBusyAttendies(array $entryFields)
Определения base.php:143
excludeAttendees(array $entryFields)
Определения base.php:116
static get($userId=null)
Определения usersettings.php:86
static getTimezoneOffsetUTC(string $timezoneName)
Определения util.php:767
static convertEntitiesToCodes($entityList=[])
Определения util.php:167
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799