1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
double.php
См. документацию.
1<?php
2namespace Bitrix\Bizproc\BaseType;
3
4use Bitrix\Main;
5use Bitrix\Main\Localization\Loc;
6use Bitrix\Bizproc\FieldType;
7
8Loc::loadMessages(__FILE__);
9
14class Double extends Base
15{
16
20 public static function getType()
21 {
22 return FieldType::DOUBLE;
23 }
24
32 public static function toSingleValue(FieldType $fieldType, $value)
33 {
34 if (is_array($value))
35 {
36 reset($value);
37 $value = current($value);
38 }
39 return $value;
40 }
41
48 public static function convertTo(FieldType $fieldType, $value, $toTypeClass)
49 {
51 $type = $toTypeClass::getType();
52 switch ($type)
53 {
54 case FieldType::BOOL:
55 $value = (bool)$value ? 'Y' : 'N';
56 break;
57 case FieldType::DATE:
58 $value = date(Main\Type\Date::convertFormatToPhp(\FORMAT_DATE), (int)$value);
59 break;
61 $value = date(Main\Type\DateTime::convertFormatToPhp(\FORMAT_DATETIME), (int)$value);
62 break;
64 $value = (float)$value;
65 break;
66 case FieldType::INT:
67 $value = (int)$value;
68 break;
70 case FieldType::TEXT:
71 $value = (string) $value;
72 break;
73 case FieldType::USER:
74 $value = 'user_'.(int)$value;
75 break;
76 default:
77 $value = null;
78 }
79
80 return $value;
81 }
82
87 public static function getConversionMap()
88 {
89 return array(
90 array(
99 )
100 );
101 }
102
111 protected static function renderControl(FieldType $fieldType, array $field, $value, $allowSelection, $renderMode)
112 {
113 if ($allowSelection && !($renderMode & FieldType::RENDER_MODE_PUBLIC))
114 {
115 return static::renderControlSelector($field, $value, 'combine', '', $fieldType);
116 }
117
118 $name = static::generateControlName($field);
119 $controlId = static::generateControlId($field);
120 $className = static::generateControlClassName($fieldType, $field);
121
122 if ($renderMode & FieldType::RENDER_MODE_PUBLIC)
123 {
124 $selectorAttributes = '';
125 if ($allowSelection)
126 {
127 $selectorAttributes = sprintf(
128 'data-role="inline-selector-target" data-property="%s" ',
129 htmlspecialcharsbx(Main\Web\Json::encode($fieldType->getProperty()))
130 );
131 }
132
133 $renderResult = sprintf(
134 '<input type="text" class="%s" name="%s" value="%s" placeholder="%s" %s/>',
135 htmlspecialcharsbx($className),
137 htmlspecialcharsbx((string)$value),
138 htmlspecialcharsbx($fieldType->getDescription()),
139 $selectorAttributes
140 );
141 }
142 else
143 {
144 $renderResult = '<input type="text" class="'.htmlspecialcharsbx($className)
145 .'" size="10" id="'.htmlspecialcharsbx($controlId).'" name="'
146 .htmlspecialcharsbx($name).'" value="'.htmlspecialcharsbx((string) $value).'"/>';
147 }
148
149 return $renderResult;
150 }
151
156 public static function canRenderControl($renderMode)
157 {
158 return true;
159 }
160
169 public static function renderControlSingle(FieldType $fieldType, array $field, $value, $allowSelection, $renderMode)
170 {
171 $value = static::toSingleValue($fieldType, $value);
172 return static::renderControl($fieldType, $field, $value, $allowSelection, $renderMode);
173 }
174
183 public static function renderControlMultiple(FieldType $fieldType, array $field, $value, $allowSelection, $renderMode)
184 {
185 if (!is_array($value) || is_array($value) && \CBPHelper::isAssociativeArray($value))
186 $value = array($value);
187
188 if (empty($value))
189 $value[] = null;
190
191 $controls = array();
192
193 foreach ($value as $k => $v)
194 {
195 $singleField = $field;
196 $singleField['Index'] = $k;
197 $controls[] = static::renderControl(
198 $fieldType,
199 $singleField,
200 $v,
201 $allowSelection,
202 $renderMode
203 );
204 }
205
206 if ($renderMode & FieldType::RENDER_MODE_PUBLIC)
207 {
208 $renderResult = static::renderPublicMultipleWrapper($fieldType, $field, $controls);
209 }
210 else
211 {
212 $renderResult = static::wrapCloneableControls($controls, static::generateControlName($field));
213 }
214
215 return $renderResult;
216 }
217
224 protected static function extractValue(FieldType $fieldType, array $field, array $request)
225 {
226 $value = parent::extractValue($fieldType, $field, $request);
227
228 if ($value !== null && is_string($value) && $value <> '')
229 {
230 if (\CBPActivity::isExpression($value))
231 return $value;
232
233 $value = str_replace(' ', '', str_replace(',', '.', $value));
234 if (is_numeric($value))
235 {
236 $value = (float) $value;
237 }
238 else
239 {
240 $value = null;
241 static::addError(array(
242 'code' => 'ErrorValue',
243 'message' => Loc::getMessage('BPDT_DOUBLE_INVALID'),
244 'parameter' => static::generateControlName($field),
245 ));
246 }
247 }
248 else
249 {
250 $value = null;
251 }
252
253 return $value;
254 }
255}
$type
Определения options.php:106
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
static convertTo(FieldType $fieldType, $value, $toTypeClass)
Определения base.php:209
static renderControl(FieldType $fieldType, array $field, $value, $allowSelection, $renderMode)
Определения double.php:111
static getType()
Определения double.php:20
static extractValue(FieldType $fieldType, array $field, array $request)
Определения double.php:224
static renderControlSingle(FieldType $fieldType, array $field, $value, $allowSelection, $renderMode)
Определения double.php:169
static toSingleValue(FieldType $fieldType, $value)
Определения double.php:32
static renderControlMultiple(FieldType $fieldType, array $field, $value, $allowSelection, $renderMode)
Определения double.php:183
static getConversionMap()
Определения double.php:87
static canRenderControl($renderMode)
Определения double.php:156
const USER
Определения fieldtype.php:67
const BOOL
Определения fieldtype.php:17
const DATE
Определения fieldtype.php:22
getDescription()
Определения fieldtype.php:295
const STRING
Определения fieldtype.php:57
const TEXT
Определения fieldtype.php:62
const RENDER_MODE_PUBLIC
Определения fieldtype.php:92
const DATETIME
Определения fieldtype.php:27
getProperty()
Определения fieldtype.php:133
const INT
Определения fieldtype.php:42
const DOUBLE
Определения fieldtype.php:32
static isExpression($text)
Определения activity.php:1718
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
const FORMAT_DATETIME
Определения include.php:64
const FORMAT_DATE
Определения include.php:63
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
Определения tools.php:2701
$name
Определения menu_edit.php:35
Определения collection.php:2
Определения cookie.php:3
$k
Определения template_pdf.php:567