ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilNotificationGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
26 
31 {
33  private array $handler = [];
34  private readonly Container $dic;
35  private readonly ilObjUser $user;
37  private readonly ilCtrlInterface $controller;
38  private readonly ilLanguage $language;
39 
40  public function __construct(
41  ?ilObjUser $user = null,
42  ?ilGlobalTemplateInterface $template = null,
43  ?ilCtrlInterface $controller = null,
44  ?ilLanguage $language = null,
45  ?Container $dic = null
46  ) {
47  if ($dic === null) {
48  global $DIC;
49  $dic = $DIC;
50  }
51  $this->dic = $dic;
52 
53  if ($user === null) {
54  $user = $dic->user();
55  }
56  $this->user = $user;
57 
58  if ($template === null) {
59  $template = $dic->ui()->mainTemplate();
60  }
61  $this->template = $template;
62 
63  if ($controller === null) {
64  $controller = $dic->ctrl();
65  }
66  $this->controller = $controller;
67 
68  if ($language === null) {
69  $language = $dic->language();
70  }
71  $this->language = $language;
72  }
73 
74  public function executeCommand(): void
75  {
76  if (!$this->controller->getCmd()) {
77  return;
78  }
79 
80  $cmd = $this->controller->getCmd() . 'Object';
81  $this->$cmd();
82  }
83 
87  public function getHandler(string $type): ?array
88  {
89  return $this->handler[$type] ?? null;
90  }
91 
96  private function getAvailableTypes(array $types = []): array
97  {
98  return ilNotificationDatabaseHandler::getAvailableTypes($types);
99  }
100 
105  private function getAvailableChannels(array $types = []): array
106  {
107  return ilNotificationDatabaseHandler::getAvailableChannels($types);
108  }
109 
110  public function getOSDNotificationsObject(): void
111  {
113 
114  $toasts = [];
115  foreach ($this->dic->globalScreen()->collector()->toasts()->getToasts() as $toast) {
116  $renderer = $toast->getRenderer();
117  $toasts[] = $renderer->getToastComponentForItem($toast);
118  }
119 
120  $this->dic->http()->saveResponse(
121  $this->dic->http()->response()
122  ->withBody(Streams::ofString(
123  $this->dic->ui()->renderer()->renderAsync($toasts)
124  ))
125  );
126  $this->dic->http()->sendResponse();
127  $this->dic->http()->close();
128  }
129 
130  public function addHandler(string $channel, ilNotificationHandler $handler): void
131  {
132  if (!array_key_exists($channel, $this->handler)) {
133  $this->handler[$channel] = [];
134  }
135 
136  $this->handler[$channel][] = $handler;
137  }
138 
139  public function showSettingsObject(): void
140  {
141  $userTypes = ilNotificationDatabaseHandler::loadUserConfig($this->user->getId());
142 
143  $this->language->loadLanguageModule('notification');
144 
145  $form = new ilPropertyFormGUI();
146  $chk = new ilCheckboxInputGUI($this->language->txt('enable_custom_notification_configuration'), 'enable_custom_notification_configuration');
147  $chk->setValue('1');
148  $chk->setChecked($this->dic->refinery()->kindlyTo()->int()->transform($this->user->getPref('use_custom_notification_setting')) === 1);
149  $form->addItem($chk);
150 
151  $form->setFormAction($this->controller->getFormAction($this, 'showSettingsObject'));
152  $form->addCommandButton('saveCustomizingOption', $this->language->txt('save'));
153  $form->addCommandButton('showSettings', $this->language->txt('cancel'));
154 
155  $table = new ilNotificationSettingsTable($this, 'a title', $this->getAvailableChannels(['set_by_user']), $userTypes);
156 
157  $table->setFormAction($this->controller->getFormAction($this, 'saveSettings'));
158  $table->setData($this->getAvailableTypes(['set_by_user']));
159 
160  if (
161  $this->dic->refinery()->kindlyTo()->int()->transform(
162  $this->user->getPref('use_custom_notification_setting')
163  ) === 1
164  ) {
165  $table->addCommandButton('saveSettings', $this->language->txt('save'));
166  $table->addCommandButton('showSettings', $this->language->txt('cancel'));
167  $table->setEditable(true);
168  } else {
169  $table->setEditable(false);
170  }
171 
172  $this->template->setContent($form->getHtml() . $table->getHTML());
173  }
174 }
static enableWebAccessWithoutSession(bool $enable_web_access_without_session)
$renderer
user()
Get the current user.
Definition: Container.php:71
readonly ilObjUser $user
getAvailableChannels(array $types=[])
addHandler(string $channel, ilNotificationHandler $handler)
__construct(?ilObjUser $user=null, ?ilGlobalTemplateInterface $template=null, ?ilCtrlInterface $controller=null, ?ilLanguage $language=null, ?Container $dic=null)
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:35
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
readonly Container $dic
getAvailableTypes(array $types=[])
readonly ilLanguage $language
global $DIC
Definition: shib_login.php:26
readonly ilCtrlInterface $controller
language()
description: > Example for rendring a language glyph.
Definition: language.php:41
readonly ilGlobalTemplateInterface $template