Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
base.php
1<?
2
4
6
7class Base
8{
9 protected $entityTypeId;
10 protected $userFieldsReserved = [];
11
12 public function __construct($entityTypeId)
13 {
14 $this->entityTypeId = $entityTypeId;
15 }
16
17 protected function getEntityUFList()
18 {
19 global $USER_FIELD_MANAGER;
20
21 static $result = [];
22 if (!isset($result[$this->entityTypeId]))
23 {
24 $ufList = $USER_FIELD_MANAGER->getUserFields($this->entityTypeId, 0, LANGUAGE_ID, false);
25 $result[$this->entityTypeId] = $this->postFilterFields($ufList);
26 }
27
28 return $result[$this->entityTypeId];
29 }
30
31 protected function getUserFieldsReserved()
32 {
34 }
35
36 public function addUFHeaders(&$gridHeaders, $import = false)
37 {
38 $userUFList = $this->getEntityUFList();
39
40 foreach($userUFList as $FIELD_NAME => $uf)
41 {
42 if(
43 !isset($uf['SHOW_IN_LIST'])
44 || $uf['SHOW_IN_LIST'] !== 'Y'
45 )
46 {
47 continue;
48 }
49
50 $editable = true;
51 $type = $uf['USER_TYPE']['BASE_TYPE'];
52
53 if (
54 $uf['EDIT_IN_LIST'] === 'N'
55 || $uf['MULTIPLE'] === 'Y'
56 || $uf['USER_TYPE']['BASE_TYPE'] === 'file'
57 || $uf['USER_TYPE']['USER_TYPE_ID'] === 'employee'
58 || $uf['USER_TYPE']['USER_TYPE_ID'] === 'crm'
59 )
60 {
61 $editable = false;
62 }
63 elseif (in_array($uf['USER_TYPE']['USER_TYPE_ID'], ['enumeration', 'iblock_section', 'iblock_element']))
64 {
65 $type = 'list';
66 $editable = [
67 'items' => ['' => '']
68 ];
69
70 if (is_callable([$uf['USER_TYPE']['CLASS_NAME'], 'GetList']))
71 {
72 $enumRes = call_user_func_array([$uf['USER_TYPE']['CLASS_NAME'], 'GetList'], [$uf]);
73 if ($enumRes)
74 {
75 while ($enumFields = $enumRes->fetch())
76 {
77 $editable['items'][$enumFields['ID']] = $enumFields['VALUE'];
78 }
79 }
80 }
81 }
82 else if ($uf['USER_TYPE']['USER_TYPE_ID'] == 'boolean')
83 {
84 $type = 'list';
85
86 //Default value must be placed at first position.
87 $defaultValue = (
88 isset($uf['SETTINGS']['DEFAULT_VALUE'])
89 ? (int)$uf['SETTINGS']['DEFAULT_VALUE']
90 : 0
91 );
92
93 if($defaultValue === 1)
94 {
95 $editable = [
96 'items' => [
97 '1' => GetMessage('MAIN_YES'),
98 '0' => GetMessage('MAIN_NO')
99 ]
100 ];
101 }
102 else
103 {
104 $editable = [
105 'items' => [
106 '0' => GetMessage('MAIN_NO'),
107 '1' => GetMessage('MAIN_YES')
108 ]
109 ];
110 }
111 }
112 elseif ($uf['USER_TYPE']['BASE_TYPE'] == 'datetime')
113 {
114 $type = 'date';
115 }
116 elseif (
117 $uf['USER_TYPE']['USER_TYPE_ID'] == 'crm_status'
118 && Loader::includeModule('crm')
119 )
120 {
121 $type = 'list';
122 $editable = [
123 'items' => ['' => ''] + \CCrmStatus::getStatusList($uf['SETTINGS']['ENTITY_TYPE'])
124 ];
125 }
126 elseif(mb_substr($uf['USER_TYPE']['USER_TYPE_ID'], 0, 5) === 'rest_')
127 {
128 // skip REST type fields here
129 continue;
130 }
131
132 if($type === 'string')
133 {
134 $type = 'text';
135 }
136 elseif(
137 $type === 'int'
138 || $type === 'double'
139 )
140 {
141 //HACK: \CMainUIGrid::prepareEditable does not recognize 'number' type
142 $type = 'int';
143 }
144
145 if (!empty($uf['LIST_COLUMN_LABEL']))
146 {
147 $name = htmlspecialcharsbx($uf['LIST_COLUMN_LABEL']);
148 }
149 elseif (!empty(['EDIT_FORM_LABEL']))
150 {
151 $name = htmlspecialcharsbx($uf['EDIT_FORM_LABEL']);
152 }
153 else
154 {
155 $name = htmlspecialcharsbx($FIELD_NAME);
156 }
157
158 $gridHeaders[$FIELD_NAME] = array(
159 'id' => $FIELD_NAME,
160 'name' => $name,
161 'sort' => $uf['MULTIPLE'] == 'N' ? $FIELD_NAME : false,
162 'default' => $uf['SHOW_IN_LIST'] == 'Y',
163 'editable' => $editable,
164 'type' => $type
165 );
166
167 if ($import)
168 {
169 $gridHeaders[$FIELD_NAME]['mandatory'] = (
170 $uf['MANDATORY'] === 'Y'
171 ? 'Y'
172 : 'N'
173 );
174 }
175 }
176
177 }
178
179 protected function postFilterFields(array $fields)
180 {
181 foreach ($this->getUserFieldsReserved() as $ufId)
182 {
183 if (isset($fields[$ufId]))
184 {
185 unset($fields[$ufId]);
186 }
187 }
188
189 return $fields;
190 }
191
192}
postFilterFields(array $fields)
Definition base.php:179
__construct($entityTypeId)
Definition base.php:12
addUFHeaders(&$gridHeaders, $import=false)
Definition base.php:36
static includeModule($moduleName)
Definition loader.php:69