Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
userdataprovider.php
1<?php
2namespace Bitrix\Main\Filter;
3
8
10{
12 protected $settings = null;
13
15 {
16 $this->settings = $settings;
17 }
18
19 public static function extranetSite()
20 {
21 static $result = null;
22
23 if ($result === null)
24 {
25 $result = (
26 Loader::includeModule('extranet')
27 && \CExtranet::isExtranetSite()
28 );
29 }
30
31 return $result;
32 }
33
34 public static function getFiredAvailability(): bool
35 {
36 global $USER;
37
38 static $result = null;
39
40 if ($result === null)
41 {
42 $result = (
43 (
44 Option::get('bitrix24', 'show_fired_employees', 'Y') === 'Y'
45 || $USER->canDoOperation('edit_all_users')
46 )
47 && !self::extranetSite()
48 );
49 }
50
51 return $result;
52 }
53
54 public static function getExtranetAvailability(): bool
55 {
56 static $result = null;
57
58 if ($result === null)
59 {
60 $result = (
62 && Option::get('extranet', 'extranet_site') !== ''
63 );
64 }
65
66 return $result;
67 }
68
69 public static function getInvitedAvailability()
70 {
71 global $USER;
72
73 static $result = null;
74
75 if ($result === null)
76 {
77 $result = (
78 $USER->canDoOperation('edit_all_users')
79 && (
81 || Option::get("extranet", "extranet_site") == '' // master hasn't been run
83 )
84 );
85 }
86
87 return $result;
88 }
89
90 public static function getIntegratorAvailability()
91 {
92 global $USER;
93
94 static $result = null;
95
96 if ($result === null)
97 {
98 $result = (
99 $USER->canDoOperation('edit_all_users')
101 && (
103 || (
104 Option::get("extranet", "extranet_site") <> ''
106 )
107 )
108 );
109 }
110
111 return $result;
112 }
113
114 public static function getAdminAvailability()
115 {
116 global $USER;
117
118 static $result = null;
119
120 if ($result === null)
121 {
122 $result = (
123 $USER->canDoOperation('edit_all_users')
124 && (
126 || Option::get("extranet", "extranet_site", "") === ""
128 )
129 );
130 }
131
132 return $result;
133 }
134
135 public static function getVisitorAvailability(): bool
136 {
137 global $USER;
138
139 static $result = null;
140
141 if ($result === null)
142 {
143 $result = (
144 $USER->canDoOperation('edit_all_users')
145 );
146 }
147
148 return $result;
149 }
150
155 public function getSettings()
156 {
157 return $this->settings;
158 }
159
165 protected function getFieldName($fieldID)
166 {
167 $name = Loc::getMessage("MAIN_USER_FILTER_{$fieldID}");
168
169 if($name === null)
170 {
171 $name = $fieldID;
172 }
173
174 return $name;
175 }
176
177 public function prepareFieldData($fieldID)
178 {
179 $result = null;
180
181 if ($fieldID === 'GENDER')
182 {
183 $result = [
184 'params' => ['multiple' => 'N'],
185 'items' => [
186 'F' => Loc::getMessage('MAIN_USER_FILTER_GENDER_F'),
187 'M' => Loc::getMessage('MAIN_USER_FILTER_GENDER_M')
188 ]
189 ];
190 }
191 elseif (in_array($fieldID, [ 'INTEGRATOR', 'ADMIN' ]))
192 {
193 $result = [
194 'params' => ['multiple' => 'N'],
195 'items' => [
196 'Y' => Loc::getMessage('MAIN_USER_FILTER_Y'),
197 ]
198 ];
199 }
200 elseif (
201 $fieldID === 'PERSONAL_COUNTRY'
202 || $fieldID === 'WORK_COUNTRY'
203 )
204 {
205 $countriesList = [];
206 $countries = getCountryArray();
207 foreach($countries['reference_id'] as $key => $countryId)
208 {
209 $countriesList[$countryId] = $countries['reference'][$key];
210 }
211
212 $result = [
213 'items' => $countriesList
214 ];
215 }
216 elseif (
217 $fieldID === 'DEPARTMENT'
218 || $fieldID === 'DEPARTMENT_FLAT'
219 )
220 {
221 return [
222 'params' => [
223 'apiVersion' => 3,
224 'context' => 'USER_LIST_FILTER_DEPARTMENT',
225 'multiple' => 'N',
226 'contextCode' => 'DR',
227 'enableDepartments' => 'Y',
228 'departmentFlatEnable' => ($fieldID === 'DEPARTMENT_FLAT' ? 'Y' : 'N'),
229 'enableAll' => 'N',
230 'enableUsers' => 'N',
231 'enableSonetgroups' => 'N',
232 'allowEmailInvitation' => 'N',
233 'allowSearchEmailUsers' => 'N',
234 'departmentSelectDisable' => 'N',
235 'isNumeric' => 'N',
236 ]
237 ];
238 }
239
240 return $result;
241 }
242
247 public function prepareFields()
248 {
249 $result = [];
250
251 $whiteList = $this->getSettings()->getWhiteList();
252
253 $fieldsList = [
254 'ID' => [],
255 'NAME' => [
256 'whiteList' => [ 'FULL_NAME', 'NAME' ]
257 ],
258 'LAST_NAME' => [
259 'whiteList' => [ 'FULL_NAME', 'LAST_NAME' ],
260 'options' => [ 'default' => true ]
261 ],
262 'SECOND_NAME' => [
263 'whiteList' => [ 'SECOND_NAME' ]
264 ],
265 'FIRED' => [
266// 'conditionMethod' => 'self::getFiredAvailability',
267 'options' => [ 'type' => 'checkbox' ]
268 ],
269 'EXTRANET' => [
270 'conditionMethod' => 'self::getExtranetAvailability',
271 'options' => [ 'type' => 'checkbox' ]
272 ],
273 'INVITED' => [
274 'conditionMethod' => 'self::getInvitedAvailability',
275 'options' => [ 'type' => 'checkbox' ]
276 ],
277 'VISITOR' => [
278 'conditionMethod' => 'self::getVisitorAvailability',
279 'options' => ['type' => 'checkbox']
280 ],
281 'INTEGRATOR' => [
282 'conditionMethod' => 'self::getIntegratorAvailability',
283 'options' => [ 'type' => 'list', 'partial' => true ]
284 ],
285 'ADMIN' => [
286 'conditionMethod' => 'self::getAdminAvailability',
287 'options' => [ 'type' => 'list', 'partial' => true ]
288 ],
289 'IS_ONLINE' => [
290 'options' => [ 'type' => 'checkbox' ]
291 ],
292 'DEPARTMENT' => [
293 'whiteList' => [ 'UF_DEPARTMENT' ],
294 'options' => [ 'default' => true, 'type' => 'dest_selector', 'partial' => true ]
295 ],
296 'DEPARTMENT_FLAT' => [
297 'whiteList' => [ 'UF_DEPARTMENT_FLAT' ],
298 'options' => [ 'type' => 'dest_selector', 'partial' => true ]
299 ],
300 'TAGS' => [
301 'whiteList' => [ 'TAGS' ],
302 'options' => [ 'default' => true ]
303 ],
304 'LOGIN' => [
305 'whiteList' => [ 'LOGIN' ]
306 ],
307 'EMAIL' => [
308 'whiteList' => [ 'EMAIL' ]
309 ],
310 'DATE_REGISTER' => [
311 'whiteList' => [ 'DATE_REGISTER' ],
312 'options' => [ 'type' => 'date' ]
313 ],
314 'LAST_ACTIVITY_DATE' => [
315 'whiteList' => [ 'LAST_ACTIVITY_DATE' ],
316 'options' => [ 'type' => 'date' ]
317 ],
318 'BIRTHDAY' => [
319 'whiteList' => [ 'PERSONAL_BIRTHDAY' ],
320 'options' => [ 'type' => 'date' ]
321 ],
322 'GENDER' => [
323 'whiteList' => [ 'PERSONAL_GENDER' ],
324 'options' => [ 'type' => 'list', 'partial' => true ]
325 ],
326 'PHONE_MOBILE' => [
327 'whiteList' => [ 'PERSONAL_MOBILE' ]
328 ],
329 'PERSONAL_CITY' => [
330 'whiteList' => [ 'PERSONAL_CITY' ]
331 ],
332 'PERSONAL_STREET' => [
333 'whiteList' => [ 'PERSONAL_STREET' ]
334 ],
335 'PERSONAL_STATE' => [
336 'whiteList' => [ 'PERSONAL_STATE' ]
337 ],
338 'PERSONAL_ZIP' => [
339 'whiteList' => [ 'PERSONAL_ZIP' ]
340 ],
341 'PERSONAL_MAILBOX' => [
342 'whiteList' => [ 'PERSONAL_MAILBOX' ]
343 ],
344 'PERSONAL_COUNTRY' => [
345 'whiteList' => [ 'PERSONAL_COUNTRY' ],
346 'options' => [ 'type' => 'list', 'partial' => true ]
347 ],
348 'WORK_CITY' => [
349 'whiteList' => [ 'WORK_CITY' ]
350 ],
351 'WORK_STREET' => [
352 'whiteList' => [ 'WORK_STREET' ]
353 ],
354 'WORK_STATE' => [
355 'whiteList' => [ 'WORK_STATE' ]
356 ],
357 'WORK_ZIP' => [
358 'whiteList' => [ 'WORK_ZIP' ]
359 ],
360 'WORK_MAILBOX' => [
361 'whiteList' => [ 'WORK_MAILBOX' ]
362 ],
363 'WORK_COUNTRY' => [
364 'whiteList' => [ 'WORK_COUNTRY' ],
365 'options' => [ 'type' => 'list', 'partial' => true ]
366 ],
367 'WORK_PHONE' => [
368 'whiteList' => [ 'WORK_PHONE' ]
369 ],
370 'POSITION' => [
371 'whiteList' => [ 'WORK_POSITION' ]
372 ],
373 'COMPANY' => [
374 'whiteList' => [ 'WORK_COMPANY' ]
375 ],
376 'WORK_DEPARTMENT' => [
377 'whiteList' => [ 'WORK_DEPARTMENT' ]
378 ],
379 ];
380
381 foreach($fieldsList as $column => $field)
382 {
383 $whiteListPassed = false;
384 if (
385 !empty($field['conditionMethod'])
386 && is_callable($field['conditionMethod'])
387 )
388 {
389 $whiteListPassed = call_user_func_array($field['conditionMethod'], []);
390 }
391 elseif (
392 empty($whiteList)
393 || empty($field['whiteList'])
394 )
395 {
396 $whiteListPassed = true;
397 }
398 else
399 {
400 foreach($field['whiteList'] as $whiteListField)
401 {
402 if (in_array($whiteListField, $whiteList))
403 {
404 $whiteListPassed = true;
405 break;
406 }
407 }
408 }
409
410 if ($whiteListPassed)
411 {
412 $result[$column] = $this->createField(
413 $column,
414 (!empty($field['options']) ? $field['options'] : [])
415 );
416 }
417 }
418
419 return $result;
420 }
421
422}
createField($fieldID, array $params=null)
static includeModule($moduleName)
Definition loader.php:69
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static isModuleInstalled($moduleName)