1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
entityufdataprovider.php
См. документацию.
1<?php
2namespace Bitrix\Main\Filter;
3
4use Bitrix\Main\UserField\Types\EnumType;
5
7{
9 protected $settings = null;
10 protected $ufReserved = [];
11
13 {
14 $this->settings = $settings;
15 }
16
21 public function getSettings()
22 {
23 return $this->settings;
24 }
25
30 public function getUserFieldEntityID()
31 {
32 return $this->settings->getUserFieldEntityID();
33 }
34
39 protected function getUserFields()
40 {
42
43 static $result = [];
44
46 if (empty($entityId))
47 {
48 return [];
49 }
50
51 if (!isset($result[$entityId]))
52 {
53 $result[$entityId] = $USER_FIELD_MANAGER->getUserFields($entityId, 0, LANGUAGE_ID, false);
55 }
56 return $result[$entityId];
57 }
58
63 public function prepareFields()
64 {
65 $result = [];
66 foreach($this->getUserFields() as $fieldName => $userField)
67 {
68 if (
69 $userField['SHOW_FILTER'] === 'N'
70 || $userField['USER_TYPE']['BASE_TYPE'] === 'file'
71 )
72 {
73 continue;
74 }
75
76 $typeID = $userField['USER_TYPE']['USER_TYPE_ID'];
77 //$isMultiple = isset($userField['MULTIPLE']) && $userField['MULTIPLE'] === 'Y';
78
79 $fieldLabel = $userField['LIST_FILTER_LABEL'] ?? '';
80 if($fieldLabel === '')
81 {
82 if(isset($userField['LIST_COLUMN_LABEL']))
83 {
84 $fieldLabel = $userField['LIST_COLUMN_LABEL'];
85 }
86 elseif(isset($userField['EDIT_FORM_LABEL']))
87 {
88 $fieldLabel = $userField['EDIT_FORM_LABEL'];
89 }
90 }
91 if ($fieldLabel == '')
92 {
93 $fieldLabel = $fieldName;
94 }
95
96 if($typeID === 'employee')
97 {
98 $result[$fieldName] = $this->createField(
99 $fieldName,
100 [
101 'type' => 'entity_selector',
102 'name' => $fieldLabel,
103 'partial' => true,
104 'subtype' => $typeID,
105 ]
106 );
107 }
108 elseif($typeID === 'string' || $typeID === 'url' || $typeID === 'address' || $typeID === 'money')
109 {
110 $result[$fieldName] = $this->createField(
111 $fieldName,
112 [
113 'type' => 'text',
114 'name' => $fieldLabel,
115 'data' => [
116 'additionalFilter' => [
117 'isEmpty',
118 'hasAnyValue',
119 ],
120 ],
121 'subtype' => $typeID,
122 ]
123 );
124 continue;
125 }
126 elseif($typeID === 'integer' || $typeID === 'double')
127 {
128 $result[$fieldName] = $this->createField(
129 $fieldName,
130 [
131 'type' => 'number',
132 'name' => $fieldLabel,
133 'data' => [
134 'additionalFilter' => [
135 'isEmpty',
136 'hasAnyValue',
137 ],
138 ],
139 'subtype' => $typeID,
140 ]
141 );
142 continue;
143 }
144 elseif($typeID === 'boolean')
145 {
146 $result[$fieldName] = $this->createField(
147 $fieldName,
148 [
149 'type' => 'checkbox',
150 'name' => $fieldLabel,
151 'data' => ['valueType' => 'numeric'],
152 'subtype' => $typeID,
153 ]
154 );
155 }
156 elseif($typeID === 'datetime' || $typeID === 'date')
157 {
158 $result[$fieldName] = $this->createField(
159 $fieldName,
160 [
161 'type' => 'date',
162 'name' => $fieldLabel,
163 'data' =>
164 [
165 'time' => $typeID === 'datetime',
166 'additionalFilter' => [
167 'isEmpty',
168 'hasAnyValue',
169 ],
170 ],
171 'subtype' => $typeID,
172 ]
173 );
174 }
175 elseif(
176 ($typeID === 'enumeration' || $typeID === 'crm_status')
177 && isset($userField['SETTINGS']['DISPLAY'])
178 && $userField['SETTINGS']['DISPLAY'] === EnumType::DISPLAY_DIALOG
179 )
180 {
181 $result[$fieldName] = $this->createField(
182 $fieldName,
183 [
184 'type' => 'entity_selector',
185 'name' => $fieldLabel,
186 'partial' => true,
187 'subtype' => $typeID,
188 ]
189 );
190 }
191 elseif(
192 $typeID === 'enumeration'
193 || $typeID === 'crm_status'
194 || $typeID === 'iblock_element'
195 || $typeID === 'iblock_section'
196 )
197 {
198 $result[$fieldName] = $this->createField(
199 $fieldName,
200 [
201 'type' => 'list',
202 'name' => $fieldLabel,
203 'partial' => true,
204 'subtype' => $typeID,
205 ]
206 );
207 }
208 elseif($typeID === 'crm')
209 {
210 $result[$fieldName] = $this->createField(
211 $fieldName,
212 [
213 'type' => 'dest_selector',
214 'name' => $fieldLabel,
215 'partial' => true,
216 'subtype' => $typeID,
217 ]
218 );
219 }
220 else
221 {
222 $result[$fieldName] = $this->createField(
223 $fieldName,
224 [
225 'type' => 'custom',
226 'name' => $fieldLabel,
227 'data' => ['value' => ''],
228 'subtype' => $typeID,
229 ]
230 );
231 }
232 }
233
234 return $result;
235 }
236
242 public function prepareFieldData($fieldID)
243 {
244 $userFields = $this->getUserFields();
245 if(!isset($userFields[$fieldID]))
246 {
247 return null;
248 }
249
250 $userField = $userFields[$fieldID];
251 $typeID = $userField['USER_TYPE']['USER_TYPE_ID'];
252 $isMultiple = isset($userField['MULTIPLE']) && $userField['MULTIPLE'] === 'Y';
253 $ID = $userField['ID'];
254 if ($typeID === 'employee')
255 {
256 return [
257 'params' => [
258 'multiple' => $isMultiple ? 'Y' : 'N',
259 'dialogOptions' => [
260 'height' => 200,
261 'context' => 'CRM_UF_FILTER_' . $fieldID,
262 'entities' => [
263 [
264 'id' => 'user',
265 'options' => [
266 'inviteEmployeeLink' => false,
267 'intranetUsersOnly' => true,
268 ]
269 ],
270 ],
271 'showAvatars' => true,
272 'dropdownMode' => false,
273 ],
274 ],
275 ];
276 }
277 elseif($typeID === 'enumeration')
278 {
279 $entity = new \CUserFieldEnum();
280 $dbResult = $entity->GetList(array('SORT' => 'ASC'), array('USER_FIELD_ID' => $ID));
281
282 $items = array();
283 if(is_object($dbResult))
284 {
285 while($ary = $dbResult->Fetch())
286 {
287 $items[$ary['ID']] = $ary['VALUE'];
288 }
289 }
290
291 if ($userField['SETTINGS']['DISPLAY'] === EnumType::DISPLAY_DIALOG)
292 {
293 $dialogItems = [];
294 foreach ($items as $itemId => $itemTitle)
295 {
296 $dialogItems[] = [
297 'id' => $itemId,
298 'entityId' => $userField['FIELD_NAME'],
299 'title' => $itemTitle,
300 'tabs' => $userField['FIELD_NAME'],
301 ];
302 }
303 return [
304 'params' => [
305 'multiple' => 'Y',
306 'dialogOptions' => [
307 'items' => $dialogItems,
308 'height' => 200,
309 'dropdownMode' => true,
310 'compactView' => true,
311 'tabs' => [
312 [
313 'id' => $userField['FIELD_NAME'],
314 'title' => $userField['EDIT_FORM_LABEL'],
315 ],
316 ],
317 ],
318 ],
319 ];
320 }
321
322 return array(
323 'params' => array('multiple' => 'Y'),
324 'items' => $items
325 );
326 }
327 elseif($typeID === 'iblock_element')
328 {
329 $entity = new \CUserTypeIBlockElement();
330 $dbResult = $entity->GetList($userField);
331
332 $items = array();
333 if(is_object($dbResult))
334 {
335 $count = 0;
336 while($ary = $dbResult->Fetch())
337 {
338 $items[$ary['ID']] = $ary['NAME'];
339
340 if(++$count > 500)
341 {
342 break;
343 }
344 }
345 }
346
347 return array(
348 'params' => array('multiple' => 'Y'),
349 'items' => $items
350 );
351 }
352 elseif($typeID === 'iblock_section')
353 {
354 $entity = new \CUserTypeIBlockSection();
355 $dbResult = $entity->GetList($userField);
356
357 $items = array();
358 if(is_object($dbResult))
359 {
360 $count = 0;
361 while($ary = $dbResult->Fetch())
362 {
363 $items[$ary['ID']] = isset($ary['DEPTH_LEVEL']) && $ary['DEPTH_LEVEL'] > 1
364 ? str_repeat('. ', ($ary['DEPTH_LEVEL'] - 1)).$ary['NAME'] : $ary['NAME'];
365
366 if(++$count > 500)
367 {
368 break;
369 }
370 }
371 }
372
373 return array(
374 'params' => array('multiple' => 'Y'),
375 'items' => $items
376 );
377 }
378 elseif($typeID === 'crm')
379 {
380 $settings = isset($userField['SETTINGS']) && is_array($userField['SETTINGS'])
381 ? $userField['SETTINGS'] : array();
382
383 $entityTypeNames = array();
384 $supportedEntityTypeNames = array(
385 \CCrmOwnerType::LeadName,
386 \CCrmOwnerType::DealName,
387 \CCrmOwnerType::ContactName,
388 \CCrmOwnerType::CompanyName
389 );
390 foreach($supportedEntityTypeNames as $entityTypeName)
391 {
392 if(isset($settings[$entityTypeName]) && $settings[$entityTypeName] === 'Y')
393 {
394 $entityTypeNames[] = $entityTypeName;
395 }
396 }
397
398 $destSelectorParams = array(
399 'apiVersion' => 3,
400 'context' => 'CRM_UF_FILTER_ENTITY',
401 'contextCode' => 'CRM',
402 'useClientDatabase' => 'N',
403 'enableAll' => 'N',
404 'enableDepartments' => 'N',
405 'enableUsers' => 'N',
406 'enableSonetgroups' => 'N',
407 'allowEmailInvitation' => 'N',
408 'allowSearchEmailUsers' => 'N',
409 'departmentSelectDisable' => 'Y',
410 'enableCrm' => 'Y',
411 'multiple' => ($isMultiple ? 'Y' : 'N'),
412 'convertJson' => 'Y'
413 );
414
415 $entityTypeCounter = 0;
416 foreach($entityTypeNames as $entityTypeName)
417 {
418 switch($entityTypeName)
419 {
420 case \CCrmOwnerType::LeadName:
421 $destSelectorParams['enableCrmLeads'] = 'Y';
422 $destSelectorParams['addTabCrmLeads'] = 'Y';
423 $entityTypeCounter++;
424 break;
425 case \CCrmOwnerType::DealName:
426 $destSelectorParams['enableCrmDeals'] = 'Y';
427 $destSelectorParams['addTabCrmDeals'] = 'Y';
428 $entityTypeCounter++;
429 break;
430 case \CCrmOwnerType::ContactName:
431 $destSelectorParams['enableCrmContacts'] = 'Y';
432 $destSelectorParams['addTabCrmContacts'] = 'Y';
433 $entityTypeCounter++;
434 break;
435 case \CCrmOwnerType::CompanyName:
436 $destSelectorParams['enableCrmCompanies'] = 'Y';
437 $destSelectorParams['addTabCrmCompanies'] = 'Y';
438 $entityTypeCounter++;
439 break;
440 default:
441 }
442 }
443 if ($entityTypeCounter <= 1)
444 {
445 $destSelectorParams['addTabCrmLeads'] = 'N';
446 $destSelectorParams['addTabCrmDeals'] = 'N';
447 $destSelectorParams['addTabCrmContacts'] = 'N';
448 $destSelectorParams['addTabCrmCompanies'] = 'N';
449 }
450
451 return array(
452 'params' => $destSelectorParams
453 );
454 }
455 elseif($typeID === 'crm_status')
456 {
457 $items = array();
458 if(isset($userField['SETTINGS'])
459 && is_array($userField['SETTINGS'])
460 && isset($userField['SETTINGS']['ENTITY_TYPE'])
461 )
462 {
463 $entityType = $userField['SETTINGS']['ENTITY_TYPE'];
464 if($entityType !== '')
465 {
466 $items = \CCrmStatus::GetStatusList($entityType);
467 }
468 }
469
470 return array(
471 'params' => array('multiple' => 'Y'),
472 'items' => $items
473 );
474 }
475 return null;
476 }
477
484 protected function createField($fieldID, array $params = null)
485 {
486 return new Field($this, $fieldID, $params);
487 }
488
489 public function getUfReserved()
490 {
491 return $this->ufReserved;
492 }
493
494 protected function postFilterFields(array $fields)
495 {
496 foreach ($this->getUfReserved() as $ufId)
497 {
498 if (isset($fields[$ufId]))
499 {
500 unset($fields[$ufId]);
501 }
502 }
503
504 return $fields;
505 }
506
507}
$count
Определения admin_tab.php:4
__construct(EntitySettings $settings)
Определения entityufdataprovider.php:12
createField($fieldID, array $params=null)
Определения entityufdataprovider.php:484
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
global $USER_FIELD_MANAGER
Определения attempt.php:6
$result
Определения get_property_values.php:14
if($ajaxMode) $ID
Определения get_user.php:27
$entity
$entityId
Определения payment.php:4
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$items
Определения template.php:224
$dbResult
Определения updtr957.php:3
$fields
Определения yandex_run.php:501