Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
type.php
1<?php
9
10use Bitrix\Main;
13
17
18Loc::loadMessages(__FILE__);
19
36class TypeTable extends Entity\DataManager
37{
38 public static function getFilePath()
39 {
40 return __FILE__;
41 }
42
43 public static function getTableName()
44 {
45 return 'b_sale_loc_type';
46 }
47
48 public static function add(array $data)
49 {
50 $res = self::getList(array(
51 'filter' => array('=CODE' => $data['CODE'])
52 ));
53
54 if($res->fetch())
55 {
56 $addResult = new Entity\AddResult();
57 $addResult->addError(new Main\Error(Loc::getMessage('SALE_LOCATION_TYPE_ENTITY_CODE_FIELD_EXIST_ERROR')));
58 return $addResult;
59 }
60
61 if(isset($data['NAME']))
62 {
63 $name = $data['NAME'];
64 unset($data['NAME']);
65 }
66
67 if((string) $data['DISPLAY_SORT'] == '' && (string) $data['SORT'] != '')
68 {
69 $data['DISPLAY_SORT'] = $data['SORT'];
70 }
71
72 $addResult = parent::add($data);
73
74 // add connected data
75 if($addResult->isSuccess())
76 {
77 $primary = $addResult->getId();
78
79 // names
80 if(isset($name))
81 Name\TypeTable::addMultipleForOwner($primary, $name);
82 }
83
84 return $addResult;
85 }
86
87 public static function update($primary, array $data)
88 {
89 $primary = Assert::expectIntegerPositive($primary, '$primary');
90
91 if(isset($data['CODE']))
92 {
93 $res = self::getList(array(
94 'filter' => array(
95 '=CODE' => $data['CODE'],
96 '!=ID' => $primary
97 )
98 ));
99
100 if($res->fetch())
101 {
102 $updResult = new Entity\UpdateResult();
103 $updResult->addError(new Main\Error(Loc::getMessage('SALE_LOCATION_TYPE_ENTITY_CODE_FIELD_EXIST_ERROR')));
104 return $updResult;
105 }
106 }
107
108 // first update parent, and if it succeed, do updates of the connected data
109
110 if(isset($data['NAME']))
111 {
112 $name = $data['NAME'];
113 unset($data['NAME']);
114 }
115
116 $updResult = parent::update($primary, $data);
117
118 // update connected data
119 if($updResult->isSuccess())
120 {
121 // names
122 if(isset($name))
123 Name\TypeTable::updateMultipleForOwner($primary, $name);
124 }
125
126 return $updResult;
127 }
128
129 public static function delete($primary)
130 {
131 $primary = Assert::expectIntegerPositive($primary, '$primary');
132
133 $delResult = parent::delete($primary);
134
135 // delete connected data
136 if($delResult->isSuccess())
137 Name\TypeTable::deleteMultipleForOwner($primary);
138
139 return $delResult;
140 }
141
142 public static function getMap()
143 {
144 return array(
145
146 'ID' => array(
147 'data_type' => 'integer',
148 'primary' => true,
149 'autocomplete' => true,
150 ),
151 'CODE' => array(
152 'data_type' => 'string',
153 'required' => true,
154 'title' => Loc::getMessage('SALE_LOCATION_TYPE_ENTITY_CODE_FIELD')
155 ),
156 'SORT' => array(
157 'data_type' => 'integer',
158 'title' => Loc::getMessage('SALE_LOCATION_TYPE_ENTITY_DEPTH_LEVEL_FIELD')
159 ),
160
161 'DISPLAY_SORT' => array(
162 'data_type' => 'integer',
163 'title' => Loc::getMessage('SALE_LOCATION_TYPE_ENTITY_DISPLAY_SORT_FIELD')
164 ),
165
166 // virtual
167 'NAME' => array(
168 'data_type' => 'Bitrix\Sale\Location\Name\Type',
169 'reference' => array(
170 '=this.ID' => 'ref.TYPE_ID'
171 ),
172 ),
173 'LOCATION' => array(
174 'data_type' => 'Bitrix\Sale\Location\Location',
175 'reference' => array(
176 '=this.ID' => 'ref.TYPE_ID'
177 ),
178 )
179 );
180 }
181}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static add(array $data)
Definition type.php:48
static update($primary, array $data)
Definition type.php:87