1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
EntityLink.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Im\V2\Chat;
4
5
use Bitrix\Im\V2\Chat;
6
use Bitrix\Im\V2\Chat\EntityLink\CalendarType;
7
use Bitrix\Im\V2\Chat\EntityLink\CrmType;
8
use Bitrix\Im\V2\Chat\EntityLink\MailType;
9
use Bitrix\Im\V2\Chat\EntityLink\SonetType;
10
use Bitrix\Im\V2\Chat\EntityLink\TasksType;
11
use Bitrix\Im\V2\Chat\EntityLink\CallType;
12
use Bitrix\Im\V2\Common\ContextCustomer;
13
use Bitrix\Im\V2\Rest\RestConvertible;
14
use Bitrix\Main\Application;
15
use Bitrix\Main\Loader;
16
17
class
EntityLink
implements
RestConvertible
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
$type
Определения
options.php:106
Bitrix\Im\V2\Chat\EntityLink\CalendarType
Определения
CalendarType.php:10
Bitrix\Im\V2\Chat\EntityLink\CallType
Определения
CallType.php:6
Bitrix\Im\V2\Chat\EntityLink\CrmType
Определения
CrmType.php:9
Bitrix\Im\V2\Chat\EntityLink\MailType
Определения
MailType.php:9
Bitrix\Im\V2\Chat\EntityLink\SonetType
Определения
SonetType.php:9
Bitrix\Im\V2\Chat\EntityLink\TasksType
Определения
TasksType.php:9
Bitrix\Im\V2\Chat\EntityLink\getEntityId
getEntityId()
Определения
EntityLink.php:34
Bitrix\Im\V2\Chat\EntityLink\toArray
toArray(array $options=[])
Определения
EntityLink.php:159
Bitrix\Im\V2\Chat\EntityLink\getRestEntityName
static getRestEntityName()
Определения
EntityLink.php:142
Bitrix\Im\V2\Chat\EntityLink\__construct
__construct()
Определения
EntityLink.php:30
Bitrix\Im\V2\Chat\EntityLink\toRestFormat
toRestFormat(array $option=[])
Определения
EntityLink.php:147
Bitrix\Im\V2\Chat\EntityLink\cleanCache
static cleanCache(int $chatId)
Определения
EntityLink.php:110
Bitrix\Im\V2\Chat\EntityLink\getRestType
getRestType()
Определения
EntityLink.php:137
Bitrix\Im\V2\Chat\EntityLink\$entityId
string $entityId
Определения
EntityLink.php:26
Bitrix\Im\V2\Chat\EntityLink\$chatId
int $chatId
Определения
EntityLink.php:25
Bitrix\Im\V2\Chat\EntityLink\$type
string $type
Определения
EntityLink.php:27
Bitrix\Im\V2\Chat\EntityLink\getInstance
static getInstance(Chat $chat)
Определения
EntityLink.php:39
Bitrix\Im\V2\Chat\EntityLink\HAS_URL
const HAS_URL
Определения
EntityLink.php:21
Bitrix\Im\V2\Chat\EntityLink\$url
string $url
Определения
EntityLink.php:28
Bitrix\Im\V2\Chat\EntityLink\getUrl
getUrl()
Определения
EntityLink.php:132
Bitrix\Im\V2\Chat\EntityLink\fillUrl
fillUrl()
Определения
EntityLink.php:79
Bitrix\Im\V2\Chat\EntityLink\fillUrlWithCache
fillUrlWithCache()
Определения
EntityLink.php:89
Bitrix\Main\DI\ServiceLocator\getInstance
static getInstance()
Определения
servicelocator.php:33
$options
$options
Определения
commerceml2.php:49
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
Bitrix\Im\V2\Rest\RestConvertible
Определения
RestConvertible.php:6
Bitrix\Im\V2\Chat\EntityLink
Определения
CalendarType.php:3
Bitrix\Im\V2\Chat
$entityId
$entityId
Определения
payment.php:4
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
$instance
$instance
Определения
ps_b24_final.php:14
$option
$option
Определения
options.php:1711
$url
$url
Определения
iframe.php:7
bitrix
modules
im
lib
V2
Chat
EntityLink.php
Создано системой
1.14.0