Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
users.php
1<?
3
8
10{
11 public static function getNameTemplate($requestNameTemplate = '')
12 {
13 if (!empty($requestNameTemplate))
14 {
15 preg_match_all("/(#NAME#)|(#LAST_NAME#)|(#SECOND_NAME#)|(#NAME_SHORT#)|(#SECOND_NAME_SHORT#)|\\s|\\,/", urldecode($requestNameTemplate), $matches);
16 $result = implode("", $matches[0]);
17 }
18 else
19 {
20 $result = \CSite::getNameFormat(false);
21 }
22
23 return $result;
24 }
25
26 public function getData($params = array())
27 {
28 $result = array(
29 'ITEMS' => array(),
30 'ITEMS_LAST' => array(),
31 'ITEMS_HIDDEN' => array(),
32 'ADDITIONAL_INFO' => array(
33 'PREFIX' => 'U',
34 'GROUPS_LIST' => array(
35 'users' => array(
36 'TITLE' => Loc::getMessage('MAIN_UI_SELECTOR_TITLE_USERS'),
38 'DESC_LESS_MODE' => 'Y',
39 'SORT' => 10
40 )
41 ),
42 'SORT_SELECTED' => 200
43 )
44 );
45
46 $entityType = Handler::ENTITY_TYPE_USERS;
47
48 $options = (!empty($params['options']) ? $params['options'] : array());
49
50 $lastItems = (!empty($params['lastItems']) ? $params['lastItems'] : array());
51 $selectedItems = (!empty($params['selectedItems']) ? $params['selectedItems'] : array());
52
53 $selectedUserList = array();
54 if (!empty($selectedItems[$entityType]))
55 {
56 $selectedUserList = array_map(
57 function($code)
58 {
59 return preg_replace('/^U(\d+)$/', '$1', $code);
60 },
61 $selectedItems[$entityType]
62 );
63 }
64
65 $allowSearchSelf = (!isset($options['allowSearchSelf']) || $options['allowSearchSelf'] !== 'N');
66
67 $selected = array();
68 if (!empty($selectedUserList))
69 {
70 $selected = \CSocNetLogDestination::getUsers([
71 'id' => $selectedUserList,
72 'CRM_ENTITY' => ModuleManager::isModuleInstalled('crm'),
73 'IGNORE_ACTIVITY' => 'Y',
74 'ALLOW_BOTS' => (isset($options['allowBots']) && $options['allowBots'] === 'Y')
75 ], $allowSearchSelf);
76 }
77
79 {
80 $items[$entityType] = \CSocNetLogDestination::getExtranetUser();
81 $result['ADDITIONAL_INFO']['EXTRANET_USER'] = 'Y';
82
83 if (!empty($selectedItems[$entityType]))
84 {
85 foreach($selectedItems[$entityType] as $code)
86 {
87 if (!isset($items[$entityType][$code]))
88 {
89 $result['ITEMS_HIDDEN'][] = $code;
90 }
91 }
92 }
93
94 $result['ITEMS'] = $items[$entityType];
95 if(!empty($lastItems[$entityType]))
96 {
97 $result["ITEMS_LAST"] = array_values($lastItems[$entityType]);
98 }
99 $result["ITEMS_LAST"] = array_values(array_intersect($result["ITEMS_LAST"], array_keys($result['ITEMS'])));
100 }
101 else
102 {
103 $lastUserList = [];
104 if(!empty($lastItems[$entityType]))
105 {
106 $lastUserList = array_map(
107 function($code)
108 {
109 return preg_replace('/^U(\d+)$/', '$1', $code);
110 },
111 $lastItems[$entityType]
112 );
113 }
114
115 $result['ADDITIONAL_INFO']['EXTRANET_USER'] = 'N';
116
117 $items[$entityType] = [];
118 if (!empty($lastUserList))
119 {
120 $items[$entityType] = \CSocNetLogDestination::getUsers([
121 'id' => $lastUserList,
122 'CRM_ENTITY' => ModuleManager::isModuleInstalled('crm'),
123 'ONLY_WITH_EMAIL' => (isset($options['onlyWithEmail']) && $options['onlyWithEmail'] === 'Y' ? 'Y' : ''),
124 'ALLOW_BOTS' => (isset($options['allowBots']) && $options['allowBots'] === 'Y')
125 ], $allowSearchSelf);
126 }
127
128 $items[$entityType] = array_merge($items[$entityType], $selected);
129
130 if (
131 isset($options['extranetContext'])
132 && in_array($options['extranetContext'], array(Entities::EXTRANET_CONTEXT_INTERNAL, Entities::EXTRANET_CONTEXT_EXTERNAL))
133 )
134 {
135 foreach($items[$entityType] as $key => $value)
136 {
137 if (isset($value["isExtranet"]))
138 {
139 if (
140 (
141 $value["isExtranet"] === 'Y'
142 && $options['extranetContext'] == Entities::EXTRANET_CONTEXT_INTERNAL
143 )
144 || (
145 $value["isExtranet"] === 'N'
146 && $options['extranetContext'] == Entities::EXTRANET_CONTEXT_EXTERNAL
147 )
148 )
149 {
150 unset($items[$entityType][$key]);
151 unset($lastItems[$entityType][$key]);
152 }
153 }
154 }
155 }
156
157 if (!empty($selectedItems[$entityType]))
158 {
159 foreach($selectedItems[$entityType] as $code)
160 {
161 if (!isset($items[$entityType][$code]))
162 {
163 $result['ITEMS_HIDDEN'][] = $code;
164 }
165 }
166 }
167
168 foreach($items[$entityType] as $key => $value)
169 {
170 if (
171 !empty($value['isEmail'])
172 && $value['isEmail'] === 'Y'
173 )
174 {
175 unset($items[$entityType][$key]);
176 unset($lastItems[$entityType][$key]);
177 }
178 }
179
180 $result["ITEMS_LAST"] = array_values($lastItems[$entityType]);
181
182 if (
183 (
184 isset($options["allowAddUser"])
185 && $options["allowAddUser"] === 'Y'
186 )
187 || (
188 isset($options["allowSearchEmailUsers"])
189 && $options["allowSearchEmailUsers"] === 'Y'
190 )
191 || (
192 isset($options["allowEmailInvitation"])
193 && $options["allowEmailInvitation"] === 'Y'
194 )
195 )
196 {
197 $items['LAST'] = $result["ITEMS_LAST"];
198 \CSocNetLogDestination::fillEmails($items);
199 $result["ITEMS_LAST"] = $items['LAST'];
200 unset($items['LAST']);
201 }
202
203 if (
204 (
205 empty($items[$entityType])
206 || (
207 is_array($items[$entityType])
208 && count($items[$entityType]) < 3
209 )
210 )
211 && ModuleManager::isModuleInstalled('intranet')
212 && (
213 !isset($options['extranetContext'])
214 || $options['extranetContext'] != Entities::EXTRANET_CONTEXT_EXTERNAL
215 )
216 )
217 {
218 $lastUserList = array();
219
220 $res = UserTable::getList(array(
221 'order' => array(
222 'LAST_ACTIVITY_DATE' => 'DESC'
223 ),
224 'filter' => array(
225 '!=UF_DEPARTMENT' => false,
226 '=ACTIVE' => 'Y',
227 'CONFIRM_CODE' => false
228 ),
229 'select' => array('ID'),
230 'limit' => 10
231 ));
232 while($userFields = $res->fetch())
233 {
234 $lastUserList[] = $userFields['ID'];
235 }
236
237 $items[$entityType] = array_merge((is_array($items[$entityType]) ? $items[$entityType] : array()), \CSocNetLogDestination::getUsers([
238 'id' => $lastUserList,
239 'ONLY_WITH_EMAIL' => (isset($options['onlyWithEmail']) && $options['onlyWithEmail'] === 'Y' ? 'Y' : ''),
240 'ALLOW_BOTS' => (isset($options['allowBots']) && $options['allowBots'] === 'Y')
241 ], $allowSearchSelf));
242 foreach($items[$entityType] as $item)
243 {
244 $result["ITEMS_LAST"][] = 'U'.$item['entityId'];
245 }
246 }
247 }
248
249 if (
250 isset($options["showVacations"])
251 && $options["showVacations"] === 'Y'
252 )
253 {
254 $result['ADDITIONAL_INFO']['USERS_VACATION'] = \Bitrix\Socialnetwork\Integration\Intranet\Absence\User::getDayVacationList();
255 }
256
257 $result['ITEMS'] = $items[$entityType];
258
259 return $result;
260 }
261
262 public function search($params = array())
263 {
264 $result = array(
265 'ITEMS' => array(),
266 'ADDITIONAL_INFO' => array()
267 );
268
269 $entityOptions = (!empty($params['options']) ? $params['options'] : array());
270
271 if (
272 !empty($entityOptions['allowSearch'])
273 && $entityOptions['allowSearch'] === 'N'
274 )
275 {
276 return $result;
277 }
278
279 $requestFields = (!empty($params['requestFields']) ? $params['requestFields'] : []);
280 $commonOptions = (!empty($requestFields['options']) ? $requestFields['options'] : []);
281
282 $search = $requestFields['searchString'];
283 $searchConverted = (!empty($requestFields['searchStringConverted']) ? $requestFields['searchStringConverted'] : false);
284 $nameTemplate = self::getNameTemplate($commonOptions['userNameTemplate'] ?? '');
285
286 $searchModified = false;
287 $result["ITEMS"] = \CSocNetLogDestination::searchUsers(
288 array(
289 "SEARCH" => $search,
290 "NAME_TEMPLATE" => $nameTemplate,
291 "SELF" => (!empty($entityOptions['allowSearchSelf']) && $entityOptions['allowSearchSelf'] === 'Y'),
292 "EMPLOYEES_ONLY" => (!empty($entityOptions['scope']) && $entityOptions['scope'] === "I"),
293 "EXTRANET_ONLY" => (!empty($entityOptions['scope']) && $entityOptions['scope'] === "E"),
294 "DEPARTAMENT_ID" => (
295 !empty($commonOptions['siteDepartmentId'])
296 && (int)$commonOptions['siteDepartmentId'] > 0
297 ? (int)$commonOptions['siteDepartmentId']
298 : false
299 ),
300 "EMAIL_USERS" => (!empty($entityOptions['allowSearchByEmail']) && $entityOptions['allowSearchByEmail'] === 'Y'),
301 "CRMEMAIL_USERS" => (!empty($entityOptions['allowSearchCrmEmailUsers']) && $entityOptions['allowSearchCrmEmailUsers'] === 'Y'),
302 "NETWORK_SEARCH" => false,
303 "ONLY_WITH_EMAIL" => (isset($entityOptions['onlyWithEmail']) && $entityOptions['onlyWithEmail'] === 'Y' ? 'Y' : ''),
304 'ALLOW_BOTS' => (isset($entityOptions['allowBots']) && $entityOptions['allowBots'] === 'Y'),
305 'SHOW_ALL_EXTRANET_CONTACTS' => (isset($entityOptions['showAllExtranetContacts']) && $entityOptions['showAllExtranetContacts'] === 'Y')
306 ),
307 $searchModified
308 );
309
310 if (!empty($searchModified))
311 {
312 $result['SEARCH'] = $searchModified;
313 }
314
315 if (
316 empty($result["ITEMS"])
317 && $searchConverted
318 && $search !== $searchConverted
319 )
320 {
321 $result["ITEMS"] = \CSocNetLogDestination::searchUsers(
322 array(
323 "SEARCH" => $searchConverted,
324 "NAME_TEMPLATE" => $nameTemplate,
325 "SELF" => (!empty($entityOptions['allowSearchSelf']) && $entityOptions['allowSearchSelf'] === 'Y'),
326 "EMPLOYEES_ONLY" => (!empty($entityOptions['scope']) && $entityOptions['scope'] === "I"),
327 "EXTRANET_ONLY" => (!empty($entityOptions['scope']) && $entityOptions['scope'] === "E"),
328 "DEPARTAMENT_ID" => (
329 !empty($commonOptions['siteDepartmentId'])
330 && (int)$commonOptions['siteDepartmentId'] > 0
331 ? (int)$commonOptions['siteDepartmentId']
332 : false
333 ),
334 "EMAIL_USERS" => (!empty($entityOptions['allowSearchByEmail']) && $entityOptions['allowSearchByEmail'] === 'Y'),
335 "CRMEMAIL_USERS" => (!empty($entityOptions['allowSearchCrmEmailUsers']) && $entityOptions['allowSearchCrmEmailUsers'] === 'Y'),
336 "NETWORK_SEARCH" => false,
337 'ALLOW_BOTS' => (isset($entityOptions['allowBots']) && $entityOptions['allowBots'] === 'Y'),
338 'SHOW_ALL_EXTRANET_CONTACTS' => (isset($entityOptions['showAllExtranetContacts']) && $entityOptions['showAllExtranetContacts'] === 'Y')
339 ),
340 $searchModified
341 );
342
343 $result['SEARCH'] = $searchConverted;
344 }
345
346 return $result;
347 }
348
349 public function loadAll()
350 {
351 return \CSocNetLogDestination::getUsers(array(
352 'all' => 'Y'
353 ));
354 }
355
356 public function getItemName($itemCode = '')
357 {
358 return \Bitrix\Socialnetwork\Integration\Main\UISelector\Users::getUserName($itemCode);
359 }
360
361 public static function getUserName($itemCode = '')
362 {
363 global $USER;
364
365 $result = '';
366
367 $entityId = (
368 preg_match('/^U(\d+)$/i', $itemCode, $matches)
369 && intval($matches[1]) > 0
370 ? intval($matches[1])
371 : 0
372 );
373
374 if (
375 $entityId > 0
376 && \CSocNetUser::canProfileView($USER->getId(), $entityId)
377 )
378 {
379 $res = UserTable::getList(array(
380 'filter' => array(
381 '=ID' => $entityId
382 ),
383 'select' => array('NAME', 'SECOND_NAME', 'LAST_NAME', 'LOGIN')
384 ));
385
386 if ($userFields = $res->fetch())
387 {
388 $result = \CUser::formatName(self::getNameTemplate(), $userFields, false);
389 }
390 }
391
392 return $result;
393 }
394}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static getNameTemplate($requestNameTemplate='')
Definition users.php:11