Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
converter.php
1
<?
2
3
namespace
Bitrix\Main\UI\EntitySelector
;
4
5
class
Converter
6
{
7
static
$sampleSortPriority
= [
8
'meta-user'
,
9
'user'
,
10
'mail-contact'
,
11
'project'
,
12
'department'
,
13
'crm-company'
,
14
'crm-contact'
,
15
'crm-lead'
,
16
'crm-deal'
,
17
'crm-quote'
,
18
'crm-order'
,
19
'crm-product'
,
20
];
21
22
public
static
function
getCompatEntities
()
23
{
24
static
$compatEntities;
25
26
if
($compatEntities)
27
{
28
return
$compatEntities;
29
}
30
31
$compatEntities = [
32
'user'
=> [
33
'prefix'
=>
'U'
,
34
'pattern'
=>
'^(?<prefix>U)(?<itemId>\d+)$'
,
35
'reversePrefix'
=>
'U'
,
36
'reversePattern'
=>
'^(?<itemId>\d+)$'
37
],
38
'project'
=> [
39
'prefix'
=>
'SG'
,
40
'pattern'
=>
'^(?<prefix>SG)(?<itemId>\d+)$'
,
41
'reversePrefix'
=>
'SG'
,
42
'reversePattern'
=>
'^(?<itemId>\d+)$'
43
],
44
'crm-company'
=> [
45
'prefix'
=>
'CRMCOMPANY'
,
46
'pattern'
=>
'^(?<prefix>CRMCOMPANY)(?<itemId>.+)$'
,
47
'reversePrefix'
=>
'CRMCOMPANY'
,
48
'reversePattern'
=>
'^(?<itemId>\d+)$'
49
],
50
'crm-contact'
=> [
51
'prefix'
=>
'CRMCONTACT'
,
52
'pattern'
=>
'^(?<prefix>CRMCONTACT)(?<itemId>.+)$'
,
53
'reversePrefix'
=>
'CRMCONTACT'
,
54
'reversePattern'
=>
'^(?<itemId>\d+)$'
55
],
56
'crm-lead'
=> [
57
'prefix'
=>
'CRMLEAD'
,
58
'pattern'
=>
'^(?<prefix>CRMLEAD)(?<itemId>.+)$'
,
59
'reversePrefix'
=>
'CRMLEAD'
,
60
'reversePattern'
=>
'^(?<itemId>\d+)$'
61
],
62
'crm-deal'
=> [
63
'prefix'
=>
'CRMDEAL'
,
64
'pattern'
=>
'^(?<prefix>CRMDEAL)(?<itemId>.+)$'
,
65
'reversePrefix'
=>
'CRMDEAL'
,
66
'reversePattern'
=>
'^(?<itemId>\d+)$'
67
],
68
'crm-quote'
=> [
69
'prefix'
=>
'CRMQUOTE'
,
70
'pattern'
=>
'^(?<prefix>CRMQUOTE)(?<itemId>.+)$'
,
71
'reversePrefix'
=>
'CRMQUOTE'
,
72
'reversePattern'
=>
'^(?<itemId>\d+)$'
73
],
74
'crm-order'
=> [
75
'prefix'
=>
'CRMORDER'
,
76
'pattern'
=>
'^(?<prefix>CRMORDER)(?<itemId>.+)$'
,
77
'reversePrefix'
=>
'CRMORDER'
,
78
'reversePattern'
=>
'^(?<itemId>\d+)$'
79
],
80
'crm-product'
=> [
81
'prefix'
=>
'CRMPRODUCT'
,
82
'pattern'
=>
'^(?<prefix>CRMPRODUCT)(?<itemId>.+)$'
,
83
'reversePrefix'
=>
'CRMPRODUCT'
,
84
'reversePattern'
=>
'^(?<itemId>\d+)$'
85
],
86
'mail-contact'
=> [
87
'prefix'
=>
'MC'
,
88
'pattern'
=>
'^(?<prefix>MC)(?<itemId>[0-9]+)$'
,
89
'reversePrefix'
=>
'MC'
,
90
'reversePattern'
=>
'^(?<itemId>\d+)$'
91
],
92
'department'
=> [
93
'prefix'
=> (
function
($itemId) {
94
return
is_string($itemId) && $itemId[-1] ===
'F'
?
'D'
:
'DR'
;
95
}),
96
'itemId'
=>
function
($prefix, $itemId) {
97
return
$prefix ===
'D'
? $itemId.
':F'
: $itemId;
98
},
99
'pattern'
=>
'^(?<prefix>DR?)(?<itemId>\d+)$'
,
100
'reversePrefix'
=> (
function
($suffix) {
101
return
$suffix ===
':F'
?
'D'
:
'DR'
;
102
}),
103
'reversePattern'
=>
'^(?<itemId>\d+)(?<suffix>.*)$'
104
],
105
];
106
107
return
$compatEntities;
108
}
109
110
public
static
function
convertFromFinderCodes
(array $codesList = [])
111
{
112
$result = [];
113
foreach
($codesList as $code)
114
{
115
if
($code ===
'UA'
)
116
{
117
$result[] = [
'meta-user'
,
'all-users'
];
118
continue
;
119
}
120
121
foreach
(self::getCompatEntities() as $entityId => $entity)
122
{
123
if
(preg_match(
'/'
.$entity[
'pattern'
].
'/i'
, $code, $matches))
124
{
125
$result[] = [ $entityId, (int)$matches[
'itemId'
] ];
126
}
127
}
128
}
129
130
return
$result;
131
}
132
133
public
static
function
convertToFinderCodes
(array $entitiesList = [])
134
{
135
$result = [];
136
137
foreach
($entitiesList as [ $entityId, $id ])
138
{
139
if
(
140
$entityId ===
'meta-user'
141
&& $id ===
'all-users'
142
)
143
{
144
$result[] =
'UA'
;
145
continue
;
146
}
147
148
foreach
(self::getCompatEntities() as $sampleEntityId => $sampleEntity)
149
{
150
if
($entityId !== $sampleEntityId)
151
{
152
continue
;
153
}
154
155
if
(preg_match(
'/'
.$sampleEntity[
'reversePattern'
].
'/i'
, $id, $matches))
156
{
157
$result[] = (is_callable($sampleEntity[
'reversePrefix'
]) ? $sampleEntity[
'reversePrefix'
]($matches[
'suffix'
]) : $sampleEntity[
'reversePrefix'
]).$matches[
'itemId'
];
158
}
159
}
160
}
161
162
return
$result;
163
}
164
165
public
static
function
sortEntities
(array $entities = [])
166
{
167
usort($entities,
function
($a, $b) {
168
$aKey = array_search($a[0], self::$sampleSortPriority,
true
);
169
$bKey = array_search($b[0], self::$sampleSortPriority,
true
);
170
171
if
($aKey < $bKey)
172
{
173
return
-1;
174
}
175
176
if
($aKey > $bKey)
177
{
178
return
1;
179
}
180
181
return
0;
182
});
183
184
return
$entities;
185
}
186
}
Bitrix\Main\Text\Converter
Definition
converter.php:5
Bitrix\Main\UI\EntitySelector\Converter\sortEntities
static sortEntities(array $entities=[])
Definition
converter.php:165
Bitrix\Main\UI\EntitySelector\Converter\convertFromFinderCodes
static convertFromFinderCodes(array $codesList=[])
Definition
converter.php:110
Bitrix\Main\UI\EntitySelector\Converter\convertToFinderCodes
static convertToFinderCodes(array $entitiesList=[])
Definition
converter.php:133
Bitrix\Main\UI\EntitySelector\Converter\getCompatEntities
static getCompatEntities()
Definition
converter.php:22
Bitrix\Main\UI\EntitySelector\Converter\$sampleSortPriority
static $sampleSortPriority
Definition
converter.php:7
Bitrix\Main\UI\EntitySelector
Definition
converter.php:3
modules
main
lib
ui
entityselector
converter.php
Создано системой
1.10.0