ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilObjChatroomGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
24
30{
31 public function __construct($data = null, ?int $id = 0, bool $call_by_reference = true, bool $prepare_output = true)
32 {
33 $this->type = 'chtr';
35 $this->lng->loadLanguageModule('chatroom');
36 $this->lng->loadLanguageModule('chatroom_adm');
37 }
38
39 public static function _goto($params): void
40 {
41 global $DIC;
42 $main_tpl = $DIC->ui()->mainTemplate();
43
44 $parts = array_filter(explode('_', (string) $params));
45 $ref_id = (int) $parts[0];
46 $sub = (int) ($parts[1] ?? 0);
47
48 if (ilChatroom::checkUserPermissions('read', $ref_id, false)) {
49 if ($sub) {
50 $DIC->ctrl()->setParameterByClass(self::class, 'sub', $sub);
51 }
52
53 $DIC->ctrl()->setParameterByClass(self::class, 'ref_id', $ref_id);
54 $DIC->ctrl()->redirectByClass(
55 [
56 ilRepositoryGUI::class,
57 self::class,
58 ],
59 'view'
60 );
61 } elseif (ilChatroom::checkUserPermissions('visible', $ref_id, false)) {
62 $DIC->ctrl()->setParameterByClass(ilInfoScreenGUI::class, 'ref_id', $ref_id);
63 $DIC->ctrl()->redirectByClass(
64 [
65 ilRepositoryGUI::class,
66 self::class,
67 ilInfoScreenGUI::class
68 ],
69 'info'
70 );
71 } elseif ($DIC->rbac()->system()->checkAccess('read', ROOT_FOLDER_ID)) {
72 $main_tpl->setOnScreenMessage('info', sprintf(
73 $DIC->language()->txt('msg_no_perm_read_item'),
75 ), true);
77 }
78
79 $DIC['ilErr']->raiseError(
80 sprintf(
81 $DIC->language()->txt('msg_no_perm_read_item'),
83 ),
84 $DIC['ilErr']->FATAL
85 );
86 }
87
89 {
91 }
92
93 protected function addLocatorItems(): void
94 {
95 if (is_object($this->object)) {
96 $this->locator->addItem(
97 $this->object->getTitle(),
98 $this->ctrl->getLinkTarget($this, 'view'),
99 '',
100 $this->getRefId()
101 );
102 }
103 }
104
105 public function getRefId(): int
106 {
107 return $this->object->getRefId();
108 }
109
110 public function getUnsafeGetCommands(): array
111 {
112 return [
113 'ban-handleTableActions',
114 ];
115 }
116
117 public function getSafePostCommands(): array
118 {
119 return [
120 'view-toggleAutoMessageDisplayState',
121 ];
122 }
123
124 public function executeCommand(): void
125 {
126 global $DIC;
127
128 if ('cancel' === $this->ctrl->getCmd() && $this->getCreationMode()) {
129 $this->cancelCreation();
130 return;
131 }
132
133 $refId = $this->http->wrapper()->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int());
134 if (!$this->getCreationMode() && ilChatroom::checkPermissionsOfUser($this->user->getId(), 'read', $refId)) {
135 $DIC['ilNavigationHistory']->addItem(
136 $refId,
137 './goto.php?target=' . $this->type . '_' . $refId,
138 $this->type
139 );
140 }
141
142 $next_class = $this->ctrl->getNextClass() ?? '';
143
144 $tabFactory = null;
145 if (!$this->getCreationMode()) {
146 $tabFactory = new ilChatroomTabGUIFactory($this);
147
148 $baseClass = $this->http->wrapper()->query()->retrieve(
149 'baseClass',
150 $this->refinery->byTrying([
151 $this->refinery->kindlyTo()->string(),
152 $this->refinery->always('')
153 ])
154 );
155 if (strtolower($baseClass) === strtolower(ilAdministrationGUI::class)) {
156 $tabFactory->getAdminTabsForCommand($this->ctrl->getCmd());
157 } else {
158 $DIC['ilHelp']->setScreenIdComponent('chtr');
159 $tabFactory->getTabsForCommand($this->ctrl->getCmd());
160 }
161 }
162
163 switch (strtolower($next_class)) {
164 case strtolower(ilInfoScreenGUI::class):
165 $this->infoScreen();
166 break;
167
168 case strtolower(ilPropertyFormGUI::class):
169 $factory = new ilChatroomFormFactory();
170 $form = $factory->getClientSettingsForm();
171 $this->ctrl->forwardCommand($form);
172 break;
173
174 case strtolower(ilPermissionGUI::class):
175 $this->prepareOutput();
176 $perm_gui = new ilPermissionGUI($this);
177 $this->ctrl->forwardCommand($perm_gui);
178 break;
179
180 case strtolower(ilExportGUI::class):
181 $this->prepareOutput();
182
183 $GLOBALS['DIC']->tabs()->setTabActive('export');
184
185 $exp = new ilExportGUI($this);
186 $this->ctrl->forwardCommand($exp);
187 break;
188
189 case strtolower(ilObjectCopyGUI::class):
190 $this->prepareOutput();
191 $cp = new ilObjectCopyGUI($this);
192 $cp->setType('chtr');
193 $this->ctrl->forwardCommand($cp);
194 break;
195
196 case strtolower(ilCommonActionDispatcherGUI::class):
197 $this->prepareOutput();
199 $this->ctrl->forwardCommand($gui);
200 break;
201
202 default:
203 try {
204 $res = explode('-', (string) $this->ctrl->getCmd('infoScreen'), 2);
205 $result = $this->dispatchCall($res[0], $res[1] ?? '');
206 if (!$result && method_exists($this, $this->ctrl->getCmd() . 'Object')) {
207 $this->prepareOutput();
208 $this->{$this->ctrl->getCmd() . 'Object'}();
209 }
210 } catch (Exception $e) {
211 if ($this->ctrl->isAsynch()) {
212 $responseStream = Streams::ofString(json_encode([
213 'success' => false,
214 'reason' => $e->getMessage()
215 ], JSON_THROW_ON_ERROR));
216 $this->http->saveResponse(
217 $this->http->response()
218 ->withBody($responseStream)
219 ->withHeader(ResponseHeader::CONTENT_TYPE, 'application/json')
220 );
221 $this->http->sendResponse();
222 $this->http->close();
223 } else {
224 throw $e;
225 }
226 }
227 break;
228 }
229
230 if ($this->object?->getType() !== 'chta') {
231 $this->addHeaderAction();
232 }
233
234 if ($tabFactory !== null &&
235 $tabFactory->getActivatedTab() !== null &&
236 $this->tabs_gui->getActiveTab() !== $tabFactory->getActivatedTab()) {
237 $this->tabs_gui->activateTab($tabFactory->getActivatedTab());
238 }
239 }
240
242 {
243 global $DIC;
244
247 new AccessBridge($DIC->rbac()->system()),
248 $this->object->getType(),
249 $this->ref_id,
250 $this->object->getId()
251 );
252 }
253
254 protected function infoScreen(): void
255 {
256 if (strtolower($this->ctrl->getCmd() ?? '') === 'info') {
257 $this->ctrl->redirectByClass(ilInfoScreenGUI::class, 'showSummary');
258 }
259
260 $this->prepareOutput();
261
262 $info = new ilInfoScreenGUI($this);
263
264 $info->enablePrivateNotes();
265
266 $refId = $this->request_wrapper->retrieve(
267 'ref_id',
268 $this->refinery->kindlyTo()->int()
269 );
270 if (ilChatroom::checkUserPermissions('read', $refId, false)) {
271 $info->enableNews();
272 }
273
274 $this->ctrl->forwardCommand($info);
275 }
276
278 {
280 }
281
282 public function fallback(): void
283 {
284 $this->prepareOutput();
285 $this->tpl->setVariable('ADM_CONTENT', $this->lng->txt('invalid_operation'));
286 }
287
288 public function settings(): void
289 {
290 $this->prepareOutput();
291 }
292
293 protected function afterImport(ilObject $new_object): void
294 {
295 $room = ilChatroom::byObjectId($new_object->getId());
296 $connector = $this->getConnector();
297 $response = $connector->sendCreatePrivateRoom($room->getRoomId(), $new_object->getOwner(), $new_object->getTitle());
298
299 parent::afterImport($new_object);
300 }
301
302 protected function afterSave(ilObject $new_object): void
303 {
304 $room = new ilChatroom();
305 $room->saveSettings([
306 'object_id' => $new_object->getId(),
307 'autogen_usernames' => 'Autogen #',
308 'display_past_msgs' => 100,
309 ]);
310
311 $connector = $this->getConnector();
312 $response = $connector->sendCreatePrivateRoom(
313 $room->getRoomId(),
314 $new_object->getOwner(),
315 $new_object->getTitle()
316 );
317
318 $this->tpl->setOnScreenMessage('success', $this->lng->txt('object_added'), true);
319 $this->ctrl->setParameter($this, 'ref_id', $new_object->getRefId());
320 $this->ctrl->redirect($this, 'settings-general');
321 }
322}
Stream factory which enables the user to create streams without the knowledge of the concrete class.
Definition: Streams.php:32
static getDefaultConfiguration()
Instantiates and returns ilChatroomAdmin object using instance_id and settings from settingsTable.
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 byObjectId(int $object_id)
Class ilCommonActionDispatcherGUI.
static getInstanceFromAjaxCall()
(Re-)Build instance from ajax call
Export User Interface Class.
Class ilInfoScreenGUI.
@ilCtrl_Calls ilObjChatroomGUI: ilMDEditorGUI, ilInfoScreenGUI, ilPermissionGUI, ilObjectCopyGUI @ilC...
afterImport(ilObject $new_object)
Post (successful) object import hook.
afterSave(ilObject $new_object)
Post (successful) object creation hook.
getSafePostCommands()
This method must return a list of safe POST commands.
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()
This method must return a list of unsafe GET commands.
GUI class for the workflow of copying objects.
cancelCreation()
cancel create action and go back to repository parent
addHeaderAction()
Add header action menu.
static _gotoRepositoryNode(int $ref_id, string $cmd="")
prepareOutput(bool $show_sub_objects=true)
Class ilObject Basic functions for all objects.
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
const ROOT_FOLDER_ID
Definition: constants.php:32
$info
Definition: entry_point.php:21
Interface ResponseHeader.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:31
$res
Definition: ltiservices.php:69
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:61
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26
$GLOBALS["DIC"]
Definition: wac.php:54
$refId
Definition: xapitoken.php:58
$response
Definition: xapitoken.php:93