1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
sharingeventmanager.php
См. документацию.
1<?php
2
3namespace Bitrix\Calendar\Sharing;
4
5use Bitrix\Calendar\Core\Base\Result;
6use Bitrix\Calendar\Core\Builders\EventBuilderFromArray;
7use Bitrix\Calendar\Core\Event\Event;
8use Bitrix\Calendar\Core\Event\Tools\Dictionary;
9use Bitrix\Calendar\Core\Mappers;
10use Bitrix\Calendar\Integration\Crm\DealHandler;
11use Bitrix\Calendar\Internals\EventTable;
12use Bitrix\Calendar\Sharing;
13use Bitrix\Calendar\Util;
14use Bitrix\Crm;
15use Bitrix\Main\ArgumentException;
16use Bitrix\Main\Loader;
17use Bitrix\Main\LoaderException;
18use Bitrix\Main\ObjectPropertyException;
19use Bitrix\Main\PhoneNumber;
20use Bitrix\Main\Error;
21use Bitrix\Main\Localization\Loc;
22use Bitrix\Main\SystemException;
23use Bitrix\Main\Type\DateTime;
24use CUser;
25
27{
28 public const SHARED_EVENT_TYPE = Dictionary::EVENT_TYPE['shared'];
29 public const SHARED_EVENT_CRM_TYPE = Dictionary::EVENT_TYPE['shared_crm'];
30 public const SHARED_EVENT_COLLAB_TYPE = Dictionary::EVENT_TYPE['shared_collab'];
32 private Event $event;
34 private ?int $hostId;
36 private ?int $ownerId;
38 private ?Sharing\Link\Link $link;
39
46 public function __construct(Event $event, ?int $hostId = null, ?int $ownerId = null, ?Sharing\Link\Link $link = null)
47 {
48 $this->event = $event;
49 $this->hostId = $hostId;
50 $this->ownerId = $ownerId;
51 $this->link = $link;
52 }
53
58 public function setEvent(Event $event): self
59 {
60 $this->event = $event;
61
62 return $this;
63 }
64
71 public function createEvent(bool $sendInvitations = true, string $externalUserName = ''): Result
72 {
73 $result = new Result();
74
75 if (!$this->doesEventHasCorrectTime())
76 {
77 $result->addError(new Error('Incorrect time has given'));
78
79 return $result;
80 }
81
82 if (!$this->doesEventSatisfyRule())
83 {
84 $result->addError(new Error('Event time does not satisfy owner rule'));
85
86 return $result;
87 }
88
89 $members = $this->link->getMembers();
90 $users = array_map(static fn ($member) => $member->getId(), $members);
91 if ($this->link->getObjectType() === Sharing\Link\Helper::GROUP_SHARING_TYPE)
92 {
93 $users[] = $this->link->getHostId();
94 }
95 else
96 {
97 $users[] = $this->link->getOwnerId();
98 }
99
100 if (!$this->checkUserAccessibility($users))
101 {
102 $result->addError(new Error(Loc::getMessage('EC_SHARINGAJAX_USER_BUSY')));
103
104 return $result;
105 }
106
107 $eventId = (new Mappers\Event())->create($this->event, [
108 'sendInvitations' => $sendInvitations,
109 ])?->getId();
110
111 $this->event->setId($eventId);
112
113 if (!$eventId)
114 {
115 $result->addError(new Error(Loc::getMessage('EC_SHARINGAJAX_EVENT_SAVE_ERROR')));
116
117 return $result;
118 }
119
120 $eventLinkParams = [
121 'eventId' => $eventId,
122 'ownerId' => $this->ownerId,
123 'hostId' => $this->hostId,
124 'parentLinkHash' => $this->link->getHash(),
125 'expiryDate' => Helper::createSharingLinkExpireDate(
126 DateTime::createFromTimestamp($this->event->getEnd()->getTimestamp()),
127 Sharing\Link\Helper::EVENT_SHARING_TYPE
128 ),
129 'externalUserName' => $externalUserName,
130 ];
131
132 $eventLink = (new Sharing\Link\Factory())->createEventLink($eventLinkParams);
133
134 $result->setData([
135 'eventLink' => $eventLink,
136 'event' => $this->event,
137 ]);
138
139 return $result;
140 }
141
146 public function deleteEvent(): Result
147 {
148 $result = new Result();
149
150 (new Mappers\Event())->delete($this->event);
151 $this->notifyEventDeleted();
152
153 return $result;
154 }
155
160 public function deactivateEventLink(Sharing\Link\EventLink $eventLink): self
161 {
162 $eventLink
163 ->setCanceledTimestamp(time())
164 ->setActive(false)
165 ;
166
167 (new Sharing\Link\EventLinkMapper())->update($eventLink);
168
169 return $this;
170 }
171
176 public static function validateContactData(string $userContact): bool
177 {
178 return self::isEmailCorrect($userContact)
179 || self::isPhoneNumberCorrect($userContact)
180 ;
181 }
182
187 public static function validateContactName(string $userName): bool
188 {
189 return self::isUserNameCorrect($userName);
190 }
191
192 private static function isUserNameCorrect(string $userName): bool
193 {
194 return $userName !== '';
195 }
196
197 public static function isEmailCorrect(string $userContact): bool
198 {
199 return check_email($userContact);
200 }
201
202 public static function isPhoneNumberCorrect(string $userContact): bool
203 {
204 return Helper::isPhoneFeatureEnabled()
205 && PhoneNumber\Parser::getInstance()->parse($userContact)->isValid()
206 ;
207 }
208
214 public static function prepareEventForSave($data, $userId, Sharing\Link\Joint\JointLink $link): Event
215 {
216 $meeting = [
217 'HOST_NAME' => \CCalendar::GetUserName($userId),
218 'NOTIFY' => true,
219 'REINVITE' => false,
220 'ALLOW_INVITE' => true,
221 'MEETING_CREATOR' => $userId,
222 'HIDE_GUESTS' => false,
223 ];
224
225 $eventData = [
226 'NAME' => (string)($data['eventName'] ?? ''),
227 'DATE_FROM' => (string)($data['dateFrom'] ?? ''),
228 'DATE_TO' => (string)($data['dateTo'] ?? ''),
229 'TZ_FROM' => (string)($data['timezone'] ?? ''),
230 'TZ_TO' => (string)($data['timezone'] ?? ''),
231 'SKIP_TIME' => 'N',
232 'ACCESSIBILITY' => 'busy',
233 'IMPORTANCE' => 'normal',
234 'MEETING_HOST' => $userId,
235 'IS_MEETING' => true,
236 'MEETING' => $meeting,
237 'DESCRIPTION' => (string)($data['description'] ?? ''),
238 ];
239
240 $eventData = array_merge($eventData, self::prepareTypeDependedEventFields($link, (int)$userId));
241
242 return (new EventBuilderFromArray($eventData))->build();
243 }
244
245 public static function getEventDataFromRequest($request): array
246 {
247 return [
248 'ownerId' => (int)($request['ownerId'] ?? 0),
249 'dateFrom' => (string)($request['dateFrom'] ?? ''),
250 'dateTo' => (string)($request['dateTo'] ?? ''),
251 'timezone' => (string)($request['timezone'] ?? ''),
252 'description' => (string)($request['description'] ?? ''),
253 ];
254 }
255
256 public static function getSharingEventNameByUserId(int $userId): string
257 {
258 $user = CUser::GetByID($userId)->Fetch();
259 $userName = ($user['NAME'] ?? '') . ' ' . ($user['LAST_NAME'] ?? '');
260
262 }
263
264 public static function getSharingEventNameByUserName(?string $userName): string
265 {
266 if (!empty($userName))
267 {
268 $result = Loc::getMessage('CALENDAR_SHARING_EVENT_MANAGER_EVENT_NAME', [
269 '#GUEST_NAME#' => trim($userName),
270 ]);
271 }
272 else
273 {
274 $result = Loc::getMessage('CALENDAR_SHARING_EVENT_MANAGER_EVENT_NAME_WITHOUT_GUEST');
275 }
276
277 return $result;
278 }
279
280 public static function getSharingEventNameByDealId(int $dealId): string
281 {
282 $deal = DealHandler::getDeal($dealId);
283 if (!$deal)
284 {
285 return '';
286 }
287
288 return Loc::getMessage('CALENDAR_SHARING_EVENT_MANAGER_EVENT_NAME_DEAL', [
289 '#DEAL_NAME#' => trim($deal->getTitle()),
290 ]);
291 }
292
298 {
299 return [
300 'ownerId' =>(int)($request['ownerId'] ?? 0),
301 'dateFrom' => (string)($request['dateFrom'] ?? ''),
302 'dateTo' => (string)($request['dateTo'] ?? ''),
303 'timezone' => (string)($request['timezone'] ?? ''),
304 'description' => (string)($request['description'] ?? ''),
305 'eventType' => Dictionary::EVENT_TYPE['shared_crm'],
306 ];
307 }
308
312 public static function getSharingEventTypes(): array
313 {
314 return [
315 self::SHARED_EVENT_CRM_TYPE,
316 self::SHARED_EVENT_TYPE,
317 self::SHARED_EVENT_COLLAB_TYPE,
318 ];
319 }
320
328 public static function onSharingEventEdit(array $fields): void
329 {
330 $eventId = $fields['ID'];
331 $eventLink = (new Sharing\Link\Factory())->getEventLinkByEventId($eventId);
332 if ($eventLink instanceof Sharing\Link\EventLink)
333 {
334 self::updateEventSharingLink($eventLink, $fields);
335 }
336 }
337
345 public static function setCanceledTimeOnSharedLink(int $eventId): void
346 {
347 $eventLink = (new Sharing\Link\Factory())->getEventLinkByEventId($eventId);
348 if ($eventLink instanceof Sharing\Link\EventLink)
349 {
350 $eventLink->setCanceledTimestamp(time());
351 (new Sharing\Link\EventLinkMapper())->update($eventLink);
352 }
353 }
354
368 public static function onSharingEventMeetingStatusChange(
369 int $userId,
370 string $currentMeetingStatus,
371 array $userEventBeforeChange,
372 bool $isAutoAccept = false
373 )
374 {
376 $eventLink = (new Sharing\Link\Factory())->getEventLinkByEventId((int)$userEventBeforeChange['PARENT_ID']);
377
378 if (!$eventLink)
379 {
380 return;
381 }
382
383 $ownerId = $eventLink->getOwnerId();
384 //if not the link owner's event has changed, send notification to link owner
385 if ($ownerId !== $userId && !$isAutoAccept)
386 {
387 self::onSharingEventGuestStatusChange($currentMeetingStatus, $userEventBeforeChange, $eventLink, $userId);
388 }
389 else if ($userEventBeforeChange['EVENT_TYPE'] === Dictionary::EVENT_TYPE['shared'])
390 {
391 self::onSharingCommonEventMeetingStatusChange($eventLink, $userId);
392 }
393 else if ($userEventBeforeChange['EVENT_TYPE'] === Dictionary::EVENT_TYPE['shared_crm'])
394 {
395 self::onSharingCrmEventStatusChange($currentMeetingStatus, $userEventBeforeChange, $userId, $ownerId);
396 }
397 }
398
399 private static function onSharingEventGuestStatusChange(
400 string $currentMeetingStatus,
401 array $event,
402 Sharing\Link\EventLink $eventLink,
403 int $userId
404 ): void
405 {
406 \CCalendarNotify::Send([
407 'mode' => $currentMeetingStatus === "Y" ? 'accept' : 'decline',
408 'name' => $event['NAME'],
409 'from' => $event["DATE_FROM"],
410 'to' => $event["DATE_TO"],
411 'location' => \CCalendar::GetTextLocation($userEvent["LOCATION"] ?? null),
412 'guestId' => $userId,
413 'eventId' => $event['PARENT_ID'],
414 'userId' => $eventLink->getOwnerId(),
415 'fields' => $event,
416 ]);
417 }
418
424 private static function onSharingCommonEventMeetingStatusChange(
425 Sharing\Link\EventLink $eventLink,
426 ?int $initiatorId = null,
427 ): void
428 {
430 $event = (new Mappers\Event())->getById($eventLink->getEventId());
431
432 $host = CUser::GetByID($eventLink->getHostId())->Fetch();
433 $email = $host['PERSONAL_MAILBOX'] ?? null;
434 $phone = $host['PERSONAL_PHONE'] ?? null;
435 $userContact = !empty($email) ? $email : $phone;
436
437 $notificationService = null;
438 if ($userContact && self::isEmailCorrect($userContact))
439 {
440 $notificationService =
441 (new Sharing\Notification\Mail())
442 ->setEventLink($eventLink)
443 ->setEvent($event)
444 ->setInitiatorId($initiatorId)
445 ;
446 }
447
448 $notificationService?->notifyAboutMeetingStatus($userContact);
449 }
450
457 private static function onSharingCrmEventStatusChange(
458 string $currentMeetingStatus,
459 array $userEventBeforeChange,
460 int $userId,
461 int $ownerId
462 ): void
463 {
464 if (!Loader::includeModule('crm'))
465 {
466 return;
467 }
468
469 $previousMeetingStatus = $userEventBeforeChange['MEETING_STATUS'] ?? null;
470
471 if (
472 $currentMeetingStatus === Dictionary::MEETING_STATUS['Yes']
473 && $previousMeetingStatus === Dictionary::MEETING_STATUS['Question']
474 && $userId === $ownerId
475 )
476 {
477 self::onSharingCrmEventConfirmed(
478 (int)$userEventBeforeChange['PARENT_ID'],
479 $userEventBeforeChange['DATE_FROM'] ?? null,
480 $userEventBeforeChange['TZ_FROM'] ?? null,
481 );
482 }
483
484 if (
485 $currentMeetingStatus === Dictionary::MEETING_STATUS['No']
486 && (
487 $previousMeetingStatus === Dictionary::MEETING_STATUS['Question']
488 || $previousMeetingStatus === Dictionary::MEETING_STATUS['Yes']
489 )
490 )
491 {
492 self::onSharingCrmEventDeclined((int)$userEventBeforeChange['PARENT_ID'], $userId);
493 }
494 }
495
503 private static function onSharingCrmEventConfirmed(int $eventId, ?string $dateFrom, ?string $timezone): void
504 {
505 $crmDealLink = self::getCrmDealLink($eventId);
506
507 $activity = \CCrmActivity::GetByCalendarEventId($eventId, false);
508
509 if ($crmDealLink && $activity)
510 {
511 (new Sharing\Crm\NotifyManager($crmDealLink, Sharing\Crm\NotifyManager::NOTIFY_TYPE_EVENT_CONFIRMED))
512 ->sendSharedCrmActionsEvent(
513 Util::getDateTimestamp($dateFrom, $timezone),
514 $activity['ID'],
515 \CCrmOwnerType::Activity,
516 )
517 ;
518 }
519 }
520
526 private static function onSharingCrmEventDeclined(int $eventId, ?int $initiatorId = null): void
527 {
528 $sharingFactory = new Sharing\Link\Factory();
529
531 $eventLink = $sharingFactory->getEventLinkByEventId($eventId);
532
534 $crmDealLink = $sharingFactory->getLinkByHash($eventLink->getParentLinkHash());
535
537 $event = (new Mappers\Event())->getById($eventId);
538
539 $completeActivityStatus = Sharing\Crm\ActivityManager::STATUS_CANCELED_BY_MANAGER;
540
541 $userId = \CCalendar::GetUserId();
542 if ($userId === 0 || $userId === $event->getEventHost()->getId())
543 {
544 $completeActivityStatus = Sharing\Crm\ActivityManager::STATUS_CANCELED_BY_CLIENT;
545 }
546
547 (new Sharing\Crm\ActivityManager($eventId))
548 ->completeSharedCrmActivity($completeActivityStatus)
549 ;
551 if ($crmDealLink->getContactId() > 0)
552 {
553 $notificationService =
554 Crm\Integration\Calendar\Notification\Manager::getSenderInstance($crmDealLink)
555 ->setCrmDealLink($crmDealLink)
556 ->setEventLink($eventLink)
557 ->setEvent($event)
558 ;
559
560 if (method_exists($notificationService, 'setInitiatorId'))
561 {
562 $notificationService->setInitiatorId($initiatorId);
563 }
564
565 $notificationService->sendCrmSharingCancelled();
566 }
567 else
568 {
569 $email = CUser::GetByID($eventLink->getHostId())->Fetch()['PERSONAL_MAILBOX'] ?? null;
570 if (!is_string($email))
571 {
572 return;
573 }
574
575 $eventLink->setCanceledTimestamp(time());
576
577 (new Sharing\Notification\Mail())
578 ->setEventLink($eventLink)
579 ->setEvent($event)
580 ->setInitiatorId($initiatorId)
581 ->notifyAboutMeetingCancelled($email)
582 ;
583 }
584
586 }
587
597 public static function onSharingEventDeleted(int $eventId, string $eventType, ?int $initiatorId = null): void
598 {
599 $linkFactory = (new Sharing\Link\Factory());
600
602 $eventLink = $linkFactory->getEventLinkByEventId($eventId);
603
604 if ($eventLink)
605 {
607
608 if ($eventType === Dictionary::EVENT_TYPE['shared'])
609 {
610 self::onSharingCommonEventDeclined($eventLink, $initiatorId);
611 }
612 else if ($eventType === Dictionary::EVENT_TYPE['shared_crm'])
613 {
614 self::onSharingCrmEventDeclined($eventId, $initiatorId);
615 }
616
617 }
618 }
619
628 public static function onSharingCommonEventDeclined(
629 Sharing\Link\EventLink $eventLink,
630 ?int $initiatorId = null,
631 ): void
632 {
633 self::setCanceledTimeOnSharedLink($eventLink->getEventId());
635 $event = (new Mappers\Event())->getById($eventLink->getEventId());
636
637 $host = CUser::GetByID($eventLink->getHostId())->Fetch();
638 $email = $host['PERSONAL_MAILBOX'] ?? null;
639 $phone = $host['PERSONAL_PHONE'] ?? null;
640 $userContact = !empty($email) ? $email : $phone;
641
642 $notificationService = null;
643 if ($userContact && self::isEmailCorrect($userContact))
644 {
645 $notificationService =
646 (new Sharing\Notification\Mail())
647 ->setEventLink($eventLink)
648 ->setEvent($event)
649 ->setInitiatorId($initiatorId)
650 ;
651 }
652
653 $notificationService?->notifyAboutMeetingCancelled($userContact);
654 }
655
656 public static function setDeclinedStatusOnLinkOwnerEvent(Sharing\Link\EventLink $eventLink)
657 {
658 $userId = \CCalendar::GetUserId();
659 if ($userId !== 0 && $userId !== $eventLink->getHostId())
660 {
661 $ownerId = $eventLink->getOwnerId();
662 $event = EventTable::query()
663 ->setSelect(['ID'])
664 ->where('PARENT_ID', $eventLink->getEventId())
665 ->whereIn('EVENT_TYPE', self::getSharingEventTypes())
666 ->where('OWNER_ID', $ownerId)
667 ->exec()
668 ->fetch()
669 ;
670 if ($event['ID'] ?? false)
671 {
672 EventTable::update((int)$event['ID'], ['MEETING_STATUS' => Dictionary::MEETING_STATUS['No']]);
673 }
674 }
675 }
676
682 private static function updateEventSharingLink(Sharing\Link\EventLink $eventLink, array $fields): void
683 {
684 if (!empty($fields['DATE_TO']))
685 {
686 $expireDate = Helper::createSharingLinkExpireDate(
687 DateTime::createFromText($fields['DATE_TO']),
688 Sharing\Link\Helper::EVENT_SHARING_TYPE
689 );
690 $eventLink->setDateExpire($expireDate);
691 }
692
693 (new Sharing\Link\EventLinkMapper())->update($eventLink);
694 }
695
700 private static function getCrmDealLink(int $eventId): ?Link\CrmDealLink
701 {
702 $sharingLinkFactory = new Sharing\Link\Factory();
704 $eventLink = $sharingLinkFactory->getEventLinkByEventId($eventId);
705 if ($eventLink instanceof Sharing\Link\EventLink)
706 {
708 $crmDealLink = $sharingLinkFactory->getLinkByHash($eventLink->getParentLinkHash());
709 if ($crmDealLink instanceof Sharing\Link\CrmDealLink)
710 {
711 return $crmDealLink;
712 }
713 }
714
715 return null;
716 }
717
718 private function doesEventHasCorrectTime(): bool
719 {
720 $start = new DateTime($this->event->getStart()->toString());
721 $end = new DateTime($this->event->getEnd()->toString());
722
723 $offset = $this->getOffset();
724 $fromTs = Util::getDateTimestampUtc($start, $this->event->getStartTimeZone());
725 $toTs = Util::getDateTimestampUtc($end, $this->event->getEndTimeZone());
726
727 if ($fromTs < time())
728 {
729 return false;
730 }
731
732 $ownerDate = new \DateTime('now', new \DateTimeZone('UTC'));
733
734 $holidays = $this->getYearHolidays();
735 $intersectedHolidays = array_filter($holidays, static fn($holiday) => in_array($holiday, [
736 $ownerDate->setTimestamp($fromTs + $offset)->format('j.m'),
737 $ownerDate->setTimestamp($toTs + $offset)->format('j.m'),
738 ], true));
739
740 if (!empty($intersectedHolidays))
741 {
742 return false;
743 }
744
745 return true;
746 }
747
748 private function getYearHolidays(): array
749 {
750 return explode(',', \COption::GetOptionString('calendar', 'year_holidays', Loc::getMessage('EC_YEAR_HOLIDAYS_DEFAULT')));
751 }
752
753 private function doesEventSatisfyRule(): bool
754 {
755 $start = new DateTime($this->event->getStart()->toString(), null, new \DateTimeZone('UTC'));
756 $end = new DateTime($this->event->getEnd()->toString(), null, new \DateTimeZone('UTC'));
757
758 $rule = $this->link->getSharingRule();
759 $eventDurationMinutes = ($end->getTimestamp() - $start->getTimestamp()) / 60;
760 if ($eventDurationMinutes !== $rule->getSlotSize())
761 {
762 return false;
763 }
764
765 $availableTime = [];
766 foreach ($rule->getRanges() as $range)
767 {
768 foreach ($range->getWeekdays() as $weekday)
769 {
770 $availableTime[$weekday] ??= [];
771 $availableTime[$weekday][] = [
772 'from' => $range->getFrom(),
773 'to' => $range->getTo(),
774 ];
775
776 [$intersected, $notIntersected] = $this->separate(fn($interval) => Util::doIntervalsIntersect(
777 $interval['from'],
778 $interval['to'],
779 $range->getFrom(),
780 $range->getTo(),
781 ), $availableTime[$weekday]);
782
783 if (!empty($intersected))
784 {
785 $from = min(array_column($intersected, 'from'));
786 $to = max(array_column($intersected, 'to'));
787
788 $availableTime[$weekday] = [...$notIntersected, [
789 'from' => $from,
790 'to' => $to,
791 ]];
792 }
793 }
794 }
795
796
797 $eventOffset = Util::getTimezoneOffsetUTC($this->event->getStartTimeZone()?->getTimeZone()->getName());
798 $userOffset = $this->getOffset();
799
800 // Calculated as time of event in owner timezone
801 $fromTs = $start->getTimestamp() - ($eventOffset - $userOffset);
802 $toTs = $end->getTimestamp() - ($eventOffset - $userOffset);
803
804 //Minutes and range are in owner time so we can check them
805 $minutesFrom = ($fromTs % 86400) / 60;
806 $minutesTo = ($toTs % 86400) / 60;
807 $weekday = (int)gmdate('N', $fromTs) % 7;
808
809 foreach ($availableTime[$weekday] as $range)
810 {
811 if ($minutesFrom >= $range['from'] && $minutesTo <= $range['to'])
812 {
813 return true;
814 }
815 }
816
817 return false;
818 }
819
820 private function separate($take, $array): array
821 {
822 return array_reduce($array, fn($s, $e) => $take($e) ? [[...$s[0], $e], $s[1]] : [$s[0], [...$s[1], $e]], [[], []]);
823 }
824
828 private function checkUserAccessibility(array $userIds): bool
829 {
830 $start = new DateTime($this->event->getStart()->toString());
831 $end = new DateTime($this->event->getEnd()->toString());
832 $fromTs = Util::getDateTimestampUtc($start, $this->event->getStartTimeZone());
833 $toTs = Util::getDateTimestampUtc($end, $this->event->getEndTimeZone());
834
835 return (new SharingAccessibilityManager([
836 'userIds' => $userIds,
837 'timestampFrom' => $fromTs,
838 'timestampTo' => $toTs,
839 ]))->checkUsersAccessibility();
840 }
841
846 private static function getSectionId($userId)
847 {
848 $result = \CCalendarSect::GetList([
849 'arFilter' => [
850 'OWNER_ID' => $userId,
851 'CAL_TYPE' => 'user',
852 'ACTIVE' => 'Y',
853 ],
854 ]);
855
856 if (!$result)
857 {
858 $createdSection = \CCalendarSect::CreateDefault([
859 'type' => 'user',
860 'ownerId' => $userId,
861 ]);
862 $result[] = $createdSection;
863 }
864
865 return $result[0]['ID'];
866 }
867
871 private function notifyEventDeleted()
872 {
873 return \CCalendarNotify::Send([
874 'mode' => 'cancel_sharing',
875 'userId' => $this->hostId,
876 'guestId' => $this->ownerId,
877 'eventId' => $this->event->getId(),
878 'from' => $this->event->getStart()->toString(),
879 'to' => $this->event->getEnd()->toString(),
880 'name' => $this->event->getName(),
881 'isSharing' => true,
882 ]);
883 }
884
886 {
887 $event = (new Mappers\Event)->getById($eventLink->getEventId());
888 if ($event)
889 {
890 $event = \CCalendarEvent::GetList([
891 'arFilter' => [
892 'ID' => $event->getId(),
893 ],
894 'fetchAttendees' => true,
895 'checkPermissions' => false,
896 'parseRecursion' => false,
897 'setDefaultLimit' => false,
898 'limit' => null,
899 ]);
900
901 $event = $event[0] ?? null;
902 if ($event)
903 {
904 $event['ATTENDEES'] = [$eventLink->getOwnerId(), $eventLink->getHostId()];
905 $event['ATTENDEES_CODES'] = ['U' . $eventLink->getOwnerId(), 'U' . $eventLink->getHostId()];
906 \CCalendar::SaveEvent([
907 'arFields' => $event,
908 'userId' => $eventLink->getOwnerId(),
909 'checkPermission' => false,
910 'sendInvitations' => true,
911 ]);
912 }
913 }
914 }
915
916 private static function prepareTypeDependedEventFields(
917 Sharing\Link\Link $link,
918 int $userId
919 ): array
920 {
921 return match ($link->getObjectType())
922 {
923 Sharing\Link\Helper::GROUP_SHARING_TYPE => self::prepareGroupSharingEventFields($link, $userId),
924 default => self::prepareUserSharingEventFields($link, $userId),
925 };
926 }
927
928 private static function prepareGroupSharingEventFields(Sharing\Link\Link $link, int $userId): array
929 {
930 $groupId = $link->getOwnerId();
931 $section = \CCalendarSect::GetList([
932 'arFilter' => [
933 'OWNER_ID' => $groupId,
934 'CAL_TYPE' => Dictionary::CALENDAR_TYPE['group'],
935 'ACTIVE' => 'Y',
936 ],
937 'checkPermissions' => false,
938 'getPermissions' => false,
939 ]);
940
941 $attendeesCodes = ['U' . $userId];
942 $members = $link->getMembers();
943
944 if (!$members)
945 {
946 $attendeesCodes[] = 'U' . $link->getHostId();
947 }
948 else
949 {
950 foreach ($members as $member)
951 {
952 $attendeesCodes[] = 'U' . $member->getId();
953 }
954 }
955
956 return [
957 'OWNER_ID' => $link->getHostId(),
958 'SECTIONS' => [$section[0]['ID']],
959 'ATTENDEES_CODES' => $attendeesCodes,
960 'EVENT_TYPE' => Dictionary::EVENT_TYPE['shared_collab'],
961 ];
962 }
963
964 private static function prepareUserSharingEventFields(Sharing\Link\Link $link, int $userId): array
965 {
966 $sectionId = self::getSectionId($userId);
967
968 $ownerId = $link->getOwnerId();
969 $attendeesCodes = ['U' . $userId, 'U' . $ownerId];
970 $members = $link->getMembers();
971
972 foreach ($members as $member)
973 {
974 $attendeesCodes[] = 'U' . $member->getId();
975 }
976
977 return [
978 'OWNER_ID' => $userId,
979 'SECTIONS' => [$sectionId],
980 'ATTENDEES_CODES' => $attendeesCodes,
981 'EVENT_TYPE' => $link instanceof Sharing\Link\CrmDealLink
982 ? Dictionary::EVENT_TYPE['shared_crm']
983 : Dictionary::EVENT_TYPE['shared']
984 ,
985 ];
986 }
987
988 private function getOffset(): int
989 {
990 return Util::getTimezoneOffsetUTC(\CCalendar::GetUserTimezoneName($this->ownerId));
991 }
992}
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static isEmailCorrect(string $userContact)
Определения sharingeventmanager.php:197
static validateContactData(string $userContact)
Определения sharingeventmanager.php:176
static setCanceledTimeOnSharedLink(int $eventId)
Определения sharingeventmanager.php:345
static isPhoneNumberCorrect(string $userContact)
Определения sharingeventmanager.php:202
static getCrmEventDataFromRequest($request)
Определения sharingeventmanager.php:297
static validateContactName(string $userName)
Определения sharingeventmanager.php:187
static getSharingEventNameByUserId(int $userId)
Определения sharingeventmanager.php:256
static getSharingEventNameByUserName(?string $userName)
Определения sharingeventmanager.php:264
deactivateEventLink(Sharing\Link\EventLink $eventLink)
Определения sharingeventmanager.php:160
createEvent(bool $sendInvitations=true, string $externalUserName='')
Определения sharingeventmanager.php:71
static reSaveEventWithoutAttendeesExceptHostAndSharingLinkOwner(Sharing\Link\EventLink $eventLink)
Определения sharingeventmanager.php:885
static prepareEventForSave($data, $userId, Sharing\Link\Joint\JointLink $link)
Определения sharingeventmanager.php:214
static setDeclinedStatusOnLinkOwnerEvent(Sharing\Link\EventLink $eventLink)
Определения sharingeventmanager.php:656
static getEventDataFromRequest($request)
Определения sharingeventmanager.php:245
static getSharingEventNameByDealId(int $dealId)
Определения sharingeventmanager.php:280
static onSharingEventEdit(array $fields)
Определения sharingeventmanager.php:328
__construct(Event $event, ?int $hostId=null, ?int $ownerId=null, ?Sharing\Link\Link $link=null)
Определения sharingeventmanager.php:46
static getTimezoneOffsetUTC(string $timezoneName)
Определения util.php:767
static doIntervalsIntersect($from1, $to1, $from2, $to2)
Определения util.php:839
static getDateTimestamp(?string $dateFrom, ?string $timezone)
Определения util.php:724
static getDateTimestampUtc(DateTime $date, ?string $eventTimezone=null)
Определения util.php:774
Определения error.php:15
static getInstance()
Определения parser.php:78
static GetByID($ID)
Определения user.php:3820
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$start
Определения get_search.php:9
$activity
Определения options.php:214
check_email($email, $strict=false, $domainCheck=false)
Определения tools.php:4571
string $sectionId
Определения columnfields.php:71
$user
Определения mysql_to_pgsql.php:33
$host
Определения mysql_to_pgsql.php:32
$email
Определения payment.php:49
else $userName
Определения order_form.php:75
$fields
Определения yandex_run.php:501