Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
usertypepropertyhtml.php
1<?php
2
4
10
11if (Loader::requireModule('bizproc'))
12{
13 class UserTypePropertyHtml extends UserTypeProperty
14 {
15
22 public static function convertTo(FieldType $fieldType, $value, $toTypeClass)
23 {
24 if (is_array($value) && isset($value['VALUE']))
25 $value = $value['VALUE'];
26 if (is_array($value) && isset($value['TEXT']))
27 $value = $value['TEXT'];
28
29 return parent::convertTo($fieldType, $value, $toTypeClass);
30 }
31
38 public static function convertFrom(FieldType $fieldType, $value, $fromTypeClass)
39 {
40 if ($value === null)
41 return null;
42
44 $type = $fromTypeClass::getType();
45 switch ($type)
46 {
47 case FieldType::BOOL:
48 case FieldType::DATE:
49 case FieldType::DATETIME:
50 case FieldType::DOUBLE:
51 case FieldType::INT:
52 case FieldType::INTERNALSELECT:
53 case FieldType::SELECT:
54 case FieldType::STRING:
55 case FieldType::TEXT:
56 case FieldType::USER:
57 $value = array('TYPE' => 'text', 'TEXT' => (string) $value);
58 break;
59 default:
60 $value = null;
61 }
62
63 return $value;
64 }
65
70 public static function getConversionMap()
71 {
72 $parentMap = parent::getConversionMap();
73 return array(
74 $parentMap[0],
75 array(
76 FieldType::BOOL,
77 FieldType::DATE,
78 FieldType::DATETIME,
79 FieldType::DOUBLE,
80 FieldType::INT,
81 FieldType::INTERNALSELECT,
82 FieldType::SELECT,
83 FieldType::STRING,
84 FieldType::TEXT,
85 FieldType::USER
86 )
87 );
88 }
89
95 protected static function formatValuePrintable(FieldType $fieldType, $value)
96 {
97 if (is_array($value) && isset($value['VALUE']))
98 $value = $value['VALUE'];
99 if (is_array($value) && isset($value['TEXT']))
100 $value = $value['TEXT'];
101
102 return HTMLToTxt(htmlspecialcharsback((string)$value));
103 }
104
114 protected static function renderControl(FieldType $fieldType, array $field, $value, $allowSelection, $renderMode)
115 {
116 $name = static::generateControlName($field);
117 $controlId = static::generateControlId($field);
118
119 if (is_array($value) && isset($value['VALUE']))
120 $value = $value['VALUE'];
121 if (is_array($value) && isset($value['TEXT']))
122 $value = $value['TEXT'];
123
124 return \CBPViewHelper::getHtmlEditor($controlId, $name, $value);
125 }
126
135 public static function renderControlSingle(FieldType $fieldType, array $field, $value, $allowSelection, $renderMode)
136 {
137 $selectorValue = null;
138 if (\CBPActivity::isExpression($value))
139 {
140 $selectorValue = $value;
141 $value = null;
142 }
143
144 $renderResult = static::renderControl($fieldType, $field, $value, $allowSelection, $renderMode);
145
146 if ($allowSelection)
147 {
148 $renderResult .= static::renderControlSelector($field, $selectorValue, true, '', $fieldType);
149 }
150
151 return $renderResult;
152 }
153
162 public static function renderControlMultiple(FieldType $fieldType, array $field, $value, $allowSelection, $renderMode)
163 {
164 $selectorValue = null;
165 $typeValue = array();
166 if (!is_array($value) || is_array($value) && \CBPHelper::isAssociativeArray($value))
167 $value = array($value);
168
169 foreach ($value as $v)
170 {
171 if (\CBPActivity::isExpression($v))
173 else
174 $typeValue[] = $v;
175 }
176 // need to show at least one control
177 if (empty($typeValue))
178 $typeValue[] = null;
179
180 $controls = array();
181
182 foreach ($typeValue as $k => $v)
183 {
184 $singleField = $field;
185 $singleField['Index'] = $k;
186 $controls[] = static::renderControl(
187 $fieldType,
189 $v,
192 );
193 }
194
195 $renderResult = static::wrapCloneableControls($controls, static::generateControlName($field));
196
197 if ($allowSelection)
198 {
199 $renderResult .= static::renderControlSelector($field, $selectorValue, true, '', $fieldType);
200 }
201
202 return $renderResult;
203 }
204
210 protected static function wrapCloneableControls(array $controls, $wrapperId)
211 {
212 $wrapperId = Main\Text\HtmlFilter::encode((string)$wrapperId);
213 $renderResult = '<table width="100%" border="0" cellpadding="2" cellspacing="2" id="BizprocCloneable_'
214 .$wrapperId.'">';
215
216 foreach ($controls as $control)
217 {
218 $renderResult .= '<tr><td>'.$control.'</td></tr>';
219 }
220 $renderResult .= '</table>';
221 $renderResult .= '<input type="button" value="'.Loc::getMessage('BPDT_BASE_ADD')
222 .'" onclick="BX.Bizproc.cloneTypeControlHtml(\'BizprocCloneable_'
223 .$wrapperId.'\', \''.$wrapperId.'\')"/><br />';
224
225 return $renderResult;
226 }
227
228 public static function externalizeValue(FieldType $fieldType, $context, $value)
229 {
230 if (is_array($value) && isset($value['TEXT']) && !is_scalar($value['TEXT']))
231 {
232 return is_object($value['TEXT']) && method_exists($value['TEXT'], '__toString')
233 ? (string)$value['TEXT']
234 : ''
235 ;
236 }
237
238 return parent::externalizeValue($fieldType, $context, $value);
239 }
240
241 protected static function generateControlName(array $field)
242 {
243 $name = $field['Field'];
244 $index = isset($field['Index']) ? (int)$field['Index'] : null;
245 if ($index !== null)
246 {
247 $name .= "[n{$field['Index']}]";
248 }
249
250 return $name;
251 }
252 }
253}