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