Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
group.php
1<?php
2
3namespace Bitrix\Catalog;
4
8
44{
50 public static function getTableName()
51 {
52 return 'b_catalog_group';
53 }
54
60 public static function getMap()
61 {
62 return [
63 'ID' => new ORM\Fields\IntegerField(
64 'ID',
65 [
66 'primary' => true,
67 'autocomplete' => true,
68 'title' => Loc::getMessage('GROUP_ENTITY_ID_FIELD'),
69 ]
70 ),
71 'NAME' => new ORM\Fields\StringField(
72 'NAME',
73 [
74 'required' => true,
75 'validation' => function()
76 {
77 return [
79 ];
80 },
81 'title' => Loc::getMessage('GROUP_ENTITY_NAME_FIELD'),
82 ]
83 ),
84 'BASE' => new ORM\Fields\BooleanField(
85 'BASE',
86 [
87 'values' => [
88 'N',
89 'Y',
90 ],
91 'title' => Loc::getMessage('GROUP_ENTITY_BASE_FIELD'),
92 ]
93 ),
94 'SORT' => new ORM\Fields\IntegerField(
95 'SORT',
96 [
97 'title' => Loc::getMessage('GROUP_ENTITY_SORT_FIELD'),
98 ]
99 ),
100 'XML_ID' => new ORM\Fields\StringField(
101 'XML_ID',
102 [
103 'validation' => function()
104 {
105 return [
107 ];
108 },
109 'title' => Loc::getMessage('GROUP_ENTITY_XML_ID_FIELD'),
110 ]
111 ),
112 'TIMESTAMP_X' => new ORM\Fields\DatetimeField(
113 'TIMESTAMP_X',
114 [
115 'title' => Loc::getMessage('GROUP_ENTITY_TIMESTAMP_X_FIELD'),
116 'default_value' => function()
117 {
118 return new Main\Type\DateTime();
119 },
120 ]
121 ),
122 'MODIFIED_BY' => new ORM\Fields\IntegerField(
123 'MODIFIED_BY',
124 [
125 'title' => Loc::getMessage('GROUP_ENTITY_MODIFIED_BY_FIELD'),
126 ]
127 ),
128 'DATE_CREATE' => new ORM\Fields\DatetimeField(
129 'DATE_CREATE',
130 [
131 'title' => Loc::getMessage('GROUP_ENTITY_DATE_CREATE_FIELD'),
132 'default_value' => function()
133 {
134 return new Main\Type\DateTime();
135 },
136 ]
137 ),
138 'CREATED_BY' => new ORM\Fields\IntegerField(
139 'CREATED_BY',
140 [
141 'title' => Loc::getMessage('GROUP_ENTITY_CREATED_BY_FIELD'),
142 ]
143 ),
144 'CREATED_BY_USER' => new ORM\Fields\Relations\Reference(
145 'CREATED_BY_USER',
146 '\Bitrix\Main\User',
147 ['=this.CREATED_BY' => 'ref.ID']
148 ),
149 'MODIFIED_BY_USER' => new ORM\Fields\Relations\Reference(
150 'MODIFIED_BY_USER',
151 '\Bitrix\Main\User',
152 ['=this.MODIFIED_BY' => 'ref.ID']
153 ),
154 'LANG' => new ORM\Fields\Relations\Reference(
155 'LANG',
156 '\Bitrix\Catalog\GroupLang',
157 ['=this.ID' => 'ref.CATALOG_GROUP_ID']
158 ),
159 'CURRENT_LANG' => new ORM\Fields\Relations\Reference(
160 'CURRENT_LANG',
161 '\Bitrix\Catalog\GroupLang',
162 [
163 '=this.ID' => 'ref.CATALOG_GROUP_ID',
164 '=ref.LANG' => new Main\DB\SqlExpression('?', LANGUAGE_ID)
165 ],
166 ['join_type' => 'LEFT']
167 )
168 ];
169 }
170
177 public static function onAfterAdd(ORM\Event $event): void
178 {
179 Model\Price::clearSettings();
180 }
181
188 public static function onAfterUpdate(ORM\Event $event): void
189 {
190 Model\Price::clearSettings();
191 }
192
199 public static function onAfterDelete(ORM\Event $event): void
200 {
201 Model\Price::clearSettings();
202 }
203
209 public static function getBasePriceType(): ?array
210 {
211 $row = self::getList([
212 'select' => [
213 'ID',
214 'NAME',
215 'BASE',
216 'SORT',
217 'XML_ID',
218 'NAME_LANG' =>'CURRENT_LANG.NAME',
219 ],
220 'filter' => [
221 '=BASE' => 'Y',
222 ],
223 'cache' => [
224 'ttl' => 86400,
225 ],
226 ])->fetch();
227
228 if (!empty($row))
229 {
230 $row['ID'] = (int)$row['ID'];
231 $row['SORT'] = (int)$row['SORT'];
232 if ($row['NAME_LANG'] === '')
233 {
234 $row['NAME_LANG'] = null;
235 }
236
237 return $row;
238 }
239
240 return null;
241 }
242
248 public static function getBasePriceTypeId(): ?int
249 {
250 $row = self::getBasePriceType();
251
252 return $row === null ? null : $row['ID'];
253 }
254
260 public static function getTypeList(): array
261 {
262 $result = [];
263
264 $iterator = self::getList([
265 'select' => [
266 'ID',
267 'NAME',
268 'BASE',
269 'SORT',
270 'XML_ID',
271 'NAME_LANG' =>'CURRENT_LANG.NAME',
272 ],
273 'order' => [
274 'SORT' => 'ASC',
275 'ID' => 'ASC',
276 ],
277 'cache' => [
278 'ttl' => 86400,
279 ],
280 ]);
281 while ($row = $iterator->fetch())
282 {
283 $row['ID'] = (int)$row['ID'];
284 $row['SORT'] = (int)$row['SORT'];
285 if ($row['NAME_LANG'] === '')
286 {
287 $row['NAME_LANG'] = null;
288 }
289
290 $result[$row['ID']] = $row;
291 }
292 unset($row, $groupIterator);
293
294 return $result;
295 }
296}
static onAfterDelete(ORM\Event $event)
Definition group.php:199
static getBasePriceTypeId()
Definition group.php:248
static onAfterAdd(ORM\Event $event)
Definition group.php:177
static onAfterUpdate(ORM\Event $event)
Definition group.php:188
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static getList(array $parameters=array())