ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilObjNotificationAdminGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 
32 {
33  protected Container $dic;
34 
38  public function __construct($a_data, $a_id = 0, $a_call_by_reference = true, $a_prepare_output = true)
39  {
40  global $DIC;
41  $this->dic = $DIC;
42 
43  $this->type = "nota";
44  parent::__construct($a_data, $a_id, $a_call_by_reference, false);
45  $this->lng->loadLanguageModule('notifications_adm');
46  }
47 
48  public function executeCommand(): void
49  {
50  $this->prepareOutput();
51  $this->tabs_gui->activateTab('view');
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  switch ($this->ctrl->getCmd()) {
60  case 'saveOSDSettings':
61  $this->saveOSDSettings();
62  break;
63  default:
64  $this->showOSDSettings();
65  }
66  }
67  }
68 
72  public function showOSDSettings(?Form $form = null): void
73  {
74  if ($form === null) {
75  $settings = new ilSetting('notifications');
76  $value = [];
77  if ($settings->get('enable_osd') === '0' || $settings->get('enable_osd') === null) {
78  $value['enable_osd'] = null;
79  } else {
80  $value['enable_osd'] = [
81  'osd_interval' => (int) $settings->get('osd_interval'),
82  'osd_vanish' => (int) $settings->get('osd_vanish'),
83  'osd_delay' => (int) $settings->get('osd_delay'),
84  'osd_play_sound' => (bool) $settings->get('osd_play_sound'),
85  ];
86  }
87  $form = $this->getForm($value);
88  }
89 
90  $this->tpl->setContent($this->dic->ui()->renderer()->render($form));
91  }
92 
96  public function saveOSDSettings(): void
97  {
98  $settings = new ilSetting('notifications');
99 
100  $form = $this->getForm()->withRequest($this->dic->http()->request());
101  $data = $form->getData();
102  if (isset($data['osd']) && is_array($data['osd'])) {
103  if (!isset($data['osd']['enable_osd'])) {
104  global $DIC;
105  $DIC->notifications()->system()->clear('osd');
106  $settings->set('enable_osd', '0');
107  $settings->delete('osd_interval');
108  $settings->delete('osd_vanish');
109  $settings->delete('osd_delay');
110  $settings->delete('osd_play_sound');
111  } else {
112  $settings->set('enable_osd', '1');
113  $settings->set('osd_interval', ((string) $data['osd']['enable_osd']['osd_interval']));
114  $settings->set('osd_vanish', ((string) $data['osd']['enable_osd']['osd_vanish']));
115  $settings->set('osd_delay', ((string) $data['osd']['enable_osd']['osd_delay']));
116  $settings->set('osd_play_sound', ($data['osd']['enable_osd']['osd_play_sound']) ? '1' : '0');
117 
118  }
119  }
120  $this->showOSDSettings($form);
121  }
122 
126  protected function getForm(array $value = null): Form
127  {
128  $enable_osd = $this->dic->ui()->factory()->input()->field()->optionalGroup(
129  [
130  'osd_interval' => $this->dic->ui()->factory()->input()->field()->numeric(
131  $this->lng->txt('osd_interval'),
132  $this->lng->txt('osd_interval_desc')
133  )
134  ->withRequired(true)
135  ->withValue(60000)
136  ->withAdditionalTransformation($this->dic->refinery()->custom()->constraint(
137  static function ($value) {
138  return $value >= 3000;
139  },
140  $this->lng->txt('osd_error_refresh_interval_too_small')
141  )),
142  'osd_vanish' => $this->dic->ui()->factory()->input()->field()->numeric(
143  $this->lng->txt('osd_vanish'),
144  $this->lng->txt('osd_vanish_desc')
145  )
146  ->withRequired(true)
147  ->withValue(5000)
148  ->withAdditionalTransformation($this->dic->refinery()->custom()->constraint(
149  static function ($value) {
150  return $value >= 1000;
151  },
152  $this->lng->txt('osd_error_presentation_time_too_small')
153  )),
154  'osd_delay' => $this->dic->ui()->factory()->input()->field()->numeric(
155  $this->lng->txt('osd_delay'),
156  $this->lng->txt('osd_delay_desc')
157  )
158  ->withRequired(true)
159  ->withValue(500),
160  'osd_play_sound' => $this->dic->ui()->factory()->input()->field()->checkbox(
161  $this->lng->txt('osd_play_sound'),
162  $this->lng->txt('osd_play_sound_desc')
163  )
164  ],
165  $this->lng->txt('enable_osd')
166  )->withByline(
167  $this->lng->txt('enable_osd_desc')
168  )->withAdditionalTransformation($this->dic->refinery()->custom()->constraint(
169  static function ($value) {
170  return $value === null || ($value['osd_interval'] > $value['osd_delay'] + $value['osd_vanish']);
171  },
172  $this->lng->txt('osd_error_refresh_interval_smaller_than_delay_and_vanish_combined')
173  ));
174 
175  if ($value !== null) {
176  $enable_osd = $enable_osd->withValue($value['enable_osd'] ?? null);
177  }
178 
179  return $this->dic->ui()->factory()->input()->container()->form()->standard(
180  $this->ctrl->getFormAction($this, 'saveOSDSettings'),
181  [
182  'osd' => $this->dic->ui()->factory()->input()->field()->section(
183  ['enable_osd' => $enable_osd],
184  $this->lng->txt('osd_settings')
185  )
186  ]
187  );
188  }
189 }
delete(string $a_keyword)
get(string $a_keyword, ?string $a_default_value=null)
get setting
prepareOutput(bool $show_sub_objects=true)
set(string $a_key, string $a_val)
__construct($a_data, $a_id=0, $a_call_by_reference=true, $a_prepare_output=true)
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:31
global $DIC
Definition: feed.php:28
Class ilObjectGUI Basic methods of all Output classes.
__construct(Container $dic, ilPlugin $plugin)
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
ilSetting $settings