ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
class.ilObjCourseAccess.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5include_once("./Services/Object/classes/class.ilObjectAccess.php");
6include_once './Modules/Course/classes/class.ilCourseConstants.php';
7include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
8include_once 'Modules/Course/classes/class.ilCourseParticipant.php';
9include_once './Services/AccessControl/interfaces/interface.ilConditionHandling.php';
10
20{
21
22 protected static $using_code = false;
23
27 public static function getConditionOperators()
28 {
29 include_once './Services/AccessControl/classes/class.ilConditionHandler.php';
30 return array(
32 );
33 }
34
44 public static function checkCondition($a_obj_id,$a_operator,$a_value,$a_usr_id)
45 {
46 include_once "./Modules/Course/classes/class.ilCourseParticipants.php";
47 include_once './Services/AccessControl/classes/class.ilConditionHandler.php';
48
49 switch($a_operator)
50 {
52 return ilCourseParticipants::_hasPassed($a_obj_id,$a_usr_id);
53 }
54 return FALSE;
55 }
56
69 function _checkAccess($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id = "")
70 {
71 global $ilUser, $lng, $rbacsystem, $ilAccess, $ilias;
72
73
74 if ($a_user_id == "")
75 {
76 $a_user_id = $ilUser->getId();
77 }
78
79 if($ilUser->getId() == $a_user_id)
80 {
81 $participants = ilCourseParticipant::_getInstanceByObjId($a_obj_id,$a_user_id);
82 }
83 else
84 {
85 $participants = ilCourseParticipants::_getInstanceByObjId($a_obj_id);
86 }
87
88
89 switch ($a_cmd)
90 {
91 case "view":
92 if($participants->isBlocked($a_user_id) and $participants->isAssigned($a_user_id))
93 {
94 $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("crs_status_blocked"));
95 return false;
96 }
97 break;
98
99 case 'leave':
100
101 // Regular member
102 if($a_permission == 'leave')
103 {
104 include_once './Modules/Course/classes/class.ilCourseParticipants.php';
105 if(!$participants->isAssigned($a_user_id))
106 {
107 return false;
108 }
109 }
110 // Waiting list
111 if($a_permission == 'join')
112 {
113 include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
114 if(!ilCourseWaitingList::_isOnList($a_user_id, $a_obj_id))
115 {
116 return false;
117 }
118 return true;
119 }
120 break;
121
122 case 'join':
123
124 include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
125 if(ilCourseWaitingList::_isOnList($a_user_id, $a_obj_id))
126 {
127 return false;
128 }
129 break;
130 }
131
132 switch ($a_permission)
133 {
134 case 'visible':
135 $visible = null;
136 $active = self::_isActivated($a_obj_id, $visible);
137 $tutor = $rbacsystem->checkAccessOfUser($a_user_id,'write',$a_ref_id);
138 if(!$active)
139 {
140 $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
141 }
142 if(!$tutor and !$active && !$visible)
143 {
144 return false;
145 }
146 break;
147
148 case 'read':
149 $tutor = $rbacsystem->checkAccessOfUser($a_user_id,'write',$a_ref_id);
150 if($tutor)
151 {
152 return true;
153 }
154 $active = self::_isActivated($a_obj_id);
155 if(!$active)
156 {
157 $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
158 return false;
159 }
160 if($participants->isBlocked($a_user_id) and $participants->isAssigned($a_user_id))
161 {
162 $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("crs_status_blocked"));
163 return false;
164 }
165 break;
166
167 case 'join':
168 if(!self::_registrationEnabled($a_obj_id))
169 {
170 return false;
171 }
172
173 if($participants->isAssigned($a_user_id))
174 {
175 return false;
176 }
177 break;
178 }
179 return true;
180 }
181
194 function _getCommands()
195 {
196 $commands = array();
197 $commands[] = array("permission" => "crs_linked", "cmd" => "", "lang_var" => "view", "default" => true);
198
199 include_once './Services/WebServices/FileManager/classes/class.ilFMSettings.php';
200 if(ilFMSettings::getInstance()->isEnabled())
201 {
202 $commands[] = array(
203 'permission' => 'read',
204 'cmd' => 'fileManagerLaunch',
205 'lang_var' => 'fm_start',
206 'enable_anonymous' => false
207 );
208 }
209
210 $commands[] = array("permission" => "join", "cmd" => "join", "lang_var" => "join");
211
212 // on waiting list
213 $commands[] = array('permission' => "join", "cmd" => "leave", "lang_var" => "leave_waiting_list");
214
215 // regualar users
216 $commands[] = array('permission' => "leave", "cmd" => "leave", "lang_var" => "crs_unsubscribe");
217
218 include_once ('Services/WebDAV/classes/class.ilDAVActivationChecker.php');
220 {
221 include_once './Services/WebDAV/classes/class.ilDAVUtils.php';
222 if(ilDAVUtils::getInstance()->isLocalPasswordInstructionRequired())
223 {
224 $commands[] = array('permission' => 'read', 'cmd' => 'showPasswordInstruction', 'lang_var' => 'mount_webfolder', 'enable_anonymous' => 'false');
225 }
226 else
227 {
228 $commands[] = array("permission" => "read", "cmd" => "mount_webfolder", "lang_var" => "mount_webfolder", "enable_anonymous" => "false");
229 }
230 }
231
232 $commands[] = array("permission" => "write", "cmd" => "enableAdministrationPanel", "lang_var" => "edit_content");
233 $commands[] = array("permission" => "write", "cmd" => "edit", "lang_var" => "settings");
234 return $commands;
235 }
236
240 function _checkGoto($a_target)
241 {
242 global $ilAccess,$ilUser;
243
244 $t_arr = explode("_", $a_target);
245
246 // registration codes
247 if(substr($t_arr[2],0,5) == 'rcode' and $ilUser->getId() != ANONYMOUS_USER_ID)
248 {
249 self::$using_code = true;
250 return true;
251 }
252
253
254 if ($t_arr[0] != "crs" || ((int) $t_arr[1]) <= 0)
255 {
256 return false;
257 }
258
259 // checking for read results in endless loop, if read is given
260 // but visible is not given (-> see bug 5323)
261 if ($ilAccess->checkAccess("read", "", $t_arr[1]) ||
262 $ilAccess->checkAccess("visible", "", $t_arr[1]))
263 //if ($ilAccess->checkAccess("visible", "", $t_arr[1]))
264 {
265 return true;
266 }
267 return false;
268 }
269
276 function _lookupViewMode($a_id)
277 {
278 global $ilDB;
279
280 $query = "SELECT view_mode FROM crs_settings WHERE obj_id = ".$ilDB->quote($a_id ,'integer')." ";
281 $res = $ilDB->query($query);
282 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
283 {
284 return $row->view_mode;
285 }
286 return false;
287 }
288
295 protected static function _isOnline($a_obj_id)
296 {
297 global $ilDB;
298
299 $query = "SELECT * FROM crs_settings ".
300 "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
301 $res = $ilDB->query($query);
302 $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
303 return (bool)$row->activation_type;
304 }
305
315 public static function _isActivated($a_obj_id, &$a_visible_flag = null, $a_mind_member_view = true)
316 {
317 // #7669
318 if($a_mind_member_view)
319 {
320 include_once './Services/Container/classes/class.ilMemberViewSettings.php';
321 if(ilMemberViewSettings::getInstance()->isActive())
322 {
323 $a_visible_flag = true;
324 return true;
325 }
326 }
327
328 // offline?
329 if(!self::_isOnline($a_obj_id))
330 {
331 $a_visible_flag = false;
332 return false;
333 }
334
336 $ref_id = array_pop($ref_id);
337
338 $a_visible_flag = true;
339
340 include_once './Services/Object/classes/class.ilObjectActivation.php';
342 switch($item['timing_type'])
343 {
345 if(time() < $item['timing_start'] or
346 time() > $item['timing_end'])
347 {
348 $a_visible_flag = $item['visible'];
349 return false;
350 }
351 // fallthrough
352
353 default:
354 return true;
355 }
356 }
357
363 public static function _registrationEnabled($a_obj_id)
364 {
365 global $ilDB;
366
367 $query = "SELECT * FROM crs_settings ".
368 "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
369
370 $res = $ilDB->query($query);
371 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
372 {
373 $type = $row->sub_limitation_type;
374 $reg_start = $row->sub_start;
375 $reg_end = $row->sub_end;
376 }
377
378 switch($type)
379 {
381 return true;
382
384 return false;
385
387 if(time() > $reg_start and
388 time() < $reg_end)
389 {
390 return true;
391 }
392 default:
393 return false;
394 }
395 return false;
396 }
397
406 public static function lookupRegistrationInfo($a_obj_id)
407 {
408 global $ilDB, $ilUser, $lng;
409
410 $query = 'SELECT sub_limitation_type, sub_start, sub_end, sub_mem_limit, sub_max_members FROM crs_settings '.
411 'WHERE obj_id = '.$ilDB->quote($a_obj_id);
412 $res = $ilDB->query($query);
413
414 $info = array();
415 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
416 {
417 $info['reg_info_start'] = new ilDateTime($row->sub_start, IL_CAL_UNIX);
418 $info['reg_info_end'] = new ilDateTime($row->sub_end, IL_CAL_UNIX);
419 $info['reg_info_type'] = $row->sub_limitation_type;
420 $info['reg_info_max_members'] = $row->sub_max_members;
421 $info['reg_info_mem_limit'] = $row->sub_mem_limit;
422 }
423
424 $registration_possible = true;
425
426 // Limited registration
427 if($info['reg_info_type'] == ilCourseConstants::SUBSCRIPTION_LIMITED)
428 {
429 $dt = new ilDateTime(time(),IL_CAL_UNIX);
430 if(ilDateTime::_before($dt, $info['reg_info_start']))
431 {
432 $info['reg_info_list_prop']['property'] = $lng->txt('crs_list_reg_start');
433 $info['reg_info_list_prop']['value'] = ilDatePresentation::formatDate($info['reg_info_start']);
434 }
435 elseif(ilDateTime::_before($dt, $info['reg_info_end']))
436 {
437 $info['reg_info_list_prop']['property'] = $lng->txt('crs_list_reg_end');
438 $info['reg_info_list_prop']['value'] = ilDatePresentation::formatDate($info['reg_info_end']);
439 }
440 else
441 {
442 $registration_possible = false;
443 $info['reg_info_list_prop']['property'] = $lng->txt('crs_list_reg_period');
444 $info['reg_info_list_prop']['value'] = $lng->txt('crs_list_reg_noreg');
445 }
446 }
447 else if($info['reg_info_type'] == ilCourseConstants::SUBSCRIPTION_UNLIMITED)
448 {
449 $registration_possible = true;
450 }
451 else
452 {
453 $registration_possible = false;
454 $info['reg_info_list_prop']['property'] = $lng->txt('crs_list_reg_period');
455 $info['reg_info_list_prop']['value'] = $lng->txt('crs_list_reg_noreg');
456 }
457
458 if($info['reg_info_mem_limit'] && $registration_possible)
459 {
460 // Check for free places
461 include_once './Modules/Course/classes/class.ilCourseParticipant.php';
462 $part = ilCourseParticipant::_getInstanceByObjId($a_obj_id, $ilUser->getId());
463
464 include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
465 $info['reg_info_list_size'] = ilCourseWaitingList::lookupListSize($a_obj_id);
466 $GLOBALS['ilLog']->write(__METHOD__.' list_size: ' . $info['reg_info_list_size']);
467 if($info['reg_info_list_size'])
468 {
469 $info['reg_info_free_places'] = 0;
470 }
471 else
472 {
473 $info['reg_info_free_places'] = max(0,$info['reg_info_max_members'] - $part->getNumberOfMembers());
474 }
475
476 if($info['reg_info_free_places'])
477 {
478 $info['reg_info_list_prop_limit']['property'] = $lng->txt('crs_list_reg_limit_places');
479 $info['reg_info_list_prop_limit']['value'] = $info['reg_info_free_places'];
480 }
481 else
482 {
483 $info['reg_info_list_prop_limit']['property'] = '';
484 $info['reg_info_list_prop_limit']['value'] = $lng->txt('crs_list_reg_limit_full');
485 }
486 }
487
488 return $info;
489 }
490
499 static function _isOffline($a_obj_id)
500 {
501 $dummy = null;
502 return !self::_isActivated($a_obj_id, $dummy, false);
503 }
504
510 function _preloadData($a_obj_ids, $a_ref_ids)
511 {
512 global $ilUser;
513
514 include_once("./Modules/Course/classes/class.ilCourseWaitingList.php");
516
517 include_once "./Modules/Course/classes/class.ilCourseCertificateAdapter.php";
519 }
520
526 public static function _usingRegistrationCode()
527 {
528 return self::$using_code;
529 }
530
531}
532
533?>
const IL_NO_OBJECT_ACCESS
const IL_CRS_SUBSCRIPTION_LIMITED
const IL_CRS_SUBSCRIPTION_UNLIMITED
const IL_CRS_SUBSCRIPTION_DEACTIVATED
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
const IL_CAL_UNIX
static _preloadListData($a_usr_ids, $a_obj_ids)
Get certificate/passed status for all given objects and users.
static _getInstanceByObjId($a_obj_id, $a_usr_id)
Get singleton instance.
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
static getInstance()
Get singleton instance.
static formatDate(ilDateTime $date)
Format a date @access public.
@classDescription Date and time handling
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.
static getInstance()
Get singleton instance.
static getInstance()
Get instance.
Class ilObjCourseAccess.
static getConditionOperators()
Get operators.
static checkCondition($a_obj_id, $a_operator, $a_value, $a_usr_id)
@global ilObjUser $ilUser
_lookupViewMode($a_id)
Lookup view mode.
static _registrationEnabled($a_obj_id)
_preloadData($a_obj_ids, $a_ref_ids)
Preload data.
_checkGoto($a_target)
check whether goto script will succeed
static _usingRegistrationCode()
Using Registration code.
_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 _isActivated($a_obj_id, &$a_visible_flag=null, $a_mind_member_view=true)
Is activated?
static lookupRegistrationInfo($a_obj_id)
Lookup registration info @global ilDB $ilDB @global ilObjUser $ilUser @global ilLanguage $lng.
static _isOffline($a_obj_id)
Type-specific implementation of general status.
static _isOnline($a_obj_id)
Check if online setting is active.
Class ilObjectAccess.
static getItem($a_ref_id)
Get item data.
static _getAllReferences($a_id)
get all reference ids of object
static _hasPassed($a_obj_id, $a_usr_id)
Check if user has passed course.
_preloadOnListInfo($a_usr_ids, $a_obj_ids)
Preload on list info.
static _isOnList($a_usr_id, $a_obj_id)
Check if a user on the waiting list.
static lookupListSize($a_obj_id)
Lookup waiting lit size.
$GLOBALS['ct_recipient']
Interface for condition handling.
global $lng
Definition: privfeed.php:40
$ref_id
Definition: sahs_server.php:39
global $ilDB
global $ilUser
Definition: imgupload.php:15