1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
store.php
См. документацию.
1<?php
2
3namespace Bitrix\Catalog;
4
5use Bitrix\Main;
6use Bitrix\Main\Localization\Loc;
7use Bitrix\Main\ORM\Event;
8use Bitrix\Main\ORM\EventResult;
9use Bitrix\Main\UserTable;
10
56class StoreTable extends Main\Entity\DataManager
57{
63 public static function getTableName(): string
64 {
65 return 'b_catalog_store';
66 }
67
73 public static function getMap(): array
74 {
75 return [
76 'ID' => new Main\Entity\IntegerField(
77 'ID',
78 [
79 'primary' => true,
80 'autocomplete' => true,
81 'title' => Loc::getMessage('STORE_ENTITY_ID_FIELD'),
82 ]
83 ),
84 'TITLE' => new Main\Entity\StringField(
85 'TITLE',
86 [
87 'validation' => [__CLASS__, 'validateTitle'],
88 'title' => Loc::getMessage('STORE_ENTITY_TITLE_FIELD'),
89 ]
90 ),
91 'ACTIVE' => new Main\Entity\BooleanField(
92 'ACTIVE',
93 [
94 'values' => ['N', 'Y'],
95 'default_value' => 'Y',
96 'title' => Loc::getMessage('STORE_ENTITY_ACTIVE_FIELD'),
97 ]
98 ),
99 'ADDRESS' => new Main\Entity\StringField(
100 'ADDRESS',
101 [
102 'required' => true,
103 'validation' => [__CLASS__, 'validateAddress'],
104 'title' => Loc::getMessage('STORE_ENTITY_ADDRESS_FIELD'),
105 ]
106 ),
107 'DESCRIPTION' => new Main\Entity\TextField(
108 'DESCRIPTION',
109 [
110 'title' => Loc::getMessage('STORE_ENTITY_DESCRIPTION_FIELD'),
111 ]
112 ),
113 'GPS_N' => new Main\Entity\StringField(
114 'GPS_N',
115 [
116 'validation' => [__CLASS__, 'validateGpsN'],
117 'title' => Loc::getMessage('STORE_ENTITY_GPS_N_FIELD'),
118 ]
119 ),
120 'GPS_S' => new Main\Entity\StringField(
121 'GPS_S',
122 [
123 'validation' => [__CLASS__, 'validateGpsS'],
124 'title' => Loc::getMessage('STORE_ENTITY_GPS_S_FIELD'),
125 ]
126 ),
127 'IMAGE_ID' => new Main\Entity\StringField(
128 'IMAGE_ID',
129 [
130 'validation' => [__CLASS__, 'validateImageId'],
131 'title' => Loc::getMessage('STORE_ENTITY_IMAGE_ID_FIELD'),
132 ]
133 ),
134 'LOCATION_ID' => new Main\Entity\IntegerField(
135 'LOCATION_ID',
136 [
137 'title' => Loc::getMessage('STORE_ENTITY_LOCATION_ID_FIELD'),
138 ]
139 ),
140 'DATE_MODIFY' => new Main\Entity\DatetimeField(
141 'DATE_MODIFY',
142 [
143 'default_value' => function()
144 {
145 return new Main\Type\DateTime();
146 },
147 'title' => Loc::getMessage('STORE_ENTITY_DATE_MODIFY_FIELD'),
148 ]
149 ),
150 'DATE_CREATE' => new Main\Entity\DatetimeField(
151 'DATE_CREATE',
152 [
153 'default_value' => function()
154 {
155 return new Main\Type\DateTime();
156 },
157 'title' => Loc::getMessage('STORE_ENTITY_DATE_CREATE_FIELD'),
158 ]
159 ),
160 'USER_ID' => new Main\Entity\IntegerField(
161 'USER_ID',
162 [
163 'default_value' => null,
164 'title' => Loc::getMessage('STORE_ENTITY_USER_ID_FIELD'),
165 ]
166 ),
167 'CREATED_BY_USER' => new Main\ORM\Fields\Relations\Reference(
168 'CREATED_BY_USER',
169 UserTable::class,
170 Main\ORM\Query\Join::on('this.USER_ID', 'ref.ID')
171 ),
172 'MODIFIED_BY' => new Main\Entity\IntegerField(
173 'MODIFIED_BY',
174 [
175 'default_value' => null,
176 'title' => Loc::getMessage('STORE_ENTITY_MODIFIED_BY_FIELD'),
177 ]
178 ),
179 'MODIFIED_BY_USER' => new Main\ORM\Fields\Relations\Reference(
180 'MODIFIED_BY_USER',
181 UserTable::class,
182 Main\ORM\Query\Join::on('this.MODIFIED_BY', 'ref.ID')
183 ),
184 'PHONE' => new Main\Entity\StringField(
185 'PHONE',
186 [
187 'validation' => [__CLASS__, 'validatePhone'],
188 'title' => Loc::getMessage('STORE_ENTITY_PHONE_FIELD'),
189 ]
190 ),
191 'SCHEDULE' => new Main\Entity\StringField(
192 'SCHEDULE',
193 [
194 'validation' => [__CLASS__, 'validateSchedule'],
195 'title' => Loc::getMessage('STORE_ENTITY_SCHEDULE_FIELD'),
196 ]
197 ),
198 'XML_ID' => new Main\Entity\StringField(
199 'XML_ID',
200 [
201 'validation' => [__CLASS__, 'validateXmlId'],
202 'title' => Loc::getMessage('STORE_ENTITY_XML_ID_FIELD'),
203 ]
204 ),
205 'SORT' => new Main\Entity\IntegerField(
206 'SORT',
207 [
208 'default_value' => 100,
209 'title' => Loc::getMessage('STORE_ENTITY_SORT_FIELD'),
210 ]
211 ),
212 'EMAIL' => new Main\Entity\StringField(
213 'EMAIL',
214 [
215 'validation' => [__CLASS__, 'validateEmail'],
216 'title' => Loc::getMessage('STORE_ENTITY_EMAIL_FIELD'),
217 ]
218 ),
219 'ISSUING_CENTER' => new Main\Entity\BooleanField(
220 'ISSUING_CENTER',
221 [
222 'values' => ['N', 'Y'],
223 'default_value' => 'Y',
224 'title' => Loc::getMessage('STORE_ENTITY_ISSUING_CENTER_FIELD'),
225 ]
226 ),
227 'SHIPPING_CENTER' => new Main\Entity\BooleanField(
228 'SHIPPING_CENTER',
229 [
230 'values' => ['N', 'Y'],
231 'default_value' => 'Y',
232 'title' => Loc::getMessage('STORE_ENTITY_SHIPPING_CENTER_FIELD'),
233 ]
234 ),
235 'SITE_ID' => new Main\Entity\StringField(
236 'SITE_ID',
237 [
238 'validation' => [__CLASS__, 'validateSiteId'],
239 'title' => Loc::getMessage('STORE_ENTITY_SITE_ID_FIELD'),
240 ]
241 ),
242 'CODE' => new Main\Entity\StringField(
243 'CODE',
244 [
245 'validation' => [__CLASS__, 'validateCode'],
246 'title' => Loc::getMessage('STORE_ENTITY_CODE_FIELD'),
247 ]
248 ),
249 'IS_DEFAULT' => new Main\ORM\Fields\EnumField(
250 'IS_DEFAULT',
251 [
252 'values' => ['N', 'Y'],
253 'default_value' => 'N',
254 'title' => Loc::getMessage('STORE_ENTITY_IS_DEFAULT_FIELD'),
255 ]
256 ),
257 ];
258 }
259
265 public static function getUfId(): string
266 {
267 return 'CAT_STORE';
268 }
269
275 public static function validateTitle(): array
276 {
277 return [
278 new Main\Entity\Validator\Length(null, 75),
279 ];
280 }
281
287 public static function validateAddress(): array
288 {
289 return [
290 new Main\Entity\Validator\Length(null, 245),
291 ];
292 }
293
299 public static function validateGpsN(): array
300 {
301 return [
302 new Main\Entity\Validator\Length(null, 15),
303 ];
304 }
305
311 public static function validateGpsS(): array
312 {
313 return [
314 new Main\Entity\Validator\Length(null, 15),
315 ];
316 }
317
323 public static function validateImageId(): array
324 {
325 return [
326 new Main\Entity\Validator\Length(null, 45),
327 ];
328 }
329
335 public static function validatePhone(): array
336 {
337 return [
338 new Main\Entity\Validator\Length(null, 45),
339 ];
340 }
341
347 public static function validateSchedule(): array
348 {
349 return [
350 new Main\Entity\Validator\Length(null, 255),
351 ];
352 }
353
359 public static function validateXmlId(): array
360 {
361 return [
362 new Main\Entity\Validator\Length(null, 255),
363 ];
364 }
365
371 public static function validateEmail(): array
372 {
373 return [
374 new Main\Entity\Validator\Length(null, 255),
375 ];
376 }
377
383 public static function validateSiteId(): array
384 {
385 return [
386 new Main\Entity\Validator\Length(null, 2),
387 ];
388 }
389
395 public static function validateCode(): array
396 {
397 return [
398 new Main\Entity\Validator\Length(null, 255),
399 ];
400 }
401
402 public static function getDefaultStoreId(): ?int
403 {
404 $row = self::getRow([
405 'select' => [
406 'ID',
407 ],
408 'filter' => [
409 '=IS_DEFAULT' => 'Y',
410 ],
411 'cache' => ['ttl' => 86400],
412 ]);
413 $defaultStoreId = (int)($row['ID'] ?? 0);
414
415 return ($defaultStoreId > 0 ? $defaultStoreId : null);
416 }
417
418 public static function getStoreCreatorId(int $storeId): ?int
419 {
420 $row = self::getRowById($storeId, ['select' => ['USER_ID']]);
421 $creatorId = (int)($row['USER_ID'] ?? 0);
422
423 return ($creatorId > 0 ? $creatorId : null);
424 }
425
432 public static function onBeforeAdd(Event $event): EventResult
433 {
434 $result = new EventResult;
435 $data = $event->getParameter('fields');
436 if (!array_key_exists('DATE_MODIFY', $data))
437 {
438 $result->modifyFields([
439 'DATE_MODIFY' => new Main\Type\DateTime(),
440 ]);
441 }
442 if (!array_key_exists('DATE_CREATE', $data))
443 {
444 $result->modifyFields([
445 'DATE_CREATE' => new Main\Type\DateTime(),
446 ]);
447 }
448
449 return $result;
450 }
451
458 public static function onBeforeUpdate(Event $event): EventResult
459 {
460 $result = new EventResult;
461 $data = $event->getParameter('fields');
462 if (!array_key_exists('DATE_MODIFY', $data))
463 {
464 $result->modifyFields([
465 'DATE_MODIFY' => new Main\Type\DateTime(),
466 ]);
467 }
468
469 return $result;
470 }
471}
static validateGpsS()
Определения store.php:311
static getStoreCreatorId(int $storeId)
Определения store.php:418
static validateSchedule()
Определения store.php:347
static validateImageId()
Определения store.php:323
static getDefaultStoreId()
Определения store.php:402
static getMap()
Определения store.php:73
static validateSiteId()
Определения store.php:383
static getUfId()
Определения store.php:265
static validatePhone()
Определения store.php:335
static validateAddress()
Определения store.php:287
static onBeforeAdd(Event $event)
Определения store.php:432
static validateGpsN()
Определения store.php:299
static validateXmlId()
Определения store.php:359
static validateTitle()
Определения store.php:275
static onBeforeUpdate(Event $event)
Определения store.php:458
static validateEmail()
Определения store.php:371
static getTableName()
Определения store.php:63
static validateCode()
Определения store.php:395
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
Определения ufield.php:9
Определения chain.php:3
Определения collection.php:2
Определения buffer.php:3
$event
Определения prolog_after.php:141