ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilPersonalNotificationsSettingsGUI Class Reference

@ilCtrl_IsCalledBy ilPersonalNotificationsSettingsGUI: ilNotificationGUI More...

+ Collaboration diagram for ilPersonalNotificationsSettingsGUI:

Public Member Functions

 __construct (?Container $dic=null)
 
 executeCommand ()
 

Protected Member Functions

 checkSubscription (string $auth)
 
 addSubscription ()
 
 removeSubscription ()
 
 showSettings ()
 
 fetchClientData ()
 Respond a self-submitting form to fetch client data for push notifications. More...
 

Protected Attributes

Container $dic
 
PushRepository $repo
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilPersonalNotificationsSettingsGUI::__construct ( ?Container  $dic = null)

Definition at line 38 of file class.ilPersonalNotificationsSettingsGUI.php.

39 {
40 if ($dic === null) {
41 global $DIC;
42 $dic = $DIC;
43 }
44 $this->dic = $dic;
45 $this->repo = new PushRepository($this->dic->database(), $this->dic->user());
46 }
global $DIC
Definition: shib_login.php:26

References $DIC, and $dic.

Member Function Documentation

◆ addSubscription()

ilPersonalNotificationsSettingsGUI::addSubscription ( )
protected

Definition at line 85 of file class.ilPersonalNotificationsSettingsGUI.php.

85 : void
86 {
87 $data = json_decode(
88 $this->dic->http()->wrapper()->post()->retrieve('subscription', $this->dic->refinery()->to()->string()),
89 true,
90 512,
91 JSON_THROW_ON_ERROR
92 );
93 if (!$this->checkSubscription($data['keys']['auth'])) {
94 $this->repo->addSubscription(new PushSubscription(
95 $data['endpoint'],
96 $data['keys']['auth'],
97 $data['keys']['p256dh']
98 ));
99 }
100
102 $this->dic->user(),
103 $this->dic->language()->txt('push_subscription_successfull'),
104 $this->dic->language()->txt('push_subscription_successfull_desc')
105 );
106 }

References $data, and checkSubscription().

Referenced by executeCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkSubscription()

ilPersonalNotificationsSettingsGUI::checkSubscription ( string  $auth)
protected

Definition at line 71 of file class.ilPersonalNotificationsSettingsGUI.php.

71 : bool
72 {
73 if ($auth === '') {
74 return true;
75 }
76 foreach ($this->repo->getUserSubscriptions() as $subscription) {
77 if ($auth === $subscription->getAuth()) {
78 return true;
79 }
80 }
81
82 return false;
83 }

Referenced by addSubscription(), removeSubscription(), and showSettings().

+ Here is the caller graph for this function:

◆ executeCommand()

ilPersonalNotificationsSettingsGUI::executeCommand ( )

Definition at line 48 of file class.ilPersonalNotificationsSettingsGUI.php.

48 : void
49 {
50 $this->dic->language()->loadLanguageModule('notifications_adm');
51
52 $this->dic->ui()->mainTemplate()->setTitle($this->dic->language()->txt('push_settings'));
53 $this->dic->ui()->mainTemplate()->setTitleIcon(ilUtil::getImagePath('standard/icon_nota.svg'));
54
55 switch ($this->dic->ctrl()->getCmd()) {
56 case 'addSubscription':
57 $this->addSubscription();
58 break;
59 case 'removeSubscription':
60 $this->removeSubscription();
61 break;
62 case 'showSettings':
63 default:
64 if (!($this->dic->http()->wrapper()->post()->has('auth') && $this->dic->http()->wrapper()->post()->has('perm'))) {
65 $this->fetchClientData();
66 }
67 $this->showSettings();
68 }
69 }
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)

References addSubscription(), fetchClientData(), ilUtil\getImagePath(), removeSubscription(), and showSettings().

+ Here is the call graph for this function:

◆ fetchClientData()

ilPersonalNotificationsSettingsGUI::fetchClientData ( )
protected

Respond a self-submitting form to fetch client data for push notifications.

Definition at line 164 of file class.ilPersonalNotificationsSettingsGUI.php.

164 : never
165 {
166 $target = ILIAS_HTTP_PATH . '/' . $this->dic->ctrl()->getLinkTargetByClass(self::class, 'showSettings');
167
168 $this->dic->ui()->mainTemplate()->setContent($this->dic->ui()->renderer()->render(
169 $this->dic->ui()->factory()->legacy()->content('')->withOnLoadCode(
170 static fn($id) => "
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');
177 auth.name = 'auth';
178 auth.value = (sub === null) ? '' : sub.toJSON().keys.auth;
179 form.appendChild(auth);
180 perm = document.createElement('input');
181 perm.name = 'perm';
182 perm.value = (typeof Notification === 'undefined') ? '' : Notification.permission;
183 form.appendChild(perm);
184 document.body.appendChild(form);
185 form.submit();
186 })
187 });
188 "
189 )
190 ));
191 $this->dic->ui()->mainTemplate()->printToStdout();
192 $this->dic->http()->close();
193 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23

References $id.

Referenced by executeCommand().

+ Here is the caller graph for this function:

◆ removeSubscription()

ilPersonalNotificationsSettingsGUI::removeSubscription ( )
protected

Definition at line 108 of file class.ilPersonalNotificationsSettingsGUI.php.

108 : void
109 {
110 $auth = $this->dic->http()->wrapper()->post()->retrieve('auth', $this->dic->refinery()->to()->string());
111 if ($this->checkSubscription($auth)) {
112 $this->repo->deleteSubscription($auth);
113 }
114 }

References checkSubscription().

Referenced by executeCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ showSettings()

ilPersonalNotificationsSettingsGUI::showSettings ( )
protected

Definition at line 116 of file class.ilPersonalNotificationsSettingsGUI.php.

116 : void
117 {
118 $this->dic->ui()->mainTemplate()->addJavaScript('assets/js/push-subscription.js');
119
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'] ?? '';
123
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')
128 );
129 }
130 if (!$this->checkSubscription($auth)) {
131 $this->dic->ui()->mainTemplate()->setOnScreenMessage(
132 $this->dic->ui()->mainTemplate()::MESSAGE_TYPE_FAILURE,
133 $this->dic->language()->txt('push_client_already_used')
134 );
135 }
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')
140 );
141 }
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')
146 );
147 }
148
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'), '', '')
153 ->withEngagedState($auth !== '')
154 ->withAdditionalOnLoadCode(static fn($id) => "il.Notifications.initToggle($id, '$public_key', '$target')");
155 $this->dic->ui()->mainTemplate()->setContent($this->dic->ui()->renderer()->render($toggle));
156 }
157
158 $this->dic->ui()->mainTemplate()->printToStdout();
159 }
ILIAS Setting Class.

References $id, checkSubscription(), and ILIAS\UI\Implementation\Component\Button\withEngagedState().

Referenced by executeCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $dic

Container ilPersonalNotificationsSettingsGUI::$dic
protected

Definition at line 35 of file class.ilPersonalNotificationsSettingsGUI.php.

Referenced by __construct().

◆ $repo

PushRepository ilPersonalNotificationsSettingsGUI::$repo
protected

Definition at line 36 of file class.ilPersonalNotificationsSettingsGUI.php.


The documentation for this class was generated from the following file: