ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilObjGroupAccess.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5include_once("./Services/Object/classes/class.ilObjectAccess.php");
6
16{
17 protected static $using_code = false;
30 public function _checkAccess($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id = "")
31 {
32 global $ilUser, $lng, $rbacsystem, $ilAccess;
33
34 if ($a_user_id == "") {
35 $a_user_id = $ilUser->getId();
36 }
37
38 switch ($a_cmd) {
39 case "info":
40
41 include_once './Modules/Group/classes/class.ilGroupParticipants.php';
42 if (ilGroupParticipants::_isParticipant($a_ref_id, $a_user_id)) {
43 $ilAccess->addInfoItem(ilAccessInfo::IL_STATUS_INFO, $lng->txt("info_is_member"));
44 } else {
45 $ilAccess->addInfoItem(ilAccessInfo::IL_STATUS_INFO, $lng->txt("info_is_not_member"));
46 }
47 break;
48
49 case "join":
50
51 if (!self::_registrationEnabled($a_obj_id)) {
52 return false;
53 }
54
55 include_once './Modules/Group/classes/class.ilGroupWaitingList.php';
56 if (ilGroupWaitingList::_isOnList($ilUser->getId(), $a_obj_id)) {
57 return false;
58 }
59
60 include_once './Modules/Group/classes/class.ilGroupParticipants.php';
61 if (ilGroupParticipants::_isParticipant($a_ref_id, $a_user_id)) {
62 return false;
63 }
64 break;
65
66 case 'leave':
67
68 // Regular member
69 if ($a_permission == 'leave') {
70 include_once './Modules/Group/classes/class.ilObjGroup.php';
71 $limit = null;
72 if (!ilObjGroup::mayLeave($a_obj_id, $a_user_id, $limit)) {
73 $ilAccess->addInfoItem(
75 sprintf($lng->txt("grp_cancellation_end_rbac_info"), ilDatePresentation::formatDate($limit))
76 );
77 return false;
78 }
79
80 include_once './Modules/Group/classes/class.ilGroupParticipants.php';
81 if (!ilGroupParticipants::_isParticipant($a_ref_id, $a_user_id)) {
82 return false;
83 }
84 }
85 // Waiting list
86 if ($a_permission == 'join') {
87 include_once './Modules/Group/classes/class.ilGroupWaitingList.php';
88 if (!ilGroupWaitingList::_isOnList($ilUser->getId(), $a_obj_id)) {
89 return false;
90 }
91 }
92 break;
93
94 }
95
96 switch ($a_permission) {
97 case 'leave':
98 include_once './Modules/Group/classes/class.ilObjGroup.php';
99 return ilObjGroup::mayLeave($a_obj_id, $a_user_id);
100 }
101 return true;
102 }
103
116 public static function _getCommands()
117 {
118 $commands = array();
119 $commands[] = array("permission" => "grp_linked", "cmd" => "", "lang_var" => "show", "default" => true);
120
121 include_once './Services/WebServices/FileManager/classes/class.ilFMSettings.php';
122 if (ilFMSettings::getInstance()->isEnabled()) {
123 $commands[] = array(
124 'permission' => 'read',
125 'cmd' => 'fileManagerLaunch',
126 'lang_var' => 'fm_start',
127 'enable_anonymous' => false
128 );
129 }
130
131 $commands[] = array("permission" => "join", "cmd" => "join", "lang_var" => "join");
132
133 // on waiting list
134 $commands[] = array('permission' => "join", "cmd" => "leave", "lang_var" => "leave_waiting_list");
135
136 // regualar users
137 $commands[] = array('permission' => "leave", "cmd" => "leave", "lang_var" => "grp_btn_unsubscribe");
138
139 include_once('Services/WebDAV/classes/class.ilDAVActivationChecker.php');
141 include_once './Services/WebDAV/classes/class.ilDAVUtils.php';
142 if (ilDAVUtils::getInstance()->isLocalPasswordInstructionRequired()) {
143 $commands[] = array('permission' => 'read', 'cmd' => 'showPasswordInstruction', 'lang_var' => 'mount_webfolder', 'enable_anonymous' => 'false');
144 } else {
145 $commands[] = array("permission" => "read", "cmd" => "mount_webfolder", "lang_var" => "mount_webfolder", "enable_anonymous" => "false");
146 }
147 }
148
149 $commands[] = array("permission" => "write", "cmd" => "enableAdministrationPanel", "lang_var" => "edit_content");
150 $commands[] = array("permission" => "write", "cmd" => "edit", "lang_var" => "settings");
151
152 return $commands;
153 }
154
158 public static function _checkGoto($a_target)
159 {
160 global $ilAccess,$ilUser;
161
162 $t_arr = explode("_", $a_target);
163 // registration codes
164 if (substr($t_arr[2], 0, 5) == 'rcode' and $ilUser->getId() != ANONYMOUS_USER_ID) {
165 self::$using_code = true;
166 return true;
167 }
168
169 if ($t_arr[0] != "grp" || ((int) $t_arr[1]) <= 0) {
170 return false;
171 }
172
173 if ($ilAccess->checkAccess("read", "", $t_arr[1]) ||
174 $ilAccess->checkAccess("visible", "", $t_arr[1])) {
175 return true;
176 }
177 return false;
178 }
179
185 public static function _registrationEnabled($a_obj_id)
186 {
187 global $ilDB;
188
189 $query = "SELECT * FROM grp_settings " .
190 "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " ";
191
192 $res = $ilDB->query($query);
193
194 $enabled = $unlimited = false;
195 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
196 $enabled = $row->registration_enabled;
197 $unlimited = $row->registration_unlimited;
198 $start = $row->registration_start;
199 $end = $row->registration_end;
200 }
201
202 if (!$enabled) {
203 return false;
204 }
205 if ($unlimited) {
206 return true;
207 }
208
209 if (!$unlimited) {
210 $start = new ilDateTime($start, IL_CAL_DATETIME);
212 $time = new ilDateTime(time(), IL_CAL_UNIX);
213
215 }
216 return false;
217 }
218
219
225 public static function _preloadData($a_obj_ids, $a_ref_ids)
226 {
227 global $ilDB, $ilUser;
228
229 include_once("./Modules/Group/classes/class.ilGroupWaitingList.php");
231 }
232
241 public static function lookupRegistrationInfo($a_obj_id)
242 {
243 global $ilDB, $ilUser, $lng;
244
245 $query = 'SELECT registration_type, registration_enabled, registration_unlimited, registration_start, ' .
246 'registration_end, registration_mem_limit, registration_max_members FROM grp_settings ' .
247 'WHERE obj_id = ' . $ilDB->quote($a_obj_id);
248 $res = $ilDB->query($query);
249
250 $info = array();
251 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
252 $info['reg_info_start'] = new ilDateTime($row->registration_start, IL_CAL_DATETIME);
253 $info['reg_info_end'] = new ilDateTime($row->registration_end, IL_CAL_DATETIME);
254 $info['reg_info_type'] = $row->registration_type;
255 $info['reg_info_max_members'] = $row->registration_max_members;
256 $info['reg_info_mem_limit'] = $row->registration_mem_limit;
257 $info['reg_info_unlimited'] = $row->registration_unlimited;
258
259 $info['reg_info_max_members'] = 0;
260 if ($info['reg_info_mem_limit']) {
261 $info['reg_info_max_members'] = $row->registration_max_members;
262 }
263
264 $info['reg_info_enabled'] = $row->registration_enabled;
265 }
266
267 $registration_possible = $info['reg_info_enabled'];
268
269 // Limited registration (added $registration_possible, see bug 0010157)
270 if (!$info['reg_info_unlimited'] && $registration_possible) {
271 $dt = new ilDateTime(time(), IL_CAL_UNIX);
272 if (ilDateTime::_before($dt, $info['reg_info_start'])) {
273 $info['reg_info_list_prop']['property'] = $lng->txt('grp_list_reg_start');
274 $info['reg_info_list_prop']['value'] = ilDatePresentation::formatDate($info['reg_info_start']);
275 } elseif (ilDateTime::_before($dt, $info['reg_info_end'])) {
276 $info['reg_info_list_prop']['property'] = $lng->txt('grp_list_reg_end');
277 $info['reg_info_list_prop']['value'] = ilDatePresentation::formatDate($info['reg_info_end']);
278 } else {
279 $registration_possible = false;
280 $info['reg_info_list_prop']['property'] = $lng->txt('grp_list_reg_period');
281 $info['reg_info_list_prop']['value'] = $lng->txt('grp_list_reg_noreg');
282 }
283 } else {
284 // added !$registration_possible, see bug 0010157
285 if (!$registration_possible) {
286 $registration_possible = false;
287 $info['reg_info_list_prop']['property'] = $lng->txt('grp_list_reg');
288 $info['reg_info_list_prop']['value'] = $lng->txt('grp_list_reg_noreg');
289 }
290 }
291
292 if ($info['reg_info_mem_limit'] && $info['reg_info_max_members'] && $registration_possible) {
293 // Check for free places
294 include_once './Modules/Group/classes/class.ilGroupParticipants.php';
296
297 include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
298 $info['reg_info_list_size'] = ilCourseWaitingList::lookupListSize($a_obj_id);
299 if ($info['reg_info_list_size']) {
300 $info['reg_info_free_places'] = 0;
301 } else {
302 $info['reg_info_free_places'] = max(0, $info['reg_info_max_members'] - $part->getCountMembers());
303 }
304
305 if ($info['reg_info_free_places']) {
306 $info['reg_info_list_prop_limit']['property'] = $lng->txt('grp_list_reg_limit_places');
307 $info['reg_info_list_prop_limit']['value'] = $info['reg_info_free_places'];
308 } else {
309 $info['reg_info_list_prop_limit']['property'] = '';
310 $info['reg_info_list_prop_limit']['value'] = $lng->txt('grp_list_reg_limit_full');
311 }
312 }
313
314 return $info;
315 }
316
323 public static function lookupPeriodInfo($a_obj_id)
324 {
325 global $ilDB, $lng;
326
327 $start = $end = null;
328
329 $query = 'SELECT grp_start, grp_end FROM grp_settings' .
330 ' WHERE obj_id = ' . $ilDB->quote($a_obj_id);
331 $set = $ilDB->query($query);
332 while ($row = $ilDB->fetchAssoc($set)) {
333 $start = $row['grp_start']
334 ? new ilDate($row['grp_start'], IL_CAL_UNIX)
335 : null;
336 $end = $row['grp_end']
337 ? new ilDate($row['grp_end'], IL_CAL_UNIX)
338 : null;
339 }
340
341 if ($start && $end) {
342 $lng->loadLanguageModule('grp');
343
344 return array(
345 'property' => $lng->txt('grp_period'),
346 'value' => ilDatePresentation::formatPeriod($start, $end)
347 );
348 }
349 }
350
351
357 public static function _usingRegistrationCode()
358 {
359 return self::$using_code;
360 }
361}
sprintf('%.4f', $callTime)
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
const IL_CAL_DATETIME
static getInstance()
Get singleton instance.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false)
Format a date @access public.
static formatPeriod(ilDateTime $start, ilDateTime $end, $a_skip_starting_day=false)
Format a period of two date Shows: 14.
@classDescription Date and time handling
static _after(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
compare two dates and check start is after end This method does not consider tz offsets.
static _before(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
compare two dates and check start is before end This method does not consider tz offsets.
Class for single dates.
static getInstance()
Get singleton instance.
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
static _isParticipant($a_ref_id, $a_usr_id)
Static function to check if a user is a participant of the container object.
Class ilObjGroupAccess.
_checkAccess($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id="")
checks wether a user may invoke a command or not (this method is called by ilAccessHandler::checkAcce...
static _preloadData($a_obj_ids, $a_ref_ids)
Preload data.
static _checkGoto($a_target)
check whether goto script will succeed
static _usingRegistrationCode()
Using Registration code.
static lookupPeriodInfo($a_obj_id)
Lookup course period info.
static _getCommands()
get commands
static lookupRegistrationInfo($a_obj_id)
Lookup registration info @global ilDB $ilDB @global ilObjUser $ilUser @global ilLanguage $lng.
static _registrationEnabled($a_obj_id)
static mayLeave($a_group_id, $a_user_id=null, &$a_date=null)
Class ilObjectAccess.
static _isOnList($a_usr_id, $a_obj_id)
Check if a user on the waiting list.
static _preloadOnListInfo($a_usr_ids, $a_obj_ids)
Preload on list info.
static lookupListSize($a_obj_id)
Lookup waiting lit size.
$time
Definition: cron.php:21
$end
Definition: saml1-acs.php:18
$info
Definition: index.php:5
global $lng
Definition: privfeed.php:17
$query
foreach($_POST as $key=> $value) $res
global $ilDB
$ilUser
Definition: imgupload.php:18