ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
ilPersonalChatSettingsFormGUI Class Reference

Class ilPersonalChatSettingsFormGUI. More...

+ Collaboration diagram for ilPersonalChatSettingsFormGUI:

Public Member Functions

 __construct ()
 ilPersonalChatSettingsFormGUI constructor. More...
 
 executeCommand ()
 
 isAccessible ()
 
 showChatOptions (Standard $form=null)
 
 saveChatOptions ()
 

Data Fields

const PROP_ENABLE_OSC = 'chat_osc_accept_msg'
 
const PROP_ENABLE_BROWSER_NOTIFICATIONS = 'chat_osc_browser_notifications'
 
const PROP_ENABLE_SOUND = 'play_invitation_sound'
 

Protected Attributes

 $lng
 
 $ctrl
 
 $user
 
 $mainTpl
 
 $settings
 
 $chatSettings = array()
 
 $notificationSettings = array()
 
 $event
 

Private Member Functions

 shouldShowNotificationOptions ()
 
 shouldShowOnScreenChatOptions ()
 
 buildForm ()
 
 saveFormData (array $formData)
 

Private Attributes

 $uiFactory
 
 $uiRenderer
 
 $httpRequest
 
 $refinery
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilPersonalChatSettingsFormGUI::__construct ( )

ilPersonalChatSettingsFormGUI constructor.

Definition at line 61 of file class.ilPersonalChatSettingsFormGUI.php.

References $DIC, settings(), and user().

62  {
63  global $DIC;
64 
65  $this->user = $DIC->user();
66  $this->ctrl = $DIC->ctrl();
67  $this->settings = $DIC['ilSetting'];
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();
75 
76  $this->lng->loadLanguageModule('chatroom');
77  $this->lng->loadLanguageModule('chatroom_adm');
78 
79  $this->chatSettings = new ilSetting('chatroom');
80  $this->notificationSettings = new ilSetting('notifications');
81  }
settings()
Definition: settings.php:2
user()
Definition: user.php:4
$DIC
Definition: xapitoken.php:46
+ Here is the call graph for this function:

Member Function Documentation

◆ buildForm()

ilPersonalChatSettingsFormGUI::buildForm ( )
private
Returns
Standard

Definition at line 137 of file class.ilPersonalChatSettingsFormGUI.php.

References $section, settings(), shouldShowNotificationOptions(), shouldShowOnScreenChatOptions(), user(), and ilUtil\yn2tf().

Referenced by saveChatOptions(), and showChatOptions().

