1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
VoteChangesSender.php
См. документацию.
1<?php
2
4
9
11{
12 private const MAX_ACTION_UUID_LENGTH = 1000;
13
14 public function isAvailable(): bool
15 {
16 return \Bitrix\Main\Loader::includeModule("pull");
17 }
18
19 public function sendStop(
20 int $voteId,
21 int $entityId = 0,
22 string $actionUuid = '',
23 ): void
24 {
25 if (!$this->isAvailable())
26 {
27 return;
28 }
29
30 \CPullWatch::AddToStack($this->getTag($voteId),
31 [
32 "module_id" => "vote",
33 "command" => "stop",
34 "params" => [
35 "voteId" => $voteId,
36 "entityId" => $entityId,
37 "actionUuid" => $this->truncateActionUid($actionUuid),
38 ],
39 ],
40 );
41 }
42
43 public function sendResume(
44 int $voteId,
45 int $entityId = 0,
46 string $actionUuid = '',
47 ): void
48 {
49 if (!$this->isAvailable())
50 {
51 return;
52 }
53
54 \CPullWatch::AddToStack($this->getTag($voteId),
55 [
56 "module_id" => "vote",
57 "command" => "resume",
58 "params" => [
59 "voteId" => $voteId,
60 "entityId" => $entityId,
61 "actionUuid" => $this->truncateActionUid($actionUuid),
62 ],
63 ],
64 );
65 }
66
67 public function sendVoting(Attach $attach, string $actionUuid = ''): void
68 {
69 if (!$this->isAvailable())
70 {
71 return;
72 }
73
74 $voteId = $attach->getVoteId();
75 $isPublicVote = $attach->isPublicVote();
76 $userId = CurrentUser::get()?->getId();
77 $userAnswerMap = $userId ? $attach->getUserEventsAnswersStatByUserId($userId) : [];
78 $questionsUpdateData = $this->getUpdatePullData($attach);
79
80 $params = [
81 'VOTE_ID' => $voteId,
82 'AUTHOR_ID' => $isPublicVote ? $userId : null,
83 'COUNTER' => (int)($attach['COUNTER'] ?? 0),
84 'QUESTIONS' => $questionsUpdateData,
85 'entityId' => (int)$attach->getEntityId(),
86 ];
87
88 if ($isPublicVote && $userId)
89 {
91 $userDto = $provider
92 ->getByUserIds([$userId])
93 ->get($userId)
94 ;
95
96 $params += [
97 'userAnswerMap' => $userAnswerMap,
98 'user' => $userDto,
99 ];
100 }
101
102 \CPullWatch::AddToStack($this->getTag($voteId),
103 [
104 'module_id' => 'vote',
105 'command' => 'voting',
106 'params' => $params,
107 ],
108 );
109
110 if ($userId)
111 {
112 $this->sendToUser(
113 authorId: $userId,
114 attach: $attach,
115 questionsUpdateData: $questionsUpdateData,
116 userAnswerMap: $userAnswerMap,
117 actionUuid: $actionUuid,
118 );
119 }
120 }
121
122 public function addUserWatch(int $userId, int $voteId): bool
123 {
124 if (!$this->isAvailable())
125 {
126 return false;
127 }
128
129 return \CPullWatch::Add($userId, $this->getTag($voteId));
130 }
131
132 private function sendToUser(
133 int $authorId,
134 Attach $attach,
135 array $questionsUpdateData,
136 array $userAnswerMap,
137 string $actionUuid,
138 ): void
139 {
140 if (!$this->isAvailable() || $authorId <= 0)
141 {
142 return;
143 }
144
145 Event::add($authorId, [
146 'module_id' => 'vote',
147 'command' => 'user_vote',
148 'params' => [
149 'VOTE_ID' => (int)$attach->getVoteId(),
150 'AUTHOR_ID' => $authorId,
151 'COUNTER' => (int)($attach['COUNTER'] ?? 0),
152 'QUESTIONS' => $questionsUpdateData,
153 'userAnswerMap' => $userAnswerMap,
154 'entityId' => (int)$attach->getEntityId(),
155 'actionUuid' => $this->truncateActionUid($actionUuid),
156 ],
157 ]);
158 }
159
160 private function getTag(int $voteId): string
161 {
162 return "VOTE_{$voteId}";
163 }
164
165 private function getUpdatePullData(Attach $attach): array
166 {
167 $result = [];
168 foreach ($attach['QUESTIONS'] as $question)
169 {
170 $result[$question['ID']] = [
171 'ANSWERS' => [],
172 'COUNTER' => (int)($question["COUNTER"] ?? 0),
173 ];
174 foreach ($question['ANSWERS'] as $answer)
175 {
176 $result[$question['ID']]['ANSWERS'][$answer['ID']] = [
177 'PERCENT' => $answer['PERCENT'],
178 'USERS' => [], // for compatibility
179 'COUNTER' => (int)($answer['COUNTER'] ?? 0),
180 ];
181 }
182 }
183
184 return $result;
185 }
186
187 private function truncateActionUid(string $actionUuid): string
188 {
189 return mb_substr($actionUuid, 0, self::MAX_ACTION_UUID_LENGTH);
190 }
191}
if(!Loader::includeModule('messageservice')) $provider
Определения callback_ednaruimhpx.php:21
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
Определения event.php:5
Определения attach.php:180
getEntityId()
Определения attach.php:587
isPublicVote()
Определения attach.php:991
getVoteId()
Определения attach.php:563
getUserEventsAnswersStatByUserId(int $userId)
Определения attach.php:895
add(array $eventFields, array $ballot, $setCounter=true)
Определения event.php:612
sendStop(int $voteId, int $entityId=0, string $actionUuid='',)
Определения VoteChangesSender.php:19
addUserWatch(int $userId, int $voteId)
Определения VoteChangesSender.php:122
sendResume(int $voteId, int $entityId=0, string $actionUuid='',)
Определения VoteChangesSender.php:43
sendVoting(Attach $attach, string $actionUuid='')
Определения VoteChangesSender.php:67
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$entityId
Определения payment.php:4
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799