ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilChatroomAdminViewGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
29 {
30  private const string CHATROOM_README_PATH = '/components/ILIAS/Chatroom/README.md';
31 
33 
34  public function __construct(ilChatroomObjectGUI $gui)
35  {
36  global $DIC;
37 
38  parent::__construct($gui);
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 
63  $instance = ilObjectFactory::getInstanceByRefId($ref_id, false);
64  if (!($instance instanceof ilObjChatroom)) {
65  $this->createPublicRoom();
66  return;
67  }
68 
70  if (!$obj_id) {
71  $this->createPublicRoom();
72  return;
73  }
74 
75  if (!ilObject::_hasUntrashedReference($obj_id)) {
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, 'components/ILIAS/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  {
111  return ilUtil::_getHttpPath() . self::CHATROOM_README_PATH;
112  }
113 
114  public function saveClientSettings(): void
115  {
116  $this->redirectIfNoPermission('write');
117 
118  $factory = new ilChatroomFormFactory();
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  'auth' => $form->getInput('auth')
136  ];
137 
138  if (!$settings['chat_enabled']) {
139  $settings['enable_osc'] = false;
140  }
141 
142  $chatSettings = new ilSetting('chatroom');
143  $chatSettings->set('chat_enabled', (string) $settings['chat_enabled']);
144  $chatSettings->set('enable_browser_notifications', (string) $settings['enable_browser_notifications']);
145  $chatSettings->set('conversation_idle_state_in_minutes', (string) $convIdleStateTime);
146  $chatSettings->set('enable_osc', (string) $settings['enable_osc']);
147 
148  $adminSettings = new ilChatroomAdmin($this->gui->getObject()->getId());
149  $adminSettings->saveClientSettings((object) $settings);
150 
151  $fileHandler = new ilChatroomConfigFileHandler();
152  $fileHandler->createClientConfigFile($settings);
153 
154  $this->mainTpl->setOnScreenMessage('success', $this->ilLng->txt('settings_has_been_saved'), true);
155  $this->ilCtrl->redirect($this->gui, 'view-clientsettings');
156  }
157 
158  public function clientsettings(?ilPropertyFormGUI $form = null): void
159  {
160  $this->redirectIfNoPermission(['visible','read']);
161 
162  $this->defaultActions();
163  $this->gui->switchToVisibleMode();
164 
165  $adminSettings = new ilChatroomAdmin($this->gui->getObject()->getId());
166  $serverSettings = $adminSettings->loadGeneralSettings();
167 
168  if ($form === null) {
169  $clientSettings = array_map(
170  static fn($value) => is_int($value) ? (string) $value : $value,
171  $adminSettings->loadClientSettings()
172  );
173  $factory = new ilChatroomFormFactory();
174  $form = $factory->getClientSettingsForm();
175  $form->setValuesByArray($clientSettings);
176  }
177 
178  $this->checkServerConnection($serverSettings);
179 
180  $form->setTitle($this->ilLng->txt('general_settings_title'));
181  if (ilChatroom::checkUserPermissions('write', $this->gui->getRefId(), false)) {
182  $form->addCommandButton('view-saveClientSettings', $this->ilLng->txt('save'));
183  } else {
185  $item = $form->getItemByPostVar('auth');
186  $item->setIsReadOnly(true);
187  }
188  $form->setFormAction($this->ilCtrl->getFormAction($this->gui, 'view-saveClientSettings'));
189 
190  $settingsTpl = $this->createSettingTemplate($form);
191  $this->mainTpl->setVariable('ADM_CONTENT', $settingsTpl->get());
192  }
193 }
static checkUserPermissions($permissions, int $ref_id, bool $send_info=true)
Checks user permissions by given array and ref_id.
Class ilChatroomAdminViewGUI.
checkServerConnection(array $serverSettings)
redirectIfNoPermission($permission)
Checks for requested permissions and redirects if the permission check failed.
static _hasUntrashedReference(int $obj_id)
checks whether an object has at least one reference that is not in trash
static _lookupObjId(int $ref_id)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
executeDefault(string $requestedMethod)
$ref_id
Definition: ltiauth.php:65
Class ilChatroomAdmin.
Class ilChatroomGUIHandler.
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
global $DIC
Definition: shib_login.php:26
static checkServerConnection(bool $use_cache=true)
static _getHttpPath()
__construct(Container $dic, ilPlugin $plugin)
__construct(ilChatroomObjectGUI $gui)
saveClientSettings(stdClass $settings)
Saves given client $settings into settingsTable.
createSettingTemplate(ilPropertyFormGUI $form)