Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
emailusers.php
1<?
3
6
8{
9 public function getData($params = array())
10 {
11 global $USER;
12
13 $result = array(
14 'ITEMS' => array(),
15 'ITEMS_LAST' => array(),
16 'ITEMS_HIDDEN' => array(),
17 'ADDITIONAL_INFO' => array(
18 'SORT_SELECTED' => 200
19 )
20 );
21
22 if (!ModuleManager::isModuleInstalled('mail'))
23 {
24 return $result;
25 }
26
27 $options = (!empty($params['options']) ? $params['options'] : array());
28
29 $lastItems = (!empty($params['lastItems']) ? $params['lastItems'] : array());
30 $selectedItems = (!empty($params['selectedItems']) ? $params['selectedItems'] : array());
31
32 $lastUserList = array();
33 if(!empty($lastItems[Handler::ENTITY_TYPE_USERS]))
34 {
35 foreach ($lastItems[Handler::ENTITY_TYPE_USERS] as $value)
36 {
37 $lastUserList[] = str_replace('U', '', $value);
38 }
39 }
40
41 $selectedUserList = array();
42 if(!empty($selectedItems[Handler::ENTITY_TYPE_USERS]))
43 {
44 foreach ($selectedItems[Handler::ENTITY_TYPE_USERS] as $value)
45 {
46 $selectedUserList[] = str_replace('U', '', $value);
47 }
48 }
49
50 if (
51 !empty($lastUserList)
52 || !empty($selectedUserList)
53 )
54 {
55 $usersList = \CSocNetLogDestination::getUsers(array(
56 'id' => array_merge($lastUserList, $selectedUserList),
57 'CRM_ENTITY' => ModuleManager::isModuleInstalled('crm')
58 ));
59
60 $crmInstalled = ModuleManager::isModuleInstalled('crm');
61
62 foreach($usersList as $key => $user)
63 {
64 if (
65 (
66 !empty($user['isEmail'])
67 && $user['isEmail'] == 'Y'
68 )
69 && (
70 empty($user['isCrmEmail'])
71 || $user['isCrmEmail'] != 'Y'
72 || empty($options['allowSearchCrmEmailUsers'])
73 || $options['allowSearchCrmEmailUsers'] == 'N'
74 || !$crmInstalled
75 )
76 )
77 {
78 $result['ITEMS'][$key] = $user;
79 $result["ITEMS_LAST"][] = $key;
80 }
81 }
82
83 if (
84 !empty($selectedUserList)
85 && $USER->isAuthorized()
86 && !\CSocNetUser::isCurrentUserModuleAdmin(SITE_ID, false)
87 )
88 {
89 $mySelectedEmailUserIdList = [];
90 $finderDestFilter = array(
91 "USER_ID" => $USER->getId(),
92 "=CODE_TYPE" => "U",
93 "=CODE_USER.EXTERNAL_AUTH_ID" => 'email',
94 );
95 $finderDestSelect = array(
96 'CODE_USER_ID'
97 );
98 $res = \Bitrix\Main\FinderDestTable::getList(array(
99 'order' => array(),
100 'filter' => $finderDestFilter,
101 'group' => array("CODE_USER_ID"),
102 'select' => $finderDestSelect
103 ));
104 while ($userFields = $res->fetch())
105 {
106 if (!empty($userFields))
107 {
108 $mySelectedEmailUserIdList[] = 'U'.$userFields['CODE_USER_ID'];
109 }
110 }
111
112 foreach($selectedUserList as $selectedUserId)
113 {
114 $code = 'U'.$selectedUserId;
115 if (
116 isset($result['ITEMS'][$code]['isEmail'])
117 && $result['ITEMS'][$code]['isEmail'] == 'Y'
118 && !in_array($code, $mySelectedEmailUserIdList)
119 )
120 {
121 $result['ITEMS_HIDDEN'][] = $code;
122 unset($result['ITEMS'][$code]);
123 }
124 }
125 $result["ITEMS_LAST"] = array_filter(
126 $result["ITEMS_LAST"],
127 function ($item) use ($mySelectedEmailUserIdList)
128 {
129 return in_array($item, $mySelectedEmailUserIdList);
130 }
131 );
132 }
133 }
134
135 return $result;
136 }
137
138 public function getTabList($params = array())
139 {
140 $result = array();
141 $options = (!empty($params['options']) ? $params['options'] : array());
142
143 if (
144 isset($options['addTab'])
145 && $options['addTab'] == 'Y'
146 && ModuleManager::isModuleInstalled('mail')
147 )
148 {
149 $result[] = array(
150 'id' => 'emailusers',
151 'name' => Loc::getMessage('MAIN_UI_SELECTOR_TAB_EMAIL_USERS'),
152 'sort' => 100
153 );
154 }
155
156 return $result;
157 }
158
159 public function getItemName($itemCode = '')
160 {
161 return \Bitrix\Socialnetwork\Integration\Main\UISelector\Users::getUserName($itemCode);
162 }
163}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29