1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
activitymanager.php
См. документацию.
1<?php
2
4
9use Bitrix\Crm\Integration\Calendar\ActivityHandler;
12
14{
15 public const STATUS_MEETING_NOT_HELD = 'meeting_not_held';
16 public const STATUS_CANCELED_BY_MANAGER = 'canceled_by_manager';
17 public const STATUS_CANCELED_BY_CLIENT = 'canceled_by_client';
18
19 private int $eventId;
20 private ?CrmDealLink $link;
21 private ?string $guestName;
22 private ?EventLink $eventLink;
23 private ?Event $event;
24
31 public function __construct(
32 int $eventId,
33 ?CrmDealLink $link = null,
34 ?string $guestName = null,
35 ?EventLink $eventLink = null,
36 )
37 {
38 $this->eventId = $eventId;
39 $this->link = $link;
40 $this->guestName = $guestName;
41 $this->eventLink = $eventLink;
42 }
43
44 public function setEvent(Event $event): self
45 {
46 $this->event = $event;
47
48 return $this;
49 }
50
59 string $activityName,
60 ?string $description,
61 DateTime $eventStart
62 ): ?\Bitrix\Main\Result
63 {
64 if (!$this->isAvailable())
65 {
66 return null;
67 }
68
69 $fields = [
70 'SUBJECT' => $activityName,
71 'DESCRIPTION' => $description,
72 'RESPONSIBLE_ID' => $this->link->getOwnerId(),
73 'CALENDAR_EVENT_ID' => $this->eventId,
74 'BINDINGS' => $this->getBindings(),
75 'SETTINGS' => $this->getSettings(),
76 'END_TIME' => $eventStart,
77 ];
78
79 return (new \Bitrix\Crm\Activity\Provider\CalendarSharing())
80 ->createActivity(\Bitrix\Crm\Activity\Provider\CalendarSharing::PROVIDER_TYPE_ID, $fields)
81 ;
82 }
83
89 public function completeSharedCrmActivity(?string $status): bool
90 {
91 if (!$this->isAvailable())
92 {
93 return false;
94 }
95
96 $activity = \CCrmActivity::GetByCalendarEventId($this->eventId, false);
97
98 if (!$activity)
99 {
100 return false;
101 }
102
103 $crmStatus = null;
104 switch ($status)
105 {
106 case self::STATUS_MEETING_NOT_HELD:
107 $crmStatus = ActivityHandler::SHARING_STATUS_MEETING_NOT_HELD;
108 break;
109 case self::STATUS_CANCELED_BY_MANAGER:
110 $crmStatus = ActivityHandler::SHARING_STATUS_CANCELED_BY_MANAGER;
111 break;
112 case self::STATUS_CANCELED_BY_CLIENT:
113 $crmStatus = ActivityHandler::SHARING_STATUS_CANCELED_BY_CLIENT;
114 break;
115 }
116
117 (new ActivityHandler($activity, $activity['OWNER_TYPE_ID'], $activity['OWNER_ID']))
118 ->completeWithStatus($crmStatus);
119
120 return true;
121 }
122
129 public function editActivityDeadline(DateTime $deadline): bool
130 {
131 if (!$this->isAvailable())
132 {
133 return false;
134 }
135
136 $activity = \CCrmActivity::GetByCalendarEventId($this->eventId, false);
137
138 if (!$activity)
139 {
140 return false;
141 }
142
143 (new ActivityHandler($activity, $activity['OWNER_TYPE_ID'], $activity['OWNER_ID']))
144 ->updateDeadline($deadline)
145 ;
146
147 return true;
148 }
149
150 public function updateEvent(): bool
151 {
152 if (!$this->isAvailable())
153 {
154 return false;
155 }
156
157 $activity = \CCrmActivity::GetByCalendarEventId($this->eventId, false);
158
159 if (!$activity)
160 {
161 return false;
162 }
163
164 $settings = [
165 'CALENDAR_EVENT_NAME' => $this->event->getName(),
166 'CALENDAR_EVENT_MEMBER_IDS' => $this->getEventMemberIds(),
167 ];
168
169 (new ActivityHandler($activity, $activity['OWNER_TYPE_ID'], $activity['OWNER_ID']))
170 ->updateSettings($settings)
171 ;
172
173 return true;
174 }
175
179 private function isAvailable(): bool
180 {
181 return Loader::includeModule('crm') === true
182 && \Bitrix\Crm\Integration\Calendar\Helper::isSharingCrmAvaible()
183 ;
184 }
185
189 private function getBindings(): array
190 {
191 $result = [];
192 $entityTypeId = null;
193
194 switch ($this->link->getObjectType())
195 {
196 case Helper::CRM_DEAL_SHARING_TYPE:
197 $entityTypeId = \CCrmOwnerType::Deal;
198 break;
199 }
200
201 $result[] = [
202 'OWNER_TYPE_ID' => $entityTypeId,
203 'OWNER_ID' => $this->link->getObjectId(),
204 ];
205
206 if ($this->link->getContactType() && $this->link->getContactId())
207 {
208 $result[] = [
209 'OWNER_TYPE_ID' => $this->link->getContactType(),
210 'OWNER_ID' => $this->link->getContactId(),
211 ];
212 }
213
214 return $result;
215 }
216
220 private function getSettings(): array
221 {
222 $result = [];
223
224 if ($this->link->getContactType() && $this->link->getContactId())
225 {
226 $result = [
227 'CONTACT_TYPE_ID' => $this->link->getContactType(),
228 'CONTACT_ID' => $this->link->getContactId(),
229 ];
230 }
231 elseif ($this->guestName)
232 {
233 $result = [
234 'GUEST_NAME' => $this->guestName,
235 ];
236 }
237
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();
242
243 return $result;
244 }
245
249 private function getLinkMemberIds(): array
250 {
251 return array_map(static fn($member) => $member->getId(), $this->link->getMembers());
252 }
253
257 private function getEventMemberIds(): array
258 {
259 $parentId = $this->event->getParentId();
260 $memberIds = \CCalendarEvent::GetAttendeeIds([$parentId])[$parentId] ?? [];
261
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)
266 );
267 }
268}
createCalendarSharingActivity(string $activityName, ?string $description, DateTime $eventStart)
Определения activitymanager.php:58
completeSharedCrmActivity(?string $status)
Определения activitymanager.php:89
editActivityDeadline(DateTime $deadline)
Определения activitymanager.php:129
__construct(int $eventId, ?CrmDealLink $link=null, ?string $guestName=null, ?EventLink $eventLink=null,)
Определения activitymanager.php:31
Определения loader.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
if(Loader::includeModule( 'bitrix24')) elseif(Loader::includeModule('intranet') &&CIntranetUtils::getPortalZone() !=='ru') $description
Определения .description.php:24
$activity
Определения options.php:214
$status
Определения session.php:10
$settings
Определения product_settings.php:43
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$fields
Определения yandex_run.php:501