Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
notifymanager.php
1<?php
2
4
5use Bitrix\Calendar\Integration\Crm\EventData;
6use Bitrix\Calendar\Integration\Crm\EventHandlerService;
9
10final class NotifyManager
11{
12 public const NOTIFY_TYPE_NOT_VIEWED = 'notViewed';
13 public const NOTIFY_TYPE_VIEWED = 'viewed';
14 public const NOTIFY_TYPE_EVENT_CONFIRMED = 'eventConfirmed';
15
16 public const NOTIFY_TYPES = [
20 ];
21
22 private const SHARING_CRM_ACTIONS_EVENT = 'onSharedCrmActions';
23
24 private CrmDealLink $link;
25 private string $notifyType;
26
31 public function __construct(CrmDealLink $link, string $notifyType)
32 {
33 $this->link = $link;
34 $this->notifyType = $notifyType;
35 }
36
45 ?int $timestamp = null,
46 int $associatedEntityId = 0,
47 int $associatedEntityTypeId = 0
48 ): void
49 {
50 $timestamp = $this->prepareTimestamp($timestamp);
51
52 $eventData = [
53 'EVENT_TYPE' => $this->notifyType,
54 'OWNER_ID' => $this->link->getOwnerId(),
55 'LINK_ID' => $this->link->getId(),
56 'LINK_TYPE' => $this->link->getObjectType(),
57 'LINK_ENTITY_ID' => $this->link->getObjectId(),
58 'CONTACT_ID' => $this->link->getContactId(),
59 'CONTACT_TYPE_ID' => $this->link->getContactType(),
60 'LINK_HASH' => $this->link->getHash(),
61 'ASSOCIATED_ENTITY_ID' => $associatedEntityId,
62 'ASSOCIATED_ENTITY_TYPE_ID' => $associatedEntityTypeId,
63 'TIMESTAMP' => $timestamp,
64 ];
65
66 (new \Bitrix\Main\Event(
67 'calendar',
68 self::SHARING_CRM_ACTIONS_EVENT,
69 $eventData
70 ))->send();
71 }
72
77 private function prepareTimestamp($timestamp)
78 {
79 $result = $timestamp;
80
81 if ($this->notifyType === self::NOTIFY_TYPE_NOT_VIEWED || $this->notifyType === self::NOTIFY_TYPE_VIEWED)
82 {
83 $result = $this->link->getDateCreate() ? $this->link->getDateCreate()->getTimestamp() : null;
84 }
85
86 if (!$result)
87 {
88 $result = (new DateTime())->getTimestamp();
89 }
90
91 return $result;
92 }
93}
__construct(CrmDealLink $link, string $notifyType)
sendSharedCrmActionsEvent(?int $timestamp=null, int $associatedEntityId=0, int $associatedEntityTypeId=0)