Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
messagemapper.php
1
<?php
2
3
namespace
Bitrix\Calendar\Core\Queue\Message
;
4
5
use Bitrix\Calendar\Core;
6
use
Bitrix\Calendar\Core\Mappers\Mapper
;
7
use Bitrix\Calendar\Internals\EO_QueueMessage;
8
use
Bitrix\Calendar\Internals\QueueMessageTable
;
9
use
Bitrix\Main\ArgumentException
;
10
use
Bitrix\Main\ObjectPropertyException
;
11
use
Bitrix\Main\ORM\Query\Result
;
12
use
Bitrix\Main\SystemException
;
13
use
Bitrix\Main\Type\DateTime
;
14
use Exception;
15
16
class
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
}
Bitrix\Calendar\Core\Base\BaseException
Definition
baseexception.php:8
Bitrix\Calendar\Core\Mappers\Mapper
Definition
mapper.php:12
Bitrix\Calendar\Core\Mappers\Mapper\getOneEntityByFilter
getOneEntityByFilter(array $filter)
Bitrix\Calendar\Core\Queue\Message\BuilderMessageFromDataManager
Definition
buildermessagefromdatamanager.php:9
Bitrix\Calendar\Core\Queue\Message\Dictionary\MESSAGE_PARTS
const MESSAGE_PARTS
Definition
dictionary.php:7
Bitrix\Calendar\Core\Queue\Message\MessageMapper
Definition
messagemapper.php:17
Bitrix\Calendar\Core\Queue\Message\MessageMapper\convertToObject
convertToObject($objectEO)
Definition
messagemapper.php:73
Bitrix\Calendar\Core\Queue\Message\MessageMapper\updateEntity
updateEntity($entity, array $params=[])
Definition
messagemapper.php:117
Bitrix\Calendar\Core\Queue\Message\MessageMapper\getEntityName
getEntityName()
Definition
messagemapper.php:81
Bitrix\Calendar\Core\Queue\Message\MessageMapper\getEntityClass
getEntityClass()
Definition
messagemapper.php:22
Bitrix\Calendar\Core\Queue\Message\MessageMapper\deleteEntity
deleteEntity(Core\Base\EntityInterface $entity, array $params)
Definition
messagemapper.php:138
Bitrix\Calendar\Core\Queue\Message\MessageMapper\createEntity
createEntity($entity, array $params=[])
Definition
messagemapper.php:95
Bitrix\Calendar\Core\Queue\Message\MessageMapper\getDataManagerResult
getDataManagerResult(array $params)
Definition
messagemapper.php:36
Bitrix\Calendar\Internals\QueueMessageTable
Definition
queuemessagetable.php:30
Bitrix\Main\ArgumentException
Definition
exception.php:34
Bitrix\Main\ORM\Data\DataManager\getList
static getList(array $parameters=array())
Definition
datamanager.php:441
Bitrix\Main\ORM\Data\DataManager\delete
static delete($primary)
Definition
datamanager.php:1632
Bitrix\Main\ORM\Data\DataManager\add
static add(array $data)
Definition
datamanager.php:874
Bitrix\Main\ORM\Data\DataManager\update
static update($primary, array $data)
Definition
datamanager.php:1246
Bitrix\Main\ORM\Data\Result
Definition
result.php:16
Bitrix\Main\ORM\Query\Result
Definition
result.php:34
Bitrix\Main\ObjectPropertyException
Definition
exception.php:181
Bitrix\Main\SystemException
Definition
exception.php:8
Bitrix\Main\Type\DateTime
Definition
datetime.php:9
Bitrix\Calendar\Core\Base\EntityInterface
Definition
entityinterface.php:6
Bitrix\Calendar\Core\Queue\Interfaces\Message
Definition
message.php:16
Bitrix\Calendar\Core\Queue\Interfaces\Message\getHeaders
getHeaders()
Bitrix\Calendar\Core\Queue\Interfaces\Message\getBody
getBody()
Bitrix\Calendar\Core\Queue\Interfaces\Message\getProperties
getProperties()
Bitrix\Calendar\Core\Queue\Message
Definition
builderhandledmessagefromdatamanager.php:3
modules
calendar
lib
core
queue
message
messagemapper.php
Создано системой
1.10.0