Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
event.php
1<?php
2
4
8
15class 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 {
116 return new RecepientCollection(...[new Recepient($data['USER_ID'])]);
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}
__construct(protected string $hitId, protected string $type='')
Definition event.php:20