Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
subscription.php
1<?php
2
10
15use Exception;
16
17Loc::loadMessages(__FILE__);
18
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}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29