Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
usertypepropertyemployee.php
1<?php
2
4
9
10if (Loader::requireModule('bizproc'))
11{
12 class UserTypePropertyEmployee extends UserTypeProperty
13 {
14 private static $isCompatible;
15
19 public static function getType()
20 {
21 if (!static::isCompatibleMode())
22 return FieldType::USER;
23 return FieldType::STRING;
24 }
25
26 public static function convertTo(FieldType $fieldType, $value, $toTypeClass)
27 {
28 if (is_array($value) && isset($value['VALUE']))
29 $value = $value['VALUE'];
30
31 $value = (string) $value;
32 return BaseType\User::convertTo($fieldType, $value, $toTypeClass);
33 }
34
41 public static function convertFrom(FieldType $fieldType, $value, $fromTypeClass)
42 {
43 if ($value === null)
44 return null;
45
47 $type = $fromTypeClass::getType();
48 switch ($type)
49 {
50 case FieldType::DOUBLE:
51 case FieldType::INT:
52 $value = 'user_'.(int)$value;
53 break;
54 case FieldType::INTERNALSELECT:
55 case FieldType::SELECT:
56 case FieldType::STRING:
57 case FieldType::TEXT:
58 case FieldType::USER:
59 if (mb_strpos($value, 'user_') === false)
60 {
61 $value = null;
62 }
63 elseif (static::isCompatibleMode())
64 {
65 $value = \CBPHelper::stripUserPrefix($value);
66 }
67 break;
68 default:
69 $value = null;
70 }
71
72 return $value;
73 }
74
79 public static function getConversionMap()
80 {
81 $userMap = BaseType\User::getConversionMap();
82 return array(
83 $userMap[0],
84 array(
85 FieldType::DOUBLE,
86 FieldType::INT,
87 FieldType::INTERNALSELECT,
88 FieldType::SELECT,
89 FieldType::STRING,
90 FieldType::TEXT,
91 FieldType::USER
92 )
93 );
94 }
95
104 public static function renderControlSingle(FieldType $fieldType, array $field, $value, $allowSelection, $renderMode)
105 {
106 $value = static::fixUserPrefix($value);
107 $renderResult = parent::renderControlSingle($fieldType, $field, $value, false, $renderMode);
108
109 if ($allowSelection)
110 {
111 $selectorValue = \CBPActivity::isExpression($value) ? $value : null;
112 $renderResult .= static::renderControlSelector($field, $selectorValue, true, 'employee', $fieldType);
113 }
114
115 return $renderResult;
116 }
117
126 public static function renderControlMultiple(FieldType $fieldType, array $field, $value, $allowSelection, $renderMode)
127 {
128 $value = static::fixUserPrefix($value);
129 $renderResult = parent::renderControlMultiple($fieldType, $field, $value, false, $renderMode);
130
131 if ($allowSelection)
132 {
133 $selectorValue = null;
134 if (!is_array($value) || is_array($value) && \CBPHelper::isAssociativeArray($value))
135 $value = array($value);
136
137 foreach ($value as $v)
138 {
139 if (\CBPActivity::isExpression($v))
141 }
142 $renderResult .= static::renderControlSelector($field, $selectorValue, true, 'employee', $fieldType);
143 }
144
145 return $renderResult;
146 }
147
154 protected static function extractValue(FieldType $fieldType, array $field, array $request)
155 {
156 $value = (int) parent::extractValue($fieldType, $field, $request);
157 if (empty($value))
158 $value = null;
159
160 if ($value !== null && !static::isCompatibleMode())
161 {
162 $value = "user_".$value;
163 }
164
165 return $value;
166 }
167
168 public static function extractValueMultiple(FieldType $fieldType, array $field, array $request)
169 {
170 $values = parent::extractValueMultiple($fieldType, $field, $request);
171 return array_unique($values);
172 }
173
179 protected static function formatValuePrintable(FieldType $fieldType, $value)
180 {
181 $value = static::fixUserPrefix($value);
182 $userType = static::getUserType($fieldType);
183 if (is_array($value) && isset($value['VALUE']))
184 $value = $value['VALUE'];
185
186 if (!empty($userType['GetPublicViewHTML']))
187 {
188 $result = call_user_func_array(
189 $userType['GetPublicViewHTML'],
190 [
191 [
192 'LINK_IBLOCK_ID' => $fieldType->getOptions(),
193 ],
194 [
195 'VALUE' => $value,
196 ],
197 [
198 'MODE' => 'SIMPLE_TEXT',
199 ]
200 ]
201 );
202 return htmlspecialcharsback($result);
203 }
204 return parent::formatValuePrintable($fieldType, $value);
205 }
206
207 public static function toSingleValue(FieldType $fieldType, $value)
208 {
209 if (is_array($value) && !isset($value['VALUE']))
210 {
211 $value = \CBPHelper::MakeArrayFlat($value);
212 $value = current($value);
213 return $value;
214 }
215
216 return parent::toSingleValue($fieldType, $value);
217 }
218
219 private static function fixUserPrefix($value)
220 {
221 if (!static::isCompatibleMode())
222 {
223 if (is_array($value) && isset($value['VALUE']))
224 $value['VALUE'] = \CBPHelper::stripUserPrefix($value['VALUE']);
225 else
226 $value = \CBPHelper::stripUserPrefix($value);
227 }
228
229 return $value;
230 }
231
232 private static function isCompatibleMode()
233 {
234 if (static::$isCompatible === null)
235 {
236 static::$isCompatible = Config\Option::get('bizproc', 'employee_compatible_mode', 'N') == 'Y';
237 }
238 return static::$isCompatible;
239 }
240 }
241}
extractValue(array $fieldProperties, $value)