Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
CrmType.php
1<?php
2
4
7
8class CrmType extends EntityLink
9{
10 protected const HAS_URL = true;
11 protected const DYNAMIC_TYPE = 'DYNAMIC';
12
13 protected string $crmType = '';
14 protected int $crmId = 0;
15
16 protected function __construct(string $entityId)
17 {
18 parent::__construct();
19 if (Loader::includeModule('crm'))
20 {
21 $this->extractCrmData($entityId);
22 }
23 $this->type = $this->crmType;
24 }
25
26 protected function getUrl(): string
27 {
28 if($this->crmType === '' || $this->crmId === 0 || !Loader::includeModule('crm'))
29 {
30 return '';
31 }
32
33 return \Bitrix\Im\Integration\Crm\Common::getLink($this->crmType, $this->crmId);
34 }
35
36 protected function getRestType(): string
37 {
38 if ($this->isExpectedType($this->type))
39 {
40 return $this->type;
41 }
42
43 return self::DYNAMIC_TYPE;
44 }
45
46 protected function extractCrmData(string $rawCrmData): void
47 {
48 $separatedEntityId = explode('|', $rawCrmData);
49 $this->crmType = $separatedEntityId[0] ?? '';
50 $this->crmId = (int)($separatedEntityId[1] ?? 0);
51 }
52
53 private function getExpectedType(): array
54 {
55 if (!Loader::includeModule('crm'))
56 {
57 return [];
58 }
59
60 return [
61 \CCrmOwnerType::LeadName => \CCrmOwnerType::LeadName,
62 \CCrmOwnerType::DealName => \CCrmOwnerType::DealName,
63 \CCrmOwnerType::ContactName => \CCrmOwnerType::ContactName,
64 \CCrmOwnerType::CompanyName => \CCrmOwnerType::CompanyName,
65 ];
66 }
67
68 private function isExpectedType(string $type): bool
69 {
70 return isset($this->getExpectedType()[$type]);
71 }
72}