1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
Feature.php
См. документацию.
1<?php
2
3namespace Bitrix\Calendar\OpenEvents;
4
5use Bitrix\Main\Config;
6use Bitrix\Main\Engine\CurrentUser;
7use Bitrix\Main\Loader;
8use Bitrix\Calendar\Core\Common;
9
10final class Feature
11{
12 private const FEATURE_OPTION = 'feature_calendar_open_events_enabled';
13
14 private static ?self $instance;
15
16 public static function getInstance(): self
17 {
18 self::$instance ??= new self();
19
20 return self::$instance;
21 }
22
23 public function isAvailable(?int $userId = null): bool
24 {
25 if ($userId === null)
26 {
27 $userId = (int)CurrentUser::get()->getId();
28 }
29
30 return $this->isEnabled($userId) && Loader::includeModule('im');
31 }
32
33 public function enableForUser(int $userId): void
34 {
35 \CUserOptions::SetOption(
36 category: Common::CALENDAR_MODULE_ID,
37 name: $this->getOptionName(),
38 value: 'Y',
39 user_id: $userId,
40 );
41 }
42
43 public function disableForUser(int $userId): void
44 {
45 \CUserOptions::DeleteOption(
46 category: Common::CALENDAR_MODULE_ID,
47 name: $this->getOptionName(),
48 user_id: $userId,
49 );
50 }
51
52 public function enableForEveryone(): void
53 {
55 moduleId: Common::CALENDAR_MODULE_ID,
56 name: $this->getOptionName(),
57 value: 'Y',
58 );
59 }
60
61 public function disableForEveryone(): void
62 {
64 moduleId: Common::CALENDAR_MODULE_ID,
65 name: $this->getOptionName(),
66 value: 'N',
67 );
68 }
69
70 private function isEnabled(int $userId): bool
71 {
72 $enabledForEveryone = $this->isEnabledForEveryone();
73
74 if ($enabledForEveryone)
75 {
76 return true;
77 }
78
79 return $this->isEnabledForUser($userId);
80 }
81
82 private function isEnabledForEveryone(): bool
83 {
84 return Config\Option::get(
85 moduleId: Common::CALENDAR_MODULE_ID,
86 name: $this->getOptionName(),
87 default: 'N',
88 ) === 'Y';
89 }
90
91 private function isEnabledForUser(int $userId): bool
92 {
93 return \CUserOptions::GetOption(
94 category: Common::CALENDAR_MODULE_ID,
95 name: $this->getOptionName(),
96 default_value: 'N',
97 user_id: $userId,
98 ) === 'Y';
99 }
100
101 private function getOptionName(): string
102 {
103 return self::FEATURE_OPTION;
104 }
105
106 private function __construct()
107 {
108 }
109}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
disableForUser(int $userId)
Определения Feature.php:43
isAvailable(?int $userId=null)
Определения Feature.php:23
static getInstance()
Определения Feature.php:16
enableForUser(int $userId)
Определения Feature.php:33
static set($moduleId, $name, $value="", $siteId="")
Определения option.php:261