1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
AnchorItem.php
См. документацию.
1<?php
2
3declare(strict_types=1);
4
5namespace Bitrix\Im\V2\Anchor;
6
7use Bitrix\Im\Model\AnchorTable;
8use Bitrix\Im\V2\ActiveRecord;
9use Bitrix\Im\V2\Common\ActiveRecordImplementation;
10use Bitrix\Im\V2\Common\RegistryEntryImplementation;
11use Bitrix\Im\V2\Message\Reaction\ReactionItem;
12use Bitrix\Im\V2\RegistryEntry;
13use Bitrix\Im\V2\Rest\RestConvertible;
14use Bitrix\Main\Validation\ValidationError;
15use Bitrix\Main\Validation\ValidationResult;
16use Bitrix\Main\Validation\Validator\InArrayValidator;
17
19{
20 use RegistryEntryImplementation;
21 use ActiveRecordImplementation;
22
23 public const MENTION = 'MENTION';
24 public const REACTION = 'REACTION';
25
26 public const ALLOWED_ANCHORS = [
27 self::MENTION => self::MENTION,
28 self::REACTION => self::REACTION,
29 ];
30
31 private int $id;
32 private int $chatId;
33 private int $messageId;
34 private int $userId;
35 private int $fromUserId;
36 private string $type;
37 private ?string $subType = null;
38
39 // runtime fields
40 private int $parentChatId = 0;
41 private int $parentMessageId = 0;
42
43 public function getPrimaryId(): ?int
44 {
45 return $this->id ?? null;
46 }
47
48 public function setPrimaryId(int $primaryId): self
49 {
50 $this->id = $primaryId;
51
52 return $this;
53 }
54
55 public function getChatId(): int
56 {
57 return $this->chatId;
58 }
59
60 public function setChatId(int $chatId): self
61 {
62 $this->chatId = $chatId;
63
64 return $this;
65 }
66
67 public function getMessageId(): int
68 {
69 return $this->messageId;
70 }
71
72 public function setMessageId(int $messageId): self
73 {
74 $this->messageId = $messageId;
75
76 return $this;
77 }
78
79 public function getUserId(): int
80 {
81 return $this->userId;
82 }
83
84 public function setUserId(int $userId): self
85 {
86 $this->userId = $userId;
87
88 return $this;
89 }
90
91 public function getFromUserId(): int
92 {
93 return $this->fromUserId;
94 }
95
96 public function setFromUserId(int $fromUserId): self
97 {
98 $this->fromUserId = $fromUserId;
99
100 return $this;
101 }
102
103 public function getType(): string
104 {
105 return $this->type;
106 }
107
108 public function setType(string $type): self
109 {
110 $this->type = $type;
111
112 return $this;
113 }
114
115 public function getSubType(): ?string
116 {
117 return $this->subType;
118 }
119
120 public function setSubType(?string $subType): self
121 {
122 $this->subType = $subType;
123
124 return $this;
125 }
126
127 public function getParentChatId(): int
128 {
129 return $this->parentChatId;
130 }
131
132 public function setParentChatId(int $parentChatId): self
133 {
134 $this->parentChatId = $parentChatId;
135
136 return $this;
137 }
138
139 public function getParentMessageId(): int
140 {
141 return $this->parentMessageId;
142 }
143
144 public function setParentMessageId(int $parentMessageId): self
145 {
146 $this->parentMessageId = $parentMessageId;
147
148 return $this;
149 }
150
151 public static function getDataClass(): string
152 {
153 return AnchorTable::class;
154 }
155
156 public static function getRestEntityName(): string
157 {
158 return 'anchor';
159 }
160
161 public function toRestFormat(array $option = []): ?array
162 {
163 return [
164 'chatId' => $this->getChatId(),
165 'messageId' => $this->getMessageId(),
166 'userId' => $this->getUserId(),
167 'fromUserId' => $this->getFromUserId(),
168 'type' => $this->getType(),
169 'subType' => $this->getSubType(),
170 'parentChatId' => $this->getParentChatId(),
171 'parentMessageId' => $this->getParentMessageId(),
172 ];
173 }
174
175 protected static function mirrorDataEntityFields(): array
176 {
177 return [
178 'ID' => [
179 'primary' => true,
180 'field' => 'id',
181 'set' => 'setPrimaryId',
182 'get' => 'getPrimaryId',
183 ],
184 'CHAT_ID' => [
185 'field' => 'chatId',
186 'set' => 'setChatId',
187 'get' => 'getChatId',
188 ],
189 'MESSAGE_ID' => [
190 'field' => 'messageId',
191 'set' => 'setMessageId',
192 'get' => 'getMessageId',
193 ],
194 'USER_ID' => [
195 'field' => 'userId',
196 'set' => 'setUserId',
197 'get' => 'getUserId',
198 ],
199 'FROM_USER_ID' => [
200 'field' => 'fromUserId',
201 'set' => 'setFromUserId',
202 'get' => 'getFromUserId',
203 ],
204 'TYPE' => [
205 'field' => 'type',
206 'set' => 'setType',
207 'get' => 'getType',
208 'beforeSave' => 'beforeSaveType',
209 ],
210 'SUB_TYPE' => [
211 'field' => 'subType',
212 'get' => 'getSubType',
213 'set' => 'setSubType',
214 'default' => null,
215 'beforeSave' => 'beforeSaveSubType',
216 ],
217 ];
218 }
219
220
221 private function beforeSaveType(): ValidationResult
222 {
223 return (new InArrayValidator(self::ALLOWED_ANCHORS))->validate($this->type);
224 }
225
226 private function beforeSaveSubType(): ValidationResult
227 {
228 $result = new ValidationResult();
229
230 if ($this->type === self::MENTION)
231 {
232 if ($this->subType === null)
233 {
234 return $result;
235 }
236
237 return $result->addError(new ValidationError(
238 'Wrong sub type for mention',
239 'subType'
240 ));
241 }
242
243 if ($this->type === self::REACTION)
244 {
245 return (new InArrayValidator(ReactionItem::ALLOWED_REACTION))->validate($this->subType);
246 }
247
248 return $result;
249 }
250}
$type
Определения options.php:106
if(! $messageFields||!isset($messageFields['message_id'])||!isset($messageFields['status'])||!CModule::IncludeModule("messageservice")) $messageId
Определения callback_ismscenter.php:26
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static getRestEntityName()
Определения AnchorItem.php:156
setPrimaryId(int $primaryId)
Определения AnchorItem.php:48
toRestFormat(array $option=[])
Определения AnchorItem.php:161
setFromUserId(int $fromUserId)
Определения AnchorItem.php:96
const ALLOWED_ANCHORS
Определения AnchorItem.php:26
setParentChatId(int $parentChatId)
Определения AnchorItem.php:132
setSubType(?string $subType)
Определения AnchorItem.php:120
setMessageId(int $messageId)
Определения AnchorItem.php:72
setChatId(int $chatId)
Определения AnchorItem.php:60
setUserId(int $userId)
Определения AnchorItem.php:84
static getDataClass()
Определения AnchorItem.php:151
static mirrorDataEntityFields()
Определения AnchorItem.php:175
setParentMessageId(int $parentMessageId)
Определения AnchorItem.php:144
setType(string $type)
Определения AnchorItem.php:108
</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
Определения RegistryEntry.php:6
$option
Определения options.php:1711