Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
ReactionItem.php
1
<?php
2
3
namespace
Bitrix\Im\V2\Message\Reaction
;
4
5
use
Bitrix\Im\Model\ReactionTable
;
6
use
Bitrix\Im\V2\ActiveRecord
;
7
use Bitrix\Im\V2\Common\ActiveRecordImplementation;
8
use Bitrix\Im\V2\Common\ContextCustomer;
9
use Bitrix\Im\V2\Common\RegistryEntryImplementation;
10
use
Bitrix\Im\V2\Entity\User\UserPopupItem
;
11
use
Bitrix\Im\V2\RegistryEntry
;
12
use
Bitrix\Im\V2\Rest\PopupData
;
13
use
Bitrix\Im\V2\Rest\PopupDataAggregatable
;
14
use
Bitrix\Im\V2\Rest\RestConvertible
;
15
use
Bitrix\Im\V2\Result
;
16
use
Bitrix\Main\Localization\Loc
;
17
use
Bitrix\Main\Type\DateTime
;
18
19
class
ReactionItem
implements
RegistryEntry
,
ActiveRecord
,
RestConvertible
,
PopupDataAggregatable
20
{
21
use ContextCustomer;
22
use RegistryEntryImplementation;
23
use ActiveRecordImplementation;
24
25
public
const
LIKE
=
'LIKE'
;
26
public
const
KISS
=
'KISS'
;
27
public
const
LAUGH
=
'LAUGH'
;
28
public
const
WONDER
=
'WONDER'
;
29
public
const
CRY
=
'CRY'
;
30
public
const
ANGRY
=
'ANGRY'
;
31
public
const
FACEPALM
=
'FACEPALM'
;
32
33
public
const
ALLOWED_REACTION
= [
34
self::LIKE
,
35
self::KISS
,
36
self::LAUGH
,
37
self::WONDER
,
38
self::CRY
,
39
self::ANGRY
,
40
self::FACEPALM
,
41
];
42
43
private
int
$id;
44
private
int
$chatId;
45
private
int
$messageId;
46
private
int
$userId;
47
private
string
$reaction;
48
private
DateTime
$dateCreate;
49
50
public
function
__construct
($source =
null
)
51
{
52
$this->initByDefault();
53
54
if
(!empty($source))
55
{
56
$this->
load
($source);
57
}
58
}
59
60
public
static
function
getByMessage
(
int
$messageId,
string
$reaction,
int
$userId): ?self
61
{
62
$reactionObject = ReactionTable::query()
63
->setSelect([
'*'
])
64
->where(
'MESSAGE_ID'
, $messageId)
65
->where(
'REACTION'
, $reaction)
66
->where(
'USER_ID'
, $userId)
67
->fetchObject()
68
;
69
70
if
($reactionObject ===
null
)
71
{
72
return
null
;
73
}
74
75
return
new
static
($reactionObject);
76
}
77
78
public
function
getPopupData
(array $excludedList = []):
PopupData
79
{
80
return
new
PopupData
([
new
UserPopupItem
([$this->
getUserId
()])], $excludedList);
81
}
82
83
public
function
getLocName
(?
string
$languageId =
null
): ?string
84
{
85
return
Loc::getMessage
(
"IM_MESSAGE_REACTION_NAME_{$this->reaction}"
,
null
, $languageId);
86
}
87
88
public
function
getPrimaryId
(): ?int
89
{
90
return
$this->
id
??
null
;
91
}
92
93
public
function
setPrimaryId
(
int
$primaryId): self
94
{
95
$this->
id
= $primaryId;
96
97
return
$this;
98
}
99
100
public
function
getChatId
(): int
101
{
102
return
$this->chatId;
103
}
104
105
public
function
setChatId
(
int
$chatId):
ReactionItem
106
{
107
$this->chatId = $chatId;
108
return
$this;
109
}
110
111
public
function
getMessageId
(): int
112
{
113
return
$this->messageId;
114
}
115
116
public
function
setMessageId
(
int
$messageId):
ReactionItem
117
{
118
$this->messageId = $messageId;
119
return
$this;
120
}
121
122
public
function
getUserId
(): int
123
{
124
return
$this->userId;
125
}
126
127
public
function
setUserId
(
int
$userId):
ReactionItem
128
{
129
$this->userId = $userId;
130
return
$this;
131
}
132
133
public
function
getReaction
(): string
134
{
135
return
$this->reaction;
136
}
137
138
public
function
setReaction
(
string
$reaction):
ReactionItem
139
{
140
$this->reaction = $reaction;
141
return
$this;
142
}
143
144
public
function
getDateCreate
():
DateTime
145
{
146
return
$this->dateCreate;
147
}
148
149
public
function
setDateCreate
(
DateTime
$dateCreate):
ReactionItem
150
{
151
$this->dateCreate = $dateCreate;
152
return
$this;
153
}
154
155
public
function
getDefaultReaction
(): string
156
{
157
return
self::LIKE
;
158
}
159
160
public
function
beforeSaveReaction
():
Result
161
{
162
return
static::validateReaction($this->reaction);
163
}
164
165
public
function
getDefaultDateCreate
():
DateTime
166
{
167
return
new
DateTime
();
168
}
169
170
public
static
function
validateReaction
(
string
$reaction):
Result
171
{
172
$result =
new
Result
();
173
174
if
(!in_array($reaction, self::ALLOWED_REACTION,
true
))
175
{
176
$result->addError(
new
ReactionError
(
ReactionError::NOT_FOUND
));
177
}
178
179
return
$result;
180
}
181
185
protected
static
function
mirrorDataEntityFields
(): array
186
{
187
return
[
188
'ID'
=> [
189
'primary'
=>
true
,
190
'field'
=>
'id'
,
191
'set'
=>
'setPrimaryId'
,
192
'get'
=>
'getPrimaryId'
,
193
],
194
'CHAT_ID'
=> [
195
'field'
=>
'chatId'
,
196
'set'
=>
'setChatId'
,
197
'get'
=>
'getChatId'
,
198
],
199
'MESSAGE_ID'
=> [
200
'field'
=>
'messageId'
,
201
'set'
=>
'setMessageId'
,
202
'get'
=>
'getMessageId'
,
203
],
204
'USER_ID'
=> [
205
'field'
=>
'userId'
,
206
'set'
=>
'setUserId'
,
207
'get'
=>
'getUserId'
,
208
],
209
'REACTION'
=> [
210
'field'
=>
'reaction'
,
211
'set'
=>
'setReaction'
,
212
'get'
=>
'getReaction'
,
213
'default'
=>
'getDefaultReaction'
,
214
'beforeSave'
=>
'beforeSaveReaction'
,
215
],
216
'DATE_CREATE'
=> [
217
'field'
=>
'dateCreate'
,
218
'get'
=>
'getDateCreate'
,
219
'set'
=>
'setDateCreate'
,
220
'default'
=>
'getDefaultDateCreate'
,
221
],
222
];
223
}
224
225
public
static
function
getDataClass
(): string
226
{
227
return
ReactionTable::class;
228
}
229
230
public
static
function
getRestEntityName
(): string
231
{
232
return
'reaction'
;
233
}
234
235
public
function
toRestFormat
(array $option = []): array
236
{
237
return
[
238
'id'
=> $this->
getPrimaryId
(),
239
'messageId'
=> $this->
getMessageId
(),
240
'userId'
=> $this->
getUserId
(),
241
'reaction'
=> $this->
getReaction
(),
242
'dateCreate'
=> $this->
getDateCreate
()->format(
'c'
),
243
];
244
}
245
}
Bitrix\Im\Model\ReactionTable
Definition
reaction.php:42
Bitrix\Im\V2\Entity\User\UserPopupItem
Definition
UserPopupItem.php:8
Bitrix\Im\V2\Message\Reaction\ReactionError
Definition
ReactionError.php:9
Bitrix\Im\V2\Message\Reaction\ReactionError\NOT_FOUND
const NOT_FOUND
Definition
ReactionError.php:10
Bitrix\Im\V2\Message\Reaction\ReactionItem
Definition
ReactionItem.php:20
Bitrix\Im\V2\Message\Reaction\ReactionItem\getChatId
getChatId()
Definition
ReactionItem.php:100
Bitrix\Im\V2\Message\Reaction\ReactionItem\getUserId
getUserId()
Definition
ReactionItem.php:122
Bitrix\Im\V2\Message\Reaction\ReactionItem\getRestEntityName
static getRestEntityName()
Definition
ReactionItem.php:230
Bitrix\Im\V2\Message\Reaction\ReactionItem\setPrimaryId
setPrimaryId(int $primaryId)
Definition
ReactionItem.php:93
Bitrix\Im\V2\Message\Reaction\ReactionItem\ANGRY
const ANGRY
Definition
ReactionItem.php:30
Bitrix\Im\V2\Message\Reaction\ReactionItem\toRestFormat
toRestFormat(array $option=[])
Definition
ReactionItem.php:235
Bitrix\Im\V2\Message\Reaction\ReactionItem\getLocName
getLocName(?string $languageId=null)
Definition
ReactionItem.php:83
Bitrix\Im\V2\Message\Reaction\ReactionItem\getDateCreate
getDateCreate()
Definition
ReactionItem.php:144
Bitrix\Im\V2\Message\Reaction\ReactionItem\KISS
const KISS
Definition
ReactionItem.php:26
Bitrix\Im\V2\Message\Reaction\ReactionItem\ALLOWED_REACTION
const ALLOWED_REACTION
Definition
ReactionItem.php:33
Bitrix\Im\V2\Message\Reaction\ReactionItem\getDefaultReaction
getDefaultReaction()
Definition
ReactionItem.php:155
Bitrix\Im\V2\Message\Reaction\ReactionItem\getPopupData
getPopupData(array $excludedList=[])
Definition
ReactionItem.php:78
Bitrix\Im\V2\Message\Reaction\ReactionItem\__construct
__construct($source=null)
Definition
ReactionItem.php:50
Bitrix\Im\V2\Message\Reaction\ReactionItem\getPrimaryId
getPrimaryId()
Definition
ReactionItem.php:88
Bitrix\Im\V2\Message\Reaction\ReactionItem\getMessageId
getMessageId()
Definition
ReactionItem.php:111
Bitrix\Im\V2\Message\Reaction\ReactionItem\getByMessage
static getByMessage(int $messageId, string $reaction, int $userId)
Definition
ReactionItem.php:60
Bitrix\Im\V2\Message\Reaction\ReactionItem\FACEPALM
const FACEPALM
Definition
ReactionItem.php:31
Bitrix\Im\V2\Message\Reaction\ReactionItem\getDefaultDateCreate
getDefaultDateCreate()
Definition
ReactionItem.php:165
Bitrix\Im\V2\Message\Reaction\ReactionItem\setMessageId
setMessageId(int $messageId)
Definition
ReactionItem.php:116
Bitrix\Im\V2\Message\Reaction\ReactionItem\LAUGH
const LAUGH
Definition
ReactionItem.php:27
Bitrix\Im\V2\Message\Reaction\ReactionItem\setChatId
setChatId(int $chatId)
Definition
ReactionItem.php:105
Bitrix\Im\V2\Message\Reaction\ReactionItem\setUserId
setUserId(int $userId)
Definition
ReactionItem.php:127
Bitrix\Im\V2\Message\Reaction\ReactionItem\getDataClass
static getDataClass()
Definition
ReactionItem.php:225
Bitrix\Im\V2\Message\Reaction\ReactionItem\LIKE
const LIKE
Definition
ReactionItem.php:25
Bitrix\Im\V2\Message\Reaction\ReactionItem\validateReaction
static validateReaction(string $reaction)
Definition
ReactionItem.php:170
Bitrix\Im\V2\Message\Reaction\ReactionItem\setReaction
setReaction(string $reaction)
Definition
ReactionItem.php:138
Bitrix\Im\V2\Message\Reaction\ReactionItem\setDateCreate
setDateCreate(DateTime $dateCreate)
Definition
ReactionItem.php:149
Bitrix\Im\V2\Message\Reaction\ReactionItem\WONDER
const WONDER
Definition
ReactionItem.php:28
Bitrix\Im\V2\Message\Reaction\ReactionItem\getReaction
getReaction()
Definition
ReactionItem.php:133
Bitrix\Im\V2\Message\Reaction\ReactionItem\CRY
const CRY
Definition
ReactionItem.php:29
Bitrix\Im\V2\Message\Reaction\ReactionItem\mirrorDataEntityFields
static mirrorDataEntityFields()
Definition
ReactionItem.php:185
Bitrix\Im\V2\Message\Reaction\ReactionItem\beforeSaveReaction
beforeSaveReaction()
Definition
ReactionItem.php:160
Bitrix\Im\V2\Rest\PopupData
Definition
PopupData.php:6
Bitrix\Im\V2\Result
Definition
Result.php:9
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\Type\DateTime
Definition
datetime.php:9
Bitrix\Im\V2\ActiveRecord
Definition
ActiveRecord.php:8
Bitrix\Im\V2\ActiveRecord\load
load($source)
Bitrix\Im\V2\RegistryEntry
Definition
RegistryEntry.php:6
Bitrix\Im\V2\Rest\PopupDataAggregatable
Definition
PopupDataAggregatable.php:10
Bitrix\Im\V2\Rest\RestConvertible
Definition
RestConvertible.php:6
Bitrix\Im\V2\Message\Reaction
Definition
PushService.php:3
modules
im
lib
V2
Message
Reaction
ReactionItem.php
Создано системой
1.10.0