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