ILIAS  release_8 Revision v8.23
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  $settingsForm = $formFactory->getSettingsForm($this->obj_service, $this->gui->getObject());
33 
34  if (!$settingsForm->checkInput()) {
35  $settingsForm->setValuesByPost();
36  $this->general($settingsForm);
37  } else {
38  $this->gui->getObject()->setTitle($settingsForm->getInput('title'));
39  $this->gui->getObject()->setDescription($settingsForm->getInput('desc'));
40 
42  $period = $settingsForm->getItemByPostVar('access_period');
43  if ($period->getStart() && $period->getEnd()) {
44  $this->gui->getObject()->setAccessType(ilObjectActivation::TIMINGS_ACTIVATION);
45  $this->gui->getObject()->setAccessBegin($period->getStart()->get(IL_CAL_UNIX));
46  $this->gui->getObject()->setAccessEnd($period->getEnd()->get(IL_CAL_UNIX));
47  $this->gui->getObject()->setAccessVisibility((int) $settingsForm->getInput('access_visibility'));
48  } else {
49  $this->gui->getObject()->setAccessType(ilObjectActivation::TIMINGS_DEACTIVATED);
50  }
51 
52  $this->gui->getObject()->update();
53  $this->obj_service->commonSettings()->legacyForm($settingsForm, $this->gui->getObject())->saveTileImage();
54 
55  $room = ilChatroom::byObjectId($this->gui->getObject()->getId());
56  $requestSettings = $room->getSettings();
57  if (!$room) {
58  $room = new ilChatroom();
59  $requestSettings['object_id'] = $this->gui->getObject()->getId();
60  }
61 
62  foreach ($requestSettings as $setting => &$value) {
63  if ($settingsForm->getItemByPostVar($setting) !== null) {
64  $value = $settingsForm->getInput($setting);
65  }
66  }
67 
68  $room->saveSettings($requestSettings);
69 
70  $this->mainTpl->setOnScreenMessage('success', $this->ilLng->txt('saved_successfully'), true);
71  $this->ilCtrl->redirect($this->gui, 'settings-general');
72  }
73  }
74 
75  public function general(ilPropertyFormGUI $settingsForm = null): void
76  {
77  if (!ilChatroom::checkUserPermissions(['visible', 'read'], $this->gui->getRefId())) {
78  $this->ilCtrl->setParameterByClass(ilRepositoryGUI::class, 'ref_id', ROOT_FOLDER_ID);
79  $this->ilCtrl->redirectByClass(ilRepositoryGUI::class);
80  }
81 
82  $chatSettings = new ilSetting('chatroom');
83  if (!$chatSettings->get('chat_enabled', '0')) {
84  $this->mainTpl->setOnScreenMessage('info', $this->ilLng->txt('server_disabled'), true);
85  }
86 
87  $this->gui->switchToVisibleMode();
88 
89  $formFactory = new ilChatroomFormFactory();
90 
91  $room = ilChatroom::byObjectId($this->gui->getObject()->getId());
92 
93  if (!$settingsForm) {
94  $settingsForm = $formFactory->getSettingsForm($this->obj_service, $this->gui->getObject());
95 
96  $settings = [
97  'title' => $this->gui->getObject()->getTitle(),
98  'desc' => $this->gui->getObject()->getDescription(),
99  'access_period' => [
100  'start' => $this->gui->getObject()->getAccessBegin() ? (new ilDateTime(
101  $this->gui->getObject()->getAccessBegin(),
103  ))->get(IL_CAL_DATETIME) : '',
104  'end' => $this->gui->getObject()->getAccessEnd() ? (new ilDateTime(
105  $this->gui->getObject()->getAccessEnd(),
107  ))->get(IL_CAL_DATETIME) : ''
108  ],
109  'access_visibility' => (bool) $this->gui->getObject()->getAccessVisibility()
110  ];
111 
112  if ($room) {
114  $settingsForm,
115  array_merge($settings, $room->getSettings())
116  );
117  } else {
119  }
120  }
121 
122  $settingsForm->setTitle($this->ilLng->txt('settings_title'));
123  $settingsForm->addCommandButton('settings-saveGeneral', $this->ilLng->txt('save'));
124  $settingsForm->setFormAction($this->ilCtrl->getFormAction($this->gui, 'settings-saveGeneral'));
125 
126  $this->mainTpl->setVariable('ADM_CONTENT', $settingsForm->getHTML());
127  }
128 
129  public function executeDefault(string $requestedMethod): void
130  {
131  $this->general();
132  }
133 }
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
const IL_CAL_DATETIME
Class ilChatroomSettingsGUI.
const ROOT_FOLDER_ID
Definition: constants.php:32
executeDefault(string $requestedMethod)
const IL_CAL_UNIX
Class ilChatroomFormFactory.
Class ilChatroomGUIHandler.
general(ilPropertyFormGUI $settingsForm=null)
Class ilChatroom.
static byObjectId(int $object_id)
static applyValues(ilPropertyFormGUI $form, array $values)
Applies given values to field in given form.