19declare(strict_types=1);
49 $this->repo =
new PushRepository($this->dic->database(), $this->dic->user());
59 if ((
new ilSetting(
'notifications'))->
get(
'enable_push') !==
'1') {
60 $this->dic->ui()->mainTemplate()->setOnScreenMessage(
61 $this->dic->ui()->mainTemplate()::MESSAGE_TYPE_FAILURE,
62 $this->dic->language()->txt(
'permission_denied')
64 $this->dic->ui()->mainTemplate()->printToStdout();
68 $this->dic->language()->loadLanguageModule(
'notifications_adm');
69 $this->dic->ui()->mainTemplate()->setTitle($this->dic->language()->txt(
'push_settings'));
71 $this->dic->tabs()->addTab(
'client', $this->dic->language()->txt(
'client_settings'), $this->dic->ctrl()->getLinkTargetByClass(self::class,
'showClientSettings'));
72 if ($this->pushProvider !== []) {
73 $this->dic->tabs()->addTab(
'user', $this->dic->language()->txt(
'user_settings'), $this->dic->ctrl()->getLinkTargetByClass(self::class,
'showUserSettings'));
76 switch ($this->dic->ctrl()->getCmd()) {
77 case 'showUserSettings':
78 $this->dic->tabs()->activateTab(
'user');
79 if ($this->pushProvider !== []) {
80 $this->dic->ui()->mainTemplate()->setContent($this->dic->ui()->renderer()->render($this->getForm()));
81 $this->dic->ui()->mainTemplate()->printToStdout();
83 $this->dic->ctrl()->redirectByClass(self::class,
'showClientSettings');
86 case 'saveUserSettings':
87 $this->dic->tabs()->activateTab(
'user');
88 $form = $this->
getForm()->withRequest($this->dic->http()->request());
89 $data = $form->getData();
92 foreach (
$data[
'provider'] ?? [] as $key => $value) {
93 if ($value ===
true) {
97 $this->dic->user()->setPref(
'push_notification_provider', json_encode($active));
98 $this->dic->user()->update();
99 $this->dic->ui()->mainTemplate()->setOnScreenMessage(
100 $this->dic->ui()->mainTemplate()::MESSAGE_TYPE_SUCCESS,
101 $this->dic->language()->txt(
'saved_successfully')
104 $this->dic->ui()->mainTemplate()->setContent($this->dic->ui()->renderer()->render($form));
105 $this->dic->ui()->mainTemplate()->printToStdout();
107 case 'addSubscription':
110 case 'removeSubscription':
113 case 'showClientSettings':
115 $this->dic->tabs()->activateTab(
'client');
116 if (!($this->dic->http()->wrapper()->post()->has(
'auth') && $this->dic->http()->wrapper()->post()->has(
'perm'))) {
128 foreach ($this->repo->getUserSubscriptions() as $subscription) {
129 if ($auth === $subscription->getAuth()) {
140 $this->dic->http()->wrapper()->post()->retrieve(
'subscription', $this->dic->refinery()->to()->string()),
148 $data[
'keys'][
'auth'],
149 $data[
'keys'][
'p256dh']
155 $this->dic->language()->txt(
'push_subscription_successfull'),
156 $this->dic->language()->txt(
'push_subscription_successfull_desc')
162 $auth = $this->dic->http()->wrapper()->post()->retrieve(
'auth', $this->dic->refinery()->to()->string());
164 $this->repo->deleteSubscription($auth);
170 $this->dic->ui()->mainTemplate()->addJavaScript(
'assets/js/push-subscription.js');
172 $auth = $this->dic->http()->wrapper()->post()->retrieve(
'auth', $this->dic->refinery()->kindlyTo()->string());
173 $perm = $this->dic->http()->wrapper()->post()->retrieve(
'perm', $this->dic->refinery()->kindlyTo()->string());
174 $agent = $this->dic->http()->request()->getServerParams()[
'HTTP_USER_AGENT'] ??
'';
176 if ($perm ===
'denied') {
177 $this->dic->ui()->mainTemplate()->setOnScreenMessage(
178 $this->dic->ui()->mainTemplate()::MESSAGE_TYPE_QUESTION,
179 $this->dic->language()->txt(
'push_client_inactive')
183 $this->dic->ui()->mainTemplate()->setOnScreenMessage(
184 $this->dic->ui()->mainTemplate()::MESSAGE_TYPE_FAILURE,
185 $this->dic->language()->txt(
'push_client_already_used')
188 if ($perm !==
'granted' && preg_match(
'/(Edg\/)/', $agent)) {
189 $this->dic->ui()->mainTemplate()->setOnScreenMessage(
190 $this->dic->ui()->mainTemplate()::MESSAGE_TYPE_INFO,
191 $this->dic->language()->txt(
'push_client_edge_case')
194 if ($perm ===
'' && preg_match(
'/(Mac)/', $agent)) {
195 $this->dic->ui()->mainTemplate()->setOnScreenMessage(
196 $this->dic->ui()->mainTemplate()::MESSAGE_TYPE_INFO,
197 $this->dic->language()->txt(
'push_client_ios_case')
201 if ($this->
checkSubscription($auth) && ($perm ===
'granted' || $perm ===
'default')) {
202 $public_key = (
new ilSetting(
'notifications'))->
get(
'application_server_key');
203 $target = $this->dic->ctrl()->getLinkTargetByClass(self::class,
'default');
204 $toggle = $this->dic->ui()->factory()->button()->toggle($this->dic->language()->txt(
'activate'),
'',
'')
206 ->withAdditionalOnLoadCode(
static fn(
$id) =>
"il.Notifications.initToggle($id, '$public_key', '$target')");
207 $this->dic->ui()->mainTemplate()->setContent($this->dic->ui()->renderer()->render($toggle));
210 $this->dic->ui()->mainTemplate()->printToStdout();
218 $target = ILIAS_HTTP_PATH .
'/' . $this->dic->ctrl()->getLinkTargetByClass(self::class,
'showClientSettings');
220 $this->dic->ui()->mainTemplate()->setContent($this->dic->ui()->renderer()->render(
221 $this->dic->ui()->factory()->legacy()->content(
'')->withOnLoadCode(
223 navigator.serviceWorker.ready.then((reg) => {
224 (reg.pushManager || {getSubscription: () => Promise.resolve(null)}).getSubscription().then((sub) => {
225 const form = document.createElement('form');
226 form.method = 'post';
227 form.action = '$target';
228 let auth = document.createElement('input');
230 auth.value = (sub === null) ? '' : sub.toJSON().keys.auth;
231 form.appendChild(auth);
232 perm = document.createElement('input');
234 perm.value = (typeof Notification === 'undefined') ? '' : Notification.permission;
235 form.appendChild(perm);
236 document.body.appendChild(form);
243 $this->dic->ui()->mainTemplate()->printToStdout();
244 $this->dic->http()->close();
250 $prefs = json_decode($this->dic->user()->getPref(
'push_notification_provider') ??
'[]');
251 foreach ($this->pushProvider as $p) {
252 $provider[$p->getIdentifier()] = $this->dic->ui()->factory()->input()->field()->checkbox(
253 $p->getName($this->dic->language()),
254 $p->getDescription($this->dic->language()),
255 )->withValue(in_array($p->getIdentifier(), $prefs));
258 return $this->dic->ui()->factory()->input()->container()->form()->standard(
259 $this->dic->ctrl()->getLinkTargetByClass(self::class,
'saveUserSettings'),
261 'provider' => $this->dic->ui()->factory()->input()->field()->section(
263 $this->dic->language()->txt(
'available_providers'),
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Customizing of pimple-DIC for ILIAS.
This is the lowest common denominator of all popular browsers.
@ilCtrl_IsCalledBy ilPersonalNotificationsSettingsGUI: ilNotificationGUI
__construct(?Container $dic=null)
checkSubscription(string $auth)
fetchClientData()
Respond a self-submitting form to fetch client data for push notifications.
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)