1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
EntityLink.php
См. документацию.
1<?php
2
3namespace Bitrix\Im\V2\Chat;
4
5use Bitrix\Im\V2\Chat;
6use Bitrix\Im\V2\Chat\EntityLink\CalendarType;
7use Bitrix\Im\V2\Chat\EntityLink\CrmType;
8use Bitrix\Im\V2\Chat\EntityLink\MailType;
9use Bitrix\Im\V2\Chat\EntityLink\SonetType;
10use Bitrix\Im\V2\Chat\EntityLink\TasksType;
11use Bitrix\Im\V2\Chat\EntityLink\CallType;
12use Bitrix\Im\V2\Common\ContextCustomer;
13use Bitrix\Im\V2\Rest\RestConvertible;
14use Bitrix\Main\Application;
15use Bitrix\Main\Loader;
16
18{
19 use ContextCustomer;
20
21 protected const HAS_URL = false;
22
23 private const CACHE_TTL = 18144000;
24
25 protected int $chatId;
26 protected string $entityId = '';
27 protected string $type = '';
28 protected string $url = '';
29
30 protected function __construct()
31 {
32 }
33
34 public function getEntityId(): string
35 {
36 return $this->entityId;
37 }
38
39 public static function getInstance(Chat $chat): self
40 {
41 $type = $chat->getEntityType() ?? '';
42 if ($type === ExtendedType::Sonet->value && Loader::includeModule('socialnetwork'))
43 {
44 $instance = new SonetType();
45 }
46 elseif ($type === ExtendedType::Tasks->value && Loader::includeModule('tasks'))
47 {
48 $instance = new TasksType();
49 }
50 elseif ($type === ExtendedType::Calendar->value && Loader::includeModule('calendar'))
51 {
52 $instance = new CalendarType();
53 }
54 elseif ($type === ExtendedType::Crm->value && Loader::includeModule('crm'))
55 {
56 $instance = new CrmType($chat->getEntityId() ?? '');
57 }
58 elseif ($type === ExtendedType::Call->value && Loader::includeModule('crm'))
59 {
60 $instance = new CallType($chat->getEntityData1() ?? '');
61 }
62 elseif ($type === ExtendedType::Mail->value && Loader::includeModule('mail'))
63 {
64 $instance = new MailType();
65 }
66 else
67 {
68 $instance = new self();
69 }
70
71 $instance->type = $instance->type ?: $type;
72 $instance->chatId = $chat->getId() ?? 0;
73 $instance->entityId = $chat->getEntityId() ?? '';
74 $instance->fillUrl();
75
76 return $instance;
77 }
78
79 protected function fillUrl(): void
80 {
81 if (!static::HAS_URL)
82 {
83 return;
84 }
85
86 $this->url = $this->getUrl();
87 }
88
89 protected function fillUrlWithCache(): void
90 {
91 $cache = Application::getInstance()->getCache();
92 if ($cache->initCache(self::CACHE_TTL, $this->getCacheId(), $this->getCacheDir()))
93 {
94 $cachedEntityUrl = $cache->getVars();
95
96 if (!is_array($cachedEntityUrl))
97 {
98 $cachedEntityUrl = [];
99 }
100
101 $this->url = $cachedEntityUrl['url'] ?? '';
102 return;
103 }
104
105 $this->url = $this->getUrl();
106 $cache->startDataCache();
107 $cache->endDataCache(['url' => $this->url]);
108 }
109
110 public static function cleanCache(int $chatId): void
111 {
112 Application::getInstance()->getCache()->cleanDir(static::getCacheDirByChatId($chatId));
113 }
114
115 private function getCacheDir(): string
116 {
117 return static::getCacheDirByChatId($this->chatId);
118 }
119
120 private static function getCacheDirByChatId(int $chatId): string
121 {
122 $cacheSubDir = $chatId % 100;
123
124 return "/bx/imc/chatentitylink/1/{$cacheSubDir}/{$chatId}";
125 }
126
127 private function getCacheId(): string
128 {
129 return "chat_entity_link_{$this->chatId}";
130 }
131
132 protected function getUrl(): string
133 {
134 return '';
135 }
136
137 protected function getRestType(): string
138 {
139 return $this->type;
140 }
141
142 public static function getRestEntityName(): string
143 {
144 return 'entityLink';
145 }
146
147 public function toRestFormat(array $option = []): array
148 {
149 return [
150 'type' => $this->getRestType(),
151 'url' => $this->url,
152 ];
153 }
154
159 public function toArray(array $options = []): array
160 {
161 return [
162 'TYPE' => $this->getRestType(),
163 'URL' => $this->url,
164 ];
165 }
166}
$type
Определения options.php:106
static getInstance()
Определения servicelocator.php:33
$options
Определения commerceml2.php:49
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$entityId
Определения payment.php:4
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$instance
Определения ps_b24_final.php:14
$option
Определения options.php:1711
$url
Определения iframe.php:7