ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.ilObjSessionAccess.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
29{
30 protected ilObjUser $user;
31 protected static ?array $registrations = null;
32 protected static ?array $registered = null;
34
35 public function __construct()
36 {
37 global $DIC;
38
39 $this->user = $DIC->user();
40 }
41
42 public static function _getCommands(): array
43 {
44 $commands = array(
45 array("permission" => "read", "cmd" => "infoScreen", "lang_var" => "info_short", "default" => true),
46 array("permission" => "read", "cmd" => "register", "lang_var" => "join_session"),
47 array("permission" => "read", "cmd" => "unregister", "lang_var" => "event_unregister"),
48 array("permission" => "write", "cmd" => "edit", "lang_var" => "settings"),
49 array("permission" => "manage_materials", "cmd" => "materials", "lang_var" => "crs_objective_add_mat"),
50 array('permission' => 'manage_members', 'cmd' => 'members', 'lang_var' => 'event_edit_members')
51 );
52
53 return $commands;
54 }
55
56 public function _checkAccess($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id = ""): bool
57 {
58 global $DIC;
59
60 $ilUser = $this->user;
61
62 if (!$a_user_id) {
63 $a_user_id = $ilUser->getId();
64 }
65
66 switch ($a_cmd) {
67 case 'register':
68
69 if (!self::_lookupRegistration($a_obj_id)) {
70 return false;
71 }
72 if ($ilUser->isAnonymous()) {
73 return false;
74 }
75 if (self::_lookupRegistered($a_user_id, $a_obj_id)) {
76 return false;
77 }
78 if (\ilSessionParticipants::_isSubscriber($a_obj_id, $a_user_id)) {
79 return false;
80 }
81 if (ilSessionWaitingList::_isOnList($a_user_id, $a_obj_id)) {
82 return false;
83 }
84 if ($this->isRegistrationLimitExceeded($a_ref_id, $a_obj_id)) {
85 return false;
86 }
87 break;
88
89 case 'unregister':
90 if (self::_lookupRegistration($a_obj_id) && $a_user_id != ANONYMOUS_USER_ID) {
91 return self::_lookupRegistered($a_user_id, $a_obj_id);
92 }
93 return false;
94 }
95 return true;
96 }
97
98 public function isRegistrationLimitExceeded(int $ref_id, int $obj_id): bool
99 {
100 $session_data = new ilObjSession($obj_id, false);
101 if (!$session_data->isRegistrationUserLimitEnabled()) {
102 return false;
103 }
105 if ($part->getCountMembers() >= $session_data->getRegistrationMaxUsers()) {
106 return true;
107 }
108 return false;
109 }
110
111 public static function _checkGoto($a_target): bool
112 {
113 global $DIC;
114
115 $ilAccess = $DIC->access();
116
117 $t_arr = explode("_", $a_target);
118
119 if ($t_arr[0] != "sess" || ((int) $t_arr[1]) <= 0) {
120 return false;
121 }
122
123 if ($ilAccess->checkAccess("read", "", (int) $t_arr[1]) ||
124 $ilAccess->checkAccess("visible", "", (int) $t_arr[1])) {
125 return true;
126 }
127 return false;
128 }
129
130 public static function _lookupRegistration(int $a_obj_id): bool
131 {
132 global $DIC;
133
134 $ilDB = $DIC->database();
135
136 if (isset(self::$registrations[$a_obj_id])) {
137 return (bool) self::$registrations[$a_obj_id];
138 }
139
140 $query = "SELECT registration,obj_id FROM event WHERE obj_id = " .
141 $ilDB->quote($a_obj_id, ilDBConstants::T_INTEGER);
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
152 public static function preloadRegistrations(array $a_obj_ids): void
153 {
154 global $DIC;
155
156 $ilDB = $DIC->database();
157
158 self::$registrations = [];
159
160 $query = "SELECT registration,obj_id FROM event WHERE " .
161 $ilDB->in('obj_id', $a_obj_ids, false, ilDBConstants::T_INTEGER);
162 $res = $ilDB->query($query);
163 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
164 self::$registrations[$row->obj_id] = (bool) $row->registration;
165 }
166 }
167
168 public static function _lookupRegistered(int $a_usr_id, int $a_obj_id): bool
169 {
170 global $DIC;
171
172 $ilDB = $DIC->database();
173 $ilUser = $DIC->user();
174
175 if (isset(self::$registered[$a_usr_id][$a_obj_id])) {
176 return (bool) self::$registered[$a_usr_id][$a_obj_id];
177 }
178
179 $query = "SELECT event_id, registered FROM event_participants WHERE usr_id = " . $ilDB->quote($ilUser->getId(), 'integer');
180 $res = $ilDB->query($query);
181 self::$registered[$a_usr_id] = [];
182 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
183 self::$registered[$a_usr_id][$row->event_id] = (bool) $row->registered;
184 }
185 return (bool) (self::$registered[$a_usr_id][$a_obj_id] ?? false);
186 }
187
188 public static function _preloadData($a_obj_ids, $a_ref_ids): void
189 {
190 global $DIC;
191
192 self::preloadRegistrations($a_obj_ids);
193 self::$booking_repo = $DIC->bookingManager()
194 ->internal()
195 ->repo()
196 ->reservationWithContextObjCache($a_obj_ids);
197 }
198
199 public static function getBookingInfoRepo(): ?\ILIAS\BookingManager\Reservations\ReservationDBRepository
200 {
201 if (self::$booking_repo instanceof \ILIAS\BookingManager\Reservations\ReservationDBRepository) {
202 return self::$booking_repo;
203 }
204 return null;
205 }
206}
Repo class for reservations Acts on tables booking_reservation (rw), booking_reservation_group (rw) a...
static _getCommands()
get commands
static ILIAS BookingManager Reservations ReservationDBRepository $booking_repo
static _preloadData($a_obj_ids, $a_ref_ids)
static preloadRegistrations(array $a_obj_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)
isRegistrationLimitExceeded(int $ref_id, int $obj_id)
User class.
Class ilObjectAccess.
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
$ref_id
Definition: ltiauth.php:66
$res
Definition: ltiservices.php:69
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $DIC
Definition: shib_login.php:26