ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilObjGroupAccess.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
30{
31 protected static bool $using_code = false;
32
36 public function _checkAccess(string $cmd, string $permission, int $ref_id, int $obj_id, ?int $user_id = null): bool
37 {
38 global $DIC;
39
40 $ilUser = $DIC['ilUser'];
41 $lng = $DIC['lng'];
42 $ilAccess = $DIC['ilAccess'];
43
44 if (is_null($user_id)) {
45 $user_id = $ilUser->getId();
46 }
47
48 switch ($cmd) {
49 case "info":
50
52 $ilAccess->addInfoItem(ilAccessInfo::IL_STATUS_INFO, $lng->txt("info_is_member"));
53 } else {
54 $ilAccess->addInfoItem(ilAccessInfo::IL_STATUS_INFO, $lng->txt("info_is_not_member"));
55 }
56 break;
57
58 case "join":
59
60 if (!self::_registrationEnabled($obj_id)) {
61 return false;
62 }
63
64 if (ilGroupWaitingList::_isOnList($ilUser->getId(), $obj_id)) {
65 return false;
66 }
67
69 return false;
70 }
71 break;
72
73 case 'leave':
74 // Regular member
75 if ($permission == 'leave') {
76 $limit = null;
77 if (!ilObjGroup::mayLeave($obj_id, $user_id, $limit)) {
78 $ilAccess->addInfoItem(
80 sprintf($lng->txt("grp_cancellation_end_rbac_info"), ilDatePresentation::formatDate($limit))
81 );
82 return false;
83 }
84
86 return false;
87 }
88 }
89 break;
90
91 case 'leaveWaitList':
92 // Waiting list
93 if ($permission == 'join') {
94 if (!ilGroupWaitingList::_isOnList($ilUser->getId(), $obj_id)) {
95 return false;
96 }
97 }
98 break;
99 }
100
101 switch ($permission) {
102 case 'leave':
103 return ilObjGroup::mayLeave($obj_id, $user_id);
104 }
105 return true;
106 }
107
111 public static function _getCommands(): array
112 {
113 $commands = array();
114 $commands[] = array("permission" => "grp_linked", "cmd" => "", "lang_var" => "show", "default" => true);
115
116 $commands[] = array("permission" => "join", "cmd" => "join", "lang_var" => "join");
117
118 // on waiting list
119 $commands[] = array('permission' => "join", "cmd" => "leaveWaitList", "lang_var" => "leave_waiting_list");
120
121 // regualar users
122 $commands[] = array('permission' => "leave", "cmd" => "leave", "lang_var" => "grp_btn_unsubscribe");
123
125 $webdav_obj = new ilObjWebDAV();
126 $commands[] = $webdav_obj->retrieveWebDAVCommandArrayForActionMenu();
127 }
128
129 $commands[] = array("permission" => "write", "cmd" => "enableAdministrationPanel", "lang_var" => "edit_content");
130 $commands[] = array("permission" => "write", "cmd" => "edit", "lang_var" => "settings");
131
132 return $commands;
133 }
134
138 public static function _checkGoto(string $target): bool
139 {
140 global $DIC;
141
142 $ilAccess = $DIC->access();
143 $ilUser = $DIC->user();
144
145 $t_arr = explode("_", $target);
146 // registration codes
147 if (substr((string) ($t_arr[2] ?? ""), 0, 5) === 'rcode' and $ilUser->getId() != ANONYMOUS_USER_ID) {
148 self::$using_code = true;
149 return true;
150 }
151
152 if ($t_arr[0] != "grp" || ((int) $t_arr[1]) <= 0) {
153 return false;
154 }
155
156 if ($ilAccess->checkAccess("read", "", (int) $t_arr[1]) ||
157 $ilAccess->checkAccess("visible", "", (int) $t_arr[1])) {
158 return true;
159 }
160 return false;
161 }
162
163 public static function _registrationEnabled(int $a_obj_id): bool
164 {
165 global $DIC;
166
167 $ilDB = $DIC->database();
168 $query = "SELECT * FROM grp_settings " .
169 "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " ";
170
171 $res = $ilDB->query($query);
172
173 $enabled = $unlimited = false;
174 $start = $end = 0;
175 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
176 $enabled = $row->registration_enabled;
177 $unlimited = $row->registration_unlimited;
178 $start = $row->registration_start;
179 $end = $row->registration_end;
180 }
181
182 if (!$enabled) {
183 return false;
184 }
185 if ($unlimited) {
186 return true;
187 }
188 $start = new ilDateTime($start, IL_CAL_DATETIME);
189 $end = new ilDateTime($end, IL_CAL_DATETIME);
190 $time = new ilDateTime(time(), IL_CAL_UNIX);
191 return ilDateTime::_after($time, $start) and ilDateTime::_before($time, $end);
192 }
193
194
198 public static function _preloadData(array $obj_ids, array $ref_ids): void
199 {
200 global $DIC;
201
202 $ilDB = $DIC->database();
203 $ilUser = $DIC->user();
204
205 ilGroupWaitingList::_preloadOnListInfo([$ilUser->getId()], $obj_ids);
206 }
207
208 public static function lookupRegistrationInfo(int $a_obj_id): array
209 {
210 global $DIC;
211
212 $ilDB = $DIC->database();
213 $lng = $DIC->language();
214
215 $query = 'SELECT registration_type, registration_enabled, registration_unlimited, registration_start, ' .
216 'registration_end, registration_mem_limit, registration_max_members FROM grp_settings ' .
217 'WHERE obj_id = ' . $ilDB->quote($a_obj_id, ilDBConstants::T_INTEGER);
218 $res = $ilDB->query($query);
219
220 $info = array();
221 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
222 $info['reg_info_start'] = new ilDateTime($row->registration_start, IL_CAL_DATETIME);
223 $info['reg_info_end'] = new ilDateTime($row->registration_end, IL_CAL_DATETIME);
224 $info['reg_info_type'] = $row->registration_type;
225 $info['reg_info_mem_limit'] = $row->registration_mem_limit;
226 $info['reg_info_unlimited'] = $row->registration_unlimited;
227
228 $info['reg_info_max_members'] = 0;
229 if ($info['reg_info_mem_limit']) {
230 $info['reg_info_max_members'] = $row->registration_max_members;
231 }
232
233 $info['reg_info_enabled'] = $row->registration_enabled;
234 }
235
236 $registration_possible = $info['reg_info_enabled'];
237
238 // Limited registration (added $registration_possible, see bug 0010157)
239 if (!$info['reg_info_unlimited'] && $registration_possible) {
240 $dt = new ilDateTime(time(), IL_CAL_UNIX);
241 if (ilDateTime::_before($dt, $info['reg_info_start'])) {
242 $info['reg_info_list_prop']['property'] = $lng->txt('grp_list_reg_start');
243 $info['reg_info_list_prop']['value'] = ilDatePresentation::formatDate($info['reg_info_start']);
244 } elseif (ilDateTime::_before($dt, $info['reg_info_end'])) {
245 $info['reg_info_list_prop']['property'] = $lng->txt('grp_list_reg_end');
246 $info['reg_info_list_prop']['value'] = ilDatePresentation::formatDate($info['reg_info_end']);
247 } else {
248 $registration_possible = false;
249 $info['reg_info_list_prop']['property'] = $lng->txt('grp_list_reg_period');
250 $info['reg_info_list_prop']['value'] = $lng->txt('grp_list_reg_noreg');
251 }
252 } else {
253 // added !$registration_possible, see bug 0010157
254 if (!$registration_possible) {
255 $registration_possible = false;
256 $info['reg_info_list_prop']['property'] = $lng->txt('grp_list_reg');
257 $info['reg_info_list_prop']['value'] = $lng->txt('grp_list_reg_noreg');
258 }
259 }
260
261 if ($info['reg_info_mem_limit'] && $info['reg_info_max_members'] && $registration_possible) {
262 // Check for free places
264
265 $info['reg_info_list_size'] = ilCourseWaitingList::lookupListSize($a_obj_id);
266 if ($info['reg_info_list_size']) {
267 $info['reg_info_free_places'] = 0;
268 } else {
269 $info['reg_info_free_places'] = max(0, $info['reg_info_max_members'] - $part->getCountMembers());
270 }
271
272 if ($info['reg_info_free_places']) {
273 $info['reg_info_list_prop_limit']['property'] = $lng->txt('grp_list_reg_limit_places');
274 $info['reg_info_list_prop_limit']['value'] = $info['reg_info_free_places'];
275 } else {
276 $info['reg_info_list_prop_limit']['property'] = '';
277 $info['reg_info_list_prop_limit']['value'] = $lng->txt('grp_list_reg_limit_full');
278 }
279 }
280
281 return $info;
282 }
283
289 public static function lookupPeriodInfo(int $a_obj_id): ?array
290 {
291 global $DIC;
292
293 $ilDB = $DIC->database();
294 $lng = $DIC->language();
295
296 $start = $end = null;
297 $query = 'SELECT period_start, period_end, period_time_indication FROM grp_settings ' .
298 'WHERE obj_id = ' . $ilDB->quote($a_obj_id, ilDBConstants::T_INTEGER);
299
300 $res = $ilDB->query($query);
301 while ($row = $res->fetchRow(\ilDBConstants::FETCHMODE_OBJECT)) {
302 if (!$row->period_time_indication) {
303 $start = ($row->period_start
304 ? new \ilDate($row->period_start, IL_CAL_DATETIME)
305 : null);
306 $end = ($row->period_end
307 ? new \ilDate($row->period_end, IL_CAL_DATETIME)
308 : null);
309 } else {
310 $start = ($row->period_start
311 ? new \ilDateTime($row->period_start, IL_CAL_DATETIME, \ilTimeZone::UTC)
312 : null);
313 $end = ($row->period_end
314 ? new \ilDateTime($row->period_end, IL_CAL_DATETIME, \ilTimeZone::UTC)
315 : null);
316 }
317 }
318 if ($start && $end) {
319 $lng->loadLanguageModule('grp');
320
321 return
322 [
323 'property' => $lng->txt('grp_period'),
324 'value' => ilDatePresentation::formatPeriod($start, $end)
325 ];
326 }
327 return null;
328 }
329
330 public static function _usingRegistrationCode(): bool
331 {
332 return self::$using_code;
333 }
334}
const IL_CAL_UNIX
const IL_CAL_DATETIME
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
static formatPeriod(ilDateTime $start, ilDateTime $end, bool $a_skip_starting_day=false, ?ilObjUser $user=null)
Format a period of two dates Shows: 14.
@classDescription Date and time handling
static _after(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
compare two dates and check start is after end This method does not consider tz offsets.
static _before(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
compare two dates and check start is before end This method does not consider tz offsets.
static _isParticipant(int $a_ref_id, int $a_usr_id)
Static function to check if a user is a participant of the container object.
static _getInstanceByObjId(int $a_obj_id)
Get singleton instance.
Class ilObjGroupAccess.
static _checkGoto(string $target)
@inheritDoc
static lookupPeriodInfo(int $a_obj_id)
static _preloadData(array $obj_ids, array $ref_ids)
@inheritDoc
_checkAccess(string $cmd, string $permission, int $ref_id, int $obj_id, ?int $user_id=null)
@inheritDoc
static _getCommands()
@inheritDoc
static lookupRegistrationInfo(int $a_obj_id)
static _registrationEnabled(int $a_obj_id)
static mayLeave(int $a_group_id, ?int $a_user_id=null, ?ilDate &$a_date=null)
Class ilObjectAccess.
static lookupListSize(int $a_obj_id)
static _isOnList(int $a_usr_id, int $a_obj_id)
static _preloadOnListInfo(array $a_usr_ids, array $a_obj_ids)
Preload on list info.
const ANONYMOUS_USER_ID
Definition: constants.php:27
$info
Definition: entry_point.php:21
$ref_id
Definition: ltiauth.php:66
$res
Definition: ltiservices.php:69
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26