ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilPersonalChatSettingsFormGUI.php
Go to the documentation of this file.
1 <?php
2 
3 require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
4 
10 {
14  protected $lng;
15 
19  protected $ctrl;
20 
24  protected $user;
25 
29  protected $mainTpl;
30 
34  protected $settings;
35 
39  protected $chatSettings = array();
40 
45 
49  protected $event;
50 
55  public function __construct($init_form = true)
56  {
57  global $DIC;
58 
59  parent::__construct();
60 
61  $this->user = $DIC->user();
62  $this->ctrl = $DIC->ctrl();
63  $this->settings = $DIC['ilSetting'];
64  $this->mainTpl = $DIC['tpl'];
65  $this->lng = $DIC['lng'];
66  $this->event = $DIC->event();
67 
68  $this->chatSettings = new ilSetting('chatroom');
69  $this->notificationSettings = new ilSetting('notifications');
70 
71  if ($init_form) {
72  $this->initForm();
73  }
74  }
75 
79  public function executeCommand()
80  {
81  switch ($this->ctrl->getCmd()) {
82  case 'saveChatOptions':
83  $this->saveChatOptions();
84  break;
85 
86  case 'showChatOptions':
87  default:
88  $this->showChatOptions();
89  break;
90  }
91  }
92 
96  public function isAccessible()
97  {
98  return (
99  $this->chatSettings->get('chat_enabled', false) && (
101  )
102  );
103  }
104 
108  protected function shouldShowNotificationOptions()
109  {
110  return $this->notificationSettings->get('enable_osd', false) && $this->chatSettings->get('play_invitation_sound', false);
111  }
112 
116  protected function shouldShowOnScreenChatOptions()
117  {
118  return (
119  $this->chatSettings->get('enable_osc', false) &&
120  !(bool) $this->settings->get('usr_settings_hide_chat_osc_accept_msg', false)
121  );
122  }
123 
127  protected function initForm()
128  {
129  $this->lng->loadLanguageModule('chatroom');
130 
131  $this->setFormAction($this->ctrl->getFormAction($this, 'saveChatOptions'));
132  $this->setTitle($this->lng->txt("chat_settings"));
133 
134  if ($this->shouldShowNotificationOptions()) {
135  $chb = new ilCheckboxInputGUI($this->lng->txt('play_invitation_sound'), 'play_invitation_sound');
136  $chb->setInfo($this->lng->txt('play_invitation_sound_info'));
137  $this->addItem($chb);
138  }
139 
140  if ($this->shouldShowOnScreenChatOptions()) {
141  $chb = new ilCheckboxInputGUI($this->lng->txt('chat_osc_accept_msg'), 'chat_osc_accept_msg');
142  $chb->setInfo($this->lng->txt('chat_osc_accept_msg_info'));
143  $chb->setDisabled((bool) $this->settings->get('usr_settings_disable_chat_osc_accept_msg', false));
144  $this->addItem($chb);
145  }
146 
147  $this->addCommandButton('saveChatOptions', $this->lng->txt('save'));
148  }
149 
153  protected function showChatOptions()
154  {
155  if (!$this->isAccessible()) {
156  $this->ctrl->returnToParent($this);
157  }
158 
159  $this->setValuesByArray(array(
160  'play_invitation_sound' => $this->user->getPref('chat_play_invitation_sound'),
161  'chat_osc_accept_msg' => ilUtil::yn2tf($this->user->getPref('chat_osc_accept_msg'))
162  ));
163 
164  $this->mainTpl->setContent($this->getHTML());
165  $this->mainTpl->show();
166  }
167 
171  protected function saveChatOptions()
172  {
173  if (!$this->isAccessible()) {
174  $this->ctrl->returnToParent($this);
175  }
176 
177  if (!$this->checkInput()) {
178  $this->showChatOptions();
179  return;
180  }
181 
182  if ($this->shouldShowNotificationOptions()) {
183  $this->user->setPref('chat_play_invitation_sound', (int) $this->getInput('play_invitation_sound'));
184  }
185 
186  if ($this->shouldShowOnScreenChatOptions() && !(bool) $this->settings->get('usr_settings_disable_chat_osc_accept_msg', false)) {
187  $this->user->setPref('chat_osc_accept_msg', ilUtil::tf2yn((bool) $this->getInput('chat_osc_accept_msg')));
188  }
189 
190  $this->user->writePrefs();
191 
192  $this->event->raise(
193  'Modules/Chatroom',
194  'chatSettingsChanged',
195  [
196  'user' => $this->user
197  ]
198  );
199 
200  ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
201  $this->showChatOptions();
202  }
203 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static tf2yn($a_tf)
convert true/false to "y"/"n"
This class represents a property form user interface.
global $DIC
Definition: saml.php:7
This class represents a checkbox property in a property form.
setFormAction($a_formaction)
Set FormAction.
addItem($a_item)
Add Item (Property, SectionHeader).
user()
Definition: user.php:4
setInfo($a_info)
Set Information Text.
setTitle($a_title)
Set Title.
__construct($init_form=true)
ilPersonalChatSettingsFormGUI constructor.
addCommandButton($a_cmd, $a_text, $a_id="")
Add Command button.
checkInput()
Check Post Input.
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
Create styles array
The data for the language used.
settings()
Definition: settings.php:2
Class ilPersonalChatSettingsFormGUI ilPersonalChatSettingsFormGUI: ilPersonalSettingsGUI.
static yn2tf($a_yn)
convert "y"/"n" to true/false
setValuesByArray($a_values, $a_restrict_to_value_keys=false)
Set form values from an array.