Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
messagemapper.php
1<?php
2
4
5use Bitrix\Calendar\Core;
7use Bitrix\Calendar\Internals\EO_QueueMessage;
14use Exception;
15
16class MessageMapper extends Mapper
17{
18
22 protected function getEntityClass(): string
23 {
24 return Message::class;
25 }
26
36 protected function getDataManagerResult(array $params): Result
37 {
38 $params['select'] = $params['select'] ?? ["*"];
39 return QueueMessageTable::getList($params);
40 }
41
51 protected function getOneEntityByFilter(array $filter): ?object
52 {
54 $messageData = $this->getDataManagerResult([
55 'filter' => $filter,
56 'select' => ['*'],
57 'limit' => 1
58 ])->fetchObject();
59
60 if ($messageData)
61 {
62 return $this->convertToObject($messageData);
63 }
64
65 return null;
66 }
67
73 protected function convertToObject($objectEO): ?Core\Base\EntityInterface
74 {
75 return (new BuilderMessageFromDataManager($objectEO))->build();
76 }
77
81 protected function getEntityName(): string
82 {
83 return 'queueMessage';
84 }
85
95 protected function createEntity($entity, array $params = []): ?Core\Base\EntityInterface
96 {
97 $data = $this->convertToArray($entity);
98 $data['DATE_CREATE'] = new DateTime();
99 $result = QueueMessageTable::add($data);
100 if ($result->isSuccess())
101 {
102 return $entity->setId($result->getId());
103 }
104
105 throw new Core\Base\BaseException('Error of create Queue message', 400);
106 }
107
117 protected function updateEntity($entity, array $params = []): ?Core\Base\EntityInterface
118 {
119 $data = $this->convertToArray($entity);
120 $result = QueueMessageTable::update($entity->getId(), $data);
121 if ($result->isSuccess())
122 {
123 return $entity;
124 }
125
126 throw new Core\Base\BaseException('Error of update Queue message', 400);
127 }
128
138 protected function deleteEntity(Core\Base\EntityInterface $entity, array $params): ?Core\Base\EntityInterface
139 {
140 $result = QueueMessageTable::delete($entity->getId());
141 if ($result->isSuccess())
142 {
143 return null;
144 }
145
146 throw new Core\Base\BaseException('Error of delete Queue message');
147 }
148
154 private function convertToArray(Message $entity): array
155 {
156 return [
157 'MESSAGE' => [
158 Dictionary::MESSAGE_PARTS['body'] => $entity->getBody(),
159 Dictionary::MESSAGE_PARTS['headers'] => $entity->getHeaders(),
160 Dictionary::MESSAGE_PARTS['properties'] => $entity->getProperties(),
161 ],
162 ];
163 }
164}
deleteEntity(Core\Base\EntityInterface $entity, array $params)
static getList(array $parameters=array())
static update($primary, array $data)