Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
General.php
1<?php
2
4
8use CModule;
9
10class General extends BaseSettings
11{
12 public const SIMPLE_SITE = 'notifySchemeSendSite';
13 public const SIMPLE_MAIL = 'notifySchemeSendEmail';
14 public const SIMPLE_PUSH = 'notifySchemeSendPush';
15 public const SCHEME = 'notifyScheme';
16
17 public const PRIVACY_SEARCH = 'privacySearch';
18 public const OPEN_DESKTOP_FROM_PANEL = 'openDesktopFromPanel';
19
20
21 public static function getRestEntityName(): string
22 {
23 return 'general';
24 }
25
26 public function toRestFormat(array $option = []): array
27 {
28 return $this->settings;
29 }
30
36 public function updateSetting(array $settingConfiguration): void
37 {
38 $updatingSetting = [
39 $settingConfiguration['name'] => $settingConfiguration['value']
40 ];
41 $this->settings[$settingConfiguration['name']] = $settingConfiguration['value'];
42
43 \Bitrix\Im\Configuration\General::updateGroupSettings($this->groupId, $updatingSetting);
44 }
45
46 public function shouldUpdateSimpleNotifySettings(array $settingsConfiguration): bool
47 {
48 if ($settingsConfiguration['name'] === self::SCHEME && $settingsConfiguration['value'] === 'simple')
49 {
50 return true;
51 }
52
53 if ($this->getValue(self::SCHEME) === 'simple')
54 {
55 return in_array(
56 $settingsConfiguration['name'],
57 [
58 self::SIMPLE_SITE,
59 self::SIMPLE_MAIL,
60 self::SIMPLE_PUSH
61 ],
62 true
63 );
64 }
65
66 return false;
67 }
68
73 public function load($source): BaseSettings // TODO return int|array
74 {
75 if (is_int($source))
76 {
77 $this->settings = \Bitrix\Im\Configuration\General::getGroupSettings($this->groupId);
78 $this->isLoad = true;
79
80 return $this;
81 }
82
83 if (is_array($source) && !empty($source))
84 {
85 $this->settings =
86 array_replace_recursive(\Bitrix\Im\Configuration\General::getDefaultSettings(), $source)
87 ;
88 $this->isLoad = true;
89
90 return $this;
91 }
92
93 return $this;
94 }
95
96 protected function getValue(string $name, $defaultValue = null)
97 {
98 if (!$this->isLoad())
99 {
100 $this->load($this->groupId);
101 }
102
103 return $this->settings[$name] ?? $defaultValue;
104 }
105
106 public function fillDataBase(): BaseSettings
107 {
108 \Bitrix\Im\Configuration\General::setSettings($this->groupId, [], true);
109
110 $this->settings = \Bitrix\Im\Configuration\General::getDefaultSettings();
111
112 return $this;
113 }
114
115 public function isSimpleNotifySchema(): bool
116 {
117 return $this->getValue(static::SCHEME) === 'simple';
118 }
119
120 public function getSimpleNotifyScheme(): array
121 {
122 return [
123 static::SIMPLE_SITE => $this->getValue(static::SIMPLE_SITE),
124 self::SIMPLE_MAIL => $this->getValue(self::SIMPLE_MAIL),
125 self::SIMPLE_PUSH => $this->getValue(self::SIMPLE_PUSH),
126 ];
127 }
128}
shouldUpdateSimpleNotifySettings(array $settingsConfiguration)
Definition General.php:46
getValue(string $name, $defaultValue=null)
Definition General.php:96
updateSetting(array $settingConfiguration)
Definition General.php:36