ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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  'ban-handleTableActions',
120  ];
121  }
122 
123  public function executeCommand(): void
124  {
125  global $DIC;
126 
127  if ('cancel' === $this->ctrl->getCmd() && $this->getCreationMode()) {
128  $this->cancelCreation();
129  return;
130  }
131 
132  $refId = $this->http->wrapper()->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int());
133  if (!$this->getCreationMode() && ilChatroom::checkPermissionsOfUser($this->user->getId(), 'read', $refId)) {
134  $DIC['ilNavigationHistory']->addItem(
135  $refId,
136  './goto.php?target=' . $this->type . '_' . $refId,
137  $this->type
138  );
139  }
140 
141  $next_class = $this->ctrl->getNextClass() ?? '';
142 
143  $tabFactory = null;
144  if (!$this->getCreationMode()) {
145  $tabFactory = new ilChatroomTabGUIFactory($this);
146 
147  $baseClass = $this->http->wrapper()->query()->retrieve(
148  'baseClass',
149  $this->refinery->byTrying([
150  $this->refinery->kindlyTo()->string(),
151  $this->refinery->always('')
152  ])
153  );
154  if (strtolower($baseClass) === strtolower(ilAdministrationGUI::class)) {
155  $tabFactory->getAdminTabsForCommand($this->ctrl->getCmd());
156  } else {
157  $DIC['ilHelp']->setScreenIdComponent('chtr');
158  $tabFactory->getTabsForCommand($this->ctrl->getCmd());
159  }
160  }
161 
162  switch (strtolower($next_class)) {
163  case strtolower(ilInfoScreenGUI::class):
164  $this->infoScreen();
165  break;
166 
167  case strtolower(ilPropertyFormGUI::class):
168  $factory = new ilChatroomFormFactory();
169  $form = $factory->getClientSettingsForm();
170  $this->ctrl->forwardCommand($form);
171  break;
172 
173  case strtolower(ilPermissionGUI::class):
174  $this->prepareOutput();
175  $perm_gui = new ilPermissionGUI($this);
176  $this->ctrl->forwardCommand($perm_gui);
177  break;
178 
179  case strtolower(ilExportGUI::class):
180  $this->prepareOutput();
181 
182  $GLOBALS['DIC']->tabs()->setTabActive('export');
183 
184  $exp = new ilExportGUI($this);
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  $this->ctrl->forwardCommand($info);
274  }
275 
277  {
278  return new ilChatroomServerConnector(ilChatroomAdmin::getDefaultConfiguration()->getServerSettings());
279  }
280 
281  public function fallback(): void
282  {
283  $this->prepareOutput();
284  $this->tpl->setVariable('ADM_CONTENT', $this->lng->txt('invalid_operation'));
285  }
286 
287  public function settings(): void
288  {
289  $this->prepareOutput();
290  }
291 
292  protected function afterImport(ilObject $new_object): void
293  {
294  $room = ilChatroom::byObjectId($new_object->getId());
295  $connector = $this->getConnector();
296  $response = $connector->sendCreatePrivateRoom($room->getRoomId(), $new_object->getOwner(), $new_object->getTitle());
297 
298  parent::afterImport($new_object);
299  }
300 
301  protected function afterSave(ilObject $new_object): void
302  {
303  $room = new ilChatroom();
304  $room->saveSettings([
305  'object_id' => $new_object->getId(),
306  'autogen_usernames' => 'Autogen #',
307  'display_past_msgs' => 100,
308  ]);
309 
310  $connector = $this->getConnector();
311  $response = $connector->sendCreatePrivateRoom(
312  $room->getRoomId(),
313  $new_object->getOwner(),
314  $new_object->getTitle()
315  );
316 
317  $this->tpl->setOnScreenMessage('success', $this->lng->txt('object_added'), true);
318  $this->ctrl->setParameter($this, 'ref_id', $new_object->getRefId());
319  $this->ctrl->redirect($this, 'settings-general');
320  }
321 }
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:26
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)
$info
Definition: entry_point.php:21
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