ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  {
73  $this->initForm();
74  }
75  }
76 
80  public function executeCommand()
81  {
82  switch($this->ctrl->getCmd())
83  {
84  case 'saveChatOptions':
85  $this->saveChatOptions();
86  break;
87 
88  case 'showChatOptions':
89  default:
90  $this->showChatOptions();
91  break;
92  }
93  }
94 
98  public function isAccessible()
99  {
100  return (
101  $this->chatSettings->get('chat_enabled', false) && (
103  )
104  );
105  }
106 
110  protected function shouldShowNotificationOptions()
111  {
112  return $this->notificationSettings->get('enable_osd', false) && $this->chatSettings->get('play_invitation_sound', false);
113  }
114 
118  protected function shouldShowOnScreenChatOptions()
119  {
120  return (
121  $this->chatSettings->get('enable_osc', false) &&
122  !(bool)$this->settings->get('usr_settings_hide_chat_osc_accept_msg', false)
123  );
124  }
125 
129  protected function initForm()
130  {
131  $this->lng->loadLanguageModule('chatroom');
132 
133  $this->setFormAction($this->ctrl->getFormAction($this, 'saveChatOptions'));
134  $this->setTitle($this->lng->txt("chat_settings"));
135 
136  if($this->shouldShowNotificationOptions())
137  {
138  $chb = new ilCheckboxInputGUI($this->lng->txt('play_invitation_sound'), 'play_invitation_sound');
139  $this->addItem($chb);
140  }
141 
142  if($this->shouldShowOnScreenChatOptions())
143  {
144  $chb = new ilCheckboxInputGUI($this->lng->txt('chat_osc_accept_msg'), 'chat_osc_accept_msg');
145  $chb->setInfo($this->lng->txt('chat_osc_accept_msg_info'));
146  $chb->setDisabled((bool)$this->settings->get('usr_settings_disable_chat_osc_accept_msg', false));
147  $this->addItem($chb);
148  }
149 
150  $this->addCommandButton('saveChatOptions', $this->lng->txt('save'));
151  }
152 
156  protected function showChatOptions()
157  {
158  if(!$this->isAccessible())
159  {
160  $this->ctrl->returnToParent($this);
161  }
162 
163  $this->setValuesByArray(array(
164  'play_invitation_sound' => $this->user->getPref('chat_play_invitation_sound'),
165  'chat_osc_accept_msg' => ilUtil::yn2tf($this->user->getPref('chat_osc_accept_msg'))
166  ));
167 
168  $this->mainTpl->setContent($this->getHTML());
169  $this->mainTpl->show();
170  }
171 
175  protected function saveChatOptions()
176  {
177  if(!$this->isAccessible())
178  {
179  $this->ctrl->returnToParent($this);
180  }
181 
182  if(!$this->checkInput())
183  {
184  $this->showChatOptions();
185  return;
186  }
187 
188  if($this->shouldShowNotificationOptions())
189  {
190  $this->user->setPref('chat_play_invitation_sound', (int)$this->getInput('play_invitation_sound'));
191  }
192 
193  if($this->shouldShowOnScreenChatOptions() && !(bool)$this->settings->get('usr_settings_disable_chat_osc_accept_msg', false))
194  {
195  $this->user->setPref('chat_osc_accept_msg', ilUtil::tf2yn((bool)$this->getInput('chat_osc_accept_msg')));
196  }
197 
198  $this->user->writePrefs();
199 
200  $this->event->raise(
201  'Services/User',
202  'chatSettingsChanged',
203  [
204  'user' => $this->user
205  ]
206  );
207 
208  ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
209  $this->showChatOptions();
210  }
211 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static tf2yn($a_tf)
convert true/false to "y"/"n"
ILIAS Setting Class.
This class represents a property form user interface.
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.
global $DIC
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.