137  : Standard
138  {
139  $fieldFactory = $this->uiFactory->input()->field();
140 
141  $fields = [];
142 
143  $checkboxStateToBooleanTrafo = $this->refinery->custom()->transformation(function ($v) {
144  if (is_array($v)) {
145  return $v;
146  }
147 
148  if (is_bool($v)) {
149  return $v;
150  }
151 
152  return $v === 'checked';
153  });
154 
155  if ($this->shouldShowOnScreenChatOptions()) {
156  $oscAvailable = (bool) $this->settings->get('usr_settings_disable_chat_osc_accept_msg', false);
157  $oscSubFormGroup = [];
158 
159  if ($this->chatSettings->get('enable_browser_notifications', false)) {
160  $enabledBrowserNotifications = $fieldFactory
161  ->checkbox(
162  $this->lng->txt('osc_enable_browser_notifications_label'),
163  sprintf(
164  $this->lng->txt('osc_enable_browser_notifications_info'),
165  (int) $this->chatSettings->get('conversation_idle_state_in_minutes')
166  )
167  )
168  ->withAdditionalTransformation($checkboxStateToBooleanTrafo)
169  ->withDisabled($oscAvailable);
170 
171  $oscSubFormGroup[self::PROP_ENABLE_BROWSER_NOTIFICATIONS] = $enabledBrowserNotifications;
172 
173  $groupValue = null;
174  if (ilUtil::yn2tf($this->user->getPref('chat_osc_accept_msg'))) {
175  $groupValue = [
176  self::PROP_ENABLE_BROWSER_NOTIFICATIONS => ilUtil::yn2tf($this->user->getPref('chat_osc_browser_notifications')),
177  ];
178  }
179  $enabledOsc = $fieldFactory
180  ->optionalGroup(
181  $oscSubFormGroup,
182  $this->lng->txt('chat_osc_accept_msg'),
183  $this->lng->txt('chat_osc_accept_msg_info')
184  )
185  ->withAdditionalTransformation($checkboxStateToBooleanTrafo)
186  ->withDisabled($oscAvailable)
187  ->withValue($groupValue);
188  } else {
189  $enabledOsc = $fieldFactory
190  ->checkbox(
191  $this->lng->txt('chat_osc_accept_msg'),
192  $this->lng->txt('chat_osc_accept_msg_info')
193  )
194  ->withAdditionalTransformation($checkboxStateToBooleanTrafo)
195  ->withDisabled($oscAvailable)
196  ->withValue(ilUtil::yn2tf($this->user->getPref('chat_osc_accept_msg')));
197  }
198 
199  $fields[self::PROP_ENABLE_OSC] = $enabledOsc;
200  }
201 
202  if ($this->shouldShowNotificationOptions()) {
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'));
207  }
208 
209  $section = $fieldFactory
210  ->section($fields, $this->lng->txt('chat_settings'), '');
211 
212  return $this->uiFactory->input()
213  ->container()
214  ->form()
215  ->standard(
216  $this->ctrl->getFormAction($this, 'saveChatOptions'),
217  [$section]
218  )
219  ->withAdditionalTransformation($this->refinery->custom()->transformation(function ($values) {
220  return call_user_func_array('array_merge', $values);
221  }));
222  }
settings()
Definition: settings.php:2
user()
Definition: user.php:4
$section
Definition: Utf8Test.php:83
This describes a standard form.
Definition: Standard.php:10
static yn2tf($a_yn)
convert "y"/"n" to true/false
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ executeCommand()

ilPersonalChatSettingsFormGUI::executeCommand ( )

Definition at line 86 of file class.ilPersonalChatSettingsFormGUI.php.

References saveChatOptions(), and showChatOptions().

86  : void
87  {
88  switch ($this->ctrl->getCmd()) {
89  case 'saveChatOptions':
90  $this->saveChatOptions();
91  break;
92 
93  case 'showChatOptions':
94  default:
95  $this->showChatOptions();
96  break;
97  }
98  }
+ Here is the call graph for this function:

◆ isAccessible()

ilPersonalChatSettingsFormGUI::isAccessible ( )
Returns
bool

Definition at line 103 of file class.ilPersonalChatSettingsFormGUI.php.

References shouldShowNotificationOptions(), and shouldShowOnScreenChatOptions().

Referenced by saveChatOptions(), and showChatOptions().

