1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
Relation.php
См. документацию.
1<?php
2
3namespace Bitrix\Im\V2;
4
5use ArrayAccess;
6use Bitrix\Im\Model\RelationTable;
7use Bitrix\Im\V2\Common\ActiveRecordImplementation;
8use Bitrix\Im\V2\Common\ContextCustomer;
9use Bitrix\Im\V2\Common\FieldAccessImplementation;
10use Bitrix\Im\V2\Common\RegistryEntryImplementation;
11use Bitrix\Im\V2\Entity\User\User;
12use Bitrix\Im\V2\Relation\Reason;
13use Bitrix\Im\V2\Rest\RestEntity;
14use Bitrix\Main\Type\DateTime;
15
16class Relation implements ArrayAccess, RegistryEntry, ActiveRecord, RestEntity
17{
18 use FieldAccessImplementation;
19 use ActiveRecordImplementation
20 {
21 prepareFields as protected prepareFieldsDefault;
22 }
23 use RegistryEntryImplementation;
24 use ContextCustomer;
25
26 protected ?int $id = null;
27 protected ?int $chatId = null;
28 protected ?string $messageType = null;
29 protected ?int $userId = null;
30 protected ?int $startId = null;
31 protected ?int $unreadId = null;
32 protected ?int $lastId = null;
33 protected ?int $lastSendId = null;
34 protected ?int $lastSendMessageId = null;
35 protected ?int $lastFileId = null;
36 protected ?DateTime $lastRead = null;
37 protected ?int $status = null;
38 protected ?int $callStatus = null;
39 protected ?string $messageStatus = null;
40 protected ?bool $notifyBlock = null;
41 protected ?bool $manager = null;
42 protected ?int $counter = null;
43 protected ?int $startCounter = null;
44 protected ?User $user = null;
45 protected Reason $reason = Reason::DEFAULT;
46 protected ?bool $isHidden = null;
47 protected bool $isFake = false;
48
49 public function __construct($source = null)
50 {
51 $this->initByDefault();
52
53 if (!empty($source))
54 {
55 $this->load($source);
56 }
57 }
58
59 public function getPrimaryId(): ?int
60 {
61 return $this->getId();
62 }
63
64 public function setPrimaryId(int $primaryId): self
65 {
66 return $this->setId($primaryId);
67 }
68
69 public static function getDataClass(): string
70 {
71 return RelationTable::class;
72 }
73
74 public function getUser(): User
75 {
76 if (isset($this->user))
77 {
78 return $this->user;
79 }
80
81 $this->user = User::getInstance($this->getUserId());
82
83 return $this->user;
84 }
85
86 public function getChat(): Chat
87 {
88 return Chat::getInstance($this->getChatId());
89 }
90
91 public function fillRestriction(bool $hideHistory, Chat $chat): self
92 {
93 if ($hideHistory)
94 {
95 $this
96 ->setStartId($chat->getLastMessageId() + 1)
97 ->setLastFileId($chat->getLastFileId())
98 ->setStartCounter($chat->getMessageCount())
99 ;
100 }
101
102 if (!$hideHistory && $chat->getContext()->getUserId() > 0)
103 {
104 $selfRelation = $chat->getSelfRelation();
105 if ($selfRelation !== null && $selfRelation->getStartId() > 0)
106 {
107 $this
108 ->setStartCounter($selfRelation->getStartId())
109 ->setLastFileId($selfRelation->getLastFileId())
110 ->setStartCounter($selfRelation->getStartCounter())
111 ;
112 }
113 }
114
115 return $this;
116 }
117
118 public function prepareFields(): Result
119 {
120 if ($this->isFake)
121 {
122 return (new Result())->setData(['SKIP_SAVE' => true]);
123 }
124
125 return $this->prepareFieldsDefault();
126 }
127
128 public function toRestFormat(array $option = []): ?array
129 {
130 return [
131 'id' => $this->getId(),
132 'userId' => $this->getUserId(),
133 'chatId' => $this->getChatId(),
134 'isHidden' => $this->isHidden(),
135 'role' => mb_strtolower($this->getRole()),
136 ];
137 }
138
139 public static function getRestEntityName(): string
140 {
141 return 'relation';
142 }
143
147 protected static function mirrorDataEntityFields(): array
148 {
149 return [
150 'ID' => [
151 'primary' => true,
152 'field' => 'id',
153 'set' => 'setId',
154 'get' => 'getId',
155 ],
156 'CHAT_ID' => [
157 'field' => 'chatId',
158 'set' => 'setChatId',
159 'get' => 'getChatId',
160 ],
161 'MESSAGE_TYPE' => [
162 'field' => 'messageType',
163 'set' => 'setMessageType',
164 'get' => 'getMessageType',
165 ],
166 'USER_ID' => [
167 'field' => 'userId',
168 'set' => 'setUserId',
169 'get' => 'getUserId',
170 ],
171 'START_ID' => [
172 'field' => 'startId',
173 'set' => 'setStartId',
174 'get' => 'getStartId',
175 ],
176 'UNREAD_ID' => [
177 'field' => 'unreadId',
178 'set' => 'setUnreadId',
179 'get' => 'getUnreadId',
180 ],
181 'LAST_ID' => [
182 'field' => 'lastId',
183 'set' => 'setLastId',
184 'get' => 'getLastId',
185 ],
186 'LAST_SEND_ID' => [
187 'field' => 'lastSendId',
188 'set' => 'setLastSendId',
189 'get' => 'getLastSendId',
190 ],
191 'LAST_SEND_MESSAGE_ID' => [
192 'field' => 'lastSendMessageId',
193 'set' => 'setLastSendMessageId',
194 'get' => 'getLastSendMessageId',
195 ],
196 'LAST_FILE_ID' => [
197 'field' => 'lastFileId',
198 'set' => 'setLastFileId',
199 'get' => 'getLastFileId',
200 ],
201 'LAST_READ' => [
202 'field' => 'lastRead',
203 'set' => 'setLastReadInternal',
204 'get' => 'getLastRead',
205 ],
206 'STATUS' => [
207 'field' => 'status',
208 'set' => 'setStatus',
209 'get' => 'getStatus',
210 ],
211 'CALL_STATUS' => [
212 'field' => 'callStatus',
213 'set' => 'setCallStatus',
214 'get' => 'getCallStatus',
215 ],
216 'MESSAGE_STATUS' => [
217 'field' => 'messageStatus',
218 'set' => 'setMessageStatus',
219 'get' => 'getMessageStatus',
220 ],
221 'NOTIFY_BLOCK' => [
222 'field' => 'notifyBlock',
223 'set' => 'setNotifyBlock',
224 'get' => 'getNotifyBlock',
225 ],
226 'MANAGER' => [
227 'field' => 'manager',
228 'set' => 'setManager',
229 'get' => 'getManager',
230 ],
231 'COUNTER' => [
232 'field' => 'counter',
233 'set' => 'setCounter',
234 'get' => 'getCounter',
235 ],
236 'START_COUNTER' => [
237 'field' => 'startCounter',
238 'set' => 'setStartCounter',
239 'get' => 'getStartCounter',
240 ],
241 'REASON' => [
242 'field' => 'reason',
243 'set' => 'setReason',
244 'get' => 'getReason',
245 'loadFilter' => 'prepareReasonForLoad',
246 'saveFilter' => 'prepareReasonForSave',
247 ],
248 'IS_HIDDEN' => [
249 'field' => 'isHidden',
250 'set' => 'markAsHidden',
251 'get' => 'isHidden',
252 ],
253 ];
254 }
255
256 //region Getters & setters
257
258 public function getId(): ?int
259 {
260 return $this->id;
261 }
262
263 public function setId(?int $id): Relation
264 {
265 $this->id = $id;
266 return $this;
267 }
268
269 public function getChatId(): ?int
270 {
271 return $this->chatId;
272 }
273
274 public function setChatId(?int $chatId): Relation
275 {
276 $this->chatId = $chatId;
277 return $this;
278 }
279
280 public function getMessageType(): ?string
281 {
282 return $this->messageType;
283 }
284
285 public function setMessageType(?string $messageType): Relation
286 {
287 $this->messageType = $messageType;
288 return $this;
289 }
290
291 public function getUserId(): ?int
292 {
293 return $this->userId;
294 }
295
296 public function setUserId(?int $userId): Relation
297 {
298 $this->userId = $userId;
299 return $this;
300 }
301
302 public function getStartId(): ?int
303 {
304 return $this->startId;
305 }
306
307 public function setStartId(?int $startId): Relation
308 {
309 $this->startId = $startId;
310 return $this;
311 }
312
313 public function getUnreadId(): ?int
314 {
315 return $this->unreadId;
316 }
317
318 public function setUnreadId(?int $unreadId): Relation
319 {
320 $this->unreadId = $unreadId;
321 return $this;
322 }
323
324 public function getLastId(): ?int
325 {
326 return $this->lastId;
327 }
328
329 public function setLastId(?int $lastId): Relation
330 {
331 $this->lastId = $lastId;
332 return $this;
333 }
334
335 public function getLastSendId(): ?int
336 {
337 return $this->lastSendId;
338 }
339
340 public function setLastSendId(?int $lastSendId): Relation
341 {
342 $this->lastSendId = $lastSendId;
343 return $this;
344 }
345
346 public function getLastSendMessageId(): ?int
347 {
348 return $this->lastSendMessageId;
349 }
350
352 {
353 $this->lastSendMessageId = $lastSendMessageId;
354 return $this;
355 }
356
357 public function getLastFileId(): ?int
358 {
359 return $this->lastFileId;
360 }
361
362 public function setLastFileId(?int $lastFileId): Relation
363 {
364 $this->lastFileId = $lastFileId;
365 return $this;
366 }
367
368 public function getLastRead(): ?DateTime
369 {
370 return $this->lastRead;
371 }
372
374 {
375 $this->lastRead = $lastRead;
376 return $this;
377 }
378
379 private function setLastReadInternal($lastRead): Relation
380 {
381 $lastReadDateTime = null;
382
383 if ($lastRead instanceof DateTime)
384 {
385 $lastReadDateTime = $lastRead;
386 }
387 elseif (!empty($lastRead))
388 {
389 $lastReadDateTime = DateTime::tryParse($lastRead) ?? DateTime::tryParse($lastRead, 'Y-m-d H:i:s');
390 }
391
392 return $this->setLastRead($lastReadDateTime);
393 }
394
395 public function getStatus(): ?int
396 {
397 return $this->status;
398 }
399
400 public function setStatus(?int $status): Relation
401 {
402 $this->status = $status;
403 return $this;
404 }
405
406 public function getCallStatus(): ?int
407 {
408 return $this->callStatus;
409 }
410
411 public function setCallStatus(?int $callStatus): Relation
412 {
413 $this->callStatus = $callStatus;
414 return $this;
415 }
416
417 public function getMessageStatus(): ?string
418 {
419 return $this->messageStatus;
420 }
421
422 public function setMessageStatus(?string $messageStatus): Relation
423 {
424 $this->messageStatus = $messageStatus;
425 return $this;
426 }
427
428 public function getNotifyBlock(): ?bool
429 {
430 return $this->notifyBlock;
431 }
432
433 public function setNotifyBlock(?bool $notifyBlock): Relation
434 {
435 $this->notifyBlock = $notifyBlock;
436 return $this;
437 }
438
439 public function getManager(): ?bool
440 {
441 return $this->manager;
442 }
443
444 public function setManager(?bool $manager): Relation
445 {
446 $this->manager = $manager;
447 return $this;
448 }
449
450 public function getCounter(): ?int
451 {
452 return $this->counter;
453 }
454
455 public function setCounter(?int $counter): Relation
456 {
457 $this->counter = $counter;
458 return $this;
459 }
460
461 public function getStartCounter(): ?int
462 {
463 return $this->startCounter;
464 }
465
467 {
468 $this->startCounter = $startCounter;
469 return $this;
470 }
471
472 public function getReason(): Reason
473 {
474 return $this->reason;
475 }
476
477 public function setReason(Reason $reason): self
478 {
479 $this->reason = $reason;
480
481 return $this;
482 }
483
484 public function prepareReasonForLoad(string $reason): Reason
485 {
486 return Reason::tryFrom($reason) ?? Reason::DEFAULT;
487 }
488
489 public function prepareReasonForSave(Reason $reason): string
490 {
491 return $reason->value;
492 }
493
494 public function isHidden(): ?bool
495 {
496 return $this->isHidden;
497 }
498
499 public function markAsHidden(?bool $isHidden): Relation
500 {
501 $this->isHidden = $isHidden;
502 return $this;
503 }
504
505 public function getRole(): string
506 {
507 if (!$this->getId())
508 {
509 return Chat::ROLE_GUEST;
510 }
511 if ($this->getManager())
512 {
513 return Chat::ROLE_MANAGER;
514 }
515 if ($this->getChat()->getAuthorId() === $this->getUserId())
516 {
517 return Chat::ROLE_OWNER;
518 }
519
520 return Chat::ROLE_MEMBER;
521 }
522
523 public function markAsFake(): self
524 {
525 $this->isFake = true;
526
527 return $this;
528 }
529
530 //endregion
531}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static getMessageCount($chatId, $userId=null)
Определения chat.php:363
static getInstance($userId=null)
Определения user.php:45
setId(?int $id)
Определения Relation.php:263
getChatId()
Определения Relation.php:269
getUserId()
Определения Relation.php:291
static getRestEntityName()
Определения Relation.php:139
int $status
Определения Relation.php:37
setPrimaryId(int $primaryId)
Определения Relation.php:64
getMessageStatus()
Определения Relation.php:417
getRole()
Определения Relation.php:505
setMessageStatus(?string $messageStatus)
Определения Relation.php:422
getId()
Определения Relation.php:258
setManager(?bool $manager)
Определения Relation.php:444
int $startCounter
Определения Relation.php:43
int $startId
Определения Relation.php:30
toRestFormat(array $option=[])
Определения Relation.php:128
bool $isHidden
Определения Relation.php:46
int $lastSendMessageId
Определения Relation.php:34
setLastRead(?DateTime $lastRead)
Определения Relation.php:373
getStartCounter()
Определения Relation.php:461
setChatId(?int $chatId)
Определения Relation.php:274
setMessageType(?string $messageType)
Определения Relation.php:285
int $id
Определения Relation.php:26
User $user
Определения Relation.php:44
getManager()
Определения Relation.php:439
setLastSendId(?int $lastSendId)
Определения Relation.php:340
setReason(Reason $reason)
Определения Relation.php:477
setStartId(?int $startId)
Определения Relation.php:307
__construct($source=null)
Определения Relation.php:49
setUserId(?int $userId)
Определения Relation.php:296
getPrimaryId()
Определения Relation.php:59
getUnreadId()
Определения Relation.php:313
int $lastFileId
Определения Relation.php:35
string $messageType
Определения Relation.php:28
prepareReasonForSave(Reason $reason)
Определения Relation.php:489
bool $manager
Определения Relation.php:41
setNotifyBlock(?bool $notifyBlock)
Определения Relation.php:433
getCounter()
Определения Relation.php:450
prepareReasonForLoad(string $reason)
Определения Relation.php:484
int $userId
Определения Relation.php:29
int $chatId
Определения Relation.php:27
int $lastSendId
Определения Relation.php:33
getChat()
Определения Relation.php:86
getLastSendMessageId()
Определения Relation.php:346
getCallStatus()
Определения Relation.php:406
getMessageType()
Определения Relation.php:280
int $callStatus
Определения Relation.php:38
getStatus()
Определения Relation.php:395
setStatus(?int $status)
Определения Relation.php:400
markAsFake()
Определения Relation.php:523
setStartCounter(?int $startCounter)
Определения Relation.php:466
setCounter(?int $counter)
Определения Relation.php:455
string $messageStatus
Определения Relation.php:39
setLastFileId(?int $lastFileId)
Определения Relation.php:362
getLastSendId()
Определения Relation.php:335
setLastSendMessageId(?int $lastSendMessageId)
Определения Relation.php:351
setCallStatus(?int $callStatus)
Определения Relation.php:411
setUnreadId(?int $unreadId)
Определения Relation.php:318
getStartId()
Определения Relation.php:302
Reason $reason
Определения Relation.php:45
getReason()
Определения Relation.php:472
static getDataClass()
Определения Relation.php:69
fillRestriction(bool $hideHistory, Chat $chat)
Определения Relation.php:91
int $unreadId
Определения Relation.php:31
isHidden()
Определения Relation.php:494
Reason
Определения Reason.php:6
getLastId()
Определения Relation.php:324
DateTime $lastRead
Определения Relation.php:36
bool $notifyBlock
Определения Relation.php:40
setLastId(?int $lastId)
Определения Relation.php:329
getNotifyBlock()
Определения Relation.php:428
int $counter
Определения Relation.php:42
getLastRead()
Определения Relation.php:368
getUser()
Определения Relation.php:74
markAsHidden(?bool $isHidden)
Определения Relation.php:499
bool $isFake
Определения Relation.php:47
int $lastId
Определения Relation.php:32
static mirrorDataEntityFields()
Определения Relation.php:147
getLastFileId()
Определения Relation.php:357
prepareFields()
Определения Relation.php:118
static getInstance()
Определения application.php:98
Определения result.php:20
if(!\Bitrix\Main\Loader::includeModule('clouds')) $lastId
Определения sync.php:68
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
Определения RegistryEntry.php:6
$status
Определения session.php:10
$user
Определения mysql_to_pgsql.php:33
$manager
Определения office365push.php:39
$counter
Определения options.php:5
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$option
Определения options.php:1711