ILIAS  release_8 Revision v8.24
class.ilObjChatroomGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23
34{
35 public function __construct($data = null, ?int $id = 0, bool $call_by_reference = true, bool $prepare_output = true)
36 {
37 $this->type = 'chtr';
39 $this->lng->loadLanguageModule('chatroom');
40 $this->lng->loadLanguageModule('chatroom_adm');
41 }
42
46 public static function _goto($params): void
47 {
48 global $DIC;
49 $main_tpl = $DIC->ui()->mainTemplate();
50
51 $parts = array_filter(explode('_', $params));
52 $ref_id = (int) $parts[0];
53 $sub = (int) ($parts[1] ?? 0);
54
55 if (ilChatroom::checkUserPermissions('read', $ref_id, false)) {
56 if ($sub) {
57 $DIC->ctrl()->setParameterByClass(self::class, 'sub', $sub);
58 }
59
60 $DIC->ctrl()->setParameterByClass(self::class, 'ref_id', $ref_id);
61 $DIC->ctrl()->redirectByClass(
62 [
63 ilRepositoryGUI::class,
64 self::class,
65 ],
66 'view'
67 );
68 } elseif (ilChatroom::checkUserPermissions('visible', $ref_id, false)) {
69 $DIC->ctrl()->setParameterByClass(ilInfoScreenGUI::class, 'ref_id', $ref_id);
70 $DIC->ctrl()->redirectByClass(
71 [
72 ilRepositoryGUI::class,
73 self::class,
74 ilInfoScreenGUI::class
75 ],
76 'info'
77 );
78 } elseif ($DIC->rbac()->system()->checkAccess('read', ROOT_FOLDER_ID)) {
79 $main_tpl->setOnScreenMessage('info', sprintf(
80 $DIC->language()->txt('msg_no_perm_read_item'),
82 ), true);
84 }
85
86 $DIC['ilErr']->raiseError(
87 sprintf(
88 $DIC->language()->txt('msg_no_perm_read_item'),
90 ),
91 $DIC['ilErr']->FATAL
92 );
93 }
94
96 {
98 }
99
100 protected function initCreationForms(string $new_type): array
101 {
102 $forms = parent::initCreationForms($new_type);
103
104 $forms[self::CFORM_NEW]->clearCommandButtons();
105 $forms[self::CFORM_NEW]->addCommandButton('create-save', $this->lng->txt($new_type . '_add'));
106 $forms[self::CFORM_NEW]->addCommandButton('cancel', $this->lng->txt('cancel'));
107
108 return $forms;
109 }
110
111 protected function addLocatorItems(): void
112 {
113 if (is_object($this->object)) {
114 $this->locator->addItem(
115 $this->object->getTitle(),
116 $this->ctrl->getLinkTarget($this, 'view'),
117 '',
118 $this->getRefId()
119 );
120 }
121 }
122
123 public function getRefId(): int
124 {
125 return $this->object->getRefId();
126 }
127
131 public function getUnsafeGetCommands(): array
132 {
133 return [];
134 }
135
139 public function getSafePostCommands(): array
140 {
141 return [
142 'view-toggleAutoMessageDisplayState',
143 ];
144 }
145
146 public function executeCommand(): void
147 {
148 global $DIC;
149
150 if ('cancel' === $this->ctrl->getCmd() && $this->getCreationMode()) {
151 $this->cancelCreation();
152 return;
153 }
154
155 $refId = $this->http->wrapper()->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int());
156 if (!$this->getCreationMode() && ilChatroom::checkPermissionsOfUser($this->user->getId(), 'read', $refId)) {
157 $DIC['ilNavigationHistory']->addItem(
158 $refId,
159 './goto.php?target=' . $this->type . '_' . $refId,
160 $this->type
161 );
162 }
163
164 $next_class = $this->ctrl->getNextClass();
165
166 $tabFactory = null;
167 if (!$this->getCreationMode()) {
168 $tabFactory = new ilChatroomTabGUIFactory($this);
169
170 $baseClass = '';
171 if ($this->http->wrapper()->query()->has('baseClass')) {
172 $baseClass = $this->http->wrapper()->query()->retrieve(
173 'baseClass',
174 $this->refinery->kindlyTo()->string()
175 );
176 }
177 if (strtolower($baseClass) === strtolower(ilAdministrationGUI::class)) {
178 $tabFactory->getAdminTabsForCommand($this->ctrl->getCmd());
179 } else {
180 $DIC['ilHelp']->setScreenIdComponent('chtr');
181 $tabFactory->getTabsForCommand($this->ctrl->getCmd());
182 }
183 }
184
185 // #8701 - infoscreen actions
186 if ($this->ctrl->getCmd() !== 'info' && strtolower($next_class) === strtolower(ilInfoScreenGUI::class)) {
187 $this->ctrl->setCmd('info-' . $this->ctrl->getCmd());
188 }
189
190 // repository info call
191 if ($this->ctrl->getCmd() === 'infoScreen') {
192 $this->ctrl->setCmdClass(ilInfoScreenGUI::class);
193 $this->ctrl->setCmd('info');
194 }
195
196 switch (strtolower($next_class)) {
197 case strtolower(ilPropertyFormGUI::class):
199 $form = $factory->getClientSettingsForm();
200 $this->ctrl->forwardCommand($form);
201 break;
202
203 case strtolower(ilPermissionGUI::class):
204 $this->prepareOutput();
205 $perm_gui = new ilPermissionGUI($this);
206 $this->ctrl->forwardCommand($perm_gui);
207 break;
208
209 case strtolower(ilExportGUI::class):
210 $this->prepareOutput();
211
212 $GLOBALS['DIC']->tabs()->setTabActive('export');
213
214 $exp = new ilExportGUI($this);
215 $exp->addFormat('xml');
216 $this->ctrl->forwardCommand($exp);
217 break;
218
219 case strtolower(ilObjectCopyGUI::class):
220 $this->prepareOutput();
221 $cp = new ilObjectCopyGUI($this);
222 $cp->setType('chtr');
223 $this->ctrl->forwardCommand($cp);
224 break;
225
226 case strtolower(ilCommonActionDispatcherGUI::class):
227 $this->prepareOutput();
229 $this->ctrl->forwardCommand($gui);
230 break;
231
232 default:
233 try {
234 $res = explode('-', $this->ctrl->getCmd(''), 2);
235 $result = $this->dispatchCall($res[0], $res[1] ?? '');
236 if (!$result && method_exists($this, $this->ctrl->getCmd() . 'Object')) {
237 $this->prepareOutput();
238 $this->{$this->ctrl->getCmd() . 'Object'}();
239 }
240 } catch (Exception $e) {
241 if ($this->ctrl->isAsynch()) {
242 $responseStream = Streams::ofString(json_encode([
243 'success' => false,
244 'reason' => $e->getMessage()
245 ], JSON_THROW_ON_ERROR));
246 $this->http->saveResponse(
247 $this->http->response()
248 ->withBody($responseStream)
249 ->withHeader(ResponseHeader::CONTENT_TYPE, 'application/json')
250 );
251 $this->http->sendResponse();
252 $this->http->close();
253 } else {
254 throw $e;
255 }
256 }
257 break;
258 }
259
260 if ($tabFactory !== null &&
261 $tabFactory->getActivatedTab() !== null &&
262 $this->tabs_gui->getActiveTab() !== $tabFactory->getActivatedTab()) {
263 $this->tabs_gui->activateTab($tabFactory->getActivatedTab());
264 }
265 }
266
268 {
270 }
271
275 public function fallback(): void
276 {
277 $this->prepareOutput();
278 $this->tpl->setVariable('ADM_CONTENT', $this->lng->txt('invalid_operation'));
279 }
280
284 public function settings(): void
285 {
286 $this->prepareOutput();
287 }
288
289 public function insertObject(): ilObjChatroom
290 {
291 $new_type = $this->type;
292 $refId = $this->http->wrapper()->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int());
293 $title = '';
294 if ($this->http->wrapper()->post()->has('title')) {
295 $title = ilUtil::stripSlashes(
296 $this->http->wrapper()->post()->retrieve(
297 'title',
298 $this->refinery->kindlyTo()->string()
299 )
300 );
301 }
302 $desc = '';
303 if ($this->http->wrapper()->post()->has('desc')) {
304 $desc = ilUtil::stripSlashes(
305 $this->http->wrapper()->post()->retrieve(
306 'desc',
307 $this->refinery->kindlyTo()->string()
308 )
309 );
310 }
311
312 // create permission is already checked in createObject.
313 // This check here is done to prevent hacking attempts
314 if (!$this->rbac_system->checkAccess('create', $refId, $new_type)) {
315 $this->ilias->raiseError(
316 $this->lng->txt('no_create_permission'),
317 $this->ilias->error_obj->MESSAGE
318 );
319 }
320
321 // create and insert object in objecttree
322 $class_name = 'ilObj' . $this->obj_definition->getClassName($new_type);
323
324 $newObj = new $class_name();
325 $newObj->setType($new_type);
326 $newObj->setTitle($title);
327 $newObj->setDescription($desc);
328 $newObj->create();
329 $newObj->createReference();
330 $newObj->putInTree($refId);
331 $newObj->setPermissions($refId);
332
333 $objId = $newObj->getId();
334
335 $room = new ilChatroom();
336 $room->saveSettings([
337 'object_id' => $objId,
338 'autogen_usernames' => 'Autogen #',
339 'display_past_msgs' => 20,
340 'private_rooms_enabled' => 0
341 ]);
342
343 $rbac_log_roles = $this->rbac_review->getParentRoleIds($newObj->getRefId());
344 $rbac_log = ilRbacLog::gatherFaPa($newObj->getRefId(), array_keys($rbac_log_roles), true);
345 ilRbacLog::add(ilRbacLog::CREATE_OBJECT, $newObj->getRefId(), $rbac_log);
346
347 $this->object = $newObj;
348
349 return $newObj;
350 }
351}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
static getDefaultConfiguration()
Instantiates and returns ilChatroomAdmin object using instance_id and settings from settingsTable.
Class ilChatroomFormFactory.
static getDefaultDefinition(string $moduleName)
Returns an Instance of ilChatroomObjectDefinition, using given $moduleName as parameter.
dispatchCall(string $gui, string $method)
Class ilChatroomServerConnector.
Class ilChatroomTabGUIFactory.
Class ilChatroom.
static checkPermissionsOfUser(int $usr_id, $permissions, int $ref_id)
Checks user permissions in question for a given user id in relation to a given ref_id.
static checkUserPermissions($permissions, int $ref_id, bool $send_info=true)
Checks user permissions by given array and ref_id.
static getInstanceFromAjaxCall()
(Re-)Build instance from ajax call
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilObjChatroomGUI GUI class for chatroom objects.
getSafePostCommands()
@inheritDoc
initCreationForms(string $new_type)
Init creation forms.
addLocatorItems()
should be overwritten to add object specific items (repository items are preloaded)
__construct($data=null, ?int $id=0, bool $call_by_reference=true, bool $prepare_output=true)
getUnsafeGetCommands()
@inheritDoc
fallback()
Calls $this->prepareOutput method and sets template variable.
settings()
Calls prepareOutput method.
static _goto($params)
@ineritdoc
Class ilObjChatroom.
GUI class for the workflow of copying objects.
cancelCreation()
cancel create action and go back to repository parent
static _gotoRepositoryNode(int $ref_id, string $cmd="")
prepareOutput(bool $show_sub_objects=true)
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
static add(int $a_action, int $a_ref_id, array $a_diff, bool $a_source_ref_id=false)
static gatherFaPa(int $a_ref_id, array $a_role_ids, bool $a_add_action=false)
const CREATE_OBJECT
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
const ROOT_FOLDER_ID
Definition: constants.php:32
global $DIC
Definition: feed.php:28
Interface ResponseHeader.
Interface ilCtrlSecurityInterface provides ilCtrl security information.
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:33
$res
Definition: ltiservices.php:69
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:64
$factory
Definition: metadata.php:75
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
header include for all ilias files.
$objId
Definition: xapitoken.php:57
$refId
Definition: xapitoken.php:58