Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
subscription.php
1
<?php
2
9
namespace
Bitrix\Socialnetwork\Item
;
10
11
use
Bitrix\Main\Error
;
12
use
Bitrix\Main\Loader
;
13
use
Bitrix\Main\Localization\Loc
;
14
use
Bitrix\Main\SystemException
;
15
use Exception;
16
17
Loc::loadMessages
(__FILE__);
18
19
class
Subscription
20
{
21
public
const
AVAILABLE_VALUES
= [
22
'Y'
,
'N'
23
];
24
25
public
static
function
onContentViewed
(array $params)
26
{
27
if
(
28
!isset($params[
'userId'
], $params[
'logId'
])
29
|| !is_array($params)
30
|| (
int
)$params[
'userId'
] <= 0
31
|| (
int
)$params[
'logId'
] <= 0
32
|| !Loader::includeModule(
'im'
)
33
)
34
{
35
return
;
36
}
37
38
$CIMNotify = new \CIMNotify();
39
$CIMNotify->markNotifyReadBySubTag(array(
"SONET|EVENT|"
.(
int
)$params[
'logId'
].
"|"
.(
int
)$params[
'userId'
]));
40
}
41
48
public
static
function
set
(array $params = [])
49
{
50
global $USER;
51
52
$groupId = (int)($params[
'GROUP_ID'
] ?? 0);
53
$userId = (int)($params[
'USER_ID'
] ?? $USER->getId());
54
$value = (isset($params[
'VALUE'
]) && in_array($params[
'VALUE'
], [
'Y'
,
'N'
]) ? $params[
'VALUE'
] :
false
);
55
56
if
(
57
$groupId <= 0
58
|| $userId <= 0
59
|| !$value
60
)
61
{
62
throw
new
SystemException
(
Loc::getMessage
(
'SOCIALNETWORK_ITEM_SUBSCRIPTION_ERROR_NO_DATA'
));
63
}
64
65
if
(!(\CSocNetGroup::getById($groupId,
true
)))
66
{
67
throw
new
SystemException
(
Loc::getMessage
(
'SOCIALNETWORK_ITEM_SUBSCRIPTION_ERROR_NO_ACCESS'
));
68
}
69
70
$userRole = \CSocNetUserToGroup::getUserRole($userId, $groupId);
71
if
(!in_array($userRole, \
Bitrix
\Socialnetwork\
UserToGroupTable::getRolesMember
()))
72
{
73
throw
new
SystemException
(
Loc::getMessage
(
'SOCIALNETWORK_ITEM_SUBSCRIPTION_ERROR_NO_ACCESS'
));
74
}
75
76
if
(!\CSocNetSubscription::set($userId,
'SG'
. $groupId, $value))
77
{
78
throw
new
SystemException
(
Loc::getMessage
(
'SOCIALNETWORK_ITEM_SUBSCRIPTION_ERROR_FAILED'
));
79
}
80
81
$res = \CSocNetSubscription::getList(
82
[],
83
[
84
'USER_ID'
=> $userId,
85
'CODE'
=>
'SG'
. $groupId,
86
]
87
);
88
89
return
$res->fetch();
90
}
91
}
Bitrix\Main\Error
Definition
error.php:14
Bitrix\Main\Loader
Definition
loader.php:12
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\SystemException
Definition
exception.php:8
Bitrix\Socialnetwork\Item\Subscription
Definition
subscription.php:20
Bitrix\Socialnetwork\Item\Subscription\AVAILABLE_VALUES
const AVAILABLE_VALUES
Definition
subscription.php:21
Bitrix\Socialnetwork\Item\Subscription\onContentViewed
static onContentViewed(array $params)
Definition
subscription.php:25
Bitrix\Socialnetwork\UserToGroupTable\getRolesMember
static getRolesMember()
Definition
usertogroup.php:73
Bitrix\Socialnetwork\Item
Definition
contentviewhandler.php:9
Bitrix
modules
socialnetwork
lib
item
subscription.php
Создано системой
1.10.0