Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
propertyvalue.php
1<?php
2
3
5
6
11
12class PropertyValue extends Base
13{
14 public function getFields()
15 {
16 return [
17 'NAME'=>[
18 'TYPE'=>DataType::TYPE_STRING
19 ],
20 'CODE'=>[
21 'TYPE'=>DataType::TYPE_STRING
22 ],
23 'ORDER_PROPS_XML_ID'=>[
24 'TYPE'=>DataType::TYPE_STRING,
25 'ATTRIBUTES'=>[Attributes::READONLY]
26 ],
27 'ID'=>[
28 'TYPE'=>DataType::TYPE_INT,
29 'ATTRIBUTES'=>[Attributes::READONLY, Attributes::IMMUTABLE] //id is always new
30 ],
31 'ORDER_ID'=>[
32 'TYPE'=>DataType::TYPE_INT,
33 'ATTRIBUTES'=>[
34 Attributes::REQUIRED,
35 Attributes::IMMUTABLE
36 ]
37 ],
38 'VALUE'=>[
39 'TYPE'=>DataType::TYPE_STRING,
40 'ATTRIBUTES'=>[Attributes::REQUIRED]
41 ],
42 'ORDER_PROPS_ID'=>[
43 'TYPE'=>DataType::TYPE_INT,
44 'ATTRIBUTES'=>[
45 Attributes::REQUIRED]
46 ]
47 ];
48 }
49
50 public function internalizeFieldsModify($fields, $fieldsInfo=[]): array
51 {
52 $result = [];
53
54 $fieldsInfo = empty($fieldsInfo)? $this->getFields():$fieldsInfo;
55 $listFieldsInfoAdd = $this->getListFieldInfo($fieldsInfo, ['filter'=>['ignoredAttributes'=>[Attributes::HIDDEN, Attributes::READONLY], 'ignoredFields'=>['ORDER_ID']]]);
56 $listFieldsInfoUpdate = $this->getListFieldInfo($fieldsInfo, ['filter'=>['ignoredAttributes'=>[Attributes::HIDDEN, Attributes::READONLY, Attributes::IMMUTABLE]]]);
57
58 if(isset($fields['ORDER']['ID']))
59 $result['ORDER']['ID'] = (int)$fields['ORDER']['ID'];
60
61 if(isset($fields['ORDER']['PROPERTY_VALUES']))
62 {
63 foreach ($fields['ORDER']['PROPERTY_VALUES'] as $k=>$item)
64 {
65 $result['ORDER']['PROPERTY_VALUES'][$k] = $this->internalizeFields($item,
66 $this->isNewItem($item)? $listFieldsInfoAdd:$listFieldsInfoUpdate
67 );
68 }
69 }
70
71 return $result;
72 }
73
74 protected function getRewriteFields(): array
75 {
76 return [
77 'ORDER_PROPS_XML_ID'=>[
78 'REFERENCE_FIELD'=>'ORDER_PROPS.XML_ID'
79 ]
80 ];
81 }
82
83 public function externalizeFieldsModify($fields)
84 {
85 return $this->externalizeListFields($fields);
86 }
87
88 public function checkFieldsModify($fields): Result
89 {
90 $r = new Result();
91
92 $emptyFields = [];
93 if(!isset($fields['ORDER']['ID']))
94 {
95 $emptyFields[] = '[order][id]';
96 }
97 if(!isset($fields['ORDER']['PROPERTY_VALUES']) || !is_array($fields['ORDER']['PROPERTY_VALUES']))
98 {
99 $emptyFields[] = '[order][propertyValues][]';
100 }
101
102 if(count($emptyFields)>0)
103 {
104 $r->addError(new Error('Required fields: '.implode(', ', $emptyFields)));
105 }
106 else
107 {
108 $r = parent::checkFieldsModify($fields);
109 }
110
111 return $r;
112 }
113
114 public function checkRequiredFieldsModify($fields): Result
115 {
116 $r = new Result();
117
118 $listFieldsInfoAdd = $this->getListFieldInfo($this->getFields(), ['filter'=>['ignoredAttributes'=>[Attributes::HIDDEN, Attributes::READONLY], 'ignoredFields'=>['ORDER_ID']]]);
119 $listFieldsInfoUpdate = $this->getListFieldInfo($this->getFields(), ['filter'=>['ignoredAttributes'=>[Attributes::HIDDEN, Attributes::READONLY, Attributes::IMMUTABLE]]]);
120
121 foreach ($fields['ORDER']['PROPERTY_VALUES'] as $k=>$item)
122 {
123 $required = $this->checkRequiredFields($item,
124 $this->isNewItem($item)? $listFieldsInfoAdd:$listFieldsInfoUpdate
125 );
126
127 if(!$required->isSuccess())
128 {
129 $r->addError(new Error('[propertyValues]['.$k.'] - '.implode(', ', $required->getErrorMessages()).'.'));
130 }
131 }
132 return $r;
133 }
134}
getListFieldInfo(array $fieldsInfo, $params=[])
Definition base.php:53
externalizeListFields($list, $fieldsInfo=[])
Definition base.php:675
internalizeFields($fields, array $fieldsInfo)
Definition base.php:179
checkRequiredFields($fields, array $fieldsInfo, $params=[])
Definition base.php:765
internalizeFieldsModify($fields, $fieldsInfo=[])