Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
ReminderItem.php
1<?php
2
4
5use Bitrix\Im\Model\EO_LinkReminder;
7use Bitrix\Im\V2\Common\ContextCustomer;
15
20{
21 use ContextCustomer;
22
24 protected bool $isReminded;
25
26 public function __construct($source = null)
27 {
28 $this->initByDefault();
29
30 if (!empty($source))
31 {
32 $this->load($source);
33 }
34 }
35
36 public static function getDataClass(): string
37 {
38 return LinkReminderTable::class;
39 }
40
41 public static function getEntityClassName(): string
42 {
43 return Message::class;
44 }
45
46 protected static function getEntityIdFieldName(): string
47 {
48 return 'MESSAGE_ID';
49 }
50
51 public static function getRestEntityName(): string
52 {
53 return 'link';
54 }
55
56 public static function initByEntity(EO_LinkReminder $entity): self
57 {
58 $reminder = new static($entity);
59
60 if ($entity->getMessage() !== null)
61 {
62 $reminder->setEntity(new Message($entity->getMessage()));
63 }
64
65 return $reminder;
66 }
67
68 public static function createFromMessage(Message $message, ?Context $context = null): self
69 {
70 $reminder = new static();
71 $reminder->setContext($context);
72
73 $reminder
74 ->setEntity($message)
75 ->setAuthorId($reminder->getContext()->getUserId())
76 ->setChatId($message->getChatId())
77 ;
78
79 return $reminder;
80 }
81
82 public static function getByMessageAndUserId(Message $message, int $userId): ?self
83 {
85 ->setSelect(['ID', 'CHAT_ID', 'AUTHOR_ID', 'DATE_CREATE', 'MESSAGE_ID', 'DATE_REMIND', 'IS_REMINDED'])
86 ->where('MESSAGE_ID', $message->getMessageId())
87 ->where('AUTHOR_ID', $userId)
88 ->setLimit(1)
89 ->fetchObject()
90 ;
91
92 if ($entity === null)
93 {
94 return null;
95 }
96
97 return static::initByEntity($entity)->setEntity($message);
98 }
99
100 public static function linkEntityToMessage(RestEntity $entity, Message $message): BaseLinkItem
101 {
102 throw new NotImplementedException();
103 }
104
105 public function setMessageInfo(Message $message): BaseLinkItem
106 {
107 $this->setEntity($message);
108
109 return $this;
110 }
111
112 public function setMessageId(?int $messageId): BaseLinkItem
113 {
114 $this->setEntityId($messageId);
115
116 return parent::setMessageId($messageId);
117 }
118
119 public function toRestFormat(array $option = []): array
120 {
121 $message = null;
122 if (!isset($option['WITHOUT_MESSAGES']) || $option['WITHOUT_MESSAGES'] === 'N')
123 {
124 $message = $this->getEntity()->toRestFormat();
125 }
126 return [
127 'id' => $this->getPrimaryId(),
128 'messageId' => $this->getMessageId(),
129 'chatId' => $this->getChatId(),
130 'authorId' => $this->getAuthorId(),
131 'dateCreate' => $this->getDateCreate()->format('c'),
132 'dateRemind' => $this->getDateRemind()->format('c'),
133 'isReminded' => $this->isReminded(),
134 'message' => $message,
135 ];
136 }
137
138 public function getMessageId(): ?int
139 {
140 return $this->getEntityId();
141 }
142
143 public function getPopupData(array $excludedList = []): PopupData
144 {
145 $excludedList[] = ReminderPopupItem::class;
146
147 return parent::getPopupData($excludedList);
148 }
149
150 protected static function mirrorDataEntityFields(): array
151 {
152 $additionalFields = [
153 'DATE_REMIND' => [
154 'field' => 'dateRemind',
155 'set' => 'setDateRemind',
156 'get' => 'getDateRemind',
157 ],
158 'IS_REMINDED' => [
159 'field' => 'isReminded',
160 'set' => 'setIsReminded',
161 'get' => 'isReminded',
162 ],
163 ];
164
165 return array_merge(parent::mirrorDataEntityFields(), $additionalFields);
166 }
167
168 //region Getters & setters
169
170 public function getDateRemind(): DateTime
171 {
172 return $this->dateRemind;
173 }
174
176 {
177 $this->dateRemind = $dateRemind;
178 return $this;
179 }
180
181 public function isReminded(): bool
182 {
183 return $this->isReminded;
184 }
185
187 {
188 $this->isReminded = $isReminded;
189 return $this;
190 }
191
192 //endregion
193}