Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
sequence.php
1<?
3
6
7if (Loader::requireModule("bizproc"))
8{
9 class Sequence extends UserTypeProperty
10 {
11 public static function getType()
12 {
13 return FieldType::INT;
14 }
15
24 public static function renderControlSingle(FieldType $fieldType, array $field, $value, $allowSelection, $renderMode)
25 {
26 return self::renderControl($fieldType, $field, $value, $allowSelection, $renderMode);
27 }
28
37 public static function renderControlMultiple(FieldType $fieldType, array $field, $value, $allowSelection, $renderMode)
38 {
39 $typeValue = [];
40 if (!is_array($value) || is_array($value) && \CBPHelper::isAssociativeArray($value))
41 {
42 $value = [$value];
43 }
44
45 foreach ($value as $v)
46 {
47 if (!\CBPActivity::isExpression($v))
48 {
49 $typeValue[] = $v;
50 }
51 }
52
53 $controls = [];
54 foreach ($typeValue as $k => $v)
55 {
56 $singleField = $field;
57 $singleField["Index"] = $k;
58 $controls[] = self::renderControlSingle($fieldType, $singleField, $v, $allowSelection, $renderMode);
59 }
60
61 return static::wrapCloneableControls($controls, static::generateControlName($field));
62 }
63
73 protected static function renderControl(FieldType $fieldType, array $field, $value, $allowSelection, $renderMode)
74 {
75 $name = static::generateControlName($field);
76 $controlId = static::generateControlId($field);
77 $className = static::generateControlClassName($fieldType, $field);
78
79 $options = $fieldType->getOptions();
80
81 $iblockId = self::getIblockId($fieldType);
82 $propertyId = 0;
83 $queryObject = \CIBlockProperty::getByID(mb_substr($field["Field"], mb_strlen("PROPERTY_")), $iblockId);
84 if ($property = $queryObject->fetch())
85 {
86 $propertyId = $property["ID"];
87 }
88
89 if ($value)
90 {
91 $value = (int) $value;
92 }
93 else
94 {
95 $sequence = new \CIBlockSequence($iblockId, $propertyId);
96 $value = $sequence->getCurrent();
97 }
98
99 $readonly = ((isset($options["write"]) && $options["write"] == "Y") ? "" : "readonly");
100
101 return '<input '.htmlspecialcharsbx($readonly).' type="text" class="'.
102 htmlspecialcharsbx($className).'" size="40" id="'.htmlspecialcharsbx($controlId).'" name="'
103 .htmlspecialcharsbx($name).'" value="'.htmlspecialcharsbx((string) $value).'"/>';
104 }
105
106 private static function getIblockId(FieldType $fieldType)
107 {
108 $documentType = $fieldType->getDocumentType();
109 $type = explode('_', $documentType[2]);
110 return intval($type[1]);
111 }
112 }
113}