ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilObjChatroomGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(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  }
114 
115  public function getSafePostCommands(): array
116  {
117  return [
118  'view-toggleAutoMessageDisplayState',
119  ];
120  }
121 
122  public function executeCommand(): void
123  {
124  global $DIC;
125 
126  if ('cancel' === $this->ctrl->getCmd() && $this->getCreationMode()) {
127  $this->cancelCreation();
128  return;
129  }
130 
131  $refId = $this->http->wrapper()->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int());
132  if (!$this->getCreationMode() && ilChatroom::checkPermissionsOfUser($this->user->getId(), 'read', $refId)) {
133  $DIC['ilNavigationHistory']->addItem(
134  $refId,
135  './goto.php?target=' . $this->type . '_' . $refId,
136  $this->type
137  );
138  }
139 
140  $next_class = $this->ctrl->getNextClass() ?? '';
141 
142  $tabFactory = null;
143  if (!$this->getCreationMode()) {
144  $tabFactory = new ilChatroomTabGUIFactory($this);
145 
146  $baseClass = $this->http->wrapper()->query()->retrieve(
147  'baseClass',
148  $this->refinery->byTrying([
149  $this->refinery->kindlyTo()->string(),
150  $this->refinery->always('')
151  ])
152  );
153  if (strtolower($baseClass) === strtolower(ilAdministrationGUI::class)) {
154  $tabFactory->getAdminTabsForCommand($this->ctrl->getCmd());
155  } else {
156  $DIC['ilHelp']->setScreenIdComponent('chtr');
157  $tabFactory->getTabsForCommand($this->ctrl->getCmd());
158  }
159  }
160 
161  switch (strtolower($next_class)) {
162  case strtolower(ilInfoScreenGUI::class):
163  $this->infoScreen();
164  break;
165 
166  case strtolower(ilPropertyFormGUI::class):
167  $factory = new ilChatroomFormFactory();
168  $form = $factory->getClientSettingsForm();
169  $this->ctrl->forwardCommand($form);
170  break;
171 
172  case strtolower(ilPermissionGUI::class):
173  $this->prepareOutput();
174  $perm_gui = new ilPermissionGUI($this);
175  $this->ctrl->forwardCommand($perm_gui);
176  break;
177 
178  case strtolower(ilExportGUI::class):
179  $this->prepareOutput();
180 
181  $GLOBALS['DIC']->tabs()->setTabActive('export');
182 
183  $exp = new ilExportGUI($this);
184  $exp->addFormat('xml');
185  $this->ctrl->forwardCommand($exp);
186  break;
187 
188  case strtolower(ilObjectCopyGUI::class):
189  $this->prepareOutput();
190  $cp = new ilObjectCopyGUI($this);
191  $cp->setType('chtr');
192  $this->ctrl->forwardCommand($cp);
193  break;
194 
195  case strtolower(ilCommonActionDispatcherGUI::class):
196  $this->prepareOutput();
198  $this->ctrl->forwardCommand($gui);
199  break;
200 
201  default:
202  try {
203  $res = explode('-', (string) $this->ctrl->getCmd(''), 2);
204  $result = $this->dispatchCall($res[0], $res[1] ?? '');
205  if (!$result && method_exists($this, $this->ctrl->getCmd() . 'Object')) {
206  $this->prepareOutput();
207  $this->{$this->ctrl->getCmd() . 'Object'}();
208  }
209  } catch (Exception $e) {
210  if ($this->ctrl->isAsynch()) {
211  $responseStream = Streams::ofString(json_encode([
212  'success' => false,
213  'reason' => $e->getMessage()
214  ], JSON_THROW_ON_ERROR));
215  $this->http->saveResponse(
216  $this->http->response()
217  ->withBody($responseStream)
218  ->withHeader(ResponseHeader::CONTENT_TYPE, 'application/json')
219  );
220  $this->http->sendResponse();
221  $this->http->close();
222  } else {
223  throw $e;
224  }
225  }
226  break;
227  }
228 
229  if ($this->object?->getType() !== 'chta') {
230  $this->addHeaderAction();
231  }
232 
233  if ($tabFactory !== null &&
234  $tabFactory->getActivatedTab() !== null &&
235  $this->tabs_gui->getActiveTab() !== $tabFactory->getActivatedTab()) {
236  $this->tabs_gui->activateTab($tabFactory->getActivatedTab());
237  }
238  }
239 
241  {
242  global $DIC;
243 
244  return new ilCommonActionDispatcherGUI(
246  new AccessBridge($DIC->rbac()->system()),
247  $this->object->getType(),
249  $this->object->getId()
250  );
251  }
252 
253  protected function infoScreen(): void
254  {
255  if (strtolower($this->ctrl->getCmd() ?? '') === 'info') {
256  $this->ctrl->redirectByClass(ilInfoScreenGUI::class, 'showSummary');
257  }
258 
259  $this->prepareOutput();
260 
261  $info = new ilInfoScreenGUI($this);
262 
263  $info->enablePrivateNotes();
264 
265  $refId = $this->request_wrapper->retrieve(
266  'ref_id',
267  $this->refinery->kindlyTo()->int()
268  );
269  if (ilChatroom::checkUserPermissions('read', $refId, false)) {
270  $info->enableNews();
271  }
272 
273  $info->addMetaDataSections(
274  $this->getObject()->getId(),
275  0,
276  $this->getObject()->getType()
277  );
278  $this->ctrl->forwardCommand($info);
279  }
280 
282  {
283  return new ilChatroomServerConnector(ilChatroomAdmin::getDefaultConfiguration()->getServerSettings());
284  }
285 
286  public function fallback(): void
287  {
288  $this->prepareOutput();
289  $this->tpl->setVariable('ADM_CONTENT', $this->lng->txt('invalid_operation'));
290  }
291 
292  public function settings(): void
293  {
294  $this->prepareOutput();
295  }
296 
297  protected function afterImport(ilObject $new_object): void
298  {
299  $room = ilChatroom::byObjectId($new_object->getId());
300  $connector = $this->getConnector();
301  $response = $connector->sendCreatePrivateRoom($room->getRoomId(), $new_object->getOwner(), $new_object->getTitle());
302 
303  parent::afterImport($new_object);
304  }
305 
306  protected function afterSave(ilObject $new_object): void
307  {
308  $room = new ilChatroom();
309  $room->saveSettings([
310  'object_id' => $new_object->getId(),
311  'autogen_usernames' => 'Autogen #',
312  'display_past_msgs' => 100,
313  ]);
314 
315  $connector = $this->getConnector();
316  $response = $connector->sendCreatePrivateRoom(
317  $room->getRoomId(),
318  $new_object->getOwner(),
319  $new_object->getTitle()
320  );
321 
322  $this->tpl->setOnScreenMessage('success', $this->lng->txt('object_added'), true);
323  $this->ctrl->setParameter($this, 'ref_id', $new_object->getRefId());
324  $this->ctrl->redirect($this, 'settings-general');
325  }
326 }
static checkUserPermissions($permissions, int $ref_id, bool $send_info=true)
Checks user permissions by given array and ref_id.
getSafePostCommands()
This method must return a list of safe POST commands.
$res
Definition: ltiservices.php:66
__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:61
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:31
prepareOutput(bool $show_sub_objects=true)
static getDefaultConfiguration()
Instantiates and returns ilChatroomAdmin object using instance_id and settings from settingsTable...
$response
Definition: xapitoken.php:93
afterImport(ilObject $new_object)
static _gotoRepositoryNode(int $ref_id, string $cmd="")
$refId
Definition: xapitoken.php:58
static _lookupObjId(int $ref_id)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static http()
Fetches the global http state from ILIAS.
static _lookupTitle(int $obj_id)
$GLOBALS["DIC"]
Definition: wac.php:53
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.
global $DIC
Definition: shib_login.php:22
dispatchCall(string $gui, string $method)
Class ilChatroomTabGUIFactory.
afterSave(ilObject $new_object)
static getDefaultDefinition(string $moduleName)
Returns an Instance of ilChatroomObjectDefinition, using given $moduleName as parameter.
__construct(Container $dic, ilPlugin $plugin)
static byObjectId(int $object_id)
getUnsafeGetCommands()
This method must return a list of unsafe GET commands.
addHeaderAction()
Add header action menu.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilCommonActionDispatcherGUI.
static getInstanceFromAjaxCall()
(Re-)Build instance from ajax call