19declare(strict_types=1);
45 $this->repo =
new PushRepository($this->dic->database(), $this->dic->user());
50 $this->dic->language()->loadLanguageModule(
'notifications_adm');
52 $this->dic->ui()->mainTemplate()->setTitle($this->dic->language()->txt(
'push_settings'));
55 switch ($this->dic->ctrl()->getCmd()) {
56 case 'addSubscription':
59 case 'removeSubscription':
64 if (!($this->dic->http()->wrapper()->post()->has(
'auth') && $this->dic->http()->wrapper()->post()->has(
'perm'))) {
76 foreach ($this->repo->getUserSubscriptions() as $subscription) {
77 if ($auth === $subscription->getAuth()) {
88 $this->dic->http()->wrapper()->post()->retrieve(
'subscription', $this->dic->refinery()->to()->string()),
96 $data[
'keys'][
'auth'],
97 $data[
'keys'][
'p256dh']
103 $this->dic->language()->txt(
'push_subscription_successfull'),
104 $this->dic->language()->txt(
'push_subscription_successfull_desc')
110 $auth = $this->dic->http()->wrapper()->post()->retrieve(
'auth', $this->dic->refinery()->to()->string());
112 $this->repo->deleteSubscription($auth);
118 $this->dic->ui()->mainTemplate()->addJavaScript(
'assets/js/push-subscription.js');
120 $auth = $this->dic->http()->wrapper()->post()->retrieve(
'auth', $this->dic->refinery()->kindlyTo()->string());
121 $perm = $this->dic->http()->wrapper()->post()->retrieve(
'perm', $this->dic->refinery()->kindlyTo()->string());
122 $agent = $this->dic->http()->request()->getServerParams()[
'HTTP_USER_AGENT'] ??
'';
124 if ($perm ===
'denied') {
125 $this->dic->ui()->mainTemplate()->setOnScreenMessage(
126 $this->dic->ui()->mainTemplate()::MESSAGE_TYPE_QUESTION,
127 $this->dic->language()->txt(
'push_client_inactive')
131 $this->dic->ui()->mainTemplate()->setOnScreenMessage(
132 $this->dic->ui()->mainTemplate()::MESSAGE_TYPE_FAILURE,
133 $this->dic->language()->txt(
'push_client_already_used')
136 if ($perm !==
'granted' && preg_match(
'/(Edg\/)/', $agent)) {
137 $this->dic->ui()->mainTemplate()->setOnScreenMessage(
138 $this->dic->ui()->mainTemplate()::MESSAGE_TYPE_INFO,
139 $this->dic->language()->txt(
'push_client_edge_case')
142 if ($perm ===
'' && preg_match(
'/(Mac)/', $agent)) {
143 $this->dic->ui()->mainTemplate()->setOnScreenMessage(
144 $this->dic->ui()->mainTemplate()::MESSAGE_TYPE_INFO,
145 $this->dic->language()->txt(
'push_client_ios_case')
149 if ($this->
checkSubscription($auth) && ($perm ===
'granted' || $perm ===
'default')) {
150 $public_key = (
new ilSetting(
'notifications'))->
get(
'application_server_key');
151 $target = $this->dic->ctrl()->getLinkTargetByClass(self::class,
'default');
152 $toggle = $this->dic->ui()->factory()->button()->toggle($this->dic->language()->txt(
'activate'),
'',
'')
154 ->withAdditionalOnLoadCode(
static fn(
$id) =>
"il.Notifications.initToggle($id, '$public_key', '$target')");
155 $this->dic->ui()->mainTemplate()->setContent($this->dic->ui()->renderer()->render($toggle));
158 $this->dic->ui()->mainTemplate()->printToStdout();
166 $target = ILIAS_HTTP_PATH .
'/' . $this->dic->ctrl()->getLinkTargetByClass(self::class,
'showSettings');
168 $this->dic->ui()->mainTemplate()->setContent($this->dic->ui()->renderer()->render(
169 $this->dic->ui()->factory()->legacy()->content(
'')->withOnLoadCode(
171 navigator.serviceWorker.ready.then((reg) => {
172 (reg.pushManager || {getSubscription: () => Promise.resolve(null)}).getSubscription().then((sub) => {
173 const form = document.createElement('form');
174 form.method = 'post';
175 form.action = '$target';
176 let auth = document.createElement('input');
178 auth.value = (sub === null) ? '' : sub.toJSON().keys.auth;
179 form.appendChild(auth);
180 perm = document.createElement('input');
182 perm.value = (typeof Notification === 'undefined') ? '' : Notification.permission;
183 form.appendChild(perm);
184 document.body.appendChild(form);
191 $this->dic->ui()->mainTemplate()->printToStdout();
192 $this->dic->http()->close();
$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)