ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
5 include_once("./Services/Object/classes/class.ilObjectAccess.php");
6 include_once './Modules/Course/classes/class.ilCourseConstants.php';
7 include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
8 include_once 'Modules/Course/classes/class.ilCourseParticipant.php';
9 include_once './Services/AccessControl/interfaces/interface.ilConditionHandling.php';
10 
20 {
21  protected static $using_code = false;
22 
26  public static function getConditionOperators()
27  {
28  include_once './Services/AccessControl/classes/class.ilConditionHandler.php';
29  return array(
31  );
32  }
33 
43  public static function checkCondition($a_obj_id, $a_operator, $a_value, $a_usr_id)
44  {
45  include_once "./Modules/Course/classes/class.ilCourseParticipants.php";
46  include_once './Services/AccessControl/classes/class.ilConditionHandler.php';
47 
48  switch ($a_operator) {
50  return ilCourseParticipants::_hasPassed($a_obj_id, $a_usr_id);
51  }
52  return false;
53  }
54 
67  public function _checkAccess($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id = "")
68  {
69  global $ilUser, $lng, $rbacsystem, $ilAccess, $ilias;
70 
71  if ($a_user_id == "") {
72  $a_user_id = $ilUser->getId();
73  }
74 
75  if ($ilUser->getId() == $a_user_id) {
76  $participants = ilCourseParticipant::_getInstanceByObjId($a_obj_id, $a_user_id);
77  } else {
78  $participants = ilCourseParticipants::_getInstanceByObjId($a_obj_id);
79  }
80 
81 
82  switch ($a_cmd) {
83  case "view":
84  if ($participants->isBlocked($a_user_id) and $participants->isAssigned($a_user_id)) {
85  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("crs_status_blocked"));
86  return false;
87  }
88  break;
89 
90  case 'leave':
91 
92  // Regular member
93  if ($a_permission == 'leave') {
94  include_once './Modules/Course/classes/class.ilObjCourse.php';
95  $limit = null;
96  if (!ilObjCourse::mayLeave($a_obj_id, $a_user_id, $limit)) {
97  $ilAccess->addInfoItem(
99  sprintf($lng->txt("crs_cancellation_end_rbac_info"), ilDatePresentation::formatDate($limit))
100  );
101  return false;
102  }
103 
104  include_once './Modules/Course/classes/class.ilCourseParticipants.php';
105  if (!$participants->isAssigned($a_user_id)) {
106  return false;
107  }
108  }
109  // Waiting list
110  if ($a_permission == 'join') {
111  include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
112  if (!ilCourseWaitingList::_isOnList($a_user_id, $a_obj_id)) {
113  return false;
114  }
115  return true;
116  }
117  break;
118 
119  case 'join':
120 
121  include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
122  if (ilCourseWaitingList::_isOnList($a_user_id, $a_obj_id)) {
123  return false;
124  }
125  break;
126  }
127 
128  switch ($a_permission) {
129  case 'visible':
130  $visible = null;
131  $active = self::_isActivated($a_obj_id, $visible);
132  $tutor = $rbacsystem->checkAccessOfUser($a_user_id, 'write', $a_ref_id);
133  if (!$active) {
134  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
135  }
136  if (!$tutor and !$active && !$visible) {
137  return false;
138  }
139  break;
140 
141  case 'read':
142  $tutor = $rbacsystem->checkAccessOfUser($a_user_id, 'write', $a_ref_id);
143  if ($tutor) {
144  return true;
145  }
146  $active = self::_isActivated($a_obj_id);
147  if (!$active) {
148  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
149  return false;
150  }
151  if ($participants->isBlocked($a_user_id) and $participants->isAssigned($a_user_id)) {
152  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("crs_status_blocked"));
153  return false;
154  }
155  break;
156 
157  case 'join':
158  if (!self::_registrationEnabled($a_obj_id)) {
159  return false;
160  }
161 
162  if ($participants->isAssigned($a_user_id)) {
163  return false;
164  }
165  break;
166 
167  case 'leave':
168  include_once './Modules/Course/classes/class.ilObjCourse.php';
169  return ilObjCourse::mayLeave($a_obj_id, $a_user_id);
170  }
171  return true;
172  }
173 
186  public static function _getCommands()
187  {
188  $commands = array();
189  $commands[] = array("permission" => "crs_linked", "cmd" => "", "lang_var" => "view", "default" => true);
190 
191  include_once './Services/WebServices/FileManager/classes/class.ilFMSettings.php';
192  if (ilFMSettings::getInstance()->isEnabled()) {
193  $commands[] = array(
194  'permission' => 'read',
195  'cmd' => 'fileManagerLaunch',
196  'lang_var' => 'fm_start',
197  'enable_anonymous' => false
198  );
199  }
200 
201  $commands[] = array("permission" => "join", "cmd" => "join", "lang_var" => "join");
202 
203  // on waiting list
204  $commands[] = array('permission' => "join", "cmd" => "leave", "lang_var" => "leave_waiting_list");
205 
206  // regualar users
207  $commands[] = array('permission' => "leave", "cmd" => "leave", "lang_var" => "crs_unsubscribe");
208 
209  include_once('Services/WebDAV/classes/class.ilDAVActivationChecker.php');
211  include_once './Services/WebDAV/classes/class.ilDAVUtils.php';
212  if (ilDAVUtils::getInstance()->isLocalPasswordInstructionRequired()) {
213  $commands[] = array('permission' => 'read', 'cmd' => 'showPasswordInstruction', 'lang_var' => 'mount_webfolder', 'enable_anonymous' => 'false');
214  } else {
215  $commands[] = array("permission" => "read", "cmd" => "mount_webfolder", "lang_var" => "mount_webfolder", "enable_anonymous" => "false");
216  }
217  }
218 
219  $commands[] = array("permission" => "write", "cmd" => "enableAdministrationPanel", "lang_var" => "edit_content");
220  $commands[] = array("permission" => "write", "cmd" => "edit", "lang_var" => "settings");
221  return $commands;
222  }
223 
227  public static function _checkGoto($a_target)
228  {
229  global $ilAccess,$ilUser;
230 
231  $t_arr = explode("_", $a_target);
232 
233  // registration codes
234  if (substr($t_arr[2], 0, 5) == 'rcode' and $ilUser->getId() != ANONYMOUS_USER_ID) {
235  self::$using_code = true;
236  return true;
237  }
238 
239 
240  if ($t_arr[0] != "crs" || ((int) $t_arr[1]) <= 0) {
241  return false;
242  }
243 
244  // checking for read results in endless loop, if read is given
245  // but visible is not given (-> see bug 5323)
246  if ($ilAccess->checkAccess("read", "", $t_arr[1]) ||
247  $ilAccess->checkAccess("visible", "", $t_arr[1])) {
248  //if ($ilAccess->checkAccess("visible", "", $t_arr[1]))
249  return true;
250  }
251  return false;
252  }
253 
260  public static function _lookupViewMode($a_id)
261  {
262  global $ilDB;
263 
264  $query = "SELECT view_mode FROM crs_settings WHERE obj_id = " . $ilDB->quote($a_id, 'integer') . " ";
265  $res = $ilDB->query($query);
266  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
267  return $row->view_mode;
268  }
269  return false;
270  }
271 
278  public static function _isOnline($a_obj_id)
279  {
280  global $ilDB;
281 
282  $query = "SELECT * FROM crs_settings " .
283  "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " ";
284  $res = $ilDB->query($query);
286  return (bool) $row->activation_type;
287  }
288 
298  public static function _isActivated($a_obj_id, &$a_visible_flag = null, $a_mind_member_view = true)
299  {
300  // #7669
301  if ($a_mind_member_view) {
302  include_once './Services/Container/classes/class.ilMemberViewSettings.php';
303  if (ilMemberViewSettings::getInstance()->isActive()) {
304  $a_visible_flag = true;
305  return true;
306  }
307  }
308 
309  // offline?
310  if (!self::_isOnline($a_obj_id)) {
311  $a_visible_flag = false;
312  return false;
313  }
314 
315  $ref_id = ilObject::_getAllReferences($a_obj_id);
316  $ref_id = array_pop($ref_id);
317 
318  $a_visible_flag = true;
319 
320  include_once './Services/Object/classes/class.ilObjectActivation.php';
321  $item = ilObjectActivation::getItem($ref_id);
322  switch ($item['timing_type']) {
324  if (time() < $item['timing_start'] or
325  time() > $item['timing_end']) {
326  $a_visible_flag = $item['visible'];
327  return false;
328  }
329  // fallthrough
330 
331  // no break
332  default:
333  return true;
334  }
335  }
336 
342  public static function _registrationEnabled($a_obj_id)
343  {
344  global $ilDB;
345 
346  $query = "SELECT * FROM crs_settings " .
347  "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " ";
348 
349  $res = $ilDB->query($query);
350  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
351  $type = $row->sub_limitation_type;
352  $reg_start = $row->sub_start;
353  $reg_end = $row->sub_end;
354  }
355 
356  switch ($type) {
358  return true;
359 
361  return false;
362 
364  if (time() > $reg_start and
365  time() < $reg_end) {
366  return true;
367  }
368  // no break
369  default:
370  return false;
371  }
372  return false;
373  }
374 
383  public static function lookupRegistrationInfo($a_obj_id)
384  {
385  global $ilDB, $ilUser, $lng;
386 
387  $query = 'SELECT sub_limitation_type, sub_start, sub_end, sub_mem_limit, sub_max_members FROM crs_settings ' .
388  'WHERE obj_id = ' . $ilDB->quote($a_obj_id);
389  $res = $ilDB->query($query);
390 
391  $info = array();
392  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
393  $info['reg_info_start'] = new ilDateTime($row->sub_start, IL_CAL_UNIX);
394  $info['reg_info_end'] = new ilDateTime($row->sub_end, IL_CAL_UNIX);
395  $info['reg_info_type'] = $row->sub_limitation_type;
396  $info['reg_info_max_members'] = $row->sub_max_members;
397  $info['reg_info_mem_limit'] = $row->sub_mem_limit;
398  }
399 
400  $registration_possible = true;
401 
402  // Limited registration
403  if ($info['reg_info_type'] == ilCourseConstants::SUBSCRIPTION_LIMITED) {
404  $dt = new ilDateTime(time(), IL_CAL_UNIX);
405  if (ilDateTime::_before($dt, $info['reg_info_start'])) {
406  $info['reg_info_list_prop']['property'] = $lng->txt('crs_list_reg_start');
407  $info['reg_info_list_prop']['value'] = ilDatePresentation::formatDate($info['reg_info_start']);
408  } elseif (ilDateTime::_before($dt, $info['reg_info_end'])) {
409  $info['reg_info_list_prop']['property'] = $lng->txt('crs_list_reg_end');
410  $info['reg_info_list_prop']['value'] = ilDatePresentation::formatDate($info['reg_info_end']);
411  } else {
412  $registration_possible = false;
413  $info['reg_info_list_prop']['property'] = $lng->txt('crs_list_reg_period');
414  $info['reg_info_list_prop']['value'] = $lng->txt('crs_list_reg_noreg');
415  }
416  } elseif ($info['reg_info_type'] == ilCourseConstants::SUBSCRIPTION_UNLIMITED) {
417  $registration_possible = true;
418  } else {
419  $registration_possible = false;
420  $info['reg_info_list_prop']['property'] = $lng->txt('crs_list_reg');
421  $info['reg_info_list_prop']['value'] = $lng->txt('crs_list_reg_noreg');
422  }
423 
424  if ($info['reg_info_mem_limit'] && $info['reg_info_max_members'] && $registration_possible) {
425  // Check for free places
426  include_once './Modules/Course/classes/class.ilCourseParticipant.php';
427  $part = ilCourseParticipant::_getInstanceByObjId($a_obj_id, $ilUser->getId());
428 
429  include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
430  $info['reg_info_list_size'] = ilCourseWaitingList::lookupListSize($a_obj_id);
431  if ($info['reg_info_list_size']) {
432  $info['reg_info_free_places'] = 0;
433  } else {
434  $info['reg_info_free_places'] = max(0, $info['reg_info_max_members'] - $part->getNumberOfMembers());
435  }
436 
437  if ($info['reg_info_free_places']) {
438  $info['reg_info_list_prop_limit']['property'] = $lng->txt('crs_list_reg_limit_places');
439  $info['reg_info_list_prop_limit']['value'] = $info['reg_info_free_places'];
440  } else {
441  $info['reg_info_list_prop_limit']['property'] = '';
442  $info['reg_info_list_prop_limit']['value'] = $lng->txt('crs_list_reg_limit_full');
443  }
444  }
445 
446  return $info;
447  }
448 
457  public static function _isOffline($a_obj_id)
458  {
459  $dummy = null;
460  return !self::_isActivated($a_obj_id, $dummy, false);
461  }
462 
468  public static function _preloadData($a_obj_ids, $a_ref_ids)
469  {
470  global $ilUser, $lng;
471 
472  $lng->loadLanguageModule("crs");
473 
474  include_once("./Modules/Course/classes/class.ilCourseWaitingList.php");
475  ilCourseWaitingList::_preloadOnListInfo($ilUser->getId(), $a_obj_ids);
476 
477  include_once "./Modules/Course/classes/class.ilCourseCertificateAdapter.php";
478  ilCourseCertificateAdapter::_preloadListData($ilUser->getId(), $a_obj_ids);
479  }
480 
486  public static function _usingRegistrationCode()
487  {
488  return self::$using_code;
489  }
490 
497  public static function lookupPeriodInfo($a_obj_id)
498  {
499  global $ilDB, $lng;
500 
501  $start = $end = null;
502 
503  $query = 'SELECT crs_start, crs_end FROM crs_settings' .
504  ' WHERE obj_id = ' . $ilDB->quote($a_obj_id);
505  $set = $ilDB->query($query);
506  while ($row = $ilDB->fetchAssoc($set)) {
507  $start = $row['crs_start']
508  ? new ilDate($row['crs_start'], IL_CAL_UNIX)
509  : null;
510  $end = $row['crs_end']
511  ? new ilDate($row['crs_end'], IL_CAL_UNIX)
512  : null;
513  }
514 
515  if ($start && $end) {
516  $lng->loadLanguageModule('crs');
517 
518  return array(
519  'property' => $lng->txt('crs_period'),
520  'value' => ilDatePresentation::formatPeriod($start, $end)
521  );
522  }
523  }
524 }
static lookupPeriodInfo($a_obj_id)
Lookup course period info.
static getConditionOperators()
Get operators.
static checkCondition($a_obj_id, $a_operator, $a_value, $a_usr_id)
ilObjUser $ilUser
static _preloadData($a_obj_ids, $a_ref_ids)
Preload data.
const IL_CRS_SUBSCRIPTION_LIMITED
_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...
$type
const IL_NO_OBJECT_ACCESS
static _registrationEnabled($a_obj_id)
static _preloadOnListInfo($a_usr_ids, $a_obj_ids)
Preload on list info.
Class ilObjCourseAccess.
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 formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false)
Format a date public.
static getItem($a_ref_id)
Get item data.
$end
Definition: saml1-acs.php:18
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
Interface for condition handling.
static _checkGoto($a_target)
check whether goto script will succeed
static _isActive()
Static getter.
const IL_CAL_UNIX
static _usingRegistrationCode()
Using Registration code.
static _getAllReferences($a_id)
get all reference ids of object
static _preloadListData($a_usr_ids, $a_obj_ids)
Get certificate/passed status for all given objects and users.
Class for single dates.
foreach($_POST as $key=> $value) $res
static _isOffline($a_obj_id)
Type-specific implementation of general status.
const IL_CRS_SUBSCRIPTION_UNLIMITED
static lookupRegistrationInfo($a_obj_id)
Lookup registration info ilDB $ilDB ilObjUser $ilUser ilLanguage $lng.
Date and time handling
static _hasPassed($a_obj_id, $a_usr_id)
Check if user has passed course.
$ilUser
Definition: imgupload.php:18
$query
static _getInstanceByObjId($a_obj_id, $a_usr_id)
Get singleton instance.
static _isOnList($a_usr_id, $a_obj_id)
Check if a user on the waiting list.
Create styles array
The data for the language used.
static mayLeave($a_course_id, $a_user_id=null, &$a_date=null)
static getInstance()
Get singleton instance.
static lookupListSize($a_obj_id)
Lookup waiting lit size.
static formatPeriod(ilDateTime $start, ilDateTime $end, $a_skip_starting_day=false)
Format a period of two date Shows: 14.
Class ilObjectAccess.
static getInstance()
Get instance.
global $lng
Definition: privfeed.php:17
static _isOnline($a_obj_id)
Check if online setting is active.
global $ilDB
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
$info
Definition: index.php:5
static _isActivated($a_obj_id, &$a_visible_flag=null, $a_mind_member_view=true)
Is activated?
static getInstance()
Get singleton instance.
const IL_CRS_SUBSCRIPTION_DEACTIVATED
static _lookupViewMode($a_id)
Lookup view mode.
static _getCommands()
get commands