Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
finderdest.php
1<?php
9namespace Bitrix\Main;
10
11use Bitrix\Main;
14
15Loc::loadMessages(__FILE__);
16
36{
37 /*public static function getTableName()
38 {
39 return 'b_finder_dest';
40 }*/
41
42 /*public static function getMap()
43 {
44 global $USER;
45
46 return array(
47 'USER_ID' => array(
48 'data_type' => 'integer',
49 'primary' => true
50 ),
51 new Entity\ReferenceField(
52 'USER',
53 'Bitrix\Main\UserTable',
54 array('=this.USER_ID' => 'ref.ID')
55 ),
56 'CODE' => array(
57 'data_type' => 'string',
58 'primary' => true
59 ),
60 'CODE_USER_ID' => array(
61 'data_type' => 'integer'
62 ),
63 'CODE_TYPE' => array(
64 'data_type' => 'string'
65 ),
66 new Entity\ReferenceField(
67 'CODE_USER',
68 'Bitrix\Main\UserTable',
69 array('=this.CODE_USER_ID' => 'ref.ID')
70 ),
71 new Entity\ReferenceField(
72 'CODE_USER_CURRENT',
73 'Bitrix\Main\UserTable',
74 array(
75 '=this.CODE_USER_ID' => 'ref.ID',
76 '=this.USER_ID' => new SqlExpression('?i', $USER->GetId())
77 )
78 ),
79 'CONTEXT' => array(
80 'data_type' => 'string',
81 'primary' => true
82 ),
83 'LAST_USE_DATE' => array(
84 'data_type' => 'datetime'
85 )
86 );
87 }*/
88
100 public static function merge(array $data)
101 {
102 global $USER;
103
104 $userId = (
105 isset($data['USER_ID']) && intval($data['USER_ID']) > 0
106 ? intval($data['USER_ID'])
107 : (is_object($GLOBALS['USER']) ? $USER->getId() : 0)
108 );
109
110 if ($userId <= 0 || empty($data['CODE']) || empty($data['CONTEXT']) || !is_string($data['CONTEXT']))
111 {
112 return;
113 }
114
115 if (is_array($data['CODE']))
116 {
117 $dataModified = $data;
118
119 foreach ($data['CODE'] as $code)
120 {
121 $dataModified['CODE'] = $code;
122 FinderDestTable::merge($dataModified);
123 }
124
125 return;
126 }
127
128 if (!is_string($data['CODE']))
129 {
130 return;
131 }
132
133 foreach (Main\UI\EntitySelector\Converter::getCompatEntities() as $entityId => $entity)
134 {
135 if (preg_match('/'.$entity['pattern'].'/i', $data['CODE'], $matches))
136 {
137 $itemId = $matches['itemId'];
138 $prefix = $matches['prefix'];
139
140 if (isset($entity['itemId']) && is_callable($entity['itemId']))
141 {
142 $itemId = $entity['itemId']($prefix, $itemId);
143 }
144
145 parent::merge([
146 'USER_ID' => $userId,
147 'CONTEXT' => mb_strtoupper($data['CONTEXT']),
148 'ENTITY_ID' => $entityId,
149 'ITEM_ID' => $itemId,
150 'PREFIX' => mb_strtoupper($prefix)
151 ]);
152
153 $cache = new \CPHPCache;
154 $cache->cleanDir('/sonet/log_dest_sort/'.intval($userId / 100));
155 $cache->cleanDir(\Bitrix\Main\UI\Selector\Entities::getCacheDir([
156 'userId' => $userId,
157 ]));
158
159 return;
160 }
161 }
162 }
163
172 public static function convertRights($rights, $excludeCodes = [])
173 {
174 $result = [];
175
176 if (is_array($rights))
177 {
178 foreach ($rights as $right)
179 {
180 if (
181 !in_array($right, $excludeCodes)
182 && (
183 preg_match('/^SG(\d+)$/i', $right, $matches)
184 || preg_match('/^U(\d+)$/i', $right, $matches)
185 || preg_match('/^DR(\d+)$/i', $right, $matches)
186 || preg_match('/^CRMCONTACT(\d+)$/i', $right, $matches)
187 || preg_match('/^CRMCOMPANY(\d+)$/i', $right, $matches)
188 || preg_match('/^CRMLEAD(\d+)$/i', $right, $matches)
189 || preg_match('/^CRMDEAL(\d+)$/i', $right, $matches)
190 )
191 )
192 {
193 $result[] = mb_strtoupper($right);
194 }
195 }
196
197 $result = array_unique($result);
198 }
199
200 return $result;
201 }
202
212 public static function onAfterDiskAjaxAction($sharings)
213 {
214 if (is_array($sharings))
215 {
216 $destinationCodes = [];
217 foreach ($sharings as $key => $sharing)
218 {
219 $destinationCodes[] = $sharing->getToEntity();
220 }
221
222 if (!empty($destinationCodes))
223 {
224 $destinationCodes = array_unique($destinationCodes);
225 \Bitrix\Main\FinderDestTable::merge([
226 "CONTEXT" => "DISK_SHARE",
227 "CODE" => \Bitrix\Main\FinderDestTable::convertRights($destinationCodes)
228 ]);
229 }
230 }
231 }
232
238 public static function migrateData()
239 {
240 $res = \CUserOptions::getList(
241 [],
242 [
243 "CATEGORY" => "socialnetwork",
244 "NAME" => "log_destination"
245 ]
246 );
247
248 while ($option = $res->fetch())
249 {
250 if (!empty($option["VALUE"]))
251 {
252 $optionValue = unserialize($option["VALUE"], ['allowed_classes' => false]);
253
254 if (is_array($optionValue))
255 {
256 foreach ($optionValue as $key => $val)
257 {
258 if (in_array(
259 $key,
260 ["users", "sonetgroups", "department", "companies", "contacts", "leads", "deals"]
261 ))
262 {
263 $codes = \CUtil::jsObjectToPhp($val);
264 if (is_array($codes))
265 {
266 \Bitrix\Main\FinderDestTable::merge(
267 [
268 "USER_ID" => $option["USER_ID"],
269 "CONTEXT" => "blog_post",
270 "CODE" => array_keys($codes)
271 ]
272 );
273 }
274 }
275 }
276 }
277 }
278 }
279
280 $res = \CUserOptions::getList(
281 [],
282 [
283 "CATEGORY" => "crm",
284 "NAME" => "log_destination"
285 ]
286 );
287
288 while ($option = $res->fetch())
289 {
290 if (!empty($option["VALUE"]))
291 {
292 $optionValue = unserialize($option["VALUE"], ['allowed_classes' => false]);
293
294 if (is_array($optionValue))
295 {
296 foreach ($optionValue as $key => $val)
297 {
298 $codes = explode(',', $val);
299 if (is_array($codes))
300 {
301 \Bitrix\Main\FinderDestTable::merge(
302 [
303 "USER_ID" => $option["USER_ID"],
304 "CONTEXT" => "crm_post",
305 "CODE" => $codes
306 ]
307 );
308 }
309 }
310 }
311 }
312 }
313 }
314
322 public static function getMailUserId($code)
323 {
324 $userId = [];
325 $result = [];
326
327 if (!is_array($code))
328 {
329 $code = [$code];
330 }
331
332 foreach ($code as $val)
333 {
334 if (preg_match('/^U(\d+)$/', $val, $matches))
335 {
336 $userId[] = $matches[1];
337 }
338 }
339
340 if (!empty($userId))
341 {
342 $res = \Bitrix\Main\UserTable::getList(
343 [
344 'order' => [],
345 'filter' => [
346 "ID" => $userId,
347 "=EXTERNAL_AUTH_ID" => 'email'
348 ],
349 'select' => ["ID"]
350 ]
351 );
352
353 while ($user = $res->fetch())
354 {
355 $result[] = $user["ID"];
356 }
357 }
358
359 return $result;
360 }
361
362}
static onAfterDiskAjaxAction($sharings)
static convertRights($rights, $excludeCodes=[])
static merge(array $data)
static loadMessages($file)
Definition loc.php:64
$GLOBALS['____1444769544']
Definition license.php:1