ILIAS  release_8 Revision v8.24
class.ilChatroomAdminViewGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
29{
30 private const CHATROOM_README_PATH = '/Modules/Chatroom/README.md';
31
33
35 {
36 global $DIC;
37
39 $this->commonSettings = new ilSetting('common');
40 }
41
42 public function executeDefault(string $requestedMethod): void
43 {
44 $this->ilCtrl->redirect($this->gui, 'view-clientsettings');
45 }
46
47 private function defaultActions(): void
48 {
49 $chatSettings = new ilSetting('chatroom');
50 if ($chatSettings->get('chat_enabled', '0')) {
51 $this->forcePublicRoom();
52 }
53 }
54
55 public function forcePublicRoom(): void
56 {
58 if (!$ref_id) {
59 $this->createPublicRoom();
60 return;
61 }
62
64 if (!($instance instanceof ilObjChatroom)) {
65 $this->createPublicRoom();
66 return;
67 }
68
70 if (!$obj_id) {
71 $this->createPublicRoom();
72 return;
73 }
74
76 $this->createPublicRoom();
77 return;
78 }
79
80 ilChatroomInstaller::ensureCorrectPublicChatroomTreeLocation($ref_id);
81 }
82
83 public function createPublicRoom(): void
84 {
85 ilChatroomInstaller::createDefaultPublicRoom(true);
86 $this->mainTpl->setOnScreenMessage('success', $this->ilLng->txt('public_chat_created'), true);
87 }
88
89 protected function checkServerConnection(array $serverSettings): void
90 {
91 if (
92 isset($serverSettings['port'], $serverSettings['address']) &&
94 ) {
95 $this->mainTpl->setOnScreenMessage('info', $this->ilLng->txt('chat_cannot_connect_to_server'));
96 }
97 }
98
100 {
101 $furtherInformation = sprintf($this->ilLng->txt('server_further_information'), $this->getReadmePath());
102 $serverTpl = new ilTemplate('tpl.chatroom_serversettings.html', true, true, 'Modules/Chatroom');
103 $serverTpl->setVariable('VAL_SERVERSETTINGS_FORM', $form->getHTML());
104 $serverTpl->setVariable('LBL_SERVERSETTINGS_FURTHER_INFORMATION', $furtherInformation);
105
106 return $serverTpl;
107 }
108
109 protected function getReadmePath(): string
110 {
112 }
113
114 public function saveClientSettings(): void
115 {
116 $this->redirectIfNoPermission('write');
117
119 $form = $factory->getClientSettingsForm();
120
121 if (!$form->checkInput()) {
122 $form->setValuesByPost();
123 $this->clientsettings($form);
124 return;
125 }
126
127 $convIdleStateTime = max(1, (int) $form->getInput('conversation_idle_state_in_minutes'));
128
129 $settings = [
130 'name' => (string) $form->getInput('client_name'),
131 'enable_osc' => (bool) $form->getInput('enable_osc'),
132 'enable_browser_notifications' => (bool) $form->getInput('enable_browser_notifications'),
133 'conversation_idle_state_in_minutes' => $convIdleStateTime,
134 'chat_enabled' => (bool) $form->getInput('chat_enabled'),
135 'enable_smilies' => (bool) $form->getInput('enable_smilies'),
136 'auth' => $form->getInput('auth')
137 ];
138
139 if (!$settings['chat_enabled']) {
140 $settings['enable_osc'] = false;
141 }
142
143 $chatSettings = new ilSetting('chatroom');
144 $chatSettings->set('chat_enabled', (string) $settings['chat_enabled']);
145 $chatSettings->set('enable_browser_notifications', (string) $settings['enable_browser_notifications']);
146 $chatSettings->set('conversation_idle_state_in_minutes', (string) $convIdleStateTime);
147 $chatSettings->set('enable_osc', (string) $settings['enable_osc']);
148
149 $adminSettings = new ilChatroomAdmin($this->gui->getObject()->getId());
150 $adminSettings->saveClientSettings((object) $settings);
151
152 $fileHandler = new ilChatroomConfigFileHandler();
153 $fileHandler->createClientConfigFile($settings);
154
155 $this->mainTpl->setOnScreenMessage('success', $this->ilLng->txt('settings_has_been_saved'), true);
156 $this->ilCtrl->redirect($this->gui, 'view-clientsettings');
157 }
158
159 public function clientsettings(ilPropertyFormGUI $form = null): void
160 {
161 $this->redirectIfNoPermission(['visible','read']);
162
163 $this->defaultActions();
164 $this->gui->switchToVisibleMode();
165
166 $adminSettings = new ilChatroomAdmin($this->gui->getObject()->getId());
167 $serverSettings = $adminSettings->loadGeneralSettings();
168
169 if ($form === null) {
170 $clientSettings = array_map(
171 static fn ($value) => is_int($value) ? (string) $value : $value,
172 $adminSettings->loadClientSettings()
173 );
175 $form = $factory->getClientSettingsForm();
176 $form->setValuesByArray($clientSettings);
177 }
178
179 $this->checkServerConnection($serverSettings);
180
181 $form->setTitle($this->ilLng->txt('general_settings_title'));
182 if (ilChatroom::checkUserPermissions('write', $this->gui->getRefId(), false)) {
183 $form->addCommandButton('view-saveClientSettings', $this->ilLng->txt('save'));
184 } else {
186 $item = $form->getItemByPostVar('auth');
187 $item->setIsReadOnly(true);
188 }
189 $form->setFormAction($this->ilCtrl->getFormAction($this->gui, 'view-saveClientSettings'));
190
191 $settingsTpl = $this->createSettingTemplate($form);
192 $this->mainTpl->setVariable('ADM_CONTENT', $settingsTpl->get());
193 }
194}
Class ilChatroomAdminViewGUI.
__construct(ilChatroomObjectGUI $gui)
executeDefault(string $requestedMethod)
checkServerConnection(array $serverSettings)
createSettingTemplate(ilPropertyFormGUI $form)
Class ilChatroomAdmin.
Class ilChatroomFormFactory.
Class ilChatroomGUIHandler.
redirectIfNoPermission($permission)
Checks for requested permissions and redirects if the permission check failed.
static checkServerConnection(bool $use_cache=true)
static checkUserPermissions($permissions, int $ref_id, bool $send_info=true)
Checks user permissions by given array and ref_id.
Class ilCtrl provides processing control methods.
redirect(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
@inheritDoc
getFormAction(object $a_gui_obj, string $a_fallback_cmd=null, string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@inheritDoc
Class ilObjChatroom.
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
static _hasUntrashedReference(int $obj_id)
checks whether an object has at least one reference that is not in trash
static _lookupObjId(int $ref_id)
This class represents a property form user interface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
special template class to simplify handling of ITX/PEAR
static _getHttpPath()
global $DIC
Definition: feed.php:28
$ref_id
Definition: ltiauth.php:67
$factory
Definition: metadata.php:75
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200