ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
PushNotification.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use Exception;
33use ilSetting;
34use ilObjUser;
36
38
40{
41 public function getIdentifier(): string
42 {
43 return 'push_notification';
44 }
45
46 public function isAvailable(): bool
47 {
48 return (new ilSetting('notifications'))->get('enable_push') === '1' && count(require PushNotificationObjective::PATH()) > 0;
49 }
50
51 public function getLabel(Language $lng): string
52 {
53 $lng->loadLanguageModule('notifications');
54 return $lng->txt($this->getIdentifier());
55 }
56
58 {
59 return AvailablePages::MainSettings;
60 }
61
62 public function getSection(): AvailableSections
63 {
64 return AvailableSections::Communication;
65 }
66
67 public function getInput(
68 FieldFactory $field_factory,
71 ilSetting $settings,
72 ?ilObjUser $user = null
73 ): Input {
74 $lng->loadLanguageModule('notifications_adm');
75
76 $pref = $user ? $this->retrieveValueFromUser($user) : [];
77 $provider = [];
78
79 foreach (require PushNotificationObjective::PATH() as $class) {
80 $obj = new $class();
81 $provider[$obj->getIdentifier()] = $field_factory->checkbox(
82 $obj->getName($lng),
83 $obj->getDescription($lng),
84 )->withValue(in_array($obj->getIdentifier(), $pref));
85 }
86
87 return $field_factory->section(
89 $lng->txt('push_settings')
90 );
91 }
92
93 public function getLegacyInput(Language $lng, ilSetting $settings, ?ilObjUser $user = null): ilFormPropertyGUI
94 {
95 throw new Exception('This Setting does not provide an legacy Input.');
96 }
97
98 public function getDefaultValueForDisplay(Language $lng, ilSetting $settings): string
99 {
100 return $lng->txt('none');
101 }
102
103 public function hasUserPersonalizedSetting(ilSetting $settings, ilObjUser $user): bool
104 {
105 return $user->getPref('push_notification_provider') !== null;
106 }
107
108 public function persistUserInput(ilObjUser $user, mixed $input): ilObjUser
109 {
110 $active = [];
111 foreach ($input ?? [] as $key => $value) {
112 if ($value === true) {
113 $active[] = $key;
114 }
115 }
116 $user->setPref('push_notification_provider', json_encode($active));
117 $user->update();
118 return $user;
119 }
120
121 public function retrieveValueFromUser(ilObjUser $user): ?array
122 {
123 return json_decode($user->getPref('push_notification_provider') ?? '[]');
124 }
125}
Builds data types.
Definition: Factory.php:36
isAvailable()
If this function returns false the setting will not be shown, even if it's PropertyAttributes would a...
hasUserPersonalizedSetting(ilSetting $settings, ilObjUser $user)
getInput(FieldFactory $field_factory, Language $lng, Refinery $refinery, ilSetting $settings, ?ilObjUser $user=null)
getLegacyInput(Language $lng, ilSetting $settings, ?ilObjUser $user=null)
getDefaultValueForDisplay(Language $lng, ilSetting $settings)
A configuration with no content.
Definition: NullConfig.php:27
This class represents a property in a property form.
User class.
setPref(string $a_keyword, ?string $a_value)
getPref(string $a_keyword)
ILIAS Setting Class.
This is what a factory for input fields looks like.
Definition: Factory.php:31
This describes commonalities between all inputs.
Definition: Input.php:47
$provider
Definition: ltitoken.php:80
global $lng
Definition: privfeed.php:31