Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
handledmessagemapper.php
1<?php
2
4
5use Bitrix\Calendar\Core;
7use Bitrix\Calendar\Internals\EO_QueueHandledMessage;
15use Exception;
16
18{
22 protected function getEntityClass(): string
23 {
24 return HandledMessage::class;
25 }
26
35 protected function getDataManagerResult(array $params): Result
36 {
37 $params['select'] = $params['select'] ?
38 array_merge($params['select'], ['MESSAGE'])
39 : ["*", 'MESSAGE'];
40 $params['select'] = array_unique($params['select']);
41
42 return QueueHandledMessageTable::getList($params);
43 }
44
54 protected function getOneEntityByFilter(array $filter): ?object
55 {
57 $data = $this->getDataManagerResult([
58 'filter' => $filter,
59 'select' => ['*', 'MESSAGE'],
60 'limit' => 1
61 ])->fetchObject();
62
63 if ($data)
64 {
65 return $this->convertToObject($data);
66 }
67
68 return null;
69 }
70
78 protected function convertToObject($objectEO): ?Core\Base\EntityInterface
79 {
80 return (new BuilderHandledMessageFromDataManager($objectEO))->build();
81 }
82
86 protected function getEntityName(): string
87 {
88 return 'handledQueueMessage';
89 }
90
100 protected function createEntity($entity, array $params = []): ?Core\Base\EntityInterface
101 {
102 $data = $this->convertToArray($entity);
103 $data['DATE_CREATE'] = new DateTime();
104 $result = QueueHandledMessageTable::add($data);
105 if ($result->isSuccess())
106 {
107 return $entity->setId($result->getId());
108 }
109
110 throw new Core\Base\BaseException('Error of create Queue handled message', 400);
111 }
112
121 protected function updateEntity($entity, array $params = []): ?Core\Base\EntityInterface
122 {
123 $data = $this->convertToArray($entity);
124 $result = QueueHandledMessageTable::update($entity->getId(), $data);
125 if ($result->isSuccess())
126 {
127 return $entity;
128 }
129
130 throw new Core\Base\BaseException('Error of update Queue handled message', 400);
131
132 }
133
142 protected function deleteEntity(Core\Base\EntityInterface $entity, array $params): ?Core\Base\EntityInterface
143 {
144
145 $result = QueueHandledMessageTable::delete($entity->getId());
146 if ($result->isSuccess())
147 {
148 return null;
149 }
150
151 throw new Core\Base\BaseException('Error of delete Queue handled message');
152 }
153
159 private function convertToArray(HandledMessage $entity): array
160 {
161 return [
162 'MESSAGE_ID' => $entity->getMessage()->getId(),
163 'QUEUE_ID' => $entity->getQueue()->getQueueId(),
164 'HASH' => $entity->getHash(),
165 ];
166 }
167}
deleteEntity(Core\Base\EntityInterface $entity, array $params)