Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
ecrm.php
1<?php
3
6
7if (Loader::requireModule('bizproc'))
8{
9 class ECrm extends UserTypeProperty
10 {
11 protected static $formatSeparator = ', ';
12
19 public static function formatValueMultiple(FieldType $fieldType, $value, $format = 'printable')
20 {
21 if (!is_array($value) || is_array($value) && \CBPHelper::isAssociativeArray($value))
22 $value = array($value);
23
24 self::$formatSeparator = static::getFormatSeparator($format);
25
26 return static::formatValuePrintable($fieldType, $value);
27 }
28
35 public static function formatValueSingle(FieldType $fieldType, $value, $format = 'printable')
36 {
37 return static::formatValueMultiple($fieldType, $value, $format);
38 }
39
40 protected static function formatValuePrintable(FieldType $fieldType, $value)
41 {
42 $property = static::getUserType($fieldType);
43 $property['IBLOCK_ID'] = self::getIblockId($fieldType);
44 if(empty($property['USER_TYPE_SETTINGS']))
45 $property['USER_TYPE_SETTINGS'] = $fieldType->getOptions();
46
47 if (array_key_exists('GetValuePrintable', $property))
48 {
49 return call_user_func_array($property['GetValuePrintable'], array($property, $value, self::$formatSeparator));
50 }
51 else
52 {
53 return '';
54 }
55 }
56
63 public static function renderControlOptions(FieldType $fieldType, $callbackFunctionName, $value)
64 {
65 $property = static::getUserType($fieldType);
66 if(empty($property['USER_TYPE_SETTINGS']))
67 $property['USER_TYPE_SETTINGS'] = $fieldType->getOptions();
68
69 if(array_key_exists('GetSettingsHTML', $property))
70 {
71 $fieldData = array();
72 return call_user_func_array($property['GetSettingsHTML'], array($property,
73 array('USE_BP' => true, 'CALLBACK_FUNCTION' => $callbackFunctionName, 'NAME' => 'ENTITY'), &$fieldData));
74 }
75 else
76 {
77 return '';
78 }
79 }
80
89 public static function renderControlSingle(FieldType $fieldType, array $field, $value, $allowSelection, $renderMode)
90 {
91 return static::renderControlMultiple($fieldType, $field, $value, $allowSelection, $renderMode);
92 }
93
102 public static function renderControlMultiple(FieldType $fieldType, array $field, $value, $allowSelection, $renderMode)
103 {
104 $selectorValue = null;
105 $typeValue = array();
106 if (!is_array($value) || is_array($value) && \CBPHelper::isAssociativeArray($value))
107 $value = array($value);
108
109 foreach ($value as $v)
110 {
111 if (\CBPActivity::isExpression($v))
113 else
114 $typeValue[] = $v;
115 }
116 // need to show at least one control
117 if (empty($typeValue))
118 $typeValue[] = null;
119
120 $property = static::getUserType($fieldType);
121
122 if(!empty($property['GetPublicEditHTMLMulty']))
123 {
124 $fieldName = static::generateControlName($field);
126 $property['GetPublicEditHTMLMulty'],
127 array(
128 array(
129 'IBLOCK_ID' => self::getIblockId($fieldType),
130 'USER_TYPE_SETTINGS' => $fieldType->getOptions(),
131 'MULTIPLE' => $fieldType->isMultiple() ? 'Y' : 'N',
132 'IS_REQUIRED' => $fieldType->isRequired() ? 'Y' : 'N',
133 'PROPERTY_USER_TYPE' => $property
134 ),
135 array('VALUE' => $typeValue),
136 array(
137 'FORM_NAME' => $field['Form'],
138 'VALUE' => $fieldName,
139 'DESCRIPTION' => '',
140 ),
141 true
142 )
143 );
144 }
145 else
146 {
147 $renderResult = static::renderControl($fieldType, $field, '', $allowSelection, $renderMode);
148 }
149
151 {
152 $renderResult .= static::renderControlSelector($field, $selectorValue, true, '', $fieldType);
153 }
154
155 return $renderResult;
156 }
157
158 public static function extractValueSingle(FieldType $fieldType, array $field, array $request)
159 {
160 return static::extractValueMultiple($fieldType, $field, $request);
161 }
162
163 private static function getIblockId(FieldType $fieldType)
164 {
165 $documentType = $fieldType->getDocumentType();
166 $type = explode('_', $documentType[2]);
167 return intval($type[1]);
168 }
169
170 public static function toSingleValue(FieldType $fieldType, $value)
171 {
172 if (is_array($value))
173 {
174 $values = array_values($value);
175 return isset($values[0]) ? $values[0] : null;
176 }
177 return parent::toSingleValue($fieldType, $value);
178 }
179
180 public static function externalizeValue(FieldType $fieldType, $context, $value)
181 {
182 return self::normalizeValue(
183 $fieldType, \CBPHelper::stringify(parent::externalizeValue($fieldType, $context, $value))
184 );
185 }
186
187 private static function isUsePrefix(FieldType $fieldType): ?bool
188 {
189 $options = $fieldType->getOptions();
190
191 if (is_array($options))
192 {
193 unset($options['VISIBLE']);
194
195 return count(array_filter($options, static fn($mark) => $mark === 'Y')) !== 1;
196 }
197
198 return null;
199 }
200
201 private static function normalizeValue(FieldType $fieldType, $value)
202 {
203 $hasPrefix = strpos($value,'_') !== false;
204 $isUsePrefix = self::isUsePrefix($fieldType);
205
206 if ($hasPrefix && $isUsePrefix === false)
207 {
208 return current(array_reverse(explode('_', $value)));
209 }
210
211 return $value;
212 }
213 }
214}