Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
switcher.php
1
<?php
2
3
namespace
Bitrix\Socialnetwork\Controller\Livefeed\Spaces
;
4
5
use
Bitrix\Main\Engine\AutoWire\BinderArgumentException
;
6
use
Bitrix\Main\Engine\AutoWire\ExactParameter
;
7
use
Bitrix\Main\Engine\Controller
;
8
use
Bitrix\Main\Engine\CurrentUser
;
9
use
Bitrix\Socialnetwork\Integration\Pull\PushService
;
10
use
Bitrix\Socialnetwork\Internals\EventService\Push\PushEventDictionary
;
11
use
Bitrix\Socialnetwork\Space\List\Item\Space
;
12
use
Bitrix\Socialnetwork\Space\Toolbar\Switcher\Factory\SwitcherFactory
;
13
use
Bitrix\Socialnetwork\Space\Toolbar\Switcher\SwitcherInterface
;
14
15
class
Switcher
extends
Controller
16
{
17
private
int
$userId;
18
22
public
function
getAutoWiredParameters
(): array
23
{
24
return
[
25
new
ExactParameter
(
26
SwitcherInterface::class,
27
'switcher'
,
28
fn (
string
$className, array $switcher):
SwitcherInterface
=>
29
SwitcherFactory::get($switcher[
'type'
], $this->userId, $switcher[
'spaceId'
])
30
),
31
new
ExactParameter
(
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(
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
}
Bitrix\Main\DB\Connection\$host
$host
Definition
connection.php:29
Bitrix\Main\Engine\AutoWire\BinderArgumentException
Definition
binderargumentexception.php:9
Bitrix\Main\Engine\AutoWire\ExactParameter
Definition
exactparameter.php:9
Bitrix\Main\Engine\Controller
Definition
controller.php:32
Bitrix\Main\Engine\Controller\addErrors
addErrors(array $errors)
Definition
controller.php:1064
Bitrix\Main\Engine\CurrentUser
Definition
currentuser.php:8
Bitrix\Socialnetwork\Controller\Livefeed\Spaces\Switcher
Definition
switcher.php:16
Bitrix\Socialnetwork\Controller\Livefeed\Spaces\Switcher\getAutoWiredParameters
getAutoWiredParameters()
Definition
switcher.php:22
Bitrix\Socialnetwork\Controller\Livefeed\Spaces\Switcher\followAction
followAction(SwitcherInterface $switcher, Space $space)
Definition
switcher.php:66
Bitrix\Socialnetwork\Controller\Livefeed\Spaces\Switcher\init
init()
Definition
switcher.php:100
Bitrix\Socialnetwork\Controller\Livefeed\Spaces\Switcher\pinAction
pinAction(SwitcherInterface $switcher, Space $space)
Definition
switcher.php:42
Bitrix\Socialnetwork\Controller\Livefeed\Spaces\Switcher\trackAction
trackAction(SwitcherInterface $switcher, Space $space)
Definition
switcher.php:86
Bitrix\Socialnetwork\Integration\Pull\PushService
Definition
pushservice.php:15
Bitrix\Socialnetwork\Internals\EventService\Push\PushEventDictionary
Definition
pusheventdictionary.php:15
Bitrix\Socialnetwork\Space\List\Item\Space
Definition
Space.php:10
Bitrix\Socialnetwork\Space\List\Item\Space\getId
getId()
Definition
Space.php:23
Bitrix\Socialnetwork\Space\Toolbar\Switcher\Factory\SwitcherFactory
Definition
SwitcherFactory.php:11
Bitrix\Socialnetwork\Space\Toolbar\Switcher\SwitcherInterface
Definition
SwitcherInterface.php:8
Bitrix\Socialnetwork\Space\Toolbar\Switcher\SwitcherInterface\switch
switch()
Bitrix\Socialnetwork\Space\Toolbar\Switcher\SwitcherInterface\isEnabled
isEnabled()
Bitrix\Sender\Internals\QueryController
Definition
action.php:8
Bitrix\Socialnetwork\Controller\Livefeed\Spaces
Definition
composition.php:3
modules
socialnetwork
lib
controller
livefeed
spaces
switcher.php
Создано системой
1.10.0