ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilChatroomAdminViewGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
5require_once 'Modules/Chatroom/classes/class.ilChatroomFormFactory.php';
6require_once 'Modules/Chatroom/classes/class.ilChatroomAdmin.php';
7require_once 'Modules/Chatroom/classes/class.ilChatroomConfigFileHandler.php';
8
17{
18 const CHATROOM_README_PATH = '/Modules/Chatroom/README.md';
19
23 protected $commonSettings;
24
28 protected $ilTpl;
29
35 {
36 global $DIC;
37
39 $this->commonSettings = new ilSetting('common');
40 $this->ilTpl = $DIC->ui()->mainTemplate();
41 }
42
46 public function executeDefault($requestedMethod)
47 {
48 $this->ilCtrl->redirect($this->gui, 'view-clientsettings');
49 }
50
51 private function defaultActions()
52 {
53 $chatSettings = new ilSetting('chatroom');
54 if ($chatSettings->get('chat_enabled', false)) {
55 $this->forcePublicRoom();
56 }
57 }
58
62 public function forcePublicRoom()
63 {
65 if (!$ref_id) {
66 $this->createPublicRoom();
67 return;
68 }
69
70 $instance = ilObjectFactory::getInstanceByRefId($ref_id, false);
71 if (!$instance) {
72 $this->createPublicRoom();
73 return;
74 }
75
76 $obj_id = ilObject::_lookupObjId($ref_id);
77 if (!$obj_id) {
78 $this->createPublicRoom();
79 return;
80 }
81
83 $this->createPublicRoom();
84 return;
85 }
86
87 require_once 'Modules/Chatroom/classes/class.ilChatroomInstaller.php';
88 ilChatroomInstaller::ensureCorrectPublicChatroomTreeLocation($ref_id);
89 }
90
94 public function createPublicRoom()
95 {
96 require_once 'Modules/Chatroom/classes/class.ilChatroomInstaller.php';
97 ilChatroomInstaller::createDefaultPublicRoom(true);
98 ilUtil::sendSuccess($this->ilLng->txt('public_chat_created'), true);
99 }
100
105 protected function checkServerConnection(array $serverSettings)
106 {
107 require_once 'Modules/Chatroom/classes/class.ilChatroomServerConnector.php';
108
109 if (
110 $serverSettings['port'] &&
111 $serverSettings['address'] &&
113 ) {
114 ilUtil::sendInfo($this->ilLng->txt('chat_cannot_connect_to_server'));
115 }
116 }
117
122 protected function createSettingTemplate(ilPropertyFormGUI $form)
123 {
124 $furtherInformation = sprintf($this->ilLng->txt('server_further_information'), $this->getReadmePath());
125 $serverTpl = new ilTemplate('tpl.chatroom_serversettings.html', true, true, 'Modules/Chatroom');
126 $serverTpl->setVariable('VAL_SERVERSETTINGS_FORM', $form->getHTML());
127 $serverTpl->setVariable('LBL_SERVERSETTINGS_FURTHER_INFORMATION', $furtherInformation);
128
129 return $serverTpl;
130 }
131
136 protected function getReadmePath()
137 {
139 }
140
144 public function saveClientSettings()
145 {
146 $this->redirectIfNoPermission('write');
147
149 $form = $factory->getClientSettingsForm();
150
151 if (!$form->checkInput()) {
152 $form->setValuesByPost();
153 $this->clientsettings($form);
154 return;
155 }
156
157 $convIdleStateTime = max(1, (int) (int) $form->getInput('conversation_idle_state_in_minutes'));
158
159 $settings = array(
160 'name' => (string) $form->getInput('client_name'),
161 'enable_osd' => (boolean) $form->getInput('enable_osd'),
162 'enable_osc' => (boolean) $form->getInput('enable_osc'),
163 'enable_browser_notifications' => (boolean) $form->getInput('enable_browser_notifications'),
164 'conversation_idle_state_in_minutes' => $convIdleStateTime,
165 'osd_intervall' => (int) $form->getInput('osd_intervall'),
166 'chat_enabled' => ((boolean) $form->getInput('chat_enabled')),
167 'enable_smilies' => (boolean) $form->getInput('enable_smilies'),
168 'play_invitation_sound' => (boolean) $form->getInput('play_invitation_sound'),
169 'auth' => $form->getInput('auth')
170 );
171
172 if (!$settings['chat_enabled']) {
173 $settings['enable_osc'] = false;
174 }
175
176 $notificationSettings = new ilSetting('notifications');
177 $notificationSettings->set('osd_polling_intervall', (int) $form->getInput('osd_intervall'));
178 $notificationSettings->set('enable_osd', (boolean) $form->getInput('enable_osd'));
179
180 $chatSettings = new ilSetting('chatroom');
181 $chatSettings->set('chat_enabled', $settings['chat_enabled']);
182 $chatSettings->set('enable_browser_notifications', $settings['enable_browser_notifications']);
183 $chatSettings->set('conversation_idle_state_in_minutes', $convIdleStateTime);
184 $chatSettings->set('enable_osc', $settings['enable_osc']);
185 $chatSettings->set('play_invitation_sound', (boolean) $form->getInput('play_invitation_sound'));
186
187 $adminSettings = new ilChatroomAdmin($this->gui->object->getId());
188 $adminSettings->saveClientSettings((object) $settings);
189
190 $fileHandler = new ilChatroomConfigFileHandler();
191 $fileHandler->createClientConfigFile($settings);
192
193 ilUtil::sendSuccess($this->ilLng->txt('settings_has_been_saved'), true);
194 $this->ilCtrl->redirect($this->gui, 'view-clientsettings');
195 }
196
200 public function clientsettings(ilPropertyFormGUI $form = null)
201 {
202 $this->redirectIfNoPermission(['visible','read']);
203
204 $this->defaultActions();
205 $this->gui->switchToVisibleMode();
206
207 $adminSettings = new ilChatroomAdmin($this->gui->object->getId());
208 $serverSettings = $adminSettings->loadGeneralSettings();
209
210 if ($form === null) {
211 $clientSettings = $adminSettings->loadClientSettings();
213 $form = $factory->getClientSettingsForm();
214 $form->setValuesByArray($clientSettings);
215 }
216
217 $this->checkServerConnection($serverSettings);
218
219 $form->setTitle($this->ilLng->txt('general_settings_title'));
220 if (ilChatroom::checkUserPermissions('write', $this->gui->ref_id, false)) {
221 $form->addCommandButton('view-saveClientSettings', $this->ilLng->txt('save'));
222 } else {
223 $form->getItemByPostVar('auth')->setIsReadOnly(true);
224 }
225 $form->setFormAction($this->ilCtrl->getFormAction($this->gui, 'view-saveClientSettings'));
226
227 $settingsTpl = $this->createSettingTemplate($form);
228 $this->ilTpl->setVariable('ADM_CONTENT', $settingsTpl->get());
229 }
230}
An exception for terminatinating execution or to throw for unit testing.
Class ilChatroomAdminViewGUI.
__construct(ilChatroomObjectGUI $gui)
Constructor.
executeDefault($requestedMethod)
@inheritDoc
createPublicRoom()
Creates a public chatroom.
checkServerConnection(array $serverSettings)
Checks for server connection.
saveClientSettings()
Saves client settings fetched from $_POST.
clientsettings(ilPropertyFormGUI $form=null)
getReadmePath()
Get the path to the README.txt file.
createSettingTemplate(ilPropertyFormGUI $form)
Class ilChatroomAdmin.
Class ilChatroomFormFactory.
Class ilChatroomGUIHandler.
redirectIfNoPermission($permission)
Checks for requested permissions and redirects if the permission check failed.
static checkServerConnection($use_cache=true)
static checkUserPermissions($permissions, $ref_id, $send_info=true)
Checks user permissions by given array and ref_id.
This class provides processing control methods.
getFormAction( $a_gui_obj, $a_fallback_cmd="", $a_anchor="", $a_asynch=false, $xml_style=false)
Get form action url for gui class object.
redirect($a_gui_obj, $a_cmd="", $a_anchor="", $a_asynch=false)
Redirect to another command.
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
static _lookupObjId($a_id)
static _hasUntrashedReference($a_obj_id)
checks wether an object has at least one reference that is not in trash
This class represents a property form user interface.
ILIAS Setting Class.
special template class to simplify handling of ITX/PEAR
static _getHttpPath()
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
global $DIC
Definition: goto.php:24
$factory
Definition: metadata.php:58
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc