Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
workgroupfavorites.php
1
<?php
2
9
namespace
Bitrix\Socialnetwork\Item
;
10
11
use
Bitrix\Main\Localization\Loc
;
12
use
Bitrix\Socialnetwork\WorkgroupFavoritesTable
;
13
use
Bitrix\Main\SystemException
;
14
15
Loc::loadMessages
(__FILE__);
16
17
class
WorkgroupFavorites
18
{
19
public
const
AVAILABLE_VALUES
= [
20
'Y'
,
'N'
21
];
22
29
public
static
function
set
(array $params = [])
30
{
31
global $USER;
32
33
$groupId = (int)($params[
'GROUP_ID'
] ?? 0);
34
$userId = (int)($params[
'USER_ID'
] ?? $USER->getId());
35
$value = (isset($params[
'VALUE'
]) && in_array($params[
'VALUE'
], [
'Y'
,
'N'
]) ? $params[
'VALUE'
] :
false
);
36
37
if
(
38
$groupId <= 0
39
|| $userId <= 0
40
|| !$value
41
)
42
{
43
throw
new
SystemException
(
Loc::getMessage
(
'SOCIALNETWORK_ITEM_WORKGROUPFAVORITES_ERROR_NO_DATA'
));
44
}
45
46
$workgroupsCount = WorkgroupFavoritesTable::getCount([
47
'GROUP_ID'
=> $groupId,
48
'USER_ID'
=> $userId,
49
]);
50
$userHasFavoriteGroup = $workgroupsCount > 0;
51
$isUnset = $value ===
'N'
;
52
53
if
(!(\CSocNetGroup::getById($groupId,
true
)) && !($isUnset && $userHasFavoriteGroup))
54
{
55
throw
new
SystemException
(
Loc::getMessage
(
'SOCIALNETWORK_ITEM_WORKGROUPFAVORITES_ERROR_NO_ACCESS'
));
56
}
57
58
if
($value ===
'Y'
)
59
{
60
return
WorkgroupFavoritesTable::set
([
61
'GROUP_ID'
=> $groupId,
62
'USER_ID'
=> $userId,
63
]);
64
}
65
66
return
self::delete
([
67
'GROUP_ID'
=> $groupId,
68
'USER_ID'
=> $userId,
69
]);
70
}
71
77
public
static
function
delete
($params)
78
{
79
global $CACHE_MANAGER, $USER;
80
81
$groupId = (isset($params[
"GROUP_ID"
]) ? intval($params[
"GROUP_ID"
]) :
false
);
82
$userId = (isset($params[
"USER_ID"
]) ? intval($params[
"USER_ID"
]) : $USER->getId());
83
84
if
(
85
intval($groupId) <= 0
86
|| intval($userId) <= 0
87
)
88
{
89
return
false
;
90
}
91
92
$res = WorkgroupFavoritesTable::delete(array(
93
'GROUP_ID'
=> $groupId,
94
'USER_ID'
=> $userId
95
));
96
97
$result = $res->isSuccess();
98
99
if
(
100
$result
101
&& defined(
"BX_COMP_MANAGED_CACHE"
)
102
)
103
{
104
$CACHE_MANAGER->clearByTag(
"sonet_group_favorites_U"
.$userId);
105
}
106
107
return
$result;
108
}
109
}
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\WorkgroupFavorites
Definition
workgroupfavorites.php:18
Bitrix\Socialnetwork\Item\WorkgroupFavorites\delete
static delete($params)
Definition
workgroupfavorites.php:77
Bitrix\Socialnetwork\Item\WorkgroupFavorites\AVAILABLE_VALUES
const AVAILABLE_VALUES
Definition
workgroupfavorites.php:19
Bitrix\Socialnetwork\WorkgroupFavoritesTable
Definition
workgroupfavorites.php:42
Bitrix\Socialnetwork\WorkgroupFavoritesTable\set
static set($params=array())
Definition
workgroupfavorites.php:85
Bitrix\Socialnetwork\Item
Definition
contentviewhandler.php:9
modules
socialnetwork
lib
item
workgroupfavorites.php
Создано системой
1.10.0