ILIAS  release_8 Revision v8.24
class.ilObjSessionAccess.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
30{
31 protected ilObjUser $user;
32 protected static ?array $registrations = null;
33 protected static ?array $registered = null;
35
36 public function __construct()
37 {
38 global $DIC;
39
40 $this->user = $DIC->user();
41 }
42
43 public static function _getCommands(): array
44 {
45 $commands = array(
46 array("permission" => "read", "cmd" => "infoScreen", "lang_var" => "info_short", "default" => true),
47 array("permission" => "read", "cmd" => "register", "lang_var" => "join_session"),
48 array("permission" => "read", "cmd" => "unregister", "lang_var" => "event_unregister"),
49 array("permission" => "write", "cmd" => "edit", "lang_var" => "settings"),
50 array("permission" => "manage_materials", "cmd" => "materials", "lang_var" => "crs_objective_add_mat"),
51 array('permission' => 'manage_members', 'cmd' => 'members', 'lang_var' => 'event_edit_members')
52 );
53
54 return $commands;
55 }
56
57 public function _checkAccess($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id = ""): bool
58 {
59 global $DIC;
60
62
63 if (!$a_user_id) {
64 $a_user_id = $ilUser->getId();
65 }
66
67 switch ($a_cmd) {
68 case 'register':
69
70 if (!self::_lookupRegistration($a_obj_id)) {
71 return false;
72 }
73 if ($ilUser->isAnonymous()) {
74 return false;
75 }
76 if (self::_lookupRegistered($a_user_id, $a_obj_id)) {
77 return false;
78 }
79 if (\ilSessionParticipants::_isSubscriber($a_obj_id, $a_user_id)) {
80 return false;
81 }
82 if (ilSessionWaitingList::_isOnList($a_user_id, $a_obj_id)) {
83 return false;
84 }
85 if ($this->isRegistrationLimitExceeded($a_ref_id, $a_obj_id)) {
86 return false;
87 }
88 break;
89
90 case 'unregister':
91 if (self::_lookupRegistration($a_obj_id) && $a_user_id != ANONYMOUS_USER_ID) {
92 return self::_lookupRegistered($a_user_id, $a_obj_id);
93 }
94 return false;
95 }
96 return true;
97 }
98
99 public function isRegistrationLimitExceeded(int $ref_id, int $obj_id): bool
100 {
101 $session_data = new ilObjSession($obj_id, false);
102 if (!$session_data->isRegistrationUserLimitEnabled()) {
103 return false;
104 }
106 if ($part->getCountMembers() >= $session_data->getRegistrationMaxUsers()) {
107 return true;
108 }
109 return false;
110 }
111
112 public static function _checkGoto($a_target): bool
113 {
114 global $DIC;
115
116 $ilAccess = $DIC->access();
117
118 $t_arr = explode("_", $a_target);
119
120 if ($t_arr[0] != "sess" || ((int) $t_arr[1]) <= 0) {
121 return false;
122 }
123
124 if ($ilAccess->checkAccess("read", "", (int) $t_arr[1]) ||
125 $ilAccess->checkAccess("visible", "", (int) $t_arr[1])) {
126 return true;
127 }
128 return false;
129 }
130
131 public static function _lookupRegistration(int $a_obj_id): bool
132 {
133 global $DIC;
134
135 $ilDB = $DIC->database();
136
137 if (!is_null(self::$registrations)) {
138 return (bool) self::$registrations[$a_obj_id];
139 }
140
141 $query = "SELECT registration,obj_id FROM event ";
142 $res = $ilDB->query($query);
143 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
144 self::$registrations[$row->obj_id] = (bool) $row->registration;
145 }
146 return (bool) self::$registrations[$a_obj_id];
147 }
148
149 public static function _lookupRegistered(int $a_usr_id, int $a_obj_id): bool
150 {
151 global $DIC;
152
153 $ilDB = $DIC->database();
154 $ilUser = $DIC->user();
155
156 if (isset(self::$registered[$a_usr_id][$a_obj_id])) {
157 return (bool) self::$registered[$a_usr_id][$a_obj_id];
158 }
159
160 $query = "SELECT event_id, registered FROM event_participants WHERE usr_id = " . $ilDB->quote($ilUser->getId(), 'integer');
161 $res = $ilDB->query($query);
162 self::$registered[$a_usr_id] = [];
163 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
164 self::$registered[$a_usr_id][$row->event_id] = (bool) $row->registered;
165 }
166 return (bool) (self::$registered[$a_usr_id][$a_obj_id] ?? false);
167 }
168
169 public static function _preloadData($a_obj_ids, $a_ref_ids): void
170 {
172 self::$booking_repo = $f->getRepoWithContextObjCache($a_obj_ids);
173 }
174
176 {
177 if (self::$booking_repo instanceof ilBookingReservationDBRepository) {
178 return self::$booking_repo;
179 }
180 return null;
181 }
182}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getCommands()
get commands
static _preloadData($a_obj_ids, $a_ref_ids)
static _lookupRegistration(int $a_obj_id)
_checkAccess($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id="")
static _lookupRegistered(int $a_usr_id, int $a_obj_id)
static ilBookingReservationDBRepository $booking_repo
isRegistrationLimitExceeded(int $ref_id, int $obj_id)
User class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _isSubscriber(int $a_obj_id, int $a_usr_id)
static getInstance(int $a_ref_id)
static _isOnList(int $a_usr_id, int $a_obj_id)
const ANONYMOUS_USER_ID
Definition: constants.php:27
global $DIC
Definition: feed.php:28
$ilUser
Definition: imgupload.php:34
$ref_id
Definition: ltiauth.php:67
$res
Definition: ltiservices.php:69
$query