ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
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 $values = null;
46 if ($this->http->request()->getMethod() === 'POST') {
47 $settingsForm = $settingsForm->withRequest($this->http->request());
48 $values = $settingsForm->getData();
49 } else {
50 $this->mainTpl->setOnScreenMessage('failure', $this->ilLng->txt('form_input_not_valid'));
51 }
52
53 if ($values === null) {
54 $this->general($settingsForm);
55 return;
56 }
57
58 $this->gui->getObject()->getObjectProperties()->storePropertyTitleAndDescription(
60 );
61 $this->gui->getObject()->getObjectProperties()->storePropertyIsOnline(
63 );
64 $this->gui->getObject()->getObjectProperties()->storePropertyTileImage(
66 );
67
68 $room = ilChatroom::byObjectId($this->gui->getObject()->getId());
69 $mutated_settings = $room->getSettings();
70 if (!$room) {
71 $room = new ilChatroom();
72 $mutated_settings['object_id'] = $this->gui->getObject()->getId();
73 }
74
75 foreach ($mutated_settings as $setting => &$value) {
77 $value = isset($values[$setting]);
78 } elseif ($setting === ilChatroomFormFactory::PROP_AUTOGEN_USERNAMES) {
80 } elseif (array_key_exists($setting, $values)) {
81 $value = $values[$setting];
82 }
83 }
84 unset($value);
85
86 $room->saveSettings($mutated_settings);
87
88 $this->mainTpl->setOnScreenMessage('success', $this->ilLng->txt('saved_successfully'), true);
89 $this->ilCtrl->redirect($this->gui, 'settings-general');
90 }
91
92 public function general(?\ILIAS\UI\Component\Input\Container\Form\Form $settingsForm = null): void
93 {
94 if (!ilChatroom::checkUserPermissions(['visible', 'read'], $this->gui->getRefId())) {
95 $this->ilCtrl->setParameterByClass(ilRepositoryGUI::class, 'ref_id', ROOT_FOLDER_ID);
96 $this->ilCtrl->redirectByClass(ilRepositoryGUI::class);
97 }
98
99 $chatSettings = new ilSetting('chatroom');
100 if (!$chatSettings->get('chat_enabled', '0')) {
101 $this->mainTpl->setOnScreenMessage('info', $this->ilLng->txt('server_disabled'), true);
102 }
103
104 $this->gui->switchToVisibleMode();
105
106 $formFactory = new ilChatroomFormFactory();
107
108 $room = ilChatroom::byObjectId($this->gui->getObject()->getId());
109
110 if ($settingsForm === null) {
111 $settings = [
112 'title' => $this->gui->getObject()->getTitle(),
113 'desc' => $this->gui->getObject()->getDescription(),
114 ];
115 if ($room) {
116 $settings = array_merge($settings, $room->getSettings());
117 }
118
119 $settingsForm = $formFactory->getSettingsForm(
120 $this->gui,
121 $this->ilCtrl,
122 $settings,
123 ilChatroom::checkUserPermissions(['write'], $this->gui->getRefId(), false)
124 );
125 }
126
127 $this->mainTpl->setVariable('ADM_CONTENT', $this->uiRenderer->render($settingsForm));
128 }
129
130 public function executeDefault(string $requestedMethod): void
131 {
132 $this->general();
133 }
134}
$settings
Definition: index.php:44
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.