ILIAS  release_8 Revision v8.24
class.ilNotificationGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
28
33{
34 private array $handler = [];
35 private Container $dic;
40
41 public function __construct(
42 ?ilObjUser $user = null,
45 ?ilLanguage $language = null,
46 ?Container $dic = null
47 ) {
48 if ($dic === null) {
49 global $DIC;
50 $dic = $DIC;
51 }
52 $this->dic = $dic;
53
54 if ($user === null) {
55 $user = $dic->user();
56 }
57 $this->user = $user;
58
59 if ($template === null) {
60 $template = $dic->ui()->mainTemplate();
61 }
62 $this->template = $template;
63
64 if ($controller === null) {
66 }
67 $this->controller = $controller;
68
69 if ($language === null) {
71 }
72 $this->language = $language;
73 }
74
75 public static function _forwards(): array
76 {
77 return [];
78 }
79
80 public function executeCommand(): void
81 {
82 if (!$this->controller->getCmd()) {
83 return;
84 }
85
86 $cmd = $this->controller->getCmd() . 'Object';
87 $this->$cmd();
88 }
89
93 public function getHandler(string $type)
94 {
95 return $this->handler[$type];
96 }
97
98 private function getAvailableTypes(array $types = []): array
99 {
100 return ilNotificationDatabaseHandler::getAvailableTypes($types);
101 }
102
103 private function getAvailableChannels(array $types = []): array
104 {
105 return ilNotificationDatabaseHandler::getAvailableChannels($types);
106 }
107
108 public function getOSDNotificationsObject(): void
109 {
111 $toasts = [];
112 foreach ($this->dic->globalScreen()->collector()->toasts()->getToasts() as $toast) {
113 $renderer = $toast->getRenderer();
114 $toasts[] = $renderer->getToastComponentForItem($toast);
115 }
116
117 $this->dic->http()->saveResponse(
118 $this->dic->http()->response()
119 ->withBody(Streams::ofString(
120 $this->dic->ui()->renderer()->renderAsync($toasts)
121 ))
122 );
123 $this->dic->http()->sendResponse();
124 $this->dic->http()->close();
125 }
126
127 public function addHandler(string $channel, ilNotificationHandler $handler): void
128 {
129 if (!array_key_exists($channel, $this->handler) || !is_array($this->handler[$channel])) {
130 $this->handler[$channel] = [];
131 }
132
133 $this->handler[$channel][] = $handler;
134 }
135
136 public function showSettingsObject(): void
137 {
138 $userTypes = ilNotificationDatabaseHandler::loadUserConfig($this->user->getId());
139
140 $this->language->loadLanguageModule('notification');
141
142 $form = new ilPropertyFormGUI();
143 $chk = new ilCheckboxInputGUI($this->language->txt('enable_custom_notification_configuration'), 'enable_custom_notification_configuration');
144 $chk->setValue('1');
145 $chk->setChecked($this->dic->refinery()->kindlyTo()->int()->transform($this->user->getPref('use_custom_notification_setting')) === 1);
146 $form->addItem($chk);
147
148 $form->setFormAction($this->controller->getFormAction($this, 'showSettingsObject'));
149 $form->addCommandButton('saveCustomizingOption', $this->language->txt('save'));
150 $form->addCommandButton('showSettings', $this->language->txt('cancel'));
151
152 $table = new ilNotificationSettingsTable($this, 'a title', $this->getAvailableChannels(['set_by_user']), $userTypes);
153
154 $table->setFormAction($this->controller->getFormAction($this, 'saveSettings'));
155 $table->setData($this->getAvailableTypes(['set_by_user']));
156
157 if (
158 $this->dic->refinery()->kindlyTo()->int()->transform(
159 $this->user->getPref('use_custom_notification_setting')
160 ) === 1
161 ) {
162 $table->addCommandButton('saveSettings', $this->language->txt('save'));
163 $table->addCommandButton('showSettings', $this->language->txt('cancel'));
164 $table->setEditable(true);
165 } else {
166 $table->setEditable(false);
167 }
168
169 $this->template->setContent($form->getHtml() . $table->getHTML());
170 }
171}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:32
user()
Get the current user.
Definition: Container.php:62
language()
Get interface to the i18n service.
Definition: Container.php:86
ui()
Get the interface to get services from UI framework.
Definition: Container.php:118
ctrl()
Get the interface to the control structure.
Definition: Container.php:54
This class represents a checkbox property in a property form.
language handling
addHandler(string $channel, ilNotificationHandler $handler)
getAvailableChannels(array $types=[])
getAvailableTypes(array $types=[])
__construct(?ilObjUser $user=null, ?ilGlobalTemplateInterface $template=null, ?ilCtrlInterface $controller=null, ?ilLanguage $language=null, ?Container $dic=null)
ilGlobalTemplateInterface $template
User class.
This class represents a property form user interface.
static enableWebAccessWithoutSession(bool $enable_web_access_without_session)
global $DIC
Definition: feed.php:28
Interface ilCtrlBaseClassInterface describes ilCtrl base classes.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$type