ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilChatroomSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
28 {
29  public function saveGeneral(): void
30  {
31  $formFactory = new ilChatroomFormFactory();
32 
33  $settingsForm = $formFactory->getSettingsForm(
34  $this->gui,
35  $this->ilCtrl
36  );
37 
38  $result = (new \ILIAS\Data\Factory())->error($this->ilLng->txt('form_input_not_valid'));
39  if ($this->http->request()->getMethod() === 'POST') {
40  $settingsForm = $settingsForm->withRequest($this->http->request());
41  $result = $settingsForm->getInputGroup()->getContent();
42  }
43 
44  if (!$result->isOK()) {
45  $this->mainTpl->setOnScreenMessage('failure', $result->error());
46  $this->general($settingsForm);
47  return;
48  }
49 
50  $values = $result->value();
51 
52  $this->gui->getObject()->getObjectProperties()->storePropertyTitleAndDescription(
54  );
55  $this->gui->getObject()->getObjectProperties()->storePropertyIsOnline(
57  );
58  $this->gui->getObject()->getObjectProperties()->storePropertyTileImage(
60  );
61 
62  $room = ilChatroom::byObjectId($this->gui->getObject()->getId());
63  $mutated_settings = $room->getSettings();
64  if (!$room) {
65  $room = new ilChatroom();
66  $mutated_settings['object_id'] = $this->gui->getObject()->getId();
67  }
68 
69  foreach ($mutated_settings as $setting => &$value) {
71  $value = is_array($values[$setting] ?? null);
72  } elseif ($setting === ilChatroomFormFactory::PROP_AUTOGEN_USERNAMES) {
74  } elseif (array_key_exists($setting, $values)) {
75  $value = $values[$setting];
76  }
77  }
78  unset($value);
79 
80  $room->saveSettings($mutated_settings);
81 
82  $this->mainTpl->setOnScreenMessage('success', $this->ilLng->txt('saved_successfully'), true);
83  $this->ilCtrl->redirect($this->gui, 'settings-general');
84  }
85 
86  public function general(\ILIAS\UI\Component\Input\Container\Form\Form $settingsForm = null): void
87  {
88  if (!ilChatroom::checkUserPermissions(['visible', 'read'], $this->gui->getRefId())) {
89  $this->ilCtrl->setParameterByClass(ilRepositoryGUI::class, 'ref_id', ROOT_FOLDER_ID);
90  $this->ilCtrl->redirectByClass(ilRepositoryGUI::class);
91  }
92 
93  $chatSettings = new ilSetting('chatroom');
94  if (!$chatSettings->get('chat_enabled', '0')) {
95  $this->mainTpl->setOnScreenMessage('info', $this->ilLng->txt('server_disabled'), true);
96  }
97 
98  $this->gui->switchToVisibleMode();
99 
100  $formFactory = new ilChatroomFormFactory();
101 
102  $room = ilChatroom::byObjectId($this->gui->getObject()->getId());
103 
104  if ($settingsForm === null) {
105  $settings = [
106  'title' => $this->gui->getObject()->getTitle(),
107  'desc' => $this->gui->getObject()->getDescription(),
108  ];
109  if ($room) {
110  $settings = array_merge($settings, $room->getSettings());
111  }
112 
113  $settingsForm = $formFactory->getSettingsForm(
114  $this->gui,
115  $this->ilCtrl,
116  $settings
117  );
118  }
119 
120  $this->mainTpl->setVariable('ADM_CONTENT', $this->uiRenderer->render($settingsForm));
121  }
122 
123  public function executeDefault(string $requestedMethod): void
124  {
125  $this->general();
126  }
127 }
static checkUserPermissions($permissions, int $ref_id, bool $send_info=true)
Checks user permissions by given array and ref_id.
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
Class ilChatroomSettingsGUI.
const ROOT_FOLDER_ID
Definition: constants.php:32
Class ChatMainBarProvider .
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
executeDefault(string $requestedMethod)
static http()
Fetches the global http state from ILIAS.
Class ilChatroomGUIHandler.
general(\ILIAS\UI\Component\Input\Container\Form\Form $settingsForm=null)
Class ilChatroom.
static byObjectId(int $object_id)