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