21 return static::getType();
35 'callable' =>
'formatValuePrintable',
46 $format = mb_strtolower($format);
48 if (isset(
$formats[$format][
'callable']))
50 $callable =
$formats[$format][
'callable'];
51 if (is_string($callable))
53 $callable = [get_called_class(), $callable];
68 $format = mb_strtolower($format);
71 if (isset(
$formats[$format][
'separator']))
73 $separator =
$formats[$format][
'separator'];
85 public static function addFormat($name, array $options)
87 $name = mb_strtolower($name);
88 if (empty($options[
'callable']))
93 static::$formats[$name] = $options;
102 return static::$formats;
125 $value = (array)$value;
127 foreach ($value as $k => $v)
129 $value[$k] = static::formatValueSingle($fieldType, $v, $format);
132 return implode(static::getFormatSeparator($format), $value);
143 $callable = static::getFormatCallable($format);
144 $value = static::toSingleValue($fieldType, $value);
146 if (is_callable($callable))
148 return call_user_func($callable, $fieldType, $value);
162 return static::convertValueSingle(clone $fieldType, $value, StringType::class);
173 $value = (array)$value;
174 foreach ($value as $k => $v)
176 $value[$k] = static::convertValueSingle($fieldType, $v, $toTypeClass);
189 public static function convertValueSingle(
FieldType $fieldType, $value, $toTypeClass)
191 $value = static::toSingleValue($fieldType, $value);
193 $result = static::convertTo($fieldType, $value, $toTypeClass);
194 if ($result ===
null)
195 $result = $toTypeClass::convertFrom($fieldType, $value, get_called_class());
197 if ($result !==
null)
200 return $result !==
null ? $result : $value;
247 if (\CBPHelper::isEmptyValue($baseValue))
249 return (array)$appendValue;
252 if (!is_array($appendValue))
254 $baseValue[] = $appendValue;
259 $isSimple = !\CBPHelper::isAssociativeArray($baseValue) && !\CBPHelper::isAssociativeArray($appendValue);
260 $result = $isSimple ? array_merge($baseValue, $appendValue) : $baseValue + $appendValue;
264 $result = array_values(array_unique($result));
280 static::$errors[] = $error;
289 static::$errors = array_merge(static::$errors,
$errors);
297 return static::$errors;
305 static::$errors = [];
314 $id =
'id_' . $field[
'Field'];
315 $index = isset($field[
'Index']) ? $field[
'Index'] :
null;
318 $id .=
'__n' . $index .
'_';
330 $name = $field[
'Field'];
331 $index = isset($field[
'Index']) ? $field[
'Index'] :
null;
343 $prefix =
'bizproc-type-control';
344 $classes = [$prefix];
345 $classes[] = $prefix .
'-' . static::getType();
349 $classes[] = $prefix .
'-multiple';
353 $classes[] = $prefix .
'-required';
356 return implode(
' ', $classes);
366 $wrapperId = (string)$wrapperId;
367 $renderResult =
'<table width="100%" border="0" cellpadding="2" cellspacing="2" id="BizprocCloneable_'
368 . htmlspecialcharsbx($wrapperId) .
'">';
370 foreach ($controls as $control)
372 $renderResult .=
'<tr><td>' . $control .
'</td></tr>';
374 $renderResult .=
'</table>';
375 $renderResult .= sprintf(
376 '<input type="button" value="%s" onclick="BX.Bizproc.cloneTypeControl(\'BizprocCloneable_%s\')"/><br />',
378 htmlspecialcharsbx($wrapperId)
381 return $renderResult;
394 $name = Main\Text\HtmlFilter::encode(\CUtil::jsEscape(static::generateControlName($field)));
395 $property = Main\Text\HtmlFilter::encode(Main\Web\Json::encode($fieldType->
getProperty()));
397 $renderResult = implode(
'', $controls) . <<<HTML
399 <a onclick=
"BX.Bizproc.FieldType.cloneControl({$property}, '{$name}', this.parentNode); return false;"
400 class=
"bizproc-type-control-clone-btn">
406 return $renderResult;
420 $name = static::generateControlName($field);
421 $controlId = static::generateControlId($field);
422 $className = static::generateControlClassName($fieldType, $field);
426 $selectorAttributes =
'';
429 $selectorAttributes = sprintf(
430 'data-role="inline-selector-target" data-property="%s" ',
431 htmlspecialcharsbx(Main\Web\Json::encode($fieldType->
getProperty()))
436 '<input type="text" class="%s" name="%s" value="%s" placeholder="%s" %s/>',
437 htmlspecialcharsbx($className),
438 htmlspecialcharsbx($name),
439 htmlspecialcharsbx((
string)$value),
447 '<input type="text" class="%s" size="40" id="%s" name="%s" value="%s"/>',
448 htmlspecialcharsbx($className),
449 htmlspecialcharsbx($controlId),
450 htmlspecialcharsbx($name),
451 htmlspecialcharsbx((
string)$value)
479 $value = static::toSingleValue($fieldType, $value);
480 $selectorValue =
null;
481 if ($allowSelection && \CBPActivity::isExpression($value))
483 $selectorValue = $value;
487 $renderResult = static::renderControl($fieldType, $field, $value, $allowSelection, $renderMode);
491 $renderResult .= static::renderControlSelector($field, $selectorValue,
true,
'', $fieldType);
494 return $renderResult;
507 $selectorValue =
null;
509 if (!is_array($value) || is_array($value) && \CBPHelper::isAssociativeArray($value))
514 foreach ($value as $v)
516 if (\CBPActivity::isExpression($v))
526 if (empty($typeValue))
533 foreach ($typeValue as $k => $v)
535 $singleField = $field;
536 $singleField[
'Index'] = $k;
537 $controls[] = static::renderControl(
548 $renderResult = static::renderPublicMultipleWrapper($fieldType, $field, $controls);
552 $renderResult = static::wrapCloneableControls($controls, static::generateControlName($field));
557 $renderResult .= static::renderControlSelector($field, $selectorValue,
true,
'', $fieldType);
560 return $renderResult;
574 $controlId = static::generateControlId($field);
575 $name = static::generateControlName($field);
579 if ($showInput !==
'combine')
581 $controlId = $controlId .
'_text';
582 $name = static::generateControlName($field) .
'_text';
586 $rows = max((static::getType() ===
FieldType::TEXT ? 5 : 1), min(5, ceil(mb_strlen((
string)$value)) / $cols));
587 $html =
'<table cellpadding="0" cellspacing="0" border="0" width="100%" style="margin: 2px 0"><tr><td valign="top"><textarea ';
588 $html .=
'rows="' . $rows .
'" ';
589 $html .=
'cols="' . $cols .
'" ';
590 $html .=
'name="' . htmlspecialcharsbx($name) .
'" ';
591 $html .=
'id="' . htmlspecialcharsbx($controlId) .
'" ';
592 $html .=
'style="width: 100%"';
593 $html .=
'>' . htmlspecialcharsbx((
string)$value);
594 $html .=
'</textarea></td>';
595 $html .=
'<td valign="top" style="padding-left:4px" width="30">';
597 $html .= static::renderControlSelectorButton($controlId, $fieldType, $selectorMode);
601 $html .=
'</td></tr></table>';
609 $baseType = $fieldType ? $fieldType->
getBaseType() :
null;
610 $selectorProps = Main\Web\Json::encode([
611 'controlId' => $controlId,
612 'baseType' => $baseType,
613 'type' => $fieldType ? $fieldType->
getType() :
null,
615 'documentId' => $fieldType ? $fieldType->
getDocumentId() :
null,
619 '<input type="button" value="..." onclick="BPAShowSelector(\'%s\', \'%s\', %s, null, %s);" data-role="bp-selector-button" data-bp-selector-props="%s">',
620 \CUtil::jsEscape(htmlspecialcharsbx($controlId)),
621 \CUtil::jsEscape(htmlspecialcharsbx($baseType)),
622 $selectorMode ?
'\'' . \CUtil::jsEscape(htmlspecialcharsbx($selectorMode)) .
'\'' :
'null',
623 htmlspecialcharsbx(Main\Web\Json::encode($fieldType ? $fieldType->
getDocumentType() :
null)),
624 htmlspecialcharsbx($selectorProps)
647 $name = $field[
'Field'];
648 $value = isset($request[$name]) ? $request[$name] :
null;
649 $fieldIndex = isset($field[
'Index']) ? $field[
'Index'] :
null;
650 if (is_array($value) && !\CBPHelper::isAssociativeArray($value))
652 if ($fieldIndex !==
null)
654 $value = isset($value[$fieldIndex]) ? $value[$fieldIndex] :
null;
659 $value = current($value);
674 static::cleanErrors();
675 $result = static::extractValue($fieldType, $field, $request);
676 if ($result ===
null || $result ===
'')
678 $nameText = $field[
'Field'] .
'_text';
679 $text = isset($request[$nameText]) ? $request[$nameText] :
null;
680 if (\CBPActivity::isExpression($text))
695 static::cleanErrors();
697 $name = $field[
'Field'];
698 $value = isset($request[$name]) ? $request[$name] : [];
700 if (!is_array($value) || is_array($value) && \CBPHelper::isAssociativeArray($value))
705 foreach ($value as $k => $v)
707 $field[
'Index'] = $k;
708 $result = static::extractValue($fieldType, $field, $request);
709 if ($result ===
null || $result ===
'')
715 $value[$k] = $result;
720 $nameText = $field[
'Field'] .
'_text';
721 $text = isset($request[$nameText]) ? $request[$nameText] :
null;
722 if (\CBPActivity::isExpression($text))
727 return array_values($value);
747 if (!is_array($value) || is_array($value) && \CBPHelper::isAssociativeArray($value))
752 foreach ($value as $v)
754 static::clearValueSingle($fieldType, $v);
777 return static::internalizeValue($fieldType, $context, $value);
788 if (is_array($value))
790 foreach ($value as $k => $v)
792 $value[$k] = static::internalizeValue($fieldType, $context, $v);
807 if (is_object($value) && method_exists($value,
'__toString'))
809 return (
string)$value;
823 return static::externalizeValue($fieldType, $context, $value);
834 if (!is_array($value) || \CBPHelper::isAssociativeArray($value))
839 foreach ($value as $k => $v)
841 $value[$k] = static::externalizeValue($fieldType, $context, $v);
854 if ($valueA > $valueB)
859 if ($valueA < $valueB)
869 return static::toSingleValue($fieldType, $value);
874 if (!is_array($value))
879 foreach ($value as $k => $v)
881 $value[$k] = static::validateValueSingle($v, $fieldType);
static formatValueMultiple(FieldType $fieldType, $value, $format='printable')
static generateControlClassName(FieldType $fieldType, array $field)
static externalizeValueSingle(FieldType $fieldType, $context, $value)
static renderControlOptions(FieldType $fieldType, $callbackFunctionName, $value)
static renderControl(FieldType $fieldType, array $field, $value, $allowSelection, $renderMode)
static extractValueSingle(FieldType $fieldType, array $field, array $request)
static extractValueMultiple(FieldType $fieldType, array $field, array $request)
static renderControlSelector(array $field, $value=null, $showInput=false, $selectorMode='', FieldType $fieldType=null)
static internalizeValueSingle(FieldType $fieldType, $context, $value)
static generateControlName(array $field)
static extractValue(FieldType $fieldType, array $field, array $request)
static externalizeValue(FieldType $fieldType, $context, $value)
static clearValueSingle(FieldType $fieldType, $value)
static renderControlSingle(FieldType $fieldType, array $field, $value, $allowSelection, $renderMode)
static formatValuePrintable(FieldType $fieldType, $value)
static clearValueMultiple(FieldType $fieldType, $value)
static getFormatSeparator($format)
static internalizeValueMultiple(FieldType $fieldType, $context, $value)
static internalizeValue(FieldType $fieldType, $context, $value)
static validateValueSingle($value, FieldType $fieldType)
static toSingleValue(FieldType $fieldType, $value)
static convertTo(FieldType $fieldType, $value, $toTypeClass)
static convertValueMultiple(FieldType $fieldType, $value, $toTypeClass)
static addErrors(array $errors)
static wrapCloneableControls(array $controls, $wrapperId)
static getFormatCallable($format)
static convertPropertyToView(FieldType $fieldType, int $viewMode, array $property)
static renderControlMultiple(FieldType $fieldType, array $field, $value, $allowSelection, $renderMode)
static getConversionMap()
static mergeValue(FieldType $fieldType, array $baseValue, $appendValue)
static generateControlId(array $field)
static convertFrom(FieldType $fieldType, $value, $fromTypeClass)
static formatValueSingle(FieldType $fieldType, $value, $format='printable')
static compareValues($valueA, $valueB)
static externalizeValueMultiple(FieldType $fieldType, $context, $value)
static canRenderControl($renderMode)
static renderControlSelectorButton($controlId, FieldType $fieldType, $selectorMode='')
static renderPublicMultipleWrapper(FieldType $fieldType, array $field, array $controls)
static addFormat($name, array $options)
static validateValueMultiple($value, FieldType $fieldType)
static getMessage($code, $replace=null, $language=null)