Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
calendareventviewform.php
1<?php
2
4
9use Bitrix\Intranet\Settings\Tools\ToolsManager;
17
19{
20
21 public function getCalendarViewSliderParamsAction(int $entryId, string $dateFrom, int $timezoneOffset = 0): array
22 {
23 $responseParams = [];
24 $userId = \CCalendar::GetCurUserId();
25
26 if (
27 Loader::includeModule('intranet')
28 && !ToolsManager::getInstance()->checkAvailabilityByToolId('calendar')
29 )
30 {
31 $this->addError(new Error(Loc::getMessage('EC_EVENT_NOT_FOUND')));
32
33 return [
34 'isAvailable' => false,
35 ];
36 }
37
38 if ($entryId)
39 {
40 $entry = \CCalendarEvent::getEventForViewInterface($entryId, [
41 'eventDate' => $dateFrom,
42 'timezoneOffset' => $timezoneOffset,
43 'userId' => $userId
44 ]);
45 }
46 else
47 {
48 $this->addError(new Error(Loc::getMessage('EC_EVENT_NOT_FOUND'), 'EVENT_NOT_FOUND_01'));
49 return [];
50 }
51
52 if (!$entry || !$entry['ID'])
53 {
54 $this->addError(new Error(Loc::getMessage('EC_EVENT_NOT_FOUND'), 'EVENT_NOT_FOUND_02'));
55 return [];
56 }
57
58 $responseParams['userId'] = $userId;
59 $responseParams['userTimezone'] = \CCalendar::GetUserTimezoneName($userId);
60 $responseParams['entry'] = $entry;
61 $responseParams['userIndex'] = \CCalendarEvent::getUserIndex();
62 $responseParams['userSettings'] = UserSettings::get($userId);
63 $responseParams['plannerFeatureEnabled'] = Bitrix24Manager::isPlannerFeatureEnabled();
64 $responseParams['entryUrl'] = \CHTTP::urlAddParams(
65 \CCalendar::GetPath($entry['CAL_TYPE'], $entry['OWNER_ID'], true),
66 [
67 'EVENT_ID' => (int)$entry['ID'],
68 'EVENT_DATE' => urlencode($entry['DATE_FROM'])
69 ]
70 );
71 $responseParams['dayOfWeekMonthFormat'] = stripslashes(
73 ->getCulture()
74 ->getDayOfWeekMonthFormat()
75 );
76
77 $sections = \CCalendarSect::GetList([
78 'arFilter' => [
79 'ID' => $entry['SECTION_ID'],
80 'ACTIVE' => 'Y',
81 ],
82 'checkPermissions' => false,
83 'getPermissions' => true
84 ]);
85 $responseParams['section'] = $sections[0] ?? null;
86
87 if (!$responseParams['section'])
88 {
89 $this->addError(new Error(Loc::getMessage('EC_EVENT_NOT_FOUND'), 'SECTION_NOT_FOUND'));
90 return [];
91 }
92
93 $params = array_merge([
94 'event' => $entry,
95 'type' => \CCalendar::GetType(),
96 'bIntranet' => \CCalendar::IsIntranetEnabled(),
97 'bSocNet' => \CCalendar::IsSocNet(),
98 'AVATAR_SIZE' => 21,
99 ], $responseParams);
100
101 $userId = \CCalendar::GetCurUserId();
102 $event = $params['event'];
103
104 $timezoneHint = Util::getTimezoneHint($userId, $event);
105
106 $UF = \CCalendarEvent::GetEventUserFields($event);
107
108 if (isset($event['UF_CRM_CAL_EVENT']))
109 {
110 $event['UF_CRM_CAL_EVENT'] = $UF['UF_CRM_CAL_EVENT'];
111 if (empty($event['UF_CRM_CAL_EVENT']['VALUE']))
112 {
113 $event['UF_CRM_CAL_EVENT'] = false;
114 }
115 }
116
117 if (isset($event['UF_WEBDAV_CAL_EVENT']))
118 {
119 $event['UF_WEBDAV_CAL_EVENT'] = $UF['UF_WEBDAV_CAL_EVENT'];
120 if(empty($event['UF_WEBDAV_CAL_EVENT']['VALUE']))
121 {
122 $event['UF_WEBDAV_CAL_EVENT'] = false;
123 }
124 }
125
126 $event['REMIND'] = \CCalendarReminder::GetTextReminders($event['REMIND'] ?? []);
127
128 $event['permissions'] = \CCalendarEvent::getEventPermissions($event, $userId);
129
130 $curUserStatus = '';
131 $userId = \CCalendar::GetCurUserId();
132
133 $viewComments = $event['permissions']['view_comments'];
134
135 //get meeting host and attendees
136 $meetingHost = false;
137 if ($event['IS_MEETING'])
138 {
139 $userIndex = \CCalendarEvent::getUserIndex();
140 $attendees = ['y' => [], 'n' => [], 'q' => [], 'i' => []];
141
142 if (isset($event['ATTENDEE_LIST']) && is_array($event['ATTENDEE_LIST']))
143 {
144 foreach ($event['ATTENDEE_LIST'] as $attendee)
145 {
146 if ($userId === (int)$attendee['id'])
147 {
148 $curUserStatus = $attendee['status'];
149 $viewComments = true;
150 }
151
152 $status = (mb_strtolower($attendee['status']) === 'h' || empty($attendee['status']))
153 ? 'y'
154 : $attendee['status']
155 ;
156 $attendees[mb_strtolower($status)][] = $userIndex[$attendee['id']];
157 if ($attendee['status'] === 'H')
158 {
159 $meetingHost = $userIndex[$attendee['id']];
160 $meetingHost['ID'] = $attendee['id'];
161 }
162 }
163 }
164 }
165
166 if (!$meetingHost && isset($event['MEETING_HOST']))
167 {
168 $meetingHost = \CCalendar::GetUser($event['MEETING_HOST'], true);
169 }
170
171 if ($meetingHost && is_array($meetingHost))
172 {
173 $meetingHost['DISPLAY_NAME'] = \CCalendar::GetUserName($meetingHost);
174 if (!isset($meetingHost['AVATAR']))
175 {
176 $meetingHost['AVATAR'] = \CCalendar::GetUserAvatarSrc($meetingHost);
177 }
178 $meetingHost['URL'] = \CCalendar::GetUserUrl($meetingHost["ID"], ($params["PATH_TO_USER"] ?? ''));
179 }
180
181 $params['id'] = 'calendar_view_slider_'.mt_rand();
182 $params['event'] = $event;
183 $params['eventId'] = $event['ID'];
184 $params['parentId'] = $event['PARENT_ID'];
185 $params['name'] = $event['NAME'];
186 $params['fromToHtml'] = $this->getFromToHtml($event);
187 $params['timezoneHint'] = $timezoneHint;
188 $params['isMeeting'] = $event['IS_MEETING'];
189 $params['isRemind'] = $event['REMIND'];
190 $params['isRrule'] = $event['RRULE'];
191 $params['rruleDescription'] = \CCalendarEvent::GetRRULEDescription($event, false);
192
193 $params['avatarSize'] = 34;
194 $params['attendees'] = $attendees ?? [];
195
196 $params['curUserStatus'] = $curUserStatus;
197 $params['meetingHost'] = $meetingHost;
198 $params['meetingHostDisplayName'] = $meetingHost['DISPLAY_NAME'] ?? null;
199 $params['meetingHostWorkPosition'] = htmlspecialcharsbx($meetingHost['WORK_POSITION'] ?? null);
200
201 $meetingCreator = $this->getMeetingCreator($event);
202 $params['meetingCreatorUrl'] = $meetingCreator['URL'] ?? null;
203 $params['meetingCreatorDisplayName'] = $meetingCreator['DISPLAY_NAME'] ?? null;
204
205 $params['isHighImportance'] = $event['IMPORTANCE'] === 'high';
206 $params['description'] = $event['~DESCRIPTION'] ?? null;
207
208 $params['isWebdavEvent'] = $event['UF_WEBDAV_CAL_EVENT'] ?? null;
209 $params['isCrmEvent'] = $event['UF_CRM_CAL_EVENT'] ?? null;
210
211 $params['accessibility'] = $event['ACCESSIBILITY'];
212 $params['isIntranetEnabled'] = \CCalendar::IsIntranetEnabled();
213 $params['isPrivate'] = $event['PRIVATE_EVENT'];
214
215 $params['location'] = htmlspecialcharsbx(\CCalendar::GetTextLocation($event['LOCATION'] ?? null));
216
217 $params['canEditCalendar'] = $event['permissions']['edit'];
218 $params['canDeleteEvent'] = $event['permissions']['delete'];
219
220 $params['showComments'] = $viewComments;
221
222 //views
223 if (!empty($params['isWebdavEvent']))
224 {
225 $params['filesView'] = $this->getFilesView($event)->getContent();
226 }
227 if (!empty($params['isCrmEvent']))
228 {
229 $params['crmView'] = $this->getCrmView($event)->getContent();
230 }
231
232 $signedEvent = [
233 'UF_CRM_CAL_EVENT' => $params['event']['UF_CRM_CAL_EVENT'] ?? null,
234 'UF_WEBDAV_CAL_EVENT' => $params['event']['UF_WEBDAV_CAL_EVENT'] ?? null,
235 'PARENT_ID' => $params['event']['PARENT_ID'],
236 'ID' => $params['event']['ID'],
237 'CREATED_BY' => $params['event']['CREATED_BY'],
238 ];
239
240 $params['event'] = \CCalendarEvent::FixCommentsIfEventIsBroken($params['event']); //TODO: remove 30.06.2025
241
242 if (
243 isset($params['event']['RELATIONS']['COMMENT_XML_ID'])
244 && $params['event']['RELATIONS']['COMMENT_XML_ID']
245 )
246 {
247 $signedEvent['ENTITY_XML_ID'] = $params['event']['RELATIONS']['COMMENT_XML_ID'];
248 }
249 else
250 {
251 $signedEvent['ENTITY_XML_ID'] = \CCalendarEvent::GetEventCommentXmlId($params['event']);
252 }
253
254 $params['signedEvent'] = (new Signer())->sign(Json::encode($signedEvent));
255
256 return $params;
257 }
258
259 //get components actions
260 public function getCrmViewAction(string $signedEvent): ?Component
261 {
262 try
263 {
264 $event = Json::decode((new Signer())->unsign($signedEvent));
265 }
266 catch (\Exception $e)
267 {
268 $this->addError(new Error(Loc::getMessage('EC_EVENT_NOT_FOUND'), 'EVENT_NOT_FOUND_01'));
269 return null;
270 }
271
272 return $this->getCrmView($event);
273 }
274
275 public function getFilesViewAction(string $signedEvent): ?Component
276 {
277 try
278 {
279 $event = Json::decode((new Signer())->unsign($signedEvent));
280 }
281 catch (\Exception $e)
282 {
283 $this->addError(new Error(Loc::getMessage('EC_EVENT_NOT_FOUND'), 'EVENT_NOT_FOUND_01'));
284 return null;
285 }
286
287 return $this->getFilesView($event);
288 }
289
290 public function getCommentsViewAction(string $signedEvent): ?Component
291 {
292 try
293 {
294 $event = Json::decode((new Signer())->unsign($signedEvent));
295 }
296 catch (\Exception $e)
297 {
298 $this->addError(new Error(Loc::getMessage('EC_EVENT_NOT_FOUND'), 'EVENT_NOT_FOUND_01'));
299 return null;
300 }
301
302 return $this->getCommentsView($event);
303 }
304
305 private function getFromToHtml(array $event): string
306 {
307 $skipTime = $event['DT_SKIP_TIME'] === "Y";
308 $fromTs = \CCalendar::Timestamp($event['DATE_FROM']);
309 $toTs = \CCalendar::Timestamp($event['DATE_TO']);
310 if ($skipTime)
311 {
312 $toTs += \CCalendar::DAY_LENGTH;
313 }
314 else
315 {
316 $fromTs -= $event['~USER_OFFSET_FROM'];
317 $toTs -= $event['~USER_OFFSET_TO'];
318 }
319
320 return \CCalendar::GetFromToHtml($fromTs, $toTs, $skipTime, $event['DT_LENGTH']);
321 }
322
323 private function getMeetingCreator(array $event): array
324 {
325 $meetingCreator = [];
326 if (
327 $event['IS_MEETING']
328 && $event['MEETING']['MEETING_CREATOR']
329 && $event['MEETING']['MEETING_CREATOR'] !== $event['MEETING_HOST']
330 )
331 {
332 $meetingCreator = \CCalendar::GetUser($event['MEETING']['MEETING_CREATOR'], true);
333 $meetingCreator['DISPLAY_NAME'] = \CCalendar::GetUserName($meetingCreator);
334 $meetingCreator['URL'] = \CCalendar::GetUserUrl(
335 $meetingCreator["ID"],
336 $meetingCreator["PATH_TO_USER"] ?? null
337 );
338 }
339 return $meetingCreator;
340 }
341
342 private function getCrmView(array $event): Component
343 {
344 return new Component(
345 "bitrix:system.field.view",
346 $event['UF_CRM_CAL_EVENT']["USER_TYPE"]["USER_TYPE_ID"],
347 array("arUserField" => $event['UF_CRM_CAL_EVENT']),
348 array("HIDE_ICONS"=>"Y")
349 );
350 }
351
352 private function getFilesView(array $event): Component
353 {
354 return new Component(
355 "bitrix:system.field.view",
356 $event['UF_WEBDAV_CAL_EVENT']["USER_TYPE"]["USER_TYPE_ID"],
357 array("arUserField" => $event['UF_WEBDAV_CAL_EVENT']),
358 array("HIDE_ICONS"=>"Y")
359 );
360 }
361
362 private function getCommentsView(array $event): Component
363 {
364 $userId = \CCalendar::GetCurUserId();
365 if (
366 $userId === (int)$event['CREATED_BY']
367 && ((int)$event['PARENT_ID'] === (int)$event['ID'] || !$event['PARENT_ID'])
368 )
369 {
370 $permission = "Y";
371 }
372 else
373 {
374 $permission = 'M';
375 }
376 $set = \CCalendar::GetSettings();
377 $eventCommentId = $event['PARENT_ID'] ?: $event['ID'];
378
379 return new Component(
380 "bitrix:forum.comments", "bitrix24", [
381 "FORUM_ID" => $set['forum_id'],
382 "ENTITY_TYPE" => "EV",
383 "ENTITY_ID" => $eventCommentId,
384 "ENTITY_XML_ID" => $event['ENTITY_XML_ID'],
385 "PERMISSION" => $permission,
386 "URL_TEMPLATES_PROFILE_VIEW" => $set['path_to_user'],
387 "SHOW_RATING" => \COption::GetOptionString('main', 'rating_vote_show', 'N'),
388 "SHOW_LINK_TO_MESSAGE" => "N",
389 "BIND_VIEWER" => "Y",
390 'LHE' => [
391 'isCopilotImageEnabledBySettings' => AI\Settings::isImageCommentAvailable(),
392 'isCopilotTextEnabledBySettings' => AI\Settings::isTextCommentAvailable(),
393 'copilotParams' => [
394 'moduleId' => 'calendar',
395 'contextId' => 'calendar_comments_' . $event['ENTITY_XML_ID'],
396 'category' => 'calendar_comments',
397 ],
398 ],
399 ],
400 ['HIDE_ICONS' => 'Y']
401 );
402 }
403
404}
getCalendarViewSliderParamsAction(int $entryId, string $dateFrom, int $timezoneOffset=0)
static get($userId=null)
static getTimezoneHint(int $userId, array $event)
Definition util.php:761
static getCurrent()
Definition context.php:241
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29