ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilChatroomAdminViewGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
29{
30 private const string CHATROOM_README_PATH = __DIR__ . '/../../README.md';
31
33
34 public function __construct(ilChatroomObjectGUI $gui)
35 {
37 $this->commonSettings = new ilSetting('common');
38 }
39
40 public function executeDefault(string $requestedMethod): void
41 {
42 $this->ilCtrl->redirect($this->gui, 'view-clientsettings');
43 }
44
45 private function defaultActions(): void
46 {
47 $chatSettings = new ilSetting('chatroom');
48 if ($chatSettings->get('chat_enabled', '0')) {
49 $this->forcePublicRoom();
50 }
51 }
52
53 public function forcePublicRoom(): void
54 {
56 if (!$ref_id) {
57 $this->createPublicRoom();
58 return;
59 }
60
62 if (!($instance instanceof ilObjChatroom)) {
63 $this->createPublicRoom();
64 return;
65 }
66
68 if (!$obj_id) {
69 $this->createPublicRoom();
70 return;
71 }
72
74 $this->createPublicRoom();
75 return;
76 }
77
78 ilChatroomInstaller::ensureCorrectPublicChatroomTreeLocation($ref_id);
79 }
80
81 public function createPublicRoom(): void
82 {
83 ilChatroomInstaller::createDefaultPublicRoom(true);
84 $this->mainTpl->setOnScreenMessage('success', $this->ilLng->txt('public_chat_created'), true);
85 }
86
87 protected function checkServerConnection(array $serverSettings): void
88 {
89 if (
90 isset($serverSettings['port'], $serverSettings['address']) &&
92 ) {
93 $this->mainTpl->setOnScreenMessage('info', $this->ilLng->txt('chat_cannot_connect_to_server'));
94 }
95 }
96
97 public function saveClientSettings(): void
98 {
99 $this->redirectIfNoPermission('write');
100
101 $factory = new ilChatroomFormFactory();
102 $form = $factory->getClientSettingsForm();
103
104 if (!$form->checkInput()) {
105 $form->setValuesByPost();
106 $this->clientsettings($form);
107 return;
108 }
109
110 $convIdleStateTime = max(1, (int) $form->getInput('conversation_idle_state_in_minutes'));
111
112 $settings = [
113 'name' => (string) $form->getInput('client_name'),
114 'enable_osc' => (bool) $form->getInput('enable_osc'),
115 'enable_browser_notifications' => (bool) $form->getInput('enable_browser_notifications'),
116 'conversation_idle_state_in_minutes' => $convIdleStateTime,
117 'chat_enabled' => (bool) $form->getInput('chat_enabled'),
118 'auth' => $form->getInput('auth')
119 ];
120
121 if (!$settings['chat_enabled']) {
122 $settings['enable_osc'] = false;
123 }
124
125 $chatSettings = new ilSetting('chatroom');
126 $chatSettings->set('chat_enabled', (string) $settings['chat_enabled']);
127 $chatSettings->set('enable_browser_notifications', (string) $settings['enable_browser_notifications']);
128 $chatSettings->set('conversation_idle_state_in_minutes', (string) $convIdleStateTime);
129 $chatSettings->set('enable_osc', (string) $settings['enable_osc']);
130
131 $adminSettings = new ilChatroomAdmin($this->gui->getObject()->getId());
132 $adminSettings->saveClientSettings((object) $settings);
133
134 $osc_accept_msg = $form->getInput('chat_osc_accept_msg');
135 $broadcast_typing = $form->getInput('chat_broadcast_typing');
136 if (in_array($osc_accept_msg, ['n', 'y'], true)) {
137 $this->commonSettings->set('chat_osc_accept_msg', $osc_accept_msg);
138 }
139
140 if (in_array($broadcast_typing, ['n', 'y'], true)) {
141 $this->commonSettings->set('chat_broadcast_typing', $broadcast_typing);
142 }
143
144 $fileHandler = new ilChatroomConfigFileHandler();
145 $fileHandler->createClientConfigFile($settings);
146
147 $this->mainTpl->setOnScreenMessage('success', $this->ilLng->txt('settings_has_been_saved'), true);
148 $this->ilCtrl->redirect($this->gui, 'view-clientsettings');
149 }
150
151 public function deliverDocumentation(): never
152 {
153 $this->redirectIfNoPermission(['visible','read']);
154
155 $this->file_delivery->delivery()->inline(
156 ILIAS\Filesystem\Stream\Streams::ofResource(
157 fopen(self::CHATROOM_README_PATH, 'rb')
158 ),
159 basename(self::CHATROOM_README_PATH),
160 'text/markdown'
161 );
162 }
163
164 public function clientsettings(?ilPropertyFormGUI $form = null): void
165 {
166 $this->redirectIfNoPermission(['visible','read']);
167
168 $this->defaultActions();
169 $this->gui->switchToVisibleMode();
170
171 $adminSettings = new ilChatroomAdmin($this->gui->getObject()->getId());
172 $serverSettings = $adminSettings->loadGeneralSettings();
173
174 if ($form === null) {
175 $clientSettings = array_map(
176 static fn($value) => is_int($value) ? (string) $value : $value,
177 $adminSettings->loadClientSettings()
178 );
179 $clientSettings['chat_osc_accept_msg'] = $this->commonSettings->get('chat_osc_accept_msg', 'n');
180 $clientSettings['chat_broadcast_typing'] = $this->commonSettings->get('chat_broadcast_typing', 'n');
181 $factory = new ilChatroomFormFactory();
182 $form = $factory->getClientSettingsForm();
183 $form->setValuesByArray($clientSettings);
184 }
185
186 $this->checkServerConnection($serverSettings);
187
188 $form->setTitle($this->ilLng->txt('general_settings_title'));
189 if (ilChatroom::checkUserPermissions('write', $this->gui->getRefId(), false)) {
190 $form->addCommandButton('view-saveClientSettings', $this->ilLng->txt('save'));
191 } else {
193 $item = $form->getItemByPostVar('auth');
194 $item->setIsReadOnly(true);
195 }
196 $form->setFormAction($this->ilCtrl->getFormAction($this->gui, 'view-saveClientSettings'));
197
198 $this->mainTpl->setContent($this->uiRenderer->render([
199 $this->uiFactory->messageBox()->info(
200 $this->ilLng->txt('server_further_information')
201 )->withLinks([
202 $this->uiFactory->link()->standard(
203 $this->ilLng->txt('server_readme_file_btn_label'),
204 $this->ilCtrl->getLinkTarget($this->gui, 'view-deliverDocumentation')
205 )->withOpenInNewViewport(true)
206 ]),
207 $this->uiFactory->legacy()->content($form->getHTML())
208 ]));
209 }
210}
Class ilChatroomAdminViewGUI.
__construct(ilChatroomObjectGUI $gui)
executeDefault(string $requestedMethod)
checkServerConnection(array $serverSettings)
Class ilChatroomAdmin.
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.
getFormAction(object $a_gui_obj, ?string $a_fallback_cmd=null, ?string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@inheritDoc
redirect(object $a_gui_obj, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false)
@inheritDoc
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.
ILIAS Setting Class.
$ref_id
Definition: ltiauth.php:66
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.