103  : bool
104  {
105  return (
106  $this->chatSettings->get('chat_enabled', false) && (
108  )
109  );
110  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveChatOptions()

ilPersonalChatSettingsFormGUI::saveChatOptions ( )

Definition at line 261 of file class.ilPersonalChatSettingsFormGUI.php.

References buildForm(), isAccessible(), saveFormData(), ilUtil\sendFailure(), and showChatOptions().

Referenced by executeCommand().

261  : void
262  {
263  if (!$this->isAccessible()) {
264  $this->ctrl->returnToParent($this);
265  }
266 
267  $form = $this->buildForm();
268 
269  if ('POST' === $this->httpRequest->getMethod()) {
270  $form = $form->withRequest($this->httpRequest);
271 
272  $formData = $form->getData();
273  $update_possible = !is_null($formData);
274  if ($update_possible) {
275  $this->saveFormData($formData);
276  }
277  }
278 
279  ilUtil::sendFailure($this->lng->txt('form_input_not_valid'));
280  $this->showChatOptions($form);
281  }
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveFormData()

ilPersonalChatSettingsFormGUI::saveFormData ( array  $formData)
private

Definition at line 283 of file class.ilPersonalChatSettingsFormGUI.php.

References settings(), shouldShowNotificationOptions(), shouldShowOnScreenChatOptions(), ilUtil\tf2yn(), user(), and ilUtil\yn2tf().

Referenced by saveChatOptions().

283  : void
284  {
285  $preferencesUpdated = false;
286 
287  if ($this->shouldShowNotificationOptions()) {
288  $oldPlaySoundValue = (int) $this->user->getPref('chat_play_invitation_sound');
289  $playASound = (int) ($formData[self::PROP_ENABLE_SOUND] ?? 0);
290 
291  if ($oldPlaySoundValue !== $playASound) {
292  $this->user->setPref('chat_play_invitation_sound', $playASound);
293  $preferencesUpdated = true;
294  }
295  }
296 
297  if ($this->shouldShowOnScreenChatOptions()) {
298  $oldEnableOscValue = ilUtil::yn2tf($this->user->getPref('chat_osc_accept_msg'));
299  $enableOsc = $formData[self::PROP_ENABLE_OSC] ?? null;
300  if (!is_bool($enableOsc)) {
301  $enableOsc = is_array($enableOsc);
302  }
303 
304  if (!(bool) $this->settings->get('usr_settings_disable_chat_osc_accept_msg', false)) {
305  $preferencesUpdated = true;
306  if ($oldEnableOscValue !== $enableOsc) {
307  $this->user->setPref('chat_osc_accept_msg', ilUtil::tf2yn($enableOsc));
308  $preferencesUpdated = true;
309  }
310  }
311 
312  if ($this->chatSettings->get('enable_browser_notifications', false) && $enableOsc) {
313  $oldBrowserNotificationValue = ilUtil::yn2tf($this->user->getPref('chat_osc_browser_notifications'));
314 
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;
319  }
320  }
321 
322  if ($oldBrowserNotificationValue !== $sendBrowserNotifications) {
323  $this->user->setPref('chat_osc_browser_notifications', ilUtil::tf2yn($sendBrowserNotifications));
324  $preferencesUpdated = true;
325  }
326  }
327  }
328 
329  if ($preferencesUpdated) {
330  $this->user->writePrefs();
331 
332  $this->event->raise(
333  'Modules/Chatroom',
334  'chatSettingsChanged',
335  [
336  'user' => $this->user
337  ]
338  );
339  }
340 
341  ilUtil::sendSuccess($this->lng->txt('saved_successfully'), true);
342  $this->ctrl->redirect($this);
343  }
static tf2yn($a_tf)
convert true/false to "y"/"n"
settings()
Definition: settings.php:2
user()
Definition: user.php:4
static yn2tf($a_yn)
convert "y"/"n" to true/false
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ shouldShowNotificationOptions()

ilPersonalChatSettingsFormGUI::shouldShowNotificationOptions ( )
private
Returns
bool

Definition at line 115 of file class.ilPersonalChatSettingsFormGUI.php.

Referenced by buildForm(), isAccessible(), and saveFormData().

115  : bool
116  {
117  return (
118  $this->notificationSettings->get('enable_osd', false) &&
119  $this->chatSettings->get('play_invitation_sound', false)
120  );
121  }
+ Here is the caller graph for this function:

◆ shouldShowOnScreenChatOptions()

ilPersonalChatSettingsFormGUI::shouldShowOnScreenChatOptions ( )
private
Returns
bool

Definition at line 126 of file class.ilPersonalChatSettingsFormGUI.php.

References settings().

Referenced by buildForm(), isAccessible(), saveFormData(), and showChatOptions().

126  : bool
127  {
128  return (
129  $this->chatSettings->get('enable_osc', false) &&
130  !(bool) $this->settings->get('usr_settings_hide_chat_osc_accept_msg', false)
131  );
132  }
settings()
Definition: settings.php:2
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ showChatOptions()

ilPersonalChatSettingsFormGUI::showChatOptions ( Standard  $form = null)
Parameters
Standard | null$form
Exceptions
ilTemplateException

