Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
event.php
1
<?php
2
3
namespace
Bitrix\Socialnetwork\Internals\EventService
;
4
5
use
Bitrix\Socialnetwork\Internals\EventService\Recepients\Recepient
;
6
use
Bitrix\Socialnetwork\Internals\EventService\Recepients\RecepientCollection
;
7
use
Bitrix\Socialnetwork\Internals\EventService\Recepients\SonetRightsRecepient
;
8
15
class
Event
16
{
17
protected
int
|
null
$eventId
=
null
;
18
protected
array
$data
= [];
19
20
public
function
__construct
(
21
protected
string
$hitId,
22
protected
string
$type =
''
23
)
24
{
25
26
}
27
28
public
function
setId
(
int
$eventId): self
29
{
30
$this->eventId = $eventId;
31
32
return
$this;
33
}
34
35
public
function
setData
(array $data = []): self
36
{
37
$this->data = $this->
prepareData
($data);
38
39
return
$this;
40
}
41
42
public
function
getId
(): int|null
43
{
44
return
$this->eventId;
45
}
46
47
public
function
getType
(): string
48
{
49
return
$this->type;
50
}
51
52
public
function
getData
(): array
53
{
54
return
$this->data;
55
}
56
57
public
function
getUserId
(): int
58
{
59
return
(
int
)($this->data[
'USER_ID'
] ?? 0);
60
}
61
62
public
function
getGroupId
(): int
63
{
64
return
(
int
)($this->data[
'GROUP_ID'
] ?? 0);
65
}
66
67
public
function
getHash
(): string
68
{
69
return
md5($this->hitId . $this->type . json_encode($this->data));
70
}
71
72
protected
function
prepareData
(array $data = []): array
73
{
74
$validFields = [
75
'GROUP_ID'
,
76
'NAME'
,
77
'PROJECT_DATE_START'
,
78
'PROJECT_DATE_FINISH'
,
79
'IMAGE_ID'
,
80
'AVATAR_TYPE'
,
81
'OPENED'
,
82
'CLOSED'
,
83
'VISIBLE'
,
84
'PROJECT'
,
85
'KEYWORDS'
,
86
'USER_ID'
,
87
'TITLE'
,
88
'RECEPIENTS'
,
89
'SONET_LOG_ID'
,
90
'SONET_LOG_COMMENT_ID'
,
91
'FEATURE_ID'
,
92
'SPACE_ID'
,
93
'TYPE_ID'
,
94
'ENTITY_ID'
,
95
];
96
97
foreach
($data as $key => $row)
98
{
99
if
(!in_array($key, $validFields,
true
))
100
{
101
unset($data[$key]);
102
}
103
}
104
105
return
$data;
106
}
107
108
public
function
getRecepients
(): \Iterator
109
{
110
$eventType = $this->
getType
();
111
$data = $this->
getData
();
112
113
switch
($eventType)
114
{
115
case
EventDictionary::EVENT_SPACE_LIVEFEED_POST_VIEW
:
116
return
new
RecepientCollection
(...[
new
Recepient
($data[
'USER_ID'
])]);
117
case
EventDictionary::EVENT_SPACE_LIVEFEED_POST_ADD
:
118
case
EventDictionary::EVENT_SPACE_LIVEFEED_POST_UPD
:
119
case
EventDictionary::EVENT_SPACE_LIVEFEED_POST_DEL
:
120
case
EventDictionary::EVENT_SPACE_LIVEFEED_COMMENT_ADD
:
121
case
EventDictionary::EVENT_SPACE_LIVEFEED_COMMENT_UPD
:
122
case
EventDictionary::EVENT_SPACE_LIVEFEED_COMMENT_DEL
:
123
return
new
SonetRightsRecepient
($data[
'SONET_LOG_ID'
]);
124
default
:
125
// in case recepient ids are defined
126
if
(isset($data[
'RECEPIENTS'
]) && is_array($data[
'RECEPIENTS'
]))
127
{
128
$recepients = [];
129
foreach
($data[
'RECEPIENTS'
] as $id)
130
{
131
$recepients[] =
new
Recepient
($id);
132
}
133
return
new
RecepientCollection
(...$recepients);
134
}
135
136
// in case there is one recepient
137
if
(isset($data[
'USER_ID'
]))
138
{
139
return
new
RecepientCollection
(...[
new
Recepient
($data[
'USER_ID'
])]);
140
}
141
}
142
143
return
new
RecepientCollection
(...[]);
144
}
145
146
public
function
collectNewData
(): void
147
{
148
return
;
149
}
150
151
public
function
getOldFields
(): array
152
{
153
return
[];
154
}
155
156
public
function
getNewFields
(): array
157
{
158
return
[];
159
}
160
}
Bitrix\Main\Event
Definition
event.php:5
Bitrix\Socialnetwork\Internals\EventService\EventDictionary\EVENT_SPACE_LIVEFEED_COMMENT_ADD
const EVENT_SPACE_LIVEFEED_COMMENT_ADD
Definition
eventdictionary.php:45
Bitrix\Socialnetwork\Internals\EventService\EventDictionary\EVENT_SPACE_LIVEFEED_COMMENT_DEL
const EVENT_SPACE_LIVEFEED_COMMENT_DEL
Definition
eventdictionary.php:47
Bitrix\Socialnetwork\Internals\EventService\EventDictionary\EVENT_SPACE_LIVEFEED_POST_ADD
const EVENT_SPACE_LIVEFEED_POST_ADD
Definition
eventdictionary.php:41
Bitrix\Socialnetwork\Internals\EventService\EventDictionary\EVENT_SPACE_LIVEFEED_POST_VIEW
const EVENT_SPACE_LIVEFEED_POST_VIEW
Definition
eventdictionary.php:44
Bitrix\Socialnetwork\Internals\EventService\EventDictionary\EVENT_SPACE_LIVEFEED_POST_UPD
const EVENT_SPACE_LIVEFEED_POST_UPD
Definition
eventdictionary.php:42
Bitrix\Socialnetwork\Internals\EventService\EventDictionary\EVENT_SPACE_LIVEFEED_POST_DEL
const EVENT_SPACE_LIVEFEED_POST_DEL
Definition
eventdictionary.php:43
Bitrix\Socialnetwork\Internals\EventService\EventDictionary\EVENT_SPACE_LIVEFEED_COMMENT_UPD
const EVENT_SPACE_LIVEFEED_COMMENT_UPD
Definition
eventdictionary.php:46
Bitrix\Socialnetwork\Internals\EventService\Event\getUserId
getUserId()
Definition
event.php:57
Bitrix\Socialnetwork\Internals\EventService\Event\prepareData
prepareData(array $data=[])
Definition
event.php:72
Bitrix\Socialnetwork\Internals\EventService\Event\getHash
getHash()
Definition
event.php:67
Bitrix\Socialnetwork\Internals\EventService\Event\getId
getId()
Definition
event.php:42
Bitrix\Socialnetwork\Internals\EventService\Event\$data
array $data
Definition
event.php:18
Bitrix\Socialnetwork\Internals\EventService\Event\collectNewData
collectNewData()
Definition
event.php:146
Bitrix\Socialnetwork\Internals\EventService\Event\$eventId
int null $eventId
Definition
event.php:17
Bitrix\Socialnetwork\Internals\EventService\Event\getOldFields
getOldFields()
Definition
event.php:151
Bitrix\Socialnetwork\Internals\EventService\Event\getGroupId
getGroupId()
Definition
event.php:62
Bitrix\Socialnetwork\Internals\EventService\Event\getData
getData()
Definition
event.php:52
Bitrix\Socialnetwork\Internals\EventService\Event\getType
getType()
Definition
event.php:47
Bitrix\Socialnetwork\Internals\EventService\Event\getNewFields
getNewFields()
Definition
event.php:156
Bitrix\Socialnetwork\Internals\EventService\Event\getRecepients
getRecepients()
Definition
event.php:108
Bitrix\Socialnetwork\Internals\EventService\Event\setData
setData(array $data=[])
Definition
event.php:35
Bitrix\Socialnetwork\Internals\EventService\Event\setId
setId(int $eventId)
Definition
event.php:28
Bitrix\Socialnetwork\Internals\EventService\Event\__construct
__construct(protected string $hitId, protected string $type='')
Definition
event.php:20
Bitrix\Socialnetwork\Internals\EventService\Recepients\RecepientCollection
Definition
recepientcollection.php:6
Bitrix\Socialnetwork\Internals\EventService\Recepients\Recepient
Definition
recepient.php:6
Bitrix\Socialnetwork\Internals\EventService\Recepients\SonetRightsRecepient
Definition
sonetrightsrecepient.php:11
Bitrix\Socialnetwork\Internals\EventService
Definition
cleanagent.php:3
modules
socialnetwork
lib
internals
eventservice
event.php
Создано системой
1.10.0