Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
Notify.php
1<?php
2
4
6
7class Notify extends BaseSettings
8{
9
10 public static function getRestEntityName(): string
11 {
12 return 'notify';
13 }
14
15 public function toRestFormat(array $option = []): array
16 {
17 if (!$this->isLoad())
18 {
19 $this->load($this->groupId);
20 }
21
22 $notifyNames = Notification::getEventNames();
23 $result = [];
24 foreach ($this->settings as $moduleId => $moduleConfig)
25 {
26 $newModuleConfig = [
27 'id' => $moduleId,
28 'label' => $notifyNames[$moduleId]['NAME'],
29 'notices' => [],
30 ];
31
32 $notices = [];
33 foreach ($moduleConfig['NOTIFY'] as $eventName => $eventConfig)
34 {
35 $notify = [
36 'id' => $eventName,
37 'label' => $eventConfig['NAME'],
38 'site' => $eventConfig['SITE'],
39 'mail' => $eventConfig['MAIL'],
40 'push' => $eventConfig['PUSH'],
41 'disabled' => [],
42 ];
43
44 $disabled = [];
45 foreach ($eventConfig['DISABLED'] as $disableType => $value)
46 {
47 if ($disableType === 'XMPP')
48 {
49 continue;
50 }
51 if ($value)
52 {
53 $disabled[] = mb_strtolower($disableType);
54 }
55 }
56 $notify['disabled'] = $disabled;
57
58 $notices[] = $notify;
59 }
60 $newModuleConfig['notices'] = $notices;
61 $result[] = $newModuleConfig;
62 }
63
64 return $result;
65 }
66
71 public function updateSetting(array $settingConfiguration)
72 {
73 $updatingSetting = [
74 $settingConfiguration['moduleId'] => [[
75 $settingConfiguration['name'] => [
76 $settingConfiguration['type'] => $settingConfiguration['value'],
77 ],
78 ]],
79 ];
80
81 Notification::updateGroupSettings($this->groupId, $updatingSetting);
82 }
83
84 public function updateSimpleSettings(array $simpleSchema): Notify
85 {
86 $this->settings = Notification::getSimpleNotifySettings($simpleSchema);
87
88 Notification::updateGroupSettings($this->groupId, $this->settings);
89
90 return $this;
91 }
92
98 public function fillDataBase(bool $isSimpleSchema = false, array $simpleSchema = []): BaseSettings
99 {
100 if ($isSimpleSchema)
101 {
102 $this->settings = Notification::getSimpleNotifySettings($simpleSchema);
103 }
104 else
105 {
106 $this->settings = Notification::getDefaultSettings();
107 }
108 Notification::setSettings($this->groupId, $this->settings);
109
110 return $this;
111 }
112
113 public function load($source): BaseSettings
114 {
115 if (is_int($source))
116 {
117 $this->settings = Notification::getGroupSettings($this->groupId);
118 $this->isLoad = true;
119
120 return $this;
121 }
122
123 if (is_array($source) && !empty($source))
124 {
125 $this->settings =
126 array_replace_recursive(Notification::getDefaultSettings(), $source)
127 ;
128 $this->isLoad = true;
129
130 return $this;
131 }
132
133 return $this;
134 }
135}
toRestFormat(array $option=[])
Definition Notify.php:15
updateSetting(array $settingConfiguration)
Definition Notify.php:71
updateSimpleSettings(array $simpleSchema)
Definition Notify.php:84
fillDataBase(bool $isSimpleSchema=false, array $simpleSchema=[])
Definition Notify.php:98