Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
PinItem.php
1<?php
2
4
5use Bitrix\Im\Model\EO_LinkPin;
7use Bitrix\Im\V2\Common\ContextCustomer;
15
19class PinItem extends BaseLinkItem
20{
21 use ContextCustomer;
22
23 public function __construct($source = null)
24 {
25 $this->initByDefault();
26
27 if (!empty($source))
28 {
29 $this->load($source);
30 }
31 }
32
33 public static function getDataClass(): string
34 {
35 return LinkPinTable::class;
36 }
37
38 protected static function getEntityIdFieldName(): string
39 {
40 return 'MESSAGE_ID';
41 }
42
43 public static function getEntityClassName(): string
44 {
45 return Message::class;
46 }
47
48 public static function getRestEntityName(): string
49 {
50 return 'pin';
51 }
52
53 public static function initByEntity(EO_LinkPin $entity): self
54 {
55 $pin = new static($entity);
56
57 if ($entity->getMessage() !== null)
58 {
59 $pin->setEntity(new Message($entity->getMessage()));
60 }
61
62 return $pin;
63 }
64
65 public static function createFromMessage(Message $message, ?Context $context = null): self
66 {
67 $pin = new static();
68 $pin->setContext($context);
69
70 $pin
71 ->setEntity($message)
72 ->setAuthorId($pin->getContext()->getUserId())
73 ->setChatId($message->getChatId())
74 ;
75
76 return $pin;
77 }
78
79 public static function getByMessage(Message $message): ?self
80 {
81 if ($message->getMessageId() === null)
82 {
83 return null;
84 }
85
86 $entity = LinkPinTable::query()
87 ->setSelect(['ID', 'CHAT_ID', 'AUTHOR_ID', 'DATE_CREATE', 'MESSAGE_ID'])
88 ->where('MESSAGE_ID', $message->getMessageId())
89 ->setLimit(1)
90 ->fetchObject()
91 ;
92
93 if ($entity === null)
94 {
95 return null;
96 }
97
98 return static::initByEntity($entity)->setEntity($message);
99 }
100
101 public function toRestFormat(array $option = []): array
102 {
103 return [
104 'id' => $this->getPrimaryId(),
105 'messageId' => $this->getMessageId(),
106 'chatId' => $this->getChatId(),
107 'authorId' => $this->getAuthorId(),
108 'dateCreate' => $this->getDateCreate()->format('c'),
109 ];
110 }
111
112 public function getMessageId(): ?int
113 {
114 return $this->getEntityId();
115 }
116
117 public function setMessageInfo(Message $message): BaseLinkItem
118 {
119 $this->setEntity($message);
120
121 return $this;
122 }
123
124 public function setMessageId(?int $messageId): BaseLinkItem
125 {
126 $this->setEntityId($messageId);
127
128 return parent::setMessageId($messageId);
129 }
130
131 public function getPopupData(array $excludedList = []): PopupData
132 {
133 return new PopupData(
135 $excludedList
136 );
137 }
138}