Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
tradebinding.php
1<?php
2
3
5
6
11
12class TradeBinding extends Base
13{
14 public function getFields()
15 {
16 return [
17 'ID'=>[
18 'TYPE'=>DataType::TYPE_INT,
19 'ATTRIBUTES'=>[Attributes::READONLY]
20 ],
21 'ORDER_ID'=>[
22 'TYPE'=>DataType::TYPE_INT,
23 'ATTRIBUTES'=>[
24 Attributes::REQUIRED,
25 Attributes::IMMUTABLE
26 ]
27 ],
28 'EXTERNAL_ORDER_ID'=>[
29 'TYPE'=>DataType::TYPE_STRING,
30 'ATTRIBUTES'=>[
31 Attributes::REQUIRED,
32 Attributes::IMMUTABLE
33 ]
34 ],
35 'TRADING_PLATFORM_ID'=>[
36 'TYPE'=>DataType::TYPE_STRING,
37 'ATTRIBUTES'=>[
38 Attributes::REQUIRED,
39 Attributes::IMMUTABLE
40 ]
41 ],
42 'PARAMS'=>[
43 'TYPE'=>DataType::TYPE_STRING
44 ],
45 'XML_ID'=>[
46 'TYPE'=>DataType::TYPE_STRING
47 ],
48 'TRADING_PLATFORM_XML_ID'=>[
49 'TYPE'=>DataType::TYPE_STRING,
50 'ATTRIBUTES'=>[Attributes::READONLY]
51 ],
52 ];
53 }
54
55 protected function getRewriteFields(): array
56 {
57 return [
58 'TRADING_PLATFORM_XML_ID'=>[
59 'REFERENCE_FIELD'=>'TRADING_PLATFORM.XML_ID'
60 ]
61 ];
62 }
63
64 public function checkRequiredFieldsModify($fields): Result
65 {
66 $r = new Result();
67
68 $listFieldsInfoAdd = $this->getListFieldInfo($this->getFields(), ['filter'=>['ignoredAttributes'=>[Attributes::Hidden, Attributes::ReadOnly], 'ignoredFields'=>['ORDER_ID', 'EXTERNAL_ORDER_ID']]]);
69 $listFieldsInfoUpdate = $this->getListFieldInfo($this->getFields(), ['filter'=>['ignoredAttributes'=>[Attributes::Hidden, Attributes::ReadOnly, Attributes::Immutable]]]);
70
71 foreach ($fields['ORDER']['TRADE_BINDINGS'] as $k=>$item)
72 {
73 $required = $this->checkRequiredFields($item,
74 $this->isNewItem($item)? $listFieldsInfoAdd:$listFieldsInfoUpdate
75 );
76 if(!$required->isSuccess())
77 {
78 $r->addError(new Error('[tradeBindings]['.$k.'] - '.implode(', ', $required->getErrorMessages()).'.'));
79 }
80 }
81 return $r;
82 }
83
84 public function internalizeFieldsModify($fields, $fieldsInfo=[]): array
85 {
86 $result = [];
87
88 $fieldsInfo = empty($fieldsInfo)? $this->getFields():$fieldsInfo;
89 $listFieldsInfoAdd = $this->getListFieldInfo($fieldsInfo, ['filter'=>['ignoredAttributes'=>[Attributes::HIDDEN, Attributes::READONLY], ['ignoredFields'=>['ORDER_ID', 'EXTERNAL_ORDER_ID']]]]);
90 $listFieldsInfoUpdate = $this->getListFieldInfo($fieldsInfo, ['filter'=>['ignoredAttributes'=>[Attributes::HIDDEN, Attributes::READONLY, Attributes::IMMUTABLE], 'skipFields'=>['ID']]]);
91
92 if(isset($fields['ORDER']['TRADE_BINDINGS']))
93 {
94 foreach ($fields['ORDER']['TRADE_BINDINGS'] as $k=>$item)
95 {
96 $result['ORDER']['TRADE_BINDINGS'][$k] = $this->internalizeFields($item,
97 $this->isNewItem($item)? $listFieldsInfoAdd:$listFieldsInfoUpdate
98 );
99 }
100 }
101
102 return $result;
103 }
104}
getListFieldInfo(array $fieldsInfo, $params=[])
Definition base.php:53
internalizeFields($fields, array $fieldsInfo)
Definition base.php:179
checkRequiredFields($fields, array $fieldsInfo, $params=[])
Definition base.php:765
internalizeFieldsModify($fields, $fieldsInfo=[])