ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilObjChatroomAccess.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
28 {
29  private static ?bool $chat_enabled = null;
30 
31  public static function _getCommands(): array
32  {
33  $commands = [];
34  $commands[] = ['permission' => 'read', 'cmd' => 'view', 'lang_var' => 'enter', 'default' => true];
35  $commands[] = ['permission' => 'write', 'cmd' => 'settings-general', 'lang_var' => 'settings'];
36 
37  return $commands;
38  }
39 
40  public static function _checkGoto(string $target): bool
41  {
42  $t_arr = explode('_', $target);
43 
44  if (count($t_arr) < 2 || $t_arr[0] !== 'chtr' || ((int) $t_arr[1]) <= 0) {
45  return false;
46  }
47 
48  if (ilChatroom::checkUserPermissions('visible', (int) $t_arr[1], false) ||
49  ilChatroom::checkUserPermissions('read', (int) $t_arr[1], false)) {
50  return true;
51  }
52 
53  return false;
54  }
55 
56  public function _checkAccess(string $cmd, string $permission, int $ref_id, int $obj_id, ?int $user_id = null): bool
57  {
58  if (!$user_id) {
59  $user_id = $GLOBALS['DIC']->user()->getId();
60  }
61 
62  return self::checkRoomAccess($permission, $ref_id, $obj_id, (int) $user_id);
63  }
64 
65  private static function checkRoomAccess(string $a_permission, int $a_ref_id, int $a_obj_id, int $a_user_id): bool
66  {
67  global $DIC;
68 
69  if (self::$chat_enabled === null) {
70  $chatSetting = new ilSetting('chatroom');
71  self::$chat_enabled = (bool) $chatSetting->get('chat_enabled', '0');
72  }
73 
74  $hasWriteAccess = $DIC->rbac()->system()->checkAccessOfUser($a_user_id, 'write', $a_ref_id);
75  if ($hasWriteAccess) {
76  return true;
77  }
78 
79  switch ($a_permission) {
80  case 'read':
81  case 'visible':
82  $is_online = self::lookupOnline($a_obj_id);
83  if (!$is_online) {
84  $DIC->access()->addInfoItem(
86  $DIC->language()->txt('offline')
87  );
88  return false;
89  }
90  break;
91  }
92 
93  return self::$chat_enabled;
94  }
95 
96  public static function lookupOnline(int $a_obj_id): bool
97  {
98  return !ilObject::lookupOfflineStatus($a_obj_id);
99  }
100 
101  public function canBeDelivered(ilWACPath $ilWACPath): bool
102  {
103  return false;
104  }
105 }
static checkUserPermissions($permissions, int $ref_id, bool $send_info=true)
Checks user permissions by given array and ref_id.
static lookupOnline(int $a_obj_id)
static checkRoomAccess(string $a_permission, int $a_ref_id, int $a_obj_id, int $a_user_id)
static _checkGoto(string $target)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
_checkAccess(string $cmd, string $permission, int $ref_id, int $obj_id, ?int $user_id=null)
static lookupOfflineStatus(int $obj_id)
Lookup offline status using objectDataCache.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$ref_id
Definition: ltiauth.php:65
Access class for chatroom objects.
$GLOBALS["DIC"]
Definition: wac.php:53
canBeDelivered(ilWACPath $ilWACPath)
global $DIC
Definition: shib_login.php:22
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...