Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
basketproperties.php
1<?php
2
3
5
6
10
12{
13 public function getFields()
14 {
15 return [
16 'ID'=>[
17 'TYPE'=>self::TYPE_INT,
18 'ATTRIBUTES'=>[Attributes::ReadOnly]
19 ],
20 'BASKET_ID'=>[
21 'TYPE'=>self::TYPE_INT,
22 'ATTRIBUTES'=>[
25 ]
26 ],
27 'NAME'=>[
28 'TYPE'=>self::TYPE_STRING,
29 'ATTRIBUTES'=>[Attributes::Required]
30 ],
31 'VALUE'=>[
32 'TYPE'=>self::TYPE_STRING,
33 'ATTRIBUTES'=>[Attributes::Required]
34 ],
35 'CODE'=>[
36 'TYPE'=>self::TYPE_STRING,
37 'ATTRIBUTES'=>[Attributes::Required]
38 ],
39 'SORT'=>[
40 'TYPE'=>self::TYPE_INT
41 ],
42 'XML_ID'=>[
43 'TYPE'=>self::TYPE_STRING,
44 ]
45 ];
46 }
47
48 public function internalizeFieldsModify($fields, $fieldsInfo=[])
49 {
50 $result = [];
51
52 $fieldsInfo = empty($fieldsInfo)? $this->getFields():$fieldsInfo;
53 $listFieldsInfoAdd = $this->getListFieldInfo($fieldsInfo, ['filter'=>['ignoredAttributes'=>[Attributes::Hidden, Attributes::ReadOnly]]]);
54 $listFieldsInfoUpdate = $this->getListFieldInfo($fieldsInfo, ['filter'=>['ignoredAttributes'=>[Attributes::Hidden, Attributes::ReadOnly, Attributes::Immutable], 'skipFields'=>['ID']]]);
55
56 foreach ($fields['BASKET_ITEM']['PROPERTIES'] as $k=>$item)
57 {
58 $result['BASKET_ITEM']['PROPERTIES'][$k] = $this->internalizeFields($item,
59 $this->isNewItem($item)? $listFieldsInfoAdd:$listFieldsInfoUpdate
60 );
61 }
62
63 return $result;
64 }
65
66 public function checkFieldsModify($fields)
67 {
68 $r = new Result();
69
70 $emptyFields = [];
71
72 if(!isset($fields['BASKET_ITEM']['ID']))
73 {
74 $emptyFields[] = '[basketItem][id]';
75 }
76 if(!isset($fields['BASKET_ITEM']['PROPERTIES']) || !is_array($fields['BASKET_ITEM']['PROPERTIES']))
77 {
78 $emptyFields[] = '[basketItem][properties][]';
79 }
80
81 if(count($emptyFields)>0)
82 {
83 $r->addError(new Error(implode(', ', $emptyFields)));
84 }
85 else
86 {
87 $r = parent::checkFieldsModify($fields);
88 }
89
90 return $r;
91 }
92
93 public function checkRequiredFieldsModify($fields)
94 {
95 $r = new Result();
96
97 $listFieldsInfoAdd = $this->getListFieldInfo($this->getFields(), ['filter'=>['ignoredAttributes'=>[Attributes::Hidden, Attributes::ReadOnly]]]);
98 $listFieldsInfoUpdate = $this->getListFieldInfo($this->getFields(), ['filter'=>['ignoredAttributes'=>[Attributes::Hidden, Attributes::ReadOnly, Attributes::Immutable]]]);
99
100 foreach ($fields['BASKET_ITEM']['PROPERTIES'] as $k=>$item)
101 {
102 $required = $this->checkRequiredFields($item,
103 $this->isNewItem($item)? $listFieldsInfoAdd:$listFieldsInfoUpdate
104 );
105 if(!$required->isSuccess())
106 {
107 $r->addError(new Error('[properties]['.$k.'] - '.implode(', ', $required->getErrorMessages()).'.'));
108 }
109 }
110
111 return $r;
112 }
113}
getListFieldInfo(array $fieldsInfo, $params=[])
Definition base.php:62
internalizeFields($fields, array $fieldsInfo)
Definition base.php:281
checkRequiredFields($fields, array $fieldsInfo, $params=[])
Definition base.php:676
internalizeFieldsModify($fields, $fieldsInfo=[])