10use Bitrix\Main\Entity\DataManager,
11 Bitrix\Main\Entity\Validator,
15use \Bitrix\Main\ORM\EventResult;
45 return 'b_sale_order_props';
53 'autocomplete' =>
true,
54 'data_type' =>
'integer',
55 'format' =>
'/^[0-9]{1,11}$/',
57 'PERSON_TYPE_ID' => array(
59 'data_type' =>
'integer',
60 'format' =>
'/^[0-9]{1,11}$/',
64 'data_type' =>
'string',
65 'validation' => array(__CLASS__,
'getNameValidators'),
70 'data_type' =>
'string',
71 'validation' => array(__CLASS__,
'getTypeValidators'),
74 'data_type' =>
'boolean',
75 'values' => array(
'N',
'Y'),
76 'save_data_modification' => array(__CLASS__,
'getRequiredSaveModifiers'),
78 'DEFAULT_VALUE' => array(
79 'data_type' =>
'string',
80 'validation' => array(__CLASS__,
'getValueValidators'),
81 'save_data_modification' => array(__CLASS__,
'getValueSaveModifiers'),
82 'fetch_data_modification' => array(__CLASS__,
'getValueFetchModifiers'),
86 'data_type' =>
'integer',
87 'format' =>
'/^[0-9]{1,11}$/',
90 'USER_PROPS' => array(
91 'data_type' =>
'boolean',
92 'values' => array(
'N',
'Y'),
94 'IS_LOCATION' => array(
95 'data_type' =>
'boolean',
96 'values' => array(
'N',
'Y'),
98 'PROPS_GROUP_ID' => array(
100 'data_type' =>
'integer',
101 'format' =>
'/^[0-9]{1,11}$/',
103 'DESCRIPTION' => array(
104 'data_type' =>
'string',
105 'validation' => array(__CLASS__,
'getDescriptionValidators'),
109 'data_type' =>
'boolean',
110 'values' => array(
'N',
'Y'),
112 'IS_PROFILE_NAME' => array(
113 'data_type' =>
'boolean',
114 'values' => array(
'N',
'Y'),
117 'data_type' =>
'boolean',
118 'values' => array(
'N',
'Y'),
120 'IS_LOCATION4TAX' => array(
121 'data_type' =>
'boolean',
122 'values' => array(
'N',
'Y'),
124 'IS_FILTERED' => array(
125 'data_type' =>
'boolean',
126 'values' => array(
'N',
'Y'),
129 'data_type' =>
'string',
130 'validation' => array(__CLASS__,
'getCodeValidators'),
134 'data_type' =>
'boolean',
135 'values' => array(
'N',
'Y'),
138 'data_type' =>
'boolean',
139 'values' => array(
'N',
'Y'),
141 'IS_ADDRESS' => array(
142 'data_type' =>
'boolean',
143 'values' => array(
'N',
'Y'),
145 'IS_ADDRESS_FROM' => array(
146 'data_type' =>
'boolean',
147 'values' => array(
'N',
'Y'),
149 'IS_ADDRESS_TO' => array(
150 'data_type' =>
'boolean',
151 'values' => array(
'N',
'Y'),
154 'data_type' =>
'boolean',
155 'values' => array(
'N',
'Y'),
158 'data_type' =>
'boolean',
159 'values' => array(
'N',
'Y'),
161 'INPUT_FIELD_LOCATION' => array(
162 'data_type' =>
'integer',
163 'format' =>
'/^[0-9]{1,11}$/',
166 'data_type' =>
'boolean',
167 'values' => array(
'N',
'Y'),
170 'data_type' =>
'string',
171 'validation' => array(__CLASS__,
'getSettingsValidators'),
172 'save_data_modification' => array(__CLASS__,
'getSettingsSaveModifiers'),
173 'fetch_data_modification' => array(__CLASS__,
'getSettingsFetchModifiers'),
177 'data_type' =>
'Bitrix\Sale\Internals\OrderPropsGroupTable',
178 'reference' => array(
'=this.PROPS_GROUP_ID' =>
'ref.ID'),
179 'join_type' =>
'LEFT',
181 'PERSON_TYPE' => array(
182 'data_type' =>
'Bitrix\Sale\Internals\PersonTypeTable',
183 'reference' => array(
'=this.PERSON_TYPE_ID' =>
'ref.ID'),
184 'join_type' =>
'LEFT',
186 'ENTITY_REGISTRY_TYPE' => array(
187 'data_type' =>
'string',
190 'data_type' =>
'string',
192 'ENTITY_TYPE' => array(
193 'data_type' =>
'enum',
196 'validation' => array(__CLASS__,
'validateEntityType'),
197 'values' => static::getEntityTypes()
207 $modifyFieldList = [];
208 if (isset($fields[
'IS_FILTERED']))
210 $multiple = $fields[
'MULTIPLE'] ??
'N';
213 && $fields[
'IS_FILTERED'] !==
'N'
216 $modifyFieldList[
'IS_FILTERED'] =
'N';
220 if (!empty($modifyFieldList))
222 $result->modifyFields($modifyFieldList);
233 $modifyFieldList = [];
234 if (isset($fields[
'IS_FILTERED']) || isset($fields[
'MULTIPLE']))
238 if (isset($fields[
'MULTIPLE']))
240 $multiple = $fields[
'MULTIPLE'];
242 if (isset($fields[
'IS_FILTERED']))
244 $filtered = $fields[
'IS_FILTERED'];
247 if ($multiple ===
null || $filtered ===
null)
250 $row = static::getRow([
256 'filter' => $primary,
260 $multiple ??= $row[
'MULTIPLE'];
261 $filtered ??= $row[
'IS_FILTERED'];
269 $modifyFieldList[
'IS_FILTERED'] =
'N';
273 if (!empty($modifyFieldList))
275 $result->modifyFields($modifyFieldList);
300 return array(array(__CLASS__,
'validateValue'));
307 $length = isset($valueForSave) ? mb_strlen($valueForSave) : 0;
309 return $length > $maxlength
310 ?
Loc::getMessage(
'SALE_ORDER_PROPS_DEFAULT_ERROR', array(
'#PROPERTY_NAME#'=> $row[
'NAME'],
'#FIELD_LENGTH#' => $length,
'#MAX_LENGTH#' => $maxlength))
316 return array(array(__CLASS__,
'modifyValueForSave'));
320 return is_array($value) ? serialize($value) : $value;
325 return array(array(__CLASS__,
'modifyValueForFetch'));
329 if (!is_string($value) || $value ===
'')
334 if (self::isSerialized($value))
337 CheckSerializedData($value)
340 $value = unserialize($value, [
'allowed_classes' =>
false]);
343 elseif (isset($property[
'MULTIPLE']) && $property[
'MULTIPLE'] ==
'Y')
345 switch($property[
'TYPE'])
348 $value = explode(
',', $value);
351 $value = explode(
', ', $value);
368 return array(array(__CLASS__,
'modifyFilteredForSave'));
380 return $data[
'MULTIPLE'] ==
'Y' ?
'N' : $value;
387 return array(array(__CLASS__,
'validateSettings'));
392 $length = mb_strlen(self::modifySettingsForSave($value));
393 return $length > $maxlength
394 ?
Loc::getMessage(
'SALE_ORDER_PROPS_SETTINGS_ERROR', array(
'#LENGTH#' => $length,
'#MAXLENGTH#' => $maxlength))
400 return array(array(__CLASS__,
'modifySettingsForSave'));
404 return serialize($value);
409 return array(array(__CLASS__,
'modifySettingsForFetch'));
418 $v = @unserialize($value, [
'allowed_classes' =>
false]);
419 return is_array($v) ? $v : array();
426 return array(array(__CLASS__,
'modifyRequiredForSave'));
430 $isProfileName = isset($property[
'IS_PROFILE_NAME']) && $property[
'IS_PROFILE_NAME'] ===
'Y';
431 $isLocation = isset($property[
'IS_LOCATION']) && $property[
'IS_LOCATION'] ===
'Y';
432 $isLocation4Tax = isset($property[
'IS_LOCATION4TAX']) && $property[
'IS_LOCATION4TAX'] ===
'Y';
433 $isPayer = isset($property[
'IS_PAYER']) && $property[
'IS_PAYER'] ===
'Y';
434 $isZip = isset($property[
'IS_ZIP']) && $property[
'IS_ZIP'] ===
'Y';
436 if ($value ==
'Y' || $isProfileName || $isLocation || $isLocation4Tax || $isPayer || $isZip)
448 return array(
new Validator\Length(1, 255));
453 return array(
new Validator\Length(1, 20));
458 return array(
new Validator\Length(
null, 255));
463 return array(
new Validator\Length(
null, 50));
468 return uniqid(
'bx_');
471 private static function isSerialized(
string $data): bool
473 $data = trim( $data );
478 if (strlen($data) < 4)
482 if (substr($data, 1, 1) !==
':')
487 $last = substr( $data, -1 );
488 if ($last !==
';' && $last !==
'}')
493 $token = substr($data, 0,1);
496 && substr( $data, -2, 1) !==
'"'
507 return (
bool) preg_match(
"/^{$token}:[0-9]+:/s", $data);
511 return (
bool) preg_match(
"/^{$token}:[0-9.E+-]+;$/", $data);
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)
static validateSettings($value)
static getValueSaveModifiers()
static getSettingsValidators()
static modifySettingsForSave($value)
static validateValue($value, $primary, array $row, $field)
static modifyValueForFetch($value, $query, $property, $alias)
static validateEntityType()
static getCodeValidators()
static modifyRequiredForSave($value, array $property)
static modifyValueForSave($value)
static onBeforeAdd(Event $event)
static getSettingsFetchModifiers()
static getFilteredSaveModifiers()
static getNameValidators()
static getValueValidators()
static getTypeValidators()
static getDescriptionValidators()
static modifySettingsForFetch($value)
static getSettingsSaveModifiers()
static getValueFetchModifiers()
static getRequiredSaveModifiers()
static modifyFilteredForSave($value, array $data)
static onBeforeUpdate(Event $event)