Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
Relation.php
1<?php
2
3namespace Bitrix\Im\V2;
4
5use ArrayAccess;
7use Bitrix\Im\V2\Common\ActiveRecordImplementation;
8use Bitrix\Im\V2\Common\ContextCustomer;
9use Bitrix\Im\V2\Common\FieldAccessImplementation;
10use Bitrix\Im\V2\Common\RegistryEntryImplementation;
13
14class Relation implements ArrayAccess, RegistryEntry, ActiveRecord
15{
16 use FieldAccessImplementation;
17 use ActiveRecordImplementation;
18 use RegistryEntryImplementation;
19 use ContextCustomer;
20
21 protected ?int $id = null;
22 protected ?int $chatId = null;
23 protected ?string $messageType = null;
24 protected ?int $userId = null;
25 protected ?int $startId = null;
26 protected ?int $unreadId = null;
27 protected ?int $lastId = null;
28 protected ?int $lastSendId = null;
29 protected ?int $lastFileId = null;
30 protected ?DateTime $lastRead = null;
31 protected ?int $status = null;
32 protected ?int $callStatus = null;
33 protected ?string $messageStatus = null;
34 protected ?bool $notifyBlock = null;
35 protected ?bool $manager = null;
36 protected ?int $counter = null;
37 protected ?int $startCounter = null;
38 protected ?User $user = null;
39
40 public function __construct($source = null)
41 {
42 $this->initByDefault();
43
44 if (!empty($source))
45 {
46 $this->load($source);
47 }
48 }
49
50 public function getPrimaryId(): ?int
51 {
52 return $this->getId();
53 }
54
55 public function setPrimaryId(int $primaryId): self
56 {
57 return $this->setId($primaryId);
58 }
59
60 public static function getDataClass(): string
61 {
62 return RelationTable::class;
63 }
64
65 public function getUser(): User
66 {
67 if (isset($this->user))
68 {
69 return $this->user;
70 }
71
72 $this->user = User::getInstance($this->getUserId());
73
74 return $this->user;
75 }
76
77 public function getChat(): Chat
78 {
79 return Chat::getInstance($this->getChatId());
80 }
81
82 public function fillRestriction(bool $hideHistory, Chat $chat): self
83 {
84 if ($hideHistory)
85 {
86 $this
87 ->setStartId($chat->getLastMessageId() + 1)
88 ->setLastFileId($chat->getLastFileId())
89 ->setStartCounter($chat->getMessageCount())
90 ;
91 }
92
93 if (!$hideHistory && $chat->getContext()->getUserId() > 0)
94 {
95 $selfRelation = $chat->getSelfRelation();
96 if ($selfRelation !== null && $selfRelation->getStartId() > 0)
97 {
98 $this
99 ->setStartCounter($selfRelation->getStartId())
100 ->setLastFileId($selfRelation->getLastFileId())
101 ->setStartCounter($selfRelation->getStartCounter())
102 ;
103 }
104 }
105
106 return $this;
107 }
108
112 protected static function mirrorDataEntityFields(): array
113 {
114 return [
115 'ID' => [
116 'primary' => true,
117 'field' => 'id',
118 'set' => 'setId',
119 'get' => 'getId',
120 ],
121 'CHAT_ID' => [
122 'field' => 'chatId',
123 'set' => 'setChatId',
124 'get' => 'getChatId',
125 ],
126 'MESSAGE_TYPE' => [
127 'field' => 'messageType',
128 'set' => 'setMessageType',
129 'get' => 'getMessageType',
130 ],
131 'USER_ID' => [
132 'field' => 'userId',
133 'set' => 'setUserId',
134 'get' => 'getUserId',
135 ],
136 'START_ID' => [
137 'field' => 'startId',
138 'set' => 'setStartId',
139 'get' => 'getStartId',
140 ],
141 'UNREAD_ID' => [
142 'field' => 'unreadId',
143 'set' => 'setUnreadId',
144 'get' => 'getUnreadId',
145 ],
146 'LAST_ID' => [
147 'field' => 'lastId',
148 'set' => 'setLastId',
149 'get' => 'getLastId',
150 ],
151 'LAST_SEND_ID' => [
152 'field' => 'lastSendId',
153 'set' => 'setLastSendId',
154 'get' => 'getLastSendId',
155 ],
156 'LAST_FILE_ID' => [
157 'field' => 'lastFileId',
158 'set' => 'setLastFileId',
159 'get' => 'getLastFileId',
160 ],
161 'LAST_READ' => [
162 'field' => 'lastRead',
163 'set' => 'setLastReadInternal',
164 'get' => 'getLastRead',
165 ],
166 'STATUS' => [
167 'field' => 'status',
168 'set' => 'setStatus',
169 'get' => 'getStatus',
170 ],
171 'CALL_STATUS' => [
172 'field' => 'callStatus',
173 'set' => 'setCallStatus',
174 'get' => 'getCallStatus',
175 ],
176 'MESSAGE_STATUS' => [
177 'field' => 'messageStatus',
178 'set' => 'setMessageStatus',
179 'get' => 'getMessageStatus',
180 ],
181 'NOTIFY_BLOCK' => [
182 'field' => 'notifyBlock',
183 'set' => 'setNotifyBlock',
184 'get' => 'getNotifyBlock',
185 ],
186 'MANAGER' => [
187 'field' => 'manager',
188 'set' => 'setManager',
189 'get' => 'getManager',
190 ],
191 'COUNTER' => [
192 'field' => 'counter',
193 'set' => 'setCounter',
194 'get' => 'getCounter',
195 ],
196 'START_COUNTER' => [
197 'field' => 'startCounter',
198 'set' => 'setStartCounter',
199 'get' => 'getStartCounter',
200 ],
201 ];
202 }
203
204 //region Getters & setters
205
206 public function getId(): ?int
207 {
208 return $this->id;
209 }
210
211 public function setId(?int $id): Relation
212 {
213 $this->id = $id;
214 return $this;
215 }
216
217 public function getChatId(): ?int
218 {
219 return $this->chatId;
220 }
221
222 public function setChatId(?int $chatId): Relation
223 {
224 $this->chatId = $chatId;
225 return $this;
226 }
227
228 public function getMessageType(): ?string
229 {
230 return $this->messageType;
231 }
232
233 public function setMessageType(?string $messageType): Relation
234 {
235 $this->messageType = $messageType;
236 return $this;
237 }
238
239 public function getUserId(): ?int
240 {
241 return $this->userId;
242 }
243
244 public function setUserId(?int $userId): Relation
245 {
246 $this->userId = $userId;
247 return $this;
248 }
249
250 public function getStartId(): ?int
251 {
252 return $this->startId;
253 }
254
255 public function setStartId(?int $startId): Relation
256 {
257 $this->startId = $startId;
258 return $this;
259 }
260
261 public function getUnreadId(): ?int
262 {
263 return $this->unreadId;
264 }
265
266 public function setUnreadId(?int $unreadId): Relation
267 {
268 $this->unreadId = $unreadId;
269 return $this;
270 }
271
272 public function getLastId(): ?int
273 {
274 return $this->lastId;
275 }
276
277 public function setLastId(?int $lastId): Relation
278 {
279 $this->lastId = $lastId;
280 return $this;
281 }
282
283 public function getLastSendId(): ?int
284 {
285 return $this->lastSendId;
286 }
287
288 public function setLastSendId(?int $lastSendId): Relation
289 {
290 $this->lastSendId = $lastSendId;
291 return $this;
292 }
293
294 public function getLastFileId(): ?int
295 {
296 return $this->lastFileId;
297 }
298
299 public function setLastFileId(?int $lastFileId): Relation
300 {
301 $this->lastFileId = $lastFileId;
302 return $this;
303 }
304
305 public function getLastRead(): ?DateTime
306 {
307 return $this->lastRead;
308 }
309
311 {
312 $this->lastRead = $lastRead;
313 return $this;
314 }
315
316 private function setLastReadInternal($lastRead): Relation
317 {
318 $lastReadDateTime = null;
319
320 if ($lastRead instanceof DateTime)
321 {
322 $lastReadDateTime = $lastRead;
323 }
324 elseif (!empty($lastRead))
325 {
326 $lastReadDateTime = DateTime::tryParse($lastRead) ?? DateTime::tryParse($lastRead, 'Y-m-d H:i:s');
327 }
328
329 return $this->setLastRead($lastReadDateTime);
330 }
331
332 public function getStatus(): ?int
333 {
334 return $this->status;
335 }
336
337 public function setStatus(?int $status): Relation
338 {
339 $this->status = $status;
340 return $this;
341 }
342
343 public function getCallStatus(): ?int
344 {
345 return $this->callStatus;
346 }
347
348 public function setCallStatus(?int $callStatus): Relation
349 {
350 $this->callStatus = $callStatus;
351 return $this;
352 }
353
354 public function getMessageStatus(): ?string
355 {
357 }
358
359 public function setMessageStatus(?string $messageStatus): Relation
360 {
361 $this->messageStatus = $messageStatus;
362 return $this;
363 }
364
365 public function getNotifyBlock(): ?bool
366 {
367 return $this->notifyBlock;
368 }
369
370 public function setNotifyBlock(?bool $notifyBlock): Relation
371 {
372 $this->notifyBlock = $notifyBlock;
373 return $this;
374 }
375
376 public function getManager(): ?bool
377 {
378 return $this->manager;
379 }
380
381 public function setManager(?bool $manager): Relation
382 {
383 $this->manager = $manager;
384 return $this;
385 }
386
387 public function getCounter(): ?int
388 {
389 return $this->counter;
390 }
391
392 public function setCounter(?int $counter): Relation
393 {
394 $this->counter = $counter;
395 return $this;
396 }
397
398 public function getStartCounter(): ?int
399 {
400 return $this->startCounter;
401 }
402
404 {
405 $this->startCounter = $startCounter;
406 return $this;
407 }
408
409 //endregion
410}
static getMessageCount($chatId, $userId=null)
Definition chat.php:414
static getInstance($userId=null)
Definition user.php:44
setPrimaryId(int $primaryId)
Definition Relation.php:55
setMessageStatus(?string $messageStatus)
Definition Relation.php:359
setManager(?bool $manager)
Definition Relation.php:381
setLastRead(?DateTime $lastRead)
Definition Relation.php:310
setChatId(?int $chatId)
Definition Relation.php:222
setMessageType(?string $messageType)
Definition Relation.php:233
setLastSendId(?int $lastSendId)
Definition Relation.php:288
setStartId(?int $startId)
Definition Relation.php:255
__construct($source=null)
Definition Relation.php:40
setUserId(?int $userId)
Definition Relation.php:244
setNotifyBlock(?bool $notifyBlock)
Definition Relation.php:370
setStatus(?int $status)
Definition Relation.php:337
setStartCounter(?int $startCounter)
Definition Relation.php:403
setCounter(?int $counter)
Definition Relation.php:392
setLastFileId(?int $lastFileId)
Definition Relation.php:299
setCallStatus(?int $callStatus)
Definition Relation.php:348
setUnreadId(?int $unreadId)
Definition Relation.php:266
fillRestriction(bool $hideHistory, Chat $chat)
Definition Relation.php:82
setLastId(?int $lastId)
Definition Relation.php:277
static mirrorDataEntityFields()
Definition Relation.php:112
static tryParse($timeString, $format=null)
Definition datetime.php:260