Definition at line 228 of file class.ilPersonalChatSettingsFormGUI.php.

References $mainTpl, $tpl, buildForm(), ilUtil\getImagePath(), isAccessible(), and shouldShowOnScreenChatOptions().

Referenced by executeCommand(), and saveChatOptions().

228  : void
229  {
230  if (!$this->isAccessible()) {
231  $this->ctrl->returnToParent($this);
232  }
233 
234  if (null === $form) {
235  $form = $this->buildForm();
236  }
237 
238  $tpl = new ilTemplate('tpl.personal_chat_settings_form.html', true, true, 'Modules/Chatroom');
239  if ($this->shouldShowOnScreenChatOptions() && $this->chatSettings->get('enable_browser_notifications', false)) {
240  $this->mainTpl->addJavascript('./Services/Notifications/js/browser_notifications.js');
241 
242  $tpl->setVariable('ALERT_IMAGE_SRC', ilUtil::getImagePath('icon_alert.svg'));
243 
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'),
248  ], $this->mainTpl);
249  }
250 
251  $this->mainTpl->setContent($this->uiRenderer->render([
252  $form,
253  $this->uiFactory->legacy($tpl->get())
254  ]));
255  $this->mainTpl->printToStdout();
256  }
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)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $chatSettings

ilPersonalChatSettingsFormGUI::$chatSettings = array()
protected

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

◆ $ctrl

ilPersonalChatSettingsFormGUI::$ctrl
protected

Definition at line 26 of file class.ilPersonalChatSettingsFormGUI.php.

◆ $event

ilPersonalChatSettingsFormGUI::$event
protected

Definition at line 44 of file class.ilPersonalChatSettingsFormGUI.php.

◆ $httpRequest

ilPersonalChatSettingsFormGUI::$httpRequest
private

Definition at line 53 of file class.ilPersonalChatSettingsFormGUI.php.

◆ $lng

ilPersonalChatSettingsFormGUI::$lng
protected

Definition at line 23 of file class.ilPersonalChatSettingsFormGUI.php.

◆ $mainTpl

ilPersonalChatSettingsFormGUI::$mainTpl
protected

Definition at line 32 of file class.ilPersonalChatSettingsFormGUI.php.

Referenced by showChatOptions().

◆ $notificationSettings

ilPersonalChatSettingsFormGUI::$notificationSettings = array()
protected

Definition at line 41 of file class.ilPersonalChatSettingsFormGUI.php.

◆ $refinery

ilPersonalChatSettingsFormGUI::$refinery
private

Definition at line 56 of file class.ilPersonalChatSettingsFormGUI.php.

◆ $settings

ilPersonalChatSettingsFormGUI::$settings
protected

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

◆ $uiFactory

ilPersonalChatSettingsFormGUI::$uiFactory
private

Definition at line 47 of file class.ilPersonalChatSettingsFormGUI.php.

◆ $uiRenderer

ilPersonalChatSettingsFormGUI::$uiRenderer
private

Definition at line 50 of file class.ilPersonalChatSettingsFormGUI.php.

◆ $user

ilPersonalChatSettingsFormGUI::$user
protected

Definition at line 29 of file class.ilPersonalChatSettingsFormGUI.php.

◆ PROP_ENABLE_BROWSER_NOTIFICATIONS

const ilPersonalChatSettingsFormGUI::PROP_ENABLE_BROWSER_NOTIFICATIONS = 'chat_osc_browser_notifications'

Definition at line 19 of file class.ilPersonalChatSettingsFormGUI.php.

◆ PROP_ENABLE_OSC

const ilPersonalChatSettingsFormGUI::PROP_ENABLE_OSC = 'chat_osc_accept_msg'

Definition at line 18 of file class.ilPersonalChatSettingsFormGUI.php.

◆ PROP_ENABLE_SOUND

const ilPersonalChatSettingsFormGUI::PROP_ENABLE_SOUND = 'play_invitation_sound'

Definition at line 20 of file class.ilPersonalChatSettingsFormGUI.php.


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