ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilChatroomSettingsGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
28{
29 public function saveGeneral(): void
30 {
31 if (!ilChatroom::checkUserPermissions(['write'], $this->gui->getRefId())) {
32 $this->ilCtrl->setParameterByClass(ilRepositoryGUI::class, 'ref_id', ROOT_FOLDER_ID);
33 $this->ilCtrl->redirectByClass(ilRepositoryGUI::class);
34 }
35
36 $formFactory = new ilChatroomFormFactory();
37
38 $settingsForm = $formFactory->getSettingsForm(
39 $this->gui,
40 $this->ilCtrl,
41 null,
42 true
43 );
44
45 $result = (new \ILIAS\Data\Factory())->error($this->ilLng->txt('form_input_not_valid'));
46 if ($this->http->request()->getMethod() === 'POST') {
47 $settingsForm = $settingsForm->withRequest($this->http->request());
48 $result = $settingsForm->getInputGroup()->getContent();
49 }
50
51 if (!$result->isOK()) {
52 $this->mainTpl->setOnScreenMessage('failure', $result->error());
53 $this->general($settingsForm);
54 return;
55 }
56
57 $values = $result->value();
58
59 $this->gui->getObject()->getObjectProperties()->storePropertyTitleAndDescription(
61 );
62 $this->gui->getObject()->getObjectProperties()->storePropertyIsOnline(
64 );
65 $this->gui->getObject()->getObjectProperties()->storePropertyTileImage(
67 );
68
69 $room = ilChatroom::byObjectId($this->gui->getObject()->getId());
70 $mutated_settings = $room->getSettings();
71 if (!$room) {
72 $room = new ilChatroom();
73 $mutated_settings['object_id'] = $this->gui->getObject()->getId();
74 }
75
76 foreach ($mutated_settings as $setting => &$value) {
78 $value = is_array($values[$setting] ?? null);
79 } elseif ($setting === ilChatroomFormFactory::PROP_AUTOGEN_USERNAMES) {
81 } elseif (array_key_exists($setting, $values)) {
82 $value = $values[$setting];
83 }
84 }
85 unset($value);
86
87 $room->saveSettings($mutated_settings);
88
89 $this->mainTpl->setOnScreenMessage('success', $this->ilLng->txt('saved_successfully'), true);
90 $this->ilCtrl->redirect($this->gui, 'settings-general');
91 }
92
93 public function general(?\ILIAS\UI\Component\Input\Container\Form\Form $settingsForm = null): void
94 {
95 if (!ilChatroom::checkUserPermissions(['visible', 'read'], $this->gui->getRefId())) {
96 $this->ilCtrl->setParameterByClass(ilRepositoryGUI::class, 'ref_id', ROOT_FOLDER_ID);
97 $this->ilCtrl->redirectByClass(ilRepositoryGUI::class);
98 }
99
100 $chatSettings = new ilSetting('chatroom');
101 if (!$chatSettings->get('chat_enabled', '0')) {
102 $this->mainTpl->setOnScreenMessage('info', $this->ilLng->txt('server_disabled'), true);
103 }
104
105 $this->gui->switchToVisibleMode();
106
107 $formFactory = new ilChatroomFormFactory();
108
109 $room = ilChatroom::byObjectId($this->gui->getObject()->getId());
110
111 if ($settingsForm === null) {
112 $settings = [
113 'title' => $this->gui->getObject()->getTitle(),
114 'desc' => $this->gui->getObject()->getDescription(),
115 ];
116 if ($room) {
117 $settings = array_merge($settings, $room->getSettings());
118 }
119
120 $settingsForm = $formFactory->getSettingsForm(
121 $this->gui,
122 $this->ilCtrl,
123 $settings,
124 ilChatroom::checkUserPermissions(['write'], $this->gui->getRefId(), false)
125 );
126 }
127
128 $this->mainTpl->setVariable('ADM_CONTENT', $this->uiRenderer->render($settingsForm));
129 }
130
131 public function executeDefault(string $requestedMethod): void
132 {
133 $this->general();
134 }
135}
error(string $a_errmsg)
Class ilChatroomGUIHandler.
Class ilChatroomSettingsGUI.
general(?\ILIAS\UI\Component\Input\Container\Form\Form $settingsForm=null)
executeDefault(string $requestedMethod)
Class ilChatroom.
static checkUserPermissions($permissions, int $ref_id, bool $send_info=true)
Checks user permissions by given array and ref_id.
static byObjectId(int $object_id)
Class ilCtrl provides processing control methods.
redirectByClass( $a_class, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false)
@inheritDoc
redirect(object $a_gui_obj, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false)
@inheritDoc
setParameterByClass(string $a_class, string $a_parameter, $a_value)
@inheritDoc
ILIAS Setting Class.
const ROOT_FOLDER_ID
Definition: constants.php:32
static http()
Fetches the global http state from ILIAS.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.