ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilObjNotificationAdminGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
24
30{
31 protected Container $dic;
32 protected bool $has_push_config = false;
33
34 public function __construct($a_data, int $a_id = 0, bool $a_call_by_reference = true, bool $a_prepare_output = true)
35 {
36 global $DIC;
37 $this->dic = $DIC;
38 $this->type = 'nota';
39 parent::__construct($a_data, $a_id, $a_call_by_reference, false);
40 $this->has_push_config = is_readable((new ilSetting('notifications'))->get('private_key_path', ''));
41 $this->lng->loadLanguageModule('notifications_adm');
42 }
43
44 public function executeCommand(): void
45 {
46 if (!$this->rbac_system->checkAccess('visible,read', $this->object->getRefId())) {
47 $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
48 }
49
50 $this->prepareOutput();
51 $this->tabs_gui->activateTab('settings');
52
53 switch (strtolower($this->ctrl->getNextClass())) {
54 case strtolower(ilPermissionGUI::class):
55 $perm_gui = new ilPermissionGUI($this);
56 $this->ctrl->forwardCommand($perm_gui);
57 break;
58 default:
59 match ($this->ctrl->getCmd()) {
60 'saveSettings' => $this->saveSettings(),
61 // no break
62 default => $this->showSettings(),
63 };
64 }
65 }
66
67 public function getAdminTabs(): void
68 {
69 if ($this->checkPermissionBool('visible,read')) {
70 $this->tabs_gui->addTab(
71 'settings',
72 $this->lng->txt('settings'),
73 $this->ctrl->getLinkTarget($this, 'editSettings')
74 );
75 }
76
77 if ($this->checkPermissionBool('edit_permission')) {
78 $this->tabs_gui->addTab(
79 'perm_settings',
80 $this->lng->txt('perm_settings'),
81 $this->ctrl->getLinkTargetByClass([$this::class, ilPermissionGUI::class], 'perm')
82 );
83 }
84 }
85
89 public function showSettings(?Form $form = null): void
90 {
91 if ($form === null) {
92 $settings = new ilSetting('notifications');
93 $values = [];
94 if ($settings->get('enable_osd') === '0' || $settings->get('enable_osd') === null) {
95 $values['enable_osd'] = null;
96 } else {
97 $values['enable_osd'] = [
98 'osd_interval' => (int) $settings->get('osd_interval'),
99 'osd_play_sound' => (bool) $settings->get('osd_play_sound'),
100 ];
101 }
102 if ($this->has_push_config) {
103 $values['enable_push'] = $settings->get('enable_push') === '1';
104 }
105 $form = $this->getForm($values);
106 }
107
108 $this->tpl->setContent($this->dic->ui()->renderer()->render($form));
109 }
110
114 public function saveSettings(): void
115 {
116 if (!$this->checkPermissionBool('write')) {
117 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
118 }
119
120 $settings = new ilSetting('notifications');
121
122 $form = $this->getForm()->withRequest($this->dic->http()->request());
123 $data = $form->getData();
124 if (isset($data['osd']) && is_array($data['osd'])) {
125 if (!isset($data['osd']['enable_osd'])) {
126 global $DIC;
127 $DIC->notifications()->system()->clear('osd');
128 $settings->set('enable_osd', '0');
129 $settings->delete('osd_interval');
130 $settings->delete('osd_play_sound');
131 } else {
132 $settings->set('enable_osd', '1');
133 $settings->set('osd_interval', ((string) $data['osd']['enable_osd']['osd_interval']));
134 $settings->set('osd_play_sound', ($data['osd']['enable_osd']['osd_play_sound']) ? '1' : '0');
135 }
136 }
137
138 $push = false;
139 if ($this->has_push_config) {
140 $push = $data['push']['enable_push'] ?? false;
141 }
142 $settings->set('enable_push', $push ? '1' : '0');
143 $this->showSettings($form);
144 }
145
150 protected function getForm(?array $values = null): Form
151 {
152 $enable_osd = $this->dic->ui()->factory()->input()->field()->optionalGroup(
153 [
154 'osd_interval' => $this->dic->ui()->factory()->input()->field()->numeric(
155 $this->lng->txt('osd_interval'),
156 $this->lng->txt('osd_interval_desc')
157 )
158 ->withRequired(true)
159 ->withValue(60000)
160 ->withAdditionalTransformation($this->dic->refinery()->custom()->constraint(
161 static function ($value) {
162 return $value >= 3000;
163 },
164 $this->lng->txt('osd_error_refresh_interval_too_small')
165 )),
166 'osd_play_sound' => $this->dic->ui()->factory()->input()->field()->checkbox(
167 $this->lng->txt('osd_play_sound'),
168 $this->lng->txt('osd_play_sound_desc')
169 )
170 ],
171 $this->lng->txt('enable_osd')
172 )->withByline($this->lng->txt('enable_osd_desc'));
173
174 $enable_push = $this->dic->ui()->factory()->input()->field()->checkbox(
175 $this->lng->txt('enable_push'),
176 $this->lng->txt('enable_push_desc'),
177 );
178
179 if (!$this->has_push_config) {
180 $enable_push = $enable_push->withDisabled(true);
181 }
182
183 if ($values !== null) {
184 $enable_osd = $enable_osd->withValue($values['enable_osd'] ?? null);
185 $enable_push = $enable_push->withValue($values['enable_push'] ?? null);
186 }
187
188 return $this->dic->ui()->factory()->input()->container()->form()->standard(
189 $this->ctrl->getFormAction($this, 'saveSettings'),
190 [
191 'osd' => $this->dic->ui()->factory()->input()->field()->section(
192 ['enable_osd' => $enable_osd,],
193 $this->lng->txt('osd_settings')
194 ),
195 'push' => $this->dic->ui()->factory()->input()->field()->section(
196 ['enable_push' => $enable_push],
197 $this->lng->txt('push_settings')
198 )
199 ]
200 );
201 }
202}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
error(string $a_errmsg)
@ilCtrl_IsCalledBy ilObjNotificationAdminGUI: ilAdministrationGUI @ilCtrl_Calls ilObjNotificationAdmi...
getAdminTabs()
administration tabs show only permissions and trash folder
__construct($a_data, int $a_id=0, bool $a_call_by_reference=true, bool $a_prepare_output=true)
Class ilObjectGUI Basic methods of all Output classes.
checkPermissionBool(string $perm, string $cmd="", string $type="", ?int $ref_id=null)
ilSetting $settings
prepareOutput(bool $show_sub_objects=true)
ILIAS Setting Class.
delete(string $a_keyword)
set(string $a_key, string $a_val)
get(string $a_keyword, ?string $a_default_value=null)
get setting
This describes commonalities between all forms.
Definition: Form.php:33
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26