ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 (!is_null(self::$registrations)) {
137 return (bool) self::$registrations[$a_obj_id];
138 }
139
140 $query = "SELECT registration,obj_id FROM event ";
141 $res = $ilDB->query($query);
142 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
143 self::$registrations[$row->obj_id] = (bool) $row->registration;
144 }
145 return (bool) self::$registrations[$a_obj_id];
146 }
147
148 public static function _lookupRegistered(int $a_usr_id, int $a_obj_id): bool
149 {
150 global $DIC;
151
152 $ilDB = $DIC->database();
153 $ilUser = $DIC->user();
154
155 if (isset(self::$registered[$a_usr_id][$a_obj_id])) {
156 return (bool) self::$registered[$a_usr_id][$a_obj_id];
157 }
158
159 $query = "SELECT event_id, registered FROM event_participants WHERE usr_id = " . $ilDB->quote($ilUser->getId(), 'integer');
160 $res = $ilDB->query($query);
161 self::$registered[$a_usr_id] = [];
162 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
163 self::$registered[$a_usr_id][$row->event_id] = (bool) $row->registered;
164 }
165 return (bool) (self::$registered[$a_usr_id][$a_obj_id] ?? false);
166 }
167
168 public static function _preloadData($a_obj_ids, $a_ref_ids): void
169 {
170 global $DIC;
171
172 self::$booking_repo = $DIC->bookingManager()
173 ->internal()
174 ->repo()
175 ->reservationWithContextObjCache($a_obj_ids);
176 }
177
178 public static function getBookingInfoRepo() : ?\ILIAS\BookingManager\Reservations\ReservationDBRepository
179 {
180 if (self::$booking_repo instanceof \ILIAS\BookingManager\Reservations\ReservationDBRepository) {
181 return self::$booking_repo;
182 }
183 return null;
184 }
185}
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 _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