76 $itemCode =
$params[
'itemCode'];
78 if (preg_match(self::CODE_USER_REGEX, $itemCode,
$matches))
82 elseif (preg_match(self::CODE_SONETGROUP_REGEX, $itemCode,
$matches))
87 preg_match(self::CODE_DEPT_REGEX, $itemCode,
$matches)
88 || preg_match(self::CODE_DEPTR_REGEX, $itemCode,
$matches)
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)
289 'DATA_ADDITIONAL' =>
array()
294 && intval(
$params[
"USER_ID"]) > 0
300 isset(
$params[
"CONTEXT_FILTER"])
301 && is_array(
$params[
"CONTEXT_FILTER"])
312 && !is_array($codeFilter)
315 $codeFilter =
array($codeFilter);
327 $cacheTtl = defined(
"BX_COMP_MANAGED_CACHE") ? 3153600 : 3600*4;
328 $cacheId =
'dest_sort_2'.$userId.serialize(
$params);
333 $cache = new \CPHPCache;
334 if($cache->initCache($cacheTtl, $cacheId, $cacheDir))
336 $cacheData = $cache->GetVars();
337 $destAll = $cacheData[
'DEST_ALL'] ??
array();
338 $dataAdditionalUsers = $cacheData[
'DATA_ADDITIONAL_USERS'] ??
array();
342 $dataAdditionalUsers =
array();
344 $cache->startDataCache();
353 !isset(
$params[
"ALLOW_EMAIL_INVITATION"])
354 || !
$params[
"ALLOW_EMAIL_INVITATION"]
358 $filter[
"!=CODE_USER.EXTERNAL_AUTH_ID"] =
'email';
361 if (!empty(
$params[
"CODE_TYPE"]))
370 $filter[
"!=CODE_TYPE"] =
"CRM";
374 is_array($contextFilter)
375 && !empty($contextFilter)
378 $filter[
"CONTEXT"] = $contextFilter;
382 is_array($codeFilter)
383 && !empty($codeFilter)
392 if (!empty(
$params[
"DEST_CONTEXT"]))
395 $helper = $conn->getSqlHelper();
398 new ExpressionField(
'CONTEXT_SORT',
"CASE WHEN CONTEXT = '".$helper->forSql(mb_strtoupper(
$params[
"DEST_CONTEXT"])).
"' THEN 1 ELSE 0 END")
402 'CONTEXT_SORT' =>
'DESC'
406 $order[
'LAST_USE_DATE'] =
'DESC';
408 $emailUserCodeList = $emailCrmUserCodeList =
array();
413 && isset(
$params[
"ALLOW_EMAIL_INVITATION"])
414 &&
$params[
"ALLOW_EMAIL_INVITATION"]
421 "=CODE_USER.EXTERNAL_AUTH_ID" =>
'email',
424 'select' =>
array(
'CODE'),
425 'runtime' => $runtime,
426 'limit' => self::LIST_USER_LIMIT
430 $emailUserCodeList[] =
$dest[
'CODE'];
432 $dataAdditionalUsers[
'UE'] = $emailUserCodeList;
436 !empty(
$params[
"DEST_CONTEXT"])
437 &&
$params[
"DEST_CONTEXT"] ==
"CRM_POST"
443 "USER_ID" =>
$USER->getId(),
444 "!=CODE_USER.UF_USER_CRM_ENTITY" =>
false,
447 'select' =>
array(
'CODE'),
448 'runtime' => $runtime,
449 'limit' => self::LIST_USER_LIMIT
453 $emailCrmUserCodeList[] =
$dest[
'CODE'];
455 $dataAdditionalUsers[
'UCRM'] = $emailCrmUserCodeList;
466 'runtime' => $runtime
477 $cache->endDataCache(
array(
478 "DEST_ALL" => $destAll,
479 "DATA_ADDITIONAL_USERS" => $dataAdditionalUsers
483 $resultData =
array();
485 foreach ($destAll as
$dest)
487 if(!isset($resultData[
$dest[
"CODE"]]))
494 && mb_strtoupper(
$params[
"DEST_CONTEXT"]) == mb_strtoupper(
$dest[
"CONTEXT"])
501 || !isset($resultData[
$dest[
"CODE"]][
"N"])
502 ||
$dest[
"LAST_USE_DATE"] > $resultData[
$dest[
"CODE"]][
"N"]
505 $resultData[
$dest[
"CODE"]][$contextType] =
$dest[
"LAST_USE_DATE"];
510 $result[
'DATA_ADDITIONAL'] = $dataAdditionalUsers;
519 'LAST_DESTINATIONS' =>
array()
524 $resultData =
array();
532 $lastDestinationList =
array(
534 'SONETGROUPS' =>
array(),
535 'DEPARTMENT' =>
array()
538 $iUCounter = $iSGCounter = $iDCounter = 0;
558 && isset(
$params[
"DATA_ADDITIONAL"])
559 && is_array(
$params[
"DATA_ADDITIONAL"])
564 if (is_array($destSortData))
566 $userIdList = $sonetGroupIdList =
array();
567 $userLimit = self::LIST_USER_LIMIT;
568 $sonetGroupLimit = 6;
569 $departmentLimit = 6;
571 foreach ($destSortData as
$code => $sortInfo)
577 && ($iUCounter >= $userLimit)
578 && $iSGCounter >= $sonetGroupLimit
579 && $iDCounter >= $departmentLimit
590 && $iUCounter >= $userLimit
595 if (!isset($lastDestinationList[
'USERS']))
597 $lastDestinationList[
'USERS'] =
array();
600 $userIdList[] = intval(
$matches[1]);
607 && $iSGCounter >= $sonetGroupLimit
612 if (!isset($lastDestinationList[
'SONETGROUPS']))
614 $lastDestinationList[
'SONETGROUPS'] =
array();
616 $lastDestinationList[
'SONETGROUPS'][
$code] =
$code;
617 $sonetGroupIdList[] = intval(
$matches[1]);
625 if ($iDCounter >= $departmentLimit)
629 if (!isset($lastDestinationList[
'DEPARTMENT']))
631 $lastDestinationList[
'DEPARTMENT'] =
array();
633 $lastDestinationList[
'DEPARTMENT'][
$code] =
$code;
639 $event =
new Event(
"main",
"OnUISelectorFillLastDestination", [
641 'destSortData' => $destSortData
644 $eventResultList =
$event->getResults();
646 if (is_array($eventResultList) && !empty($eventResultList))
648 foreach ($eventResultList as $eventResult)
650 if ($eventResult->getType() == EventResult::SUCCESS)
652 $resultParams = $eventResult->getParameters();
653 $eventLastDestinationList = $resultParams[
'lastDestinationList'];
654 if (is_array($eventLastDestinationList))
656 $lastDestinationList = array_merge($lastDestinationList, $eventLastDestinationList);
667 && !empty($userIdList)
670 $iUCounter = $iUECounter = $iUCRMCounter = 0;
671 $emailLimit = $crmLimit = 10;
673 $destUList = $destUEList = $destUCRMList =
array();
677 isset($dataAdditional[
'UE'])
678 && is_array($dataAdditional[
'UE'])
681 isset($dataAdditional[
'UCRM'])
682 && is_array($dataAdditional[
'UCRM'])
687 empty($dataAdditional[
'UE'])
688 && empty($dataAdditional[
'UCRM'])
691 foreach($userIdList as $uId)
699 foreach($userIdList as $uId)
702 $iUCounter >= $userLimit
703 && $iUECounter >= $emailLimit
704 && $iUCRMCounter >= $crmLimit
714 && in_array(
$code, $dataAdditional[
'UE'])
717 if ($iUECounter >= $emailLimit)
726 && in_array(
$code, $dataAdditional[
'UCRM'])
729 if ($iUCRMCounter >= $crmLimit)
738 if ($iUCounter >= $userLimit)
750 $cacheTtl = defined(
"BX_COMP_MANAGED_CACHE") ? 3153600 : 3600*4;
751 $cacheId =
'dest_sort_users'.$userId.serialize(
$params).intval($bAllowCrmEmail);
755 $cache = new \CPHPCache;
757 if($cache->initCache($cacheTtl, $cacheId, $cacheDir))
759 $cacheVars = $cache->getVars();
760 $destUList = $cacheVars[
'U'];
761 $destUEList = $cacheVars[
'UE'];
762 $destUCRMList = $cacheVars[
'UCRM'];
766 $cache->startDataCache();
777 "MAX_LAST_USE_DATE" =>
'DESC',
785 while ($destUser =
$res->fetch())
788 $iUCounter >= $userLimit
789 && $iUECounter >= $emailLimit
790 && $iUCRMCounter >= $crmLimit
796 $code =
'U'.$destUser[
'ID'];
798 if ($bAllowEmail && $destUser[
'EXTERNAL_AUTH_ID'] ==
'email')
800 if ($iUECounter >= $emailLimit)
809 && !empty($destUser[
'UF_USER_CRM_ENTITY'])
812 if ($iUCRMCounter >= $crmLimit)
821 if ($iUCounter >= $userLimit)
830 $cache->endDataCache(
array(
833 'UCRM' => $destUCRMList
837 $destUList = array_slice($destUList, 0, self::LIST_USER_LIMIT,
true);
839 $lastDestinationList[
'USERS'] = array_merge($destUList, $destUEList, $destUCRMList);
840 $tmp =
array(
'USERS' => $lastDestinationList[
'USERS']);
841 self::sortDestinations(
$tmp, $destSortData);
842 $lastDestinationList[
'USERS'] =
$tmp[
'USERS'];
847 && !empty($sonetGroupIdList)
850 $iSGCounter = $iSGPCounter = 0;
854 $destSGList = $destSGPList =
array();
856 $cacheTtl = defined(
"BX_COMP_MANAGED_CACHE") ? 3153600 : 3600*4;
857 $cacheId =
'dest_sort_sonetgroups'.$userId.serialize(
$params);
861 $cache = new \CPHPCache;
863 if($cache->initCache($cacheTtl, $cacheId, $cacheDir))
865 $cacheVars = $cache->getVars();
866 $destSGList = $cacheVars[
'SG'];
867 $destSGPList = $cacheVars[
'SGP'];
871 $cache->startDataCache();
873 $res = \Bitrix\Socialnetwork\WorkgroupTable::getList(
array(
875 '@ID' => $sonetGroupIdList
877 'select' =>
array(
'ID',
'PROJECT')
880 while($destSonetGroup =
$res->fetch())
883 $iSGCounter >= $sonetGroupLimit
884 && $iSGPCounter >= $projectLimit
890 $code =
'SG'.$destSonetGroup[
'ID'];
892 if ($destSonetGroup[
'PROJECT'] ==
'Y')
894 if ($iSGPCounter >= $projectLimit)
903 if ($iSGCounter >= $sonetGroupLimit)
912 $cache->endDataCache(
array(
914 'SGP' => $destSGPList
919 'SONETGROUPS' => $destSGList,
920 'PROJECTS' => $destSGPList
922 self::sortDestinations(
$tmp, $destSortData);
923 $lastDestinationList[
'SONETGROUPS'] =
$tmp[
'SONETGROUPS'];
924 $lastDestinationList[
'PROJECTS'] =
$tmp[
'PROJECTS'];
928 foreach($lastDestinationList as $groupKey => $entitiesList)
932 if (is_array($entitiesList))
936 foreach($entitiesList as
$key => $value)
945 $result[
'LAST_DESTINATIONS'] = $lastDestinationList;