ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilObjLearningSequenceAccess.php
Go to the documentation of this file.
1 <?php
2 
18 declare(strict_types=1);
19 
21 {
22  public static bool $using_code = false;
23 
27  public static function _getCommands(): array
28  {
29  return array(
30  [
32  'permission' => 'read',
33  'lang_var' => 'show',
34  'default' => true
35  ],
36  [
38  'permission' => 'read',
39  'lang_var' => 'show',
40  ],
41  [
43  'permission' => 'write',
44  'lang_var' => 'edit_content'
45  ],
46  [
48  'permission' => 'write',
49  'lang_var' => 'settings'
50  ],
51  [
53  'permission' => 'unparticipate',
54  'lang_var' => 'unparticipate'
55  ]
56  );
57  }
58 
59  public function usingRegistrationCode(): bool
60  {
61  return self::$using_code;
62  }
63 
64  public static function isOffline(int $ref_id): bool
65  {
67  $act = $obj->getLSActivation();
68  $online = $act->getIsOnline();
69 
70  if ($online
71  && ($act->getActivationStart() !== null ||
72  $act->getActivationEnd() !== null)
73  ) {
74  $ts_now = time();
75  $activation_start = $act->getActivationStart();
76  if ($activation_start !== null) {
77  $after_activation_start = $ts_now >= $activation_start->getTimestamp();
78  } else {
79  $after_activation_start = true;
80  }
81  $activation_end = $act->getActivationEnd();
82  if ($activation_end !== null) {
83  $before_activation_end = $ts_now <= $activation_end->getTimestamp();
84  } else {
85  $before_activation_end = true;
86  }
87 
88  $online = ($after_activation_start && $before_activation_end);
89  }
90 
91  if ($act->getEffectiveOnlineStatus() === false && $online === true) {
92  $obj->setEffectiveOnlineStatus(true);
93  $obj->announceLSOOnline();
94  }
95  if ($act->getEffectiveOnlineStatus() === true && $online === false) {
96  $obj->setEffectiveOnlineStatus(false);
97  $obj->announceLSOOffline();
98  }
99 
100  $new_status = ($online)
101  ? $obj->getObjectProperties()->getPropertyIsOnline()->withOnline()
102  : $obj->getObjectProperties()->getPropertyIsOnline()->withOffline();
103  $obj->getObjectProperties()->storePropertyIsOnline($new_status);
104 
105  return !$online;
106  }
107 
108  public function _checkAccess(string $cmd, string $permission, int $ref_id, int $obj_id, ?int $user_id = null): bool
109  {
110  list($rbacsystem, $il_access, $lng) = $this->getDICDependencies();
111 
112  switch ($permission) {
113  case 'visible':
114  $has_any_administrative_permission = false;
115  if (!is_null($user_id)) {
116  $has_any_administrative_permission = (
117  $rbacsystem->checkAccessOfUser($user_id, 'write', $ref_id) ||
118  $rbacsystem->checkAccessOfUser($user_id, 'edit_members', $ref_id) ||
119  $rbacsystem->checkAccessOfUser($user_id, 'edit_learning_progress', $ref_id)
120  );
121  }
122 
123  $is_offine = $this->isOffline($ref_id);
124 
125  if ($is_offine && !$has_any_administrative_permission) {
126  $il_access->addInfoItem(ilAccessInfo::IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
127  return false;
128  }
129  return true;
130 
131  default:
132  if (is_null($user_id)) {
133  return false;
134  }
135  return $rbacsystem->checkAccessOfUser($user_id, $permission, $ref_id);
136  }
137  }
138 
142  protected function getDICDependencies(): array
143  {
144  global $DIC;
145  $rbacsystem = $DIC['rbacsystem'];
146  $il_access = $DIC['ilAccess'];
147  $lng = $DIC['lng'];
148 
149  return [
150  $rbacsystem,
151  $il_access,
152  $lng
153  ];
154  }
155 }
_checkAccess(string $cmd, string $permission, int $ref_id, int $obj_id, ?int $user_id=null)
$ref_id
Definition: ltiauth.php:66
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
global $DIC
Definition: shib_login.php:25
global $lng
Definition: privfeed.php:32