Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
optiongrouptable.php
1<?php
2
3namespace Bitrix\Im\Model;
4
12use Bitrix\Main\Entity\Event;
15
16
17
37{
43 public static function getTableName(): string
44 {
45 return 'b_im_option_group';
46 }
47
54 public static function getMap(): array
55 {
56 return [
57 'ID' => (new IntegerField('ID', [
58 'primary' => true,
59 'autocomplete' => true,
60 ])),
61 'NAME' => (new StringField('NAME', [
62 'validation' => [__CLASS__, 'validateName']
63 ])),
64 'USER_ID' => (new IntegerField('USER_ID', [])),
65 'SORT' => (new IntegerField('SORT', [
66 'required' => true,
67 ])),
68 'DATE_CREATE' => (new DatetimeField('DATE_CREATE', [
69 'required' => true,
70 ])),
71 'CREATE_BY_ID' => (new IntegerField('CREATE_BY_ID', [
72 'required' => true,
73 ])),
74 'DATE_MODIFY' => (new DatetimeField('DATE_MODIFY', [])),
75 'MODIFY_BY_ID' => (new IntegerField('MODIFY_BY_ID', [])),
76 ];
77 }
78
85 public static function validateName(): array
86 {
87 return [
88 new LengthValidator(null, 255),
89 ];
90 }
91
92 public static function onBeforeAdd(Event $event): EventResult
93 {
94 $data = $event->getParameter('fields');
95 $result = new EventResult();
96 if (!isset($data['CREATE_DATE']) || !is_array($data['CREATE_DATE']))
97 {
98 $result->modifyFields(['DATE_CREATE' => new Datetime()]);
99 }
100
101 return $result;
102 }
103
104 public static function onBeforeUpdate(Event $event): EventResult
105 {
106 $data = $event->getParameter('fields');
107 $result = new EventResult();
108 if (!isset($data['MODIFY_DATE']) || !is_array($data['MODIFY_DATE']))
109 {
110 $result->modifyFields(['DATE_MODIFY' => new DateTime()]);
111 }
112
113 return $result;
114 }
115}