Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
userfieldbase.php
1<?php
2
4
8
10{
14 public static function getType()
15 {
16 return FieldType::STRING;
17 }
18
24 protected static function formatValuePrintable(FieldType $fieldType, $value)
25 {
26 global $APPLICATION, $USER_FIELD_MANAGER;
27
28 $userType = static::getUserType($fieldType);
29
30 if ($userType === 'crm')
31 {
32 return self::formatCrmValuePrintable($fieldType, $value);
33 }
34
35 $userFieldType = $USER_FIELD_MANAGER->GetUserType($userType);
36 $userField = [
37 'ENTITY_ID' => sprintf('%s_%s',
38 mb_strtoupper($fieldType->getDocumentType()[0]),
39 mb_strtoupper($fieldType->getDocumentType()[2])
40 ),
41 'FIELD_NAME' => 'UF_XXXXXXX',
42 'USER_TYPE_ID' => $userType,
43 'SORT' => 100,
44 'MULTIPLE' => $fieldType->isMultiple() ? 'Y' : 'N',
45 'MANDATORY' => $fieldType->isRequired() ? 'Y' : 'N',
46 'EDIT_FORM_LABEL' => $userFieldType['DESCRIPTION'],
47 'VALUE' => $value,
48 'USER_TYPE' => $userFieldType
49 ];
50
51 if ($settings = $fieldType->getSettings())
52 {
53 $userField['SETTINGS'] = $settings;
54 }
55
56 if ($userType === 'boolean' && ($value === 'Y' || $value === 'N'))
57 {
58 //Convert bizproc boolean values (Y/N) in to UF boolean values (1/0)
59 $userField['VALUE'] = $value = ($value === 'Y') ? 1 : 0;
60 }
61
62 ob_start();
63 $APPLICATION->IncludeComponent(
64 'bitrix:system.field.view',
65 $userType,
66 [
67 'arUserField' => $userField,
68 'bVarsFromForm' => false,
69 'form_name' => "",
70 'printable' => true,
71 'FILE_MAX_HEIGHT' => 400,
72 'FILE_MAX_WIDTH' => 400,
73 'FILE_SHOW_POPUP' => true
74 ],
75 false,
76 ['HIDE_ICONS' => 'Y']
77 );
78
79 return HTMLToTxt(ob_get_clean(), maxlen: 0);
80 }
81
88 public static function convertTo(FieldType $fieldType, $value, $toTypeClass)
89 {
90 if (is_array($value) && isset($value['VALUE']))
91 $value = $value['VALUE'];
92
93 $value = (string)$value;
94
95 return BaseType\StringType::convertTo($fieldType, $value, $toTypeClass);
96 }
97
102 public static function getConversionMap()
103 {
104 return BaseType\StringType::getConversionMap();
105 }
106
115 public static function renderControlSingle(FieldType $fieldType, array $field, $value, $allowSelection, $renderMode)
116 {
117 global $USER_FIELD_MANAGER, $APPLICATION;
118
119 $selectorValue = null;
120 $typeValue = [];
121 if (!is_array($value) || \CBPHelper::isAssociativeArray($value))
122 {
123 $value = [$value];
124 }
125
126 foreach ($value as $v)
127 {
128 if (\CBPActivity::isExpression($v))
129 {
130 $selectorValue = $v;
131 }
132 else
133 {
134 $typeValue[] = is_array($v) && isset($v['VALUE']) ? $value['VALUE'] : $v;
135 }
136 }
137
138 $sType = static::getUserType($fieldType);
139 $value = $typeValue;
140
141 $arUserFieldType = $USER_FIELD_MANAGER->GetUserType($sType);
142
143 $userField = [
144 'ENTITY_ID' => sprintf('%s_%s',
145 mb_strtoupper($fieldType->getDocumentType()[0]),
146 mb_strtoupper($fieldType->getDocumentType()[2])
147 ),
148 'FIELD_NAME' => static::generateControlName($field),
149 'USER_TYPE_ID' => $sType,
150 'SORT' => 100,
151 'MULTIPLE' => $fieldType->isMultiple() ? 'Y' : 'N',
152 'MANDATORY' => $fieldType->isRequired() ? 'Y' : 'N',
153 'EDIT_IN_LIST' => 'Y',
154 'EDIT_FORM_LABEL' => $arUserFieldType['DESCRIPTION'],
155 'VALUE' => $value,
156 'USER_TYPE' => $arUserFieldType,
157 'SETTINGS' => [],
158 'ENTITY_VALUE_ID' => 1,
159 ];
160
161 if ($sType == 'boolean' && ($userField['VALUE'] == "Y" || $userField['VALUE'] == "N"))
162 {
163 $userField['VALUE'] = ($userField['VALUE'] == "Y") ? 1 : 0;
164 }
165
166 $userField['SETTINGS'] = $fieldType->getSettings();
167
168 if (in_array($sType, ['iblock_element', 'iblock_section', 'boolean']) && ($renderMode & FieldType::RENDER_MODE_DESIGNER))
169 {
170 //TODO: fix checkboxes values
171 $userField['SETTINGS']['DISPLAY'] = 'LIST';
172 }
173 elseif ($sType == 'crm' && empty($userField['SETTINGS']))
174 {
175 $userField['SETTINGS'] = ['LEAD' => 'Y', 'CONTACT' => 'Y', 'COMPANY' => 'Y', 'DEAL' => 'Y'];
176 }
177 elseif ($sType === 'iblock_element' && $renderMode & FieldType::RENDER_MODE_PUBLIC)
178 {
179 $userField['SETTINGS']['DISPLAY'] = 'UI';
180 }
181
182 ob_start();
183 $APPLICATION->IncludeComponent(
184 'bitrix:system.field.edit',
185 $sType,
186 [
187 'arUserField' => $userField,
188 'bVarsFromForm' => false,
189 'form_name' => $field['Form'],
190 'FILE_MAX_HEIGHT' => 400,
191 'FILE_MAX_WIDTH' => 400,
192 'FILE_SHOW_POPUP' => true
193 ],
194 false,
195 ['HIDE_ICONS' => 'Y']
196 );
197
198 $renderResult = ob_get_clean();
199
200 if ($allowSelection)
201 {
202 $renderResult .= static::renderControlSelector($field, $selectorValue, true, '', $fieldType);
203 }
204
205 return $renderResult;
206 }
207
216 public static function renderControlMultiple(FieldType $fieldType, array $field, $value, $allowSelection, $renderMode)
217 {
218 return static::renderControlSingle($fieldType, $field, $value, $allowSelection, $renderMode);
219 }
220
224 public static function extractValueSingle(FieldType $fieldType, array $field, array $request)
225 {
226 static::cleanErrors();
227 $result = static::extractValue($fieldType, $field, $request);
228
229 $nameText = $field['Field'].'_text';
230 $text = isset($request[$nameText]) ? $request[$nameText] : null;
231 if (\CBPActivity::isExpression($text))
232 {
233 $result = $text;
234 }
235
236 return $result;
237 }
238
239 protected static function getUserType(FieldType $fieldType)
240 {
241 return mb_substr($fieldType->getType(), 3);
242 }
243
244 private static function formatCrmValuePrintable(FieldType $fieldType, $value)
245 {
246 if (!Loader::includeModule('crm'))
247 {
248 return '';
249 }
250
251 $defaultTypeName = 'LEAD';
252 foreach ($fieldType->getSettings() as $typeName => $flag)
253 {
254 if ($flag === 'Y')
255 {
256 $defaultTypeName = $typeName;
257 break;
258 }
259 }
260
261 return self::prepareCrmUserTypeValueView($value, $defaultTypeName);
262 }
263
264 private static function prepareCrmUserTypeValueView($value, $defaultTypeName = '')
265 {
266 $typeId = $id = null;
267 $parts = explode('_', $value);
268
269 if (count($parts) > 1)
270 {
271 $typeId = \CCrmOwnerTypeAbbr::ResolveTypeID($parts[0]);
272 $id = $parts[1];
273 }
274 elseif ($defaultTypeName !== '')
275 {
276 $typeId = \CCrmOwnerType::resolveID($defaultTypeName);
277 $id = $value;
278 }
279
280 if (!$typeId || !$id)
281 {
282 return '';
283 }
284
285 $entityName = \CCrmOwnerType::getCaption($typeId, $id, false);
286 $entityDesc = \CCrmOwnerType::GetDescription($typeId);
287 $entityUrl = \CCrmOwnerType::GetDetailsUrl($typeId, $id, false);
288
289 return sprintf('[b]%s:[/b] [url=%s]%s[/url]', $entityDesc, $entityUrl, $entityName);
290 }
291}
static extractValueSingle(FieldType $fieldType, array $field, array $request)
static getUserType(FieldType $fieldType)
static renderControlSingle(FieldType $fieldType, array $field, $value, $allowSelection, $renderMode)
static formatValuePrintable(FieldType $fieldType, $value)
static convertTo(FieldType $fieldType, $value, $toTypeClass)
static renderControlMultiple(FieldType $fieldType, array $field, $value, $allowSelection, $renderMode)