1 <?php declare(strict_types=1);
65 $this->
user = $DIC->user();
66 $this->ctrl = $DIC->ctrl();
68 $this->mainTpl = $DIC[
'tpl'];
69 $this->lng = $DIC[
'lng'];
70 $this->
event = $DIC->event();
71 $this->uiFactory = $DIC->ui()->factory();
72 $this->uiRenderer = $DIC->ui()->renderer();
73 $this->httpRequest = $DIC->http()->request();
74 $this->refinery = $DIC->refinery();
76 $this->lng->loadLanguageModule(
'chatroom');
77 $this->lng->loadLanguageModule(
'chatroom_adm');
79 $this->chatSettings =
new ilSetting(
'chatroom');
80 $this->notificationSettings =
new ilSetting(
'notifications');
88 switch ($this->ctrl->getCmd()) {
89 case 'saveChatOptions':
93 case 'showChatOptions':
106 $this->chatSettings->get(
'chat_enabled',
false) && (
118 $this->notificationSettings->get(
'enable_osd',
false) &&
119 $this->chatSettings->get(
'play_invitation_sound',
false)
129 $this->chatSettings->get(
'enable_osc',
false) &&
130 !(bool) $this->
settings->get(
'usr_settings_hide_chat_osc_accept_msg',
false)
139 $fieldFactory = $this->uiFactory->input()->field();
143 $checkboxStateToBooleanTrafo = $this->refinery->custom()->transformation(
function ($v) {
152 return $v ===
'checked';
156 $oscAvailable = (bool) $this->
settings->get(
'usr_settings_disable_chat_osc_accept_msg',
false);
157 $oscSubFormGroup = [];
159 if ($this->chatSettings->get(
'enable_browser_notifications',
false)) {
160 $enabledBrowserNotifications = $fieldFactory
162 $this->lng->txt(
'osc_enable_browser_notifications_label'),
164 $this->lng->txt(
'osc_enable_browser_notifications_info'),
165 (int) $this->chatSettings->get(
'conversation_idle_state_in_minutes')
168 ->withAdditionalTransformation($checkboxStateToBooleanTrafo)
169 ->withDisabled($oscAvailable);
171 $oscSubFormGroup[self::PROP_ENABLE_BROWSER_NOTIFICATIONS] = $enabledBrowserNotifications;
176 self::PROP_ENABLE_BROWSER_NOTIFICATIONS =>
ilUtil::yn2tf($this->
user->getPref(
'chat_osc_browser_notifications')),
179 $enabledOsc = $fieldFactory
182 $this->lng->txt(
'chat_osc_accept_msg'),
183 $this->lng->txt(
'chat_osc_accept_msg_info')
185 ->withAdditionalTransformation($checkboxStateToBooleanTrafo)
186 ->withDisabled($oscAvailable)
187 ->withValue($groupValue);
189 $enabledOsc = $fieldFactory
191 $this->lng->txt(
'chat_osc_accept_msg'),
192 $this->lng->txt(
'chat_osc_accept_msg_info')
194 ->withAdditionalTransformation($checkboxStateToBooleanTrafo)
195 ->withDisabled($oscAvailable)
199 $fields[self::PROP_ENABLE_OSC] = $enabledOsc;
203 $fields[self::PROP_ENABLE_SOUND] = $fieldFactory
204 ->checkbox($this->lng->txt(
'play_invitation_sound'), $this->lng->txt(
'play_invitation_sound_info'))
205 ->withAdditionalTransformation($checkboxStateToBooleanTrafo)
206 ->withValue((
bool) $this->
user->getPref(
'chat_play_invitation_sound'));
210 ->section($fields, $this->lng->txt(
'chat_settings'),
'');
212 return $this->uiFactory->input()
216 $this->ctrl->getFormAction($this,
'saveChatOptions'),
219 ->withAdditionalTransformation($this->refinery->custom()->transformation(
function ($values) {
220 return call_user_func_array(
'array_merge', $values);
231 $this->ctrl->returnToParent($this);
234 if (null === $form) {
238 $tpl =
new ilTemplate(
'tpl.personal_chat_settings_form.html',
true,
true,
'Modules/Chatroom');
240 $this->mainTpl->addJavascript(
'./Services/Notifications/js/browser_notifications.js');
244 $this->lng->toJSMap([
245 'osc_browser_noti_no_permission_error' => $this->lng->txt(
'osc_browser_noti_no_permission_error'),
246 'osc_browser_noti_no_support_error' => $this->lng->txt(
'osc_browser_noti_no_support_error'),
247 'osc_browser_noti_req_permission_error' => $this->lng->txt(
'osc_browser_noti_req_permission_error'),
251 $this->mainTpl->setContent($this->uiRenderer->render([
253 $this->uiFactory->legacy(
$tpl->get())
255 $this->mainTpl->printToStdout();
264 $this->ctrl->returnToParent($this);
269 if (
'POST' === $this->httpRequest->getMethod()) {
270 $form = $form->withRequest($this->httpRequest);
272 $formData = $form->getData();
273 $update_possible = !is_null($formData);
274 if ($update_possible) {
285 $preferencesUpdated =
false;
288 $oldPlaySoundValue = (int) $this->
user->getPref(
'chat_play_invitation_sound');
289 $playASound = (int) ($formData[self::PROP_ENABLE_SOUND] ?? 0);
291 if ($oldPlaySoundValue !== $playASound) {
292 $this->
user->setPref(
'chat_play_invitation_sound', $playASound);
293 $preferencesUpdated =
true;
299 $enableOsc = $formData[self::PROP_ENABLE_OSC] ?? null;
300 if (!is_bool($enableOsc)) {
301 $enableOsc = is_array($enableOsc);
304 if (!(
bool) $this->
settings->get(
'usr_settings_disable_chat_osc_accept_msg',
false)) {
305 $preferencesUpdated =
true;
306 if ($oldEnableOscValue !== $enableOsc) {
308 $preferencesUpdated =
true;
312 if ($this->chatSettings->get(
'enable_browser_notifications',
false) && $enableOsc) {
313 $oldBrowserNotificationValue =
ilUtil::yn2tf($this->
user->getPref(
'chat_osc_browser_notifications'));
315 $sendBrowserNotifications =
false;
316 if (is_array($formData[self::PROP_ENABLE_OSC])) {
317 if (
true === $formData[self::PROP_ENABLE_OSC][self::PROP_ENABLE_BROWSER_NOTIFICATIONS]) {
318 $sendBrowserNotifications =
true;
322 if ($oldBrowserNotificationValue !== $sendBrowserNotifications) {
323 $this->
user->setPref(
'chat_osc_browser_notifications',
ilUtil::tf2yn($sendBrowserNotifications));
324 $preferencesUpdated =
true;
329 if ($preferencesUpdated) {
330 $this->
user->writePrefs();
334 'chatSettingsChanged',
336 'user' => $this->
user 341 ilUtil::sendSuccess($this->lng->txt(
'saved_successfully'),
true);
342 $this->ctrl->redirect($this);
static tf2yn($a_tf)
convert true/false to "y"/"n"
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static yn2tf($a_yn)
convert "y"/"n" to true/false