Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
switcher.php
1<?php
2
4
14
15class Switcher extends Controller
16{
17 private int $userId;
18
22 public function getAutoWiredParameters(): array
23 {
24 return [
26 SwitcherInterface::class,
27 'switcher',
28 fn (string $className, array $switcher): SwitcherInterface =>
29 SwitcherFactory::get($switcher['type'], $this->userId, $switcher['spaceId'])
30 ),
33 'space',
34 fn (string $className, int $space): Space => (new Space())->setId($space)
35 )
36 ];
37 }
38
42 public function pinAction(SwitcherInterface $switcher, Space $space): ?array
43 {
44 $result = $switcher->switch();
45 if (!$result->isSuccess())
46 {
47 $this->addErrors($result->getErrors());
48 return null;
49 }
50
51 $this->sendPush(
52 PushEventDictionary::EVENT_WORKGROUP_PIN_CHANGED,
53 $space->getId(),
54 $switcher->isEnabled() ? 'pin' : 'unpin'
55 );
56
57 return [
58 'mode' => $result->getData()['value'],
59 'message' => $result->getData()['message'],
60 ];
61 }
62
66 public function followAction(SwitcherInterface $switcher, Space $space): ?array
67 {
68 $result = $switcher->switch();
69 if (!$result->isSuccess())
70 {
71 $this->addErrors($result->getErrors());
72 return null;
73 }
74
75 $this->sendPush(PushEventDictionary::EVENT_WORKGROUP_SUBSCRIBE_CHANGED, $space->getId());
76
77 return [
78 'mode' => $result->getData()['value'],
79 'message' => $result->getData()['message'],
80 ];
81 }
82
86 public function trackAction(SwitcherInterface $switcher, Space $space): ?array
87 {
88 $result = $switcher->switch();
89 if (!$result->isSuccess())
90 {
91 $this->addErrors($result->getErrors());
92 return null;
93 }
94
95 return [
96 'mode' => $result->getData()['value'],
97 ];
98 }
99
100 protected function init(): void
101 {
102 parent::init();
103 $this->userId = CurrentUser::get()->getId();
104 }
105
106 private function sendPush(string $command, int $spaceId, string $action = ''): void
107 {
108 $parameters = [
109 'GROUP_ID' => $spaceId,
110 'USER_ID' => $this->userId,
111 ];
112 if (!empty($action))
113 {
114 $parameters['ACTION'] = $action;
115 }
116
117 PushService::addEvent(
118 [$this->userId],
119 [
120 'module_id' => 'socialnetwork',
121 'command' => $command,
122 'params' => $parameters,
123 ]
124 );
125 }
126}
followAction(SwitcherInterface $switcher, Space $space)
Definition switcher.php:66
pinAction(SwitcherInterface $switcher, Space $space)
Definition switcher.php:42
trackAction(SwitcherInterface $switcher, Space $space)
Definition switcher.php:86