Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
usertypeproperty.php
1<?php
2
4
9
10if (Loader::requireModule('bizproc'))
11{
12 class UserTypeProperty extends BaseType\Base
13 {
17 public static function getType()
18 {
19 return FieldType::STRING;
20 }
21
27 protected static function formatValuePrintable(FieldType $fieldType, $value)
28 {
29 $userType = static::getUserType($fieldType);
30 if (is_array($value) && isset($value['VALUE']))
31 $value = $value['VALUE'];
32
33 if (!empty($userType['GetPublicViewHTML']))
34 {
35 $result = call_user_func_array(
36 $userType['GetPublicViewHTML'],
37 array(
38 array('LINK_IBLOCK_ID' => $fieldType->getOptions()),
39 array('VALUE' => $value),
40 ''
41 )
42 );
43
44 //replace empty links
45 $result = str_replace('<a href="">', '<a>', $result);
46 return HTMLToTxt($result);
47 }
48 return parent::formatValuePrintable($fieldType, $value);
49 }
50
57 public static function convertTo(FieldType $fieldType, $value, $toTypeClass)
58 {
59 if (is_array($value) && isset($value['VALUE']))
60 $value = $value['VALUE'];
61
62 $value = (string) $value;
63 //BaseType\String was removed for PHP7 compatibility
64 if (class_exists('\Bitrix\Bizproc\BaseType\StringType'))
65 return BaseType\StringType::convertTo($fieldType, $value, $toTypeClass);
66 return BaseType\String::convertTo($fieldType, $value, $toTypeClass);
67 }
68
73 public static function getConversionMap()
74 {
75 return BaseType\StringType::getConversionMap();
76 }
77
86 public static function renderControlSingle(FieldType $fieldType, array $field, $value, $allowSelection, $renderMode)
87 {
88 $selectorValue = null;
89 if (\CBPActivity::isExpression($value))
90 {
91 $selectorValue = $value;
92 $value = null;
93 }
94
95 $userType = static::getUserType($fieldType);
96
97 if (!empty($userType['GetPublicEditHTML']))
98 {
99 if (is_array($value) && isset($value['VALUE']))
100 $value = $value['VALUE'];
101
103 $userType['GetPublicEditHTML'],
104 [
105 [
106 'LINK_IBLOCK_ID' => $fieldType->getOptions(),
107 'FORMAT_NAME' =>
109 ->getContext()
110 ->getCulture()
111 ->getNameFormat()
112 ,
113 ],
114 ['VALUE' => $value],
115 [
116 'FORM_NAME' => $field['Form'],
117 'VALUE' => static::generateControlName($field)
118 ],
119 true
120 ]
121 );
122 }
123 else
124 $renderResult = static::renderControl($fieldType, $field, $value, $allowSelection, $renderMode);
125
126 if ($allowSelection)
127 {
128 $renderResult .= static::renderControlSelector($field, $selectorValue, true, '', $fieldType);
129 }
130
131 return $renderResult;
132 }
133
142 public static function renderControlMultiple(FieldType $fieldType, array $field, $value, $allowSelection, $renderMode)
143 {
144 $selectorValue = null;
145 $typeValue = array();
146 if (!is_array($value) || is_array($value) && \CBPHelper::isAssociativeArray($value))
147 $value = array($value);
148
149 foreach ($value as $v)
150 {
151 if (\CBPActivity::isExpression($v))
153 else
154 $typeValue[] = $v;
155 }
156
157 $userType = static::getUserType($fieldType);
158
159 if (!empty($userType['GetPublicEditHTMLMulty']))
160 {
161 foreach ($typeValue as $k => &$fld)
162 {
163 if (!is_array($fld) || !isset($fld['VALUE']))
164 $fld = array('VALUE' => $fld);
165 if ($fld['VALUE'] === null)
167 }
169
171 $userType['GetPublicEditHTMLMulty'],
172 array(
173 array('LINK_IBLOCK_ID' => $fieldType->getOptions()),
175 array(
176 'FORM_NAME' => $field['Form'],
177 'VALUE' => static::generateControlName($field)
178 ),
179 true
180 )
181 );
182 }
183 else
184 {
185 $controls = array();
186 // need to show at least one control
187 if (empty($typeValue))
188 $typeValue[] = null;
189
190 foreach ($typeValue as $k => $v)
191 {
192 $singleField = $field;
193 $singleField['Index'] = $k;
194 $controls[] = static::renderControlSingle(
195 $fieldType,
197 $v,
200 );
201 }
202
203 $renderResult = static::wrapCloneableControls($controls, static::generateControlName($field));
204 }
205
206 if ($allowSelection)
207 {
208 $renderResult .= static::renderControlSelector($field, $selectorValue, true, '', $fieldType);
209 }
210
211 return $renderResult;
212 }
213
220 protected static function extractValue(FieldType $fieldType, array $field, array $request)
221 {
222 $value = parent::extractValue($fieldType, $field, $request);
223 if (is_array($value) && isset($value['VALUE']))
224 $value = $value['VALUE'];
225
226 $userType = static::getUserType($fieldType);
227
228 if (array_key_exists('GetLength', $userType))
229 {
231 $userType['GetLength'],
232 array(
233 array('LINK_IBLOCK_ID' => $fieldType->getOptions()),
234 array('VALUE' => $value)
235 )
236 ) <= 0)
237 {
238 $value = null;
239 }
240 }
241
242 if ($value != null && array_key_exists('CheckFields', $userType))
243 {
244 $errors = call_user_func_array(
245 $userType['CheckFields'],
246 array(
247 array('LINK_IBLOCK_ID' => $fieldType->getOptions()),
248 array('VALUE' => $value)
249 )
250 );
251 if (sizeof($errors) > 0)
252 {
253 $value = null;
254 foreach ($errors as $e)
255 static::addError(array(
256 'code' => 'ErrorValue',
257 'message' => $e,
258 'parameter' => static::generateControlName($field),
259 ));
260 }
261 }
262 elseif ($value === '' && !array_key_exists('GetLength', $userType))
263 $value = null;
264
265 return $value;
266 }
267
268 protected static function getUserType(FieldType $fieldType)
269 {
270 return \CIBlockProperty::getUserType(mb_substr($fieldType->getType(), 2));
271 }
272
273 }
274}
extractValue(array $fieldProperties, $value)