21 private ?
string $guestName;
23 private ?
Event $event;
34 ?
string $guestName =
null,
38 $this->eventId = $eventId;
40 $this->guestName = $guestName;
41 $this->eventLink = $eventLink;
46 $this->
event = $event;
64 if (!$this->isAvailable())
70 'SUBJECT' => $activityName,
72 'RESPONSIBLE_ID' => $this->link->getOwnerId(),
73 'CALENDAR_EVENT_ID' => $this->eventId,
74 'BINDINGS' => $this->getBindings(),
75 'SETTINGS' => $this->getSettings(),
76 'END_TIME' => $eventStart,
79 return (
new \
Bitrix\
Crm\Activity\Provider\CalendarSharing())
80 ->createActivity(\
Bitrix\
Crm\Activity\Provider\CalendarSharing::PROVIDER_TYPE_ID,
$fields)
91 if (!$this->isAvailable())
96 $activity = \CCrmActivity::GetByCalendarEventId($this->eventId,
false);
106 case self::STATUS_MEETING_NOT_HELD:
107 $crmStatus = ActivityHandler::SHARING_STATUS_MEETING_NOT_HELD;
109 case self::STATUS_CANCELED_BY_MANAGER:
110 $crmStatus = ActivityHandler::SHARING_STATUS_CANCELED_BY_MANAGER;
112 case self::STATUS_CANCELED_BY_CLIENT:
113 $crmStatus = ActivityHandler::SHARING_STATUS_CANCELED_BY_CLIENT;
118 ->completeWithStatus($crmStatus);
131 if (!$this->isAvailable())
136 $activity = \CCrmActivity::GetByCalendarEventId($this->eventId,
false);
144 ->updateDeadline($deadline)
152 if (!$this->isAvailable())
157 $activity = \CCrmActivity::GetByCalendarEventId($this->eventId,
false);
165 'CALENDAR_EVENT_NAME' => $this->
event->getName(),
166 'CALENDAR_EVENT_MEMBER_IDS' => $this->getEventMemberIds(),
179 private function isAvailable(): bool
181 return Loader::includeModule(
'crm') ===
true
182 && \Bitrix\Crm\Integration\Calendar\Helper::isSharingCrmAvaible()
189 private function getBindings():
array
192 $entityTypeId =
null;
194 switch ($this->link->getObjectType())
196 case Helper::CRM_DEAL_SHARING_TYPE:
197 $entityTypeId = \CCrmOwnerType::Deal;
202 'OWNER_TYPE_ID' => $entityTypeId,
203 'OWNER_ID' => $this->link->getObjectId(),
206 if ($this->link->getContactType() && $this->link->getContactId())
209 'OWNER_TYPE_ID' => $this->link->getContactType(),
210 'OWNER_ID' => $this->link->getContactId(),
220 private function getSettings():
array
224 if ($this->link->getContactType() && $this->link->getContactId())
227 'CONTACT_TYPE_ID' => $this->link->getContactType(),
228 'CONTACT_ID' => $this->link->getContactId(),
234 'GUEST_NAME' => $this->guestName,
238 $result[
'LINK_ID'] = $this->link->getId();
239 $result[
'EVENT_LINK_HASH'] = $this->eventLink?->getHash();
240 $result[
'CALENDAR_EVENT_NAME'] = $this->
event->getName();
241 $result[
'CALENDAR_EVENT_MEMBER_IDS'] = $this->getLinkMemberIds();
249 private function getLinkMemberIds():
array
251 return array_map(
static fn($member) => $member->getId(), $this->link->getMembers());
257 private function getEventMemberIds():
array
259 $parentId = $this->
event->getParentId();
260 $memberIds = \CCalendarEvent::GetAttendeeIds([$parentId])[$parentId] ?? [];
262 $linkOwnerId = $this->link->getOwnerId();
263 $eventOwnerId = $this->
event->getOwner()?->getId();
264 return array_filter($memberIds,
static fn(
int $memberId) =>
265 !in_array($memberId, [$linkOwnerId, $eventOwnerId],
true)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)