Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
channeltable.php
1<?php
3
12use Bitrix\Main\ORM\Data\Internal\DeleteByFilterTrait;
13use Bitrix\Main\ORM\Data\Internal\MergeTrait;
16
17
19{
20 use MergeTrait;
21 use DeleteByFilterTrait;
22
26 public static function getTableName(): string
27 {
28 return 'b_messageservice_channel';
29 }
30
34 public static function getMap(): array
35 {
36 return [
37 'ID' =>
38 (new IntegerField('ID'))
39 ->configurePrimary()
40 ->configureAutocomplete()
41 ,
42 'SENDER_ID' =>
43 (new StringField('SENDER_ID'))
44 ->configureRequired()
45 ->configureSize(50)
46 ->addValidator(new LengthValidator(1, 50))
47 ,
48 'EXTERNAL_ID' =>
49 (new StringField('EXTERNAL_ID'))
50 ->configureRequired()
51 ->configureSize(128)
52 ->addValidator(new LengthValidator(1, 128))
53 ,
54 'TYPE' =>
55 (new StringField('TYPE'))
56 ->configureRequired()
57 ->configureSize(30)
58 ->addValidator(new LengthValidator(1, 30))
59 ,
60 'NAME' =>
61 (new StringField('NAME'))
62 ->configureRequired()
63 ->configureSize(500)
64 ->addValidator(new LengthValidator(1, 500))
65 ,
66 'ADDITIONAL_PARAMS' =>
67 (new ArrayField('ADDITIONAL_PARAMS'))
68 ->configureSerializationJson()
69 ,
70 'DATE_CREATE' =>
71 (new DatetimeField('DATE_CREATE'))
72 ->configureDefaultValue(function()
73 {
74 return new DateTime();
75 })
76 ,
77 ];
78 }
79
80 public static function getChannelsByType(string $senderId, string $type): Result
81 {
82 return self::getList([
83 'filter' => [
84 '=SENDER_ID' => $senderId,
85 '=TYPE' => $type,
86 ]
87 ]);
88 }
89
90 public static function reloadChannels(string $senderId, string $type, array $channels): void
91 {
92 foreach ($channels as $channel)
93 {
94 if (is_array($channel['ADDITIONAL_PARAMS']))
95 {
96 $channel['ADDITIONAL_PARAMS'] = Json::encode($channel['ADDITIONAL_PARAMS']);
97 }
98 self::merge(
99 $channel,
100 [
101 'NAME' => $channel['NAME'],
102 'ADDITIONAL_PARAMS' =>$channel['ADDITIONAL_PARAMS'],
103 ],
104 ['SENDER_ID', 'EXTERNAL_ID', 'TYPE']
105 );
106 }
107 self::deleteByFilter([
108 '=SENDER_ID' => $senderId,
109 '=TYPE' => $type,
110 '!=EXTERNAL_ID' => array_column($channels, 'EXTERNAL_ID')
111 ]);
112 }
113}
static getList(array $parameters=array())
static getChannelsByType(string $senderId, string $type)
static reloadChannels(string $senderId, string $type, array $channels)