1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
switcher.php
См. документацию.
1<?php
2
3namespace Bitrix\Socialnetwork\Controller\Livefeed\Spaces;
4
5use Bitrix\Main\Engine\AutoWire\BinderArgumentException;
6use Bitrix\Main\Engine\AutoWire\ExactParameter;
7use Bitrix\Main\Engine\Controller;
8use Bitrix\Main\Engine\CurrentUser;
9use Bitrix\Socialnetwork\Integration\Pull\PushService;
10use Bitrix\Socialnetwork\Internals\EventService\Push\PushEventDictionary;
11use Bitrix\Socialnetwork\Space\List\Item\Space;
12use Bitrix\Socialnetwork\Space\Toolbar\Switcher\Factory\SwitcherFactory;
13use Bitrix\Socialnetwork\Space\Toolbar\Switcher\SwitcherInterface;
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 ),
32 Space::class,
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(
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
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}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
addErrors(array $errors)
Определения controller.php:1083
followAction(SwitcherInterface $switcher, Space $space)
Определения switcher.php:66
pinAction(SwitcherInterface $switcher, Space $space)
Определения switcher.php:42
trackAction(SwitcherInterface $switcher, Space $space)
Определения switcher.php:86
</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
$action
Определения file_dialog.php:21