ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
AllowOnScreenChatConversations.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
30
32{
33 private const string KEY_ENABLE_BROWSER_NOTIFICATIONS = 'chat_osc_browser_notifications';
34
35 public function getIdentifier(): string
36 {
37 return 'chat_osc_accept_msg';
38 }
39
40 public function isAvailable(): bool
41 {
42 return (new \ilSetting('chatroom'))->get('enable_osc', '0') === '1';
43 }
44
45 public function getLabel(Language $lng): string
46 {
47 return $lng->txt('chat_osc_accept_msg');
48 }
49
51 {
52 return AvailablePages::PrivacySettings;
53 }
54
55 public function getSection(): AvailableSections
56 {
57 return AvailableSections::Main;
58 }
59
60 public function getInput(
61 FieldFactory $field_factory,
65 ?\ilObjUser $user = null
66 ): Input {
67 $chat_settings = new \ilSetting('chatroom');
68 $lng->loadLanguageModule('chatroom_adm');
69
70 if ($chat_settings->get('enable_browser_notifications', '0') !== '1') {
71 return $field_factory->checkbox(
72 $lng->txt('chat_osc_accept_msg'),
73 $lng->txt('chat_osc_accept_msg_info')
74 )->withValue(
75 $user !== null
76 ? $user->getPref('chat_osc_accept_msg') === 'y'
77 : $settings->get('chat_osc_accept_msg') === 'y'
78 );
79 }
80
81 return $field_factory->optionalGroup(
82 [
83 self::KEY_ENABLE_BROWSER_NOTIFICATIONS => $field_factory->checkbox(
84 $lng->txt('osc_enable_browser_notifications_label'),
85 \sprintf(
86 $lng->txt('osc_enable_browser_notifications_info'),
87 (int) $chat_settings->get('conversation_idle_state_in_minutes')
88 )
89 )->withDisabled(
90 $settings->get('usr_settings_disable_chat_osc_accept_msg', '0') === '1'
91 )
92 ],
93 $lng->txt('chat_osc_accept_msg'),
94 $lng->txt('chat_osc_accept_msg_info')
95 )->withValue(
96 $this->buildValueForNotificationGroup($settings, $user)
97 );
98 }
99
100 public function getLegacyInput(
103 ?\ilObjUser $user = null
105 $lng->loadLanguageModule('chatroom');
106
107 $input = new \ilCheckboxInputGUI($lng->txt('chat_osc_accept_msg'));
108 $input->setChecked(
109 $user !== null
110 ? $user->getPref('chat_osc_accept_msg') === 'y'
111 : $settings->get('chat_osc_accept_msg') === 'y'
112 );
113
114 return $input;
115 }
116
120 ): string {
121 return $lng->txt('chat_osc_accepts_messages_no');
122 }
123
126 \ilObjUser $user
127 ): bool {
128 $user_value = $this->retrieveValueFromUser($user);
129 return $user_value[$this->getIdentifier()] !== false;
130 }
131
132 public function persistUserInput(
133 \ilObjUser $user,
134 mixed $input
135 ): \ilObjUser {
136 if ($input === null) {
137 $user->deletePref($this->getIdentifier());
138 $user->deletePref(self::KEY_ENABLE_BROWSER_NOTIFICATIONS);
139 $this->updateChatServer($user->getId(), false);
140
141 return $user;
142 }
143
144 if ($input === '1' || $input === '0') {
145 $input = $input === '1';
146 }
147
148 if (\is_bool($input)) {
149 $user->setPref($this->getIdentifier(), $input ? 'y' : 'n');
150 $this->updateChatServer($user->getId(), $input);
151
152 return $user;
153 }
154
155 if (\is_array($input)) {
156 $user->setPref($this->getIdentifier(), 'y');
157 $user->setPref(
158 self::KEY_ENABLE_BROWSER_NOTIFICATIONS,
159 $input[self::KEY_ENABLE_BROWSER_NOTIFICATIONS] ? 'y' : 'n'
160 );
161 $this->updateChatServer($user->getId(), true);
162 }
163
164 return $user;
165 }
166
167 public function retrieveValueFromUser(\ilObjUser $user): array
168 {
169 if ($user->getPref($this->getIdentifier()) !== 'y') {
170 return [
171 $this->getIdentifier() => false,
172 self::KEY_ENABLE_BROWSER_NOTIFICATIONS => false
173 ];
174 }
175
176 return [
177 $this->getIdentifier() => true,
178 self::KEY_ENABLE_BROWSER_NOTIFICATIONS => $user->getPref(self::KEY_ENABLE_BROWSER_NOTIFICATIONS) === 'y'
179 ];
180 }
181
184 ?\ilObjUser $user
185 ): ?array {
186 $active = $settings->get($this->getIdentifier()) === 'y';
187 $notification = false;
188 if ($user !== null) {
189 $active = $user->getPref($this->getIdentifier()) === 'y';
190 $notification = $user->getPref(self::KEY_ENABLE_BROWSER_NOTIFICATIONS) === 'y';
191 }
192
193 if ($active === false) {
194 return null;
195 }
196
197 return [
198 self::KEY_ENABLE_BROWSER_NOTIFICATIONS => $notification
199 ];
200 }
201
202 private function updateChatServer(int $user_id, bool $osc_state): void
203 {
204 $message = [
205 $user_id => [
206 'acceptsMessages' => $osc_state,
207 ]
208 ];
209
211 $connector = new \ilChatroomServerConnector($settings);
212 $connector->sendUserConfigChange(json_encode($message, JSON_THROW_ON_ERROR));
213 }
214}
$settings
Definition: index.php:44
isAvailable()
If this function returns false the setting will not be shown, even if it's PropertyAttributes would a...
getLegacyInput(Language $lng, \ilSetting $settings, ?\ilObjUser $user=null)
You don't need to add a post_var to the input as the User will handle this for you,...
getInput(FieldFactory $field_factory, Language $lng, Refinery $refinery, \ilSetting $settings, ?\ilObjUser $user=null)
Builds data types.
Definition: Factory.php:36
static getDefaultConfiguration()
Instantiates and returns ilChatroomAdmin object using instance_id and settings from settingsTable.
This class represents a property in a property form.
User class.
setPref(string $a_keyword, ?string $a_value)
deletePref(string $key)
getPref(string $keyword)
ILIAS Setting Class.
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'vtt', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This is what a factory for input fields looks like.
Definition: Factory.php:31
This describes commonalities between all inputs.
Definition: Input.php:47
get(string $class_name)
global $lng
Definition: privfeed.php:26
if(!file_exists('../ilias.ini.php'))