1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
entities.php
См. документацию.
1<?php
2
3namespace Bitrix\Main\UI\Selector;
4
5use Bitrix\Main\Event;
6use Bitrix\Main\EventResult;
7use Bitrix\Main\Localization\Loc;
8use Bitrix\Main\ModuleManager;
9use Bitrix\Main\FinderDestTable;
10use Bitrix\Main\Loader;
11use Bitrix\Main\ORM\Fields\ExpressionField;
12
14{
15 const CODE_USER_REGEX = '/^U(\d+)$/i';
16 const CODE_USERALL_REGEX = '/^UA$/i';
17 const CODE_USERMANAGER_REGEX = '/^USER_MANAGER$/i';
18 const CODE_SONETGROUP_REGEX = '/^SG(\d+)$/i';
19 const CODE_GROUP_REGEX = '/^G(\d+)$/i';
20 const CODE_DEPT_REGEX = '/^D(\d+)$/i';
21 const CODE_DEPTR_REGEX = '/^DR(\d+)$/i';
22 const CODE_CRMCONTACT_REGEX = '/^CRMCONTACT(\d+)$/i';
23 const CODE_CRMCOMPANY_REGEX = '/^CRMCOMPANY(\d+)$/i';
24 const CODE_CRMLEAD_REGEX = '/^CRMLEAD(\d+)$/i';
25 const CODE_CRMDEAL_REGEX = '/^CRMDEAL(\d+)$/i';
26
27 const ENTITY_TYPE_DEPARTMENTS = 'DEPARTMENTS';
28
29 const LIST_USER_LIMIT = 11;
30
31 public static function getList($params = array())
32 {
33 $result = array();
34
35 if (empty($params['context']))
36 {
37 return $result;
38 }
39
40 if (empty($params['itemsSelected']))
41 {
42 return $result;
43 }
44
45 $event = new Event("main", "OnUISelectorEntitiesGetList", $params);
46 $event->send();
47 $eventResultList = $event->getResults();
48
49 if (is_array($eventResultList) && !empty($eventResultList))
50 {
51 foreach ($eventResultList as $eventResult)
52 {
53 if ($eventResult->getType() == EventResult::SUCCESS)
54 {
55 $resultParams = $eventResult->getParameters();
56 $result = $resultParams['result'];
57 break;
58 }
59 }
60 }
61
62 return $result;
63 }
64
65 public static function getEntityType($params)
66 {
67 if (
68 empty($params)
69 || empty($params['itemCode'])
70 )
71 {
72 return false;
73 }
74
75 $result = false;
76 $itemCode = $params['itemCode'];
77
78 if (preg_match(self::CODE_USER_REGEX, $itemCode, $matches))
79 {
80 $result = 'users';
81 }
82 elseif (preg_match(self::CODE_SONETGROUP_REGEX, $itemCode, $matches))
83 {
84 $result = 'sonetgroups';
85 }
86 elseif (
87 preg_match(self::CODE_DEPT_REGEX, $itemCode, $matches)
88 || preg_match(self::CODE_DEPTR_REGEX, $itemCode, $matches)
89 )
90 {
91 $result = 'department';
92 }
93 elseif (
94 preg_match(self::CODE_USERALL_REGEX, $itemCode, $matches)
95 || preg_match(self::CODE_USERMANAGER_REGEX, $itemCode, $matches)
96 || preg_match(self::CODE_GROUP_REGEX, $itemCode, $matches)
97 )
98 {
99 $result = 'groups';
100 }
101
102 return $result;
103 }
104
105 public static function getData($options = array(), $entityTypes = array(), $selectedItems = array())
106 {
107 $result = array(
108 'ENTITIES' => array(),
109 'SORT' => array()
110 );
111
112 $context = (!empty($options['context']) ? $options['context'] : false);
113
114 if (
115 empty($context)
116 || empty($entityTypes)
117 )
118 {
119 return $result;
120 }
121
122 $filterParams = array(
123 "DEST_CONTEXT" => $context,
124 "ALLOW_EMAIL_INVITATION" => (
125 (isset($options["allowEmailInvitation"]) && $options["allowEmailInvitation"] == "Y")
126 || (isset($options["allowSearchCrmEmailUsers"]) && $options["allowSearchCrmEmailUsers"] == "Y")
127 ),
128 "CRM" => (isset($options["enableCrm"]) && $options["enableCrm"] == "Y")
129 );
130
131 if (!empty($options['contextCode']))
132 {
133 $filterParams["CODE_TYPE"] = $options['contextCode'];
134 }
135
136 $res = self::getLastSort($filterParams);
137 $destSortData = $res['DATA'];
138
139 $dataAdditional = $res['DATA_ADDITIONAL'];
140
142 $destSortData,
143 array(
144 "CRM" => (
145 isset($options["enableCrm"])
146 && $options["enableCrm"] == 'Y'
147 ? 'Y'
148 : 'N'
149 ),
150 "EMAILS" => (
151 (
152 isset($options["allowAddUser"])
153 && $options["allowAddUser"] == 'Y'
154 )
155 || (
156 isset($options["allowSearchEmailUsers"])
157 && $options["allowSearchEmailUsers"] == 'Y'
158 )
159 || (
160 isset($options["allowEmailInvitation"])
161 && $options["allowEmailInvitation"] == 'Y'
162 )
163 ? 'Y'
164 : 'N'
165 ),
166 "CRMEMAILS" => (
167 isset($options["allowSearchCrmEmailUsers"])
168 && $options["allowSearchCrmEmailUsers"] == 'Y'
169 ? 'Y'
170 : 'N'
171 ),
172 "DATA_ADDITIONAL" => $dataAdditional,
173 "MULTI" => (
174 (
175 isset($options["returnMultiEmail"])
176 && $options["returnMultiEmail"] == 'Y'
177 )
178 || (
179 isset($options["returnMultiPhone"])
180 && $options["returnMultiPhone"] == 'Y'
181 )
182 ? 'Y'
183 : 'N'
184 )
185 )
186 );
187
188 $destSortData['UA'] = array(
189 'Y' => 9999999999,
190 'N' => 9999999999
191 );
192 $destSortData['EMPTY'] = array(
193 'Y' => 9999999998,
194 'N' => 9999999998
195 );
196
197 $lastItems = $res['LAST_DESTINATIONS'];
198 $result['SORT'] = $destSortData;
199
200 $result['TABS'] = array();
201
202 if (
203 !isset($options["disableLast"])
204 || $options["disableLast"] != 'Y'
205 )
206 {
207 $result['TABS']['last'] = array(
208 'id' => 'last',
209 'name' => Loc::getMessage('MAIN_UI_SELECTOR_TAB_LAST'),
210 'sort' => 10
211 );
212 }
213
214 $selectedItemsByEntityType = array();
215 if (!empty($selectedItems))
216 {
217 foreach($selectedItems as $key => $entityType)
218 {
219 $entityType = mb_strtoupper($entityType);
220 if (!isset($selectedItemsByEntityType[$entityType]))
221 {
222 $selectedItemsByEntityType[$entityType] = array();
223 }
224 $selectedItemsByEntityType[$entityType][] = $key;
225 }
226 }
227
228 foreach($entityTypes as $entityType => $description)
229 {
231 if ($provider !== false)
232 {
233 $result['ENTITIES'][$entityType] = $provider->getData(array(
234 'options' => (!empty($description['options']) ? $description['options'] : array()),
235 'lastItems' => $lastItems,
236 'selectedItems' => $selectedItemsByEntityType
237 ));
238
239 $tabList = $provider->getTabList(array(
240 'options' => (!empty($description['options']) ? $description['options'] : array())
241 ));
242 if (!empty($tabList))
243 {
244 foreach($tabList as $tab)
245 {
246 $result['TABS'][$tab['id']] = $tab;
247 }
248 }
249 }
250 }
251
252 return $result;
253 }
254
255 public static function getProviderByEntityType($entityType)
256 {
258 if ($result)
259 {
260 return $result;
261 }
262
263 $event = new Event("main", "OnUISelectorGetProviderByEntityType", array(
264 'entityType' => $entityType
265 ));
266 $event->send();
267 $eventResultList = $event->getResults();
268 if (is_array($eventResultList) && !empty($eventResultList))
269 {
270 foreach ($eventResultList as $eventResult)
271 {
272 if ($eventResult->getType() == EventResult::SUCCESS)
273 {
274 $resultParams = $eventResult->getParameters();
275 $result = $resultParams['result'];
276 break;
277 }
278 }
279 }
280 return $result;
281 }
282
283 public static function getLastSort($params = array())
284 {
285 global $USER;
286
287 $result = array(
288 'DATA' => array(),
289 'DATA_ADDITIONAL' => array()
290 );
291
292 $userId = (
293 isset($params["USER_ID"])
294 && intval($params["USER_ID"]) > 0
295 ? intval($params["USER_ID"])
296 : false
297 );
298
299 $contextFilter = (
300 isset($params["CONTEXT_FILTER"])
301 && is_array($params["CONTEXT_FILTER"])
302 ? $params["CONTEXT_FILTER"]
303 : false
304 );
305
306 $codeFilter = (
307 $params["CODE_FILTER"] ?? false
308 );
309
310 if (
311 $codeFilter
312 && !is_array($codeFilter)
313 )
314 {
315 $codeFilter = array($codeFilter);
316 }
317
318 if (!$userId)
319 {
321 if (!$userId)
322 {
323 return $result;
324 }
325 }
326
327 $cacheTtl = defined("BX_COMP_MANAGED_CACHE") ? 3153600 : 3600*4;
328 $cacheId = 'dest_sort_2'.$userId.serialize($params);
329 $cacheDir = self::getCacheDir([
330 'userId' => $userId,
331 ]);
332
333 $cache = new \CPHPCache;
334 if($cache->initCache($cacheTtl, $cacheId, $cacheDir))
335 {
336 $cacheData = $cache->GetVars();
337 $destAll = $cacheData['DEST_ALL'] ?? array();
338 $dataAdditionalUsers = $cacheData['DATA_ADDITIONAL_USERS'] ?? array();
339 }
340 else
341 {
342 $dataAdditionalUsers = array();
343
344 $cache->startDataCache();
345 $filter = array(
346 "USER_ID" => $userId
347 );
348
349 if (
352 && (
353 !isset($params["ALLOW_EMAIL_INVITATION"])
354 || !$params["ALLOW_EMAIL_INVITATION"]
355 )
356 )
357 {
358 $filter["!=CODE_USER.EXTERNAL_AUTH_ID"] = 'email';
359 }
360
361 if (!empty($params["CODE_TYPE"]))
362 {
363 $filter["=CODE_TYPE"] = mb_strtoupper($params["CODE_TYPE"]);
364 }
365 elseif (
366 empty($params["CRM"])
367 || $params["CRM"] != 'Y'
368 )
369 {
370 $filter["!=CODE_TYPE"] = "CRM";
371 }
372
373 if (
374 is_array($contextFilter)
375 && !empty($contextFilter)
376 )
377 {
378 $filter["CONTEXT"] = $contextFilter;
379 }
380
381 if (
382 is_array($codeFilter)
383 && !empty($codeFilter)
384 )
385 {
386 $filter["CODE"] = $codeFilter;
387 }
388
389 $runtime = array();
390 $order = array();
391
392 if (!empty($params["DEST_CONTEXT"]))
393 {
395 $helper = $conn->getSqlHelper();
396
397 $runtime = array(
398 new ExpressionField('CONTEXT_SORT', "CASE WHEN CONTEXT = '".$helper->forSql(mb_strtoupper($params["DEST_CONTEXT"]))."' THEN 1 ELSE 0 END")
399 );
400
401 $order = array(
402 'CONTEXT_SORT' => 'DESC'
403 );
404 }
405
406 $order['LAST_USE_DATE'] = 'DESC';
407
408 $emailUserCodeList = $emailCrmUserCodeList = array();
409
410 if (
413 && isset($params["ALLOW_EMAIL_INVITATION"])
414 && $params["ALLOW_EMAIL_INVITATION"]
415 )
416 {
418 'order' => $order,
419 'filter' => array(
420 "USER_ID" => $userId,
421 "=CODE_USER.EXTERNAL_AUTH_ID" => 'email',
422 "=CODE_TYPE" => 'U'
423 ),
424 'select' => array('CODE'),
425 'runtime' => $runtime,
426 'limit' => self::LIST_USER_LIMIT
427 ));
428 while($dest = $res->fetch())
429 {
430 $emailUserCodeList[] = $dest['CODE'];
431 }
432 $dataAdditionalUsers['UE'] = $emailUserCodeList;
433 }
434
435 if (
436 !empty($params["DEST_CONTEXT"])
437 && $params["DEST_CONTEXT"] == "CRM_POST"
438 )
439 {
441 'order' => $order,
442 'filter' => array(
443 "USER_ID" => $USER->getId(),
444 "!=CODE_USER.UF_USER_CRM_ENTITY" => false,
445 "=CODE_TYPE" => 'U'
446 ),
447 'select' => array('CODE'),
448 'runtime' => $runtime,
449 'limit' => self::LIST_USER_LIMIT
450 ));
451 while($dest = $res->fetch())
452 {
453 $emailCrmUserCodeList[] = $dest['CODE'];
454 }
455 $dataAdditionalUsers['UCRM'] = $emailCrmUserCodeList;
456 }
457
459 'order' => $order,
460 'filter' => $filter,
461 'select' => array(
462 'CONTEXT',
463 'CODE',
464 'LAST_USE_DATE'
465 ),
466 'runtime' => $runtime
467 ));
468
469 $destAll = array();
470
471 while($dest = $res->fetch())
472 {
473 $dest["LAST_USE_DATE"] = MakeTimeStamp($dest["LAST_USE_DATE"]->toString());
474 $destAll[] = $dest;
475 }
476
477 $cache->endDataCache(array(
478 "DEST_ALL" => $destAll,
479 "DATA_ADDITIONAL_USERS" => $dataAdditionalUsers
480 ));
481 }
482
483 $resultData = array();
484
485 foreach ($destAll as $dest)
486 {
487 if(!isset($resultData[$dest["CODE"]]))
488 {
489 $resultData[$dest["CODE"]] = array();
490 }
491
492 $contextType = (
493 isset($params["DEST_CONTEXT"])
494 && mb_strtoupper($params["DEST_CONTEXT"]) == mb_strtoupper($dest["CONTEXT"])
495 ? "Y"
496 : "N"
497 );
498
499 if (
500 $contextType == "Y"
501 || !isset($resultData[$dest["CODE"]]["N"])
502 || $dest["LAST_USE_DATE"] > $resultData[$dest["CODE"]]["N"]
503 )
504 {
505 $resultData[$dest["CODE"]][$contextType] = $dest["LAST_USE_DATE"];
506 }
507 }
508
509 $result['DATA'] = $resultData;
510 $result['DATA_ADDITIONAL'] = $dataAdditionalUsers;
511
512 return $result;
513 }
514
515 public static function fillLastDestination($destSortData, $params = array())
516 {
517 $result = array(
518 'DATA' => array(),
519 'LAST_DESTINATIONS' => array()
520 );
521
522 global $USER;
523
524 $resultData = array();
525
526 if (!Loader::includeModule('socialnetwork'))
527 {
528 return $result;
529 }
530
531 // initialize keys for compatibility
532 $lastDestinationList = array(
533 'USERS' => array(),
534 'SONETGROUPS' => array(),
535 'DEPARTMENT' => array()
536 );
537
538 $iUCounter = $iSGCounter = $iDCounter = 0;
539
540 $bAllowEmail = (
541 is_array($params)
542 && isset($params["EMAILS"])
543 && $params["EMAILS"] == "Y"
544 );
545 $bAllowCrmEmail = (
546 is_array($params)
547 && isset($params["CRMEMAILS"])
548 && $params["CRMEMAILS"] == "Y"
550 );
551 $bAllowProject = (
552 is_array($params)
553 && isset($params["PROJECTS"])
554 && $params["PROJECTS"] == "Y"
555 );
556 $dataAdditional = (
557 is_array($params)
558 && isset($params["DATA_ADDITIONAL"])
559 && is_array($params["DATA_ADDITIONAL"])
560 ? $params["DATA_ADDITIONAL"]
561 : array()
562 );
563
564 if (is_array($destSortData))
565 {
566 $userIdList = $sonetGroupIdList = array();
567 $userLimit = self::LIST_USER_LIMIT;
568 $sonetGroupLimit = 6;
569 $departmentLimit = 6;
570
571 foreach ($destSortData as $code => $sortInfo)
572 {
573 if (
574 !$bAllowEmail
575 && !$bAllowCrmEmail
576 && !$bAllowProject
577 && ($iUCounter >= $userLimit)
578 && $iSGCounter >= $sonetGroupLimit
579 && $iDCounter >= $departmentLimit
580 )
581 {
582 break;
583 }
584
585 if (preg_match('/^U(\d+)$/i', $code, $matches))
586 {
587 if (
588 !$bAllowEmail
589 && !$bAllowCrmEmail
590 && $iUCounter >= $userLimit
591 )
592 {
593 continue;
594 }
595 if (!isset($lastDestinationList['USERS']))
596 {
597 $lastDestinationList['USERS'] = array();
598 }
599 $lastDestinationList['USERS'][$code] = $code;
600 $userIdList[] = intval($matches[1]);
601 $iUCounter++;
602 }
603 elseif (preg_match('/^SG(\d+)$/i', $code, $matches))
604 {
605 if (
606 !$bAllowProject
607 && $iSGCounter >= $sonetGroupLimit
608 )
609 {
610 continue;
611 }
612 if (!isset($lastDestinationList['SONETGROUPS']))
613 {
614 $lastDestinationList['SONETGROUPS'] = array();
615 }
616 $lastDestinationList['SONETGROUPS'][$code] = $code;
617 $sonetGroupIdList[] = intval($matches[1]);
618 $iSGCounter++;
619 }
620 elseif (
621 preg_match('/^D(\d+)$/i', $code, $matches)
622 || preg_match('/^DR(\d+)$/i', $code, $matches)
623 )
624 {
625 if ($iDCounter >= $departmentLimit)
626 {
627 continue;
628 }
629 if (!isset($lastDestinationList['DEPARTMENT']))
630 {
631 $lastDestinationList['DEPARTMENT'] = array();
632 }
633 $lastDestinationList['DEPARTMENT'][$code] = $code;
634 $iDCounter++;
635 }
636 }
637
638
639 $event = new Event("main", "OnUISelectorFillLastDestination", [
640 'params' => $params,
641 'destSortData' => $destSortData
642 ]);
643 $event->send();
644 $eventResultList = $event->getResults();
645
646 if (is_array($eventResultList) && !empty($eventResultList))
647 {
648 foreach ($eventResultList as $eventResult)
649 {
650 if ($eventResult->getType() == EventResult::SUCCESS)
651 {
652 $resultParams = $eventResult->getParameters();
653 $eventLastDestinationList = $resultParams['lastDestinationList'];
654 if (is_array($eventLastDestinationList))
655 {
656 $lastDestinationList = array_merge($lastDestinationList, $eventLastDestinationList);
657 }
658 }
659 }
660 }
661
662 if (
663 (
664 $bAllowEmail
665 || $bAllowCrmEmail
666 )
667 && !empty($userIdList)
668 )
669 {
670 $iUCounter = $iUECounter = $iUCRMCounter = 0;
671 $emailLimit = $crmLimit = 10;
672 $userId = $USER->getId();
673 $destUList = $destUEList = $destUCRMList = array();
674
675 if (
676 (
677 isset($dataAdditional['UE'])
678 && is_array($dataAdditional['UE'])
679 )
680 || (
681 isset($dataAdditional['UCRM'])
682 && is_array($dataAdditional['UCRM'])
683 )
684 )
685 {
686 if (
687 empty($dataAdditional['UE'])
688 && empty($dataAdditional['UCRM'])
689 )
690 {
691 foreach($userIdList as $uId)
692 {
693 $code = 'U'.$uId;
694 $destUList[$code] = $code;
695 }
696 }
697 else
698 {
699 foreach($userIdList as $uId)
700 {
701 if (
702 $iUCounter >= $userLimit
703 && $iUECounter >= $emailLimit
704 && $iUCRMCounter >= $crmLimit
705 )
706 {
707 break;
708 }
709
710 $code = 'U'.$uId;
711
712 if (
713 $bAllowEmail
714 && in_array($code, $dataAdditional['UE'])
715 )
716 {
717 if ($iUECounter >= $emailLimit)
718 {
719 continue;
720 }
721 $destUEList[$code] = $code;
722 $iUECounter++;
723 }
724 elseif (
725 $bAllowCrmEmail
726 && in_array($code, $dataAdditional['UCRM'])
727 )
728 {
729 if ($iUCRMCounter >= $crmLimit)
730 {
731 continue;
732 }
733 $destUCRMList[$code] = $code;
734 $iUCRMCounter++;
735 }
736 else
737 {
738 if ($iUCounter >= $userLimit)
739 {
740 continue;
741 }
742 $destUList[$code] = $code;
743 $iUCounter++;
744 }
745 }
746 }
747 }
748 else // old method
749 {
750 $cacheTtl = defined("BX_COMP_MANAGED_CACHE") ? 3153600 : 3600*4;
751 $cacheId = 'dest_sort_users'.$userId.serialize($params).intval($bAllowCrmEmail);
752 $cacheDir = self::getCacheDir([
753 'userId' => $userId,
754 ]);;
755 $cache = new \CPHPCache;
756
757 if($cache->initCache($cacheTtl, $cacheId, $cacheDir))
758 {
759 $cacheVars = $cache->getVars();
760 $destUList = $cacheVars['U'];
761 $destUEList = $cacheVars['UE'];
762 $destUCRMList = $cacheVars['UCRM'];
763 }
764 else
765 {
766 $cache->startDataCache();
767
768 $selectList = array('ID', 'EXTERNAL_AUTH_ID');
769 if ($bAllowCrmEmail)
770 {
771 $selectList[] = 'UF_USER_CRM_ENTITY';
772 }
773 $selectList[] = new ExpressionField('MAX_LAST_USE_DATE', 'MAX(%s)', array('\Bitrix\Main\FinderDest:CODE_USER_CURRENT.LAST_USE_DATE'));
774
776 'order' => array(
777 "MAX_LAST_USE_DATE" => 'DESC',
778 ),
779 'filter' => array(
780 '@ID' => $userIdList
781 ),
782 'select' => $selectList
783 ));
784
785 while ($destUser = $res->fetch())
786 {
787 if (
788 $iUCounter >= $userLimit
789 && $iUECounter >= $emailLimit
790 && $iUCRMCounter >= $crmLimit
791 )
792 {
793 break;
794 }
795
796 $code = 'U'.$destUser['ID'];
797
798 if ($bAllowEmail && $destUser['EXTERNAL_AUTH_ID'] == 'email')
799 {
800 if ($iUECounter >= $emailLimit)
801 {
802 continue;
803 }
804 $destUEList[$code] = $code;
805 $iUECounter++;
806 }
807 elseif (
808 $bAllowCrmEmail
809 && !empty($destUser['UF_USER_CRM_ENTITY'])
810 )
811 {
812 if ($iUCRMCounter >= $crmLimit)
813 {
814 continue;
815 }
816 $destUCRMList[$code] = $code;
817 $iUCRMCounter++;
818 }
819 else
820 {
821 if ($iUCounter >= $userLimit)
822 {
823 continue;
824 }
825 $destUList[$code] = $code;
826 $iUCounter++;
827 }
828 }
829
830 $cache->endDataCache(array(
831 'U' => $destUList,
832 'UE' => $destUEList,
833 'UCRM' => $destUCRMList
834 ));
835 }
836 }
837 $destUList = array_slice($destUList, 0, self::LIST_USER_LIMIT, true);
838
839 $lastDestinationList['USERS'] = array_merge($destUList, $destUEList, $destUCRMList);
840 $tmp = array('USERS' => $lastDestinationList['USERS']);
841 self::sortDestinations($tmp, $destSortData);
842 $lastDestinationList['USERS'] = $tmp['USERS'];
843 }
844
845 if (
846 $bAllowProject
847 && !empty($sonetGroupIdList)
848 )
849 {
850 $iSGCounter = $iSGPCounter = 0;
851 $projectLimit = 10;
852 $userId = $USER->getId();
853
854 $destSGList = $destSGPList = array();
855
856 $cacheTtl = defined("BX_COMP_MANAGED_CACHE") ? 3153600 : 3600*4;
857 $cacheId = 'dest_sort_sonetgroups'.$userId.serialize($params);
858 $cacheDir = self::getCacheDir([
859 'userId' => $userId,
860 ]);
861 $cache = new \CPHPCache;
862
863 if($cache->initCache($cacheTtl, $cacheId, $cacheDir))
864 {
865 $cacheVars = $cache->getVars();
866 $destSGList = $cacheVars['SG'];
867 $destSGPList = $cacheVars['SGP'];
868 }
869 else
870 {
871 $cache->startDataCache();
872
873 $res = \Bitrix\Socialnetwork\WorkgroupTable::getList(array(
874 'filter' => array(
875 '@ID' => $sonetGroupIdList
876 ),
877 'select' => array('ID', 'PROJECT')
878 ));
879
880 while($destSonetGroup = $res->fetch())
881 {
882 if (
883 $iSGCounter >= $sonetGroupLimit
884 && $iSGPCounter >= $projectLimit
885 )
886 {
887 break;
888 }
889
890 $code = 'SG'.$destSonetGroup['ID'];
891
892 if ($destSonetGroup['PROJECT'] == 'Y')
893 {
894 if ($iSGPCounter >= $projectLimit)
895 {
896 continue;
897 }
898 $destSGPList[$code] = $code;
899 $iSGPCounter++;
900 }
901 else
902 {
903 if ($iSGCounter >= $sonetGroupLimit)
904 {
905 continue;
906 }
907 $destSGList[$code] = $code;
908 $iSGCounter++;
909 }
910 }
911
912 $cache->endDataCache(array(
913 'SG' => $destSGList,
914 'SGP' => $destSGPList
915 ));
916 }
917
918 $tmp = array(
919 'SONETGROUPS' => $destSGList,
920 'PROJECTS' => $destSGPList
921 );
922 self::sortDestinations($tmp, $destSortData);
923 $lastDestinationList['SONETGROUPS'] = $tmp['SONETGROUPS'];
924 $lastDestinationList['PROJECTS'] = $tmp['PROJECTS'];
925 }
926 }
927
928 foreach($lastDestinationList as $groupKey => $entitiesList)
929 {
930 $result[$groupKey] = array();
931
932 if (is_array($entitiesList))
933 {
934 $tmp = array();
935 $sort = 0;
936 foreach($entitiesList as $key => $value)
937 {
938 $tmp[$key] = $sort++;
939 }
940 $result[$groupKey] = $tmp;
941 }
942 }
943
944 $result['DATA'] = $resultData;
945 $result['LAST_DESTINATIONS'] = $lastDestinationList;
946
947 return $result;
948 }
949
950 private static function compareDestinations($a, $b)
951 {
952 if(!is_array($a) && !is_array($b))
953 {
954 return 0;
955 }
956 elseif(is_array($a) && !is_array($b))
957 {
958 return -1;
959 }
960 elseif(!is_array($a) && is_array($b))
961 {
962 return 1;
963 }
964 else
965 {
966 if(isset($a["SORT"]["Y"]) && !isset($b["SORT"]["Y"]))
967 {
968 return -1;
969 }
970 elseif(!isset($a["SORT"]["Y"]) && isset($b["SORT"]["Y"]))
971 {
972 return 1;
973 }
974 elseif(isset($a["SORT"]["Y"]) && isset($b["SORT"]["Y"]))
975 {
976 if(intval($a["SORT"]["Y"]) > intval($b["SORT"]["Y"]))
977 {
978 return -1;
979 }
980 elseif(intval($a["SORT"]["Y"]) < intval($b["SORT"]["Y"]))
981 {
982 return 1;
983 }
984 else
985 {
986 return 0;
987 }
988 }
989 else
990 {
991 if(intval($a["SORT"]["N"]) > intval($b["SORT"]["N"]))
992 {
993 return -1;
994 }
995 elseif(intval($a["SORT"]["N"]) < intval($b["SORT"]["N"]))
996 {
997 return 1;
998 }
999 else
1000 {
1001 return 0;
1002 }
1003 }
1004 }
1005 }
1006
1007 private static function sortDestinations(&$destinationList, $destSortData)
1008 {
1009 foreach($destinationList as $type => $dest)
1010 {
1011 if (is_array($dest))
1012 {
1013 foreach($dest as $key => $value)
1014 {
1015 if (isset($destSortData[$key]))
1016 {
1017 $destinationList[$type][$key] = array(
1018 "VALUE" => $value,
1019 "SORT" => $destSortData[$key]
1020 );
1021 }
1022 }
1023
1024 uasort($destinationList[$type], array(__CLASS__, 'compareDestinations'));
1025 }
1026 }
1027
1028 foreach($destinationList as $type => $dest)
1029 {
1030 if (is_array($dest))
1031 {
1032 foreach($dest as $key => $val)
1033 {
1034 if (is_array($val))
1035 {
1036 $destinationList[$type][$key] = $val["VALUE"];
1037 }
1038 }
1039 }
1040 }
1041 }
1042
1043 public static function search($options = array(), $entityTypes = array(), $requestFields = array())
1044 {
1045 $result = array(
1046 'ENTITIES' => array()
1047 );
1048
1049 foreach($entityTypes as $entityType => $description)
1050 {
1052 if ($provider !== false)
1053 {
1054 $options = (!empty($description['options']) ? $description['options'] : array());
1055 if (
1056 !empty($requestFields['additionalData'])
1057 && !empty($requestFields['additionalData'][$entityType])
1058 )
1059 {
1060 $options['additionalData'] = $requestFields['additionalData'][$entityType];
1061 }
1062
1063 $result['ENTITIES'][$entityType] = $provider->search(array(
1064 'options' => $options,
1065 'requestFields' => $requestFields
1066 ));
1067 }
1068 }
1069
1070 return $result;
1071 }
1072
1073 public static function loadAll($entityType)
1074 {
1075 $result = array();
1076
1077 if (empty($entityType))
1078 {
1079 $entityType = 'USERS';
1080 }
1081
1083 if($provider !== false)
1084 {
1085 $result[$entityType] = $provider->loadAll();
1086 }
1087
1088 return $result;
1089 }
1090
1091 public static function save($params = [])
1092 {
1093 if (
1094 !is_array($params)
1095 || empty($params['context'])
1096 || empty($params['code'])
1097 )
1098 {
1099 return;
1100 }
1101
1102 $context = $params['context'];
1103 $code = $params['code'];
1104
1105 $event = new Event("main", "OnUISelectorBeforeSave", $params);
1106 $event->send();
1107 $eventResultList = $event->getResults();
1108
1109 if (is_array($eventResultList) && !empty($eventResultList))
1110 {
1111 foreach ($eventResultList as $eventResult)
1112 {
1113 if ($eventResult->getType() == EventResult::SUCCESS)
1114 {
1115 $resultParams = $eventResult->getParameters();
1116 $code = $resultParams['code'];
1117 break;
1118 }
1119 }
1120 }
1121
1123 "CONTEXT" => $context,
1124 "CODE" => $code
1125 ));
1126 }
1127
1128 public static function getCacheDir(array $params = [])
1129 {
1130 global $USER;
1131
1132 $userId = (int)($params['userId'] ?? 0);
1133
1134 if (
1135 $userId <= 0
1136 && $USER->isAuthorized()
1137 )
1138 {
1139 $userId = $USER->getId();
1140 }
1141
1142 return '/ui_selector/dest_sort/' . substr(md5($userId), 2, 2) . '/' . $userId;
1143 }
1144
1145}
$type
Определения options.php:106
if(!Loader::includeModule('messageservice')) $provider
Определения callback_ednaruimhpx.php:21
$tabList
Определения catalog_reindex.php:107
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static getConnection($name="")
Определения application.php:638
static get()
Определения currentuser.php:33
Определения event.php:5
static merge(array $data)
Определения finderdest.php:99
static includeModule($moduleName)
Определения loader.php:67
static isModuleInstalled($moduleName)
Определения modulemanager.php:125
static getList(array $parameters=array())
Определения datamanager.php:431
const CODE_GROUP_REGEX
Определения entities.php:19
static getLastSort($params=array())
Определения entities.php:283
static getCacheDir(array $params=[])
Определения entities.php:1128
const CODE_USERALL_REGEX
Определения entities.php:16
const CODE_USERMANAGER_REGEX
Определения entities.php:17
static search($options=array(), $entityTypes=array(), $requestFields=array())
Определения entities.php:1043
static loadAll($entityType)
Определения entities.php:1073
const CODE_DEPT_REGEX
Определения entities.php:20
const CODE_CRMCOMPANY_REGEX
Определения entities.php:23
const CODE_SONETGROUP_REGEX
Определения entities.php:18
const CODE_CRMCONTACT_REGEX
Определения entities.php:22
static getList($params=array())
Определения entities.php:31
const LIST_USER_LIMIT
Определения entities.php:29
const CODE_CRMLEAD_REGEX
Определения entities.php:24
const CODE_CRMDEAL_REGEX
Определения entities.php:25
const CODE_DEPTR_REGEX
Определения entities.php:21
const CODE_USER_REGEX
Определения entities.php:15
static save($params=[])
Определения entities.php:1091
static getProviderByEntityType($entityType)
Определения entities.php:255
static getData($options=array(), $entityTypes=array(), $selectedItems=array())
Определения entities.php:105
static getEntityType($params)
Определения entities.php:65
static fillLastDestination($destSortData, $params=array())
Определения entities.php:515
const ENTITY_TYPE_DEPARTMENTS
Определения entities.php:27
static getProviderByEntityType($entityType)
Определения handler.php:16
$options
Определения commerceml2.php:49
if(!is_array($prop["VALUES"])) $tmp
Определения component_props.php:203
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
if(Loader::includeModule( 'bitrix24')) elseif(Loader::includeModule('intranet') &&CIntranetUtils::getPortalZone() !=='ru') $description
Определения .description.php:24
$filter
Определения iblock_catalog_list.php:54
global $USER
Определения csv_new_run.php:40
$context
Определения csv_new_setup.php:223
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
MakeTimeStamp($datetime, $format=false)
Определения tools.php:538
$order
Определения payment.php:8
$event
Определения prolog_after.php:141
return false
Определения prolog_main_admin.php:185
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if(empty($signedUserToken)) $key
Определения quickway.php:257
if(!empty($sellerData)) $dest
Определения pdf.php:818
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
else $a
Определения template.php:137
$selectList
Определения options.php:1794
$val
Определения options.php:1793
$matches
Определения index.php:22