ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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/Conditions/interfaces/interface.ilConditionHandling.php';
10 
20 {
21  protected static $using_code = false;
22 
26  protected static $booking_repo = null;
27 
31  public static function getConditionOperators()
32  {
33  include_once './Services/Conditions/classes/class.ilConditionHandler.php';
34  return array(
36  );
37  }
38 
48  public static function checkCondition($a_obj_id, $a_operator, $a_value, $a_usr_id)
49  {
50  include_once "./Modules/Course/classes/class.ilCourseParticipants.php";
51  include_once './Services/Conditions/classes/class.ilConditionHandler.php';
52 
53  switch ($a_operator) {
55  return ilCourseParticipants::_hasPassed($a_obj_id, $a_usr_id);
56  }
57  return false;
58  }
59 
72  public function _checkAccess($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id = "")
73  {
74  global $DIC;
75 
76  $ilUser = $DIC['ilUser'];
77  $lng = $DIC['lng'];
78  $rbacsystem = $DIC['rbacsystem'];
79  $ilAccess = $DIC['ilAccess'];
80  $ilias = $DIC['ilias'];
81 
82  if ($a_user_id == "") {
83  $a_user_id = $ilUser->getId();
84  }
85 
86  if ($ilUser->getId() == $a_user_id) {
87  $participants = ilCourseParticipant::_getInstanceByObjId($a_obj_id, $a_user_id);
88  } else {
89  $participants = ilCourseParticipants::_getInstanceByObjId($a_obj_id);
90  }
91 
92 
93  switch ($a_cmd) {
94  case "view":
95  if ($participants->isBlocked($a_user_id) and $participants->isAssigned($a_user_id)) {
96  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("crs_status_blocked"));
97  return false;
98  }
99  break;
100 
101  case 'leave':
102 
103  // Regular member
104  if ($a_permission == 'leave') {
105  include_once './Modules/Course/classes/class.ilObjCourse.php';
106  $limit = null;
107  if (!ilObjCourse::mayLeave($a_obj_id, $a_user_id, $limit)) {
108  $ilAccess->addInfoItem(
110  sprintf($lng->txt("crs_cancellation_end_rbac_info"), ilDatePresentation::formatDate($limit))
111  );
112  return false;
113  }
114 
115  include_once './Modules/Course/classes/class.ilCourseParticipants.php';
116  if (!$participants->isAssigned($a_user_id)) {
117  return false;
118  }
119  }
120  // Waiting list
121  if ($a_permission == 'join') {
122  include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
123  if (!ilCourseWaitingList::_isOnList($a_user_id, $a_obj_id)) {
124  return false;
125  }
126  return true;
127  }
128  break;
129 
130  case 'join':
131 
132  include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
133  if (ilCourseWaitingList::_isOnList($a_user_id, $a_obj_id)) {
134  return false;
135  }
136  break;
137  }
138 
139  switch ($a_permission) {
140  case 'visible':
141  $visible = null;
142  $active = self::_isActivated($a_obj_id, $visible);
143  $tutor = $rbacsystem->checkAccessOfUser($a_user_id, 'write', $a_ref_id);
144  if (!$active) {
145  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
146  }
147  if (!$tutor && !$active && !$visible) {
148  return false;
149  }
150  break;
151 
152  case 'read':
153  $tutor = $rbacsystem->checkAccessOfUser($a_user_id, 'write', $a_ref_id);
154  if ($tutor) {
155  return true;
156  }
157  $active = self::_isActivated($a_obj_id);
158  if (!$active) {
159  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
160  return false;
161  }
162  if ($participants->isBlocked($a_user_id) and $participants->isAssigned($a_user_id)) {
163  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("crs_status_blocked"));
164  return false;
165  }
166  break;
167 
168  case 'join':
169  if (!self::_registrationEnabled($a_obj_id)) {
170  return false;
171  }
172 
173  if ($participants->isAssigned($a_user_id)) {
174  return false;
175  }
176  break;
177 
178  case 'leave':
179  include_once './Modules/Course/classes/class.ilObjCourse.php';
180  return ilObjCourse::mayLeave($a_obj_id, $a_user_id);
181  }
182  return true;
183  }
184 
197  public static function _getCommands()
198  {
199  $commands = array();
200  $commands[] = array("permission" => "crs_linked", "cmd" => "", "lang_var" => "view", "default" => true);
201 
202  $commands[] = array("permission" => "join", "cmd" => "join", "lang_var" => "join");
203 
204  // on waiting list
205  $commands[] = array('permission' => "join", "cmd" => "leave", "lang_var" => "leave_waiting_list");
206 
207  // regualar users
208  $commands[] = array('permission' => "leave", "cmd" => "leave", "lang_var" => "crs_unsubscribe");
209 
210  include_once('Services/WebDAV/classes/class.ilDAVActivationChecker.php');
212  include_once './Services/WebDAV/classes/class.ilWebDAVUtil.php';
213  if (ilWebDAVUtil::getInstance()->isLocalPasswordInstructionRequired()) {
214  $commands[] = array('permission' => 'read', 'cmd' => 'showPasswordInstruction', 'lang_var' => 'mount_webfolder', 'enable_anonymous' => 'false');
215  } else {
216  $commands[] = array("permission" => "read", "cmd" => "mount_webfolder", "lang_var" => "mount_webfolder", "enable_anonymous" => "false");
217  }
218  }
219 
220  $commands[] = array("permission" => "write", "cmd" => "enableAdministrationPanel", "lang_var" => "edit_content");
221  $commands[] = array("permission" => "write", "cmd" => "edit", "lang_var" => "settings");
222  return $commands;
223  }
224 
228  public static function _checkGoto($a_target)
229  {
230  global $DIC;
231 
232  $ilAccess = $DIC['ilAccess'];
233  $ilUser = $DIC['ilUser'];
234 
235  $t_arr = explode("_", $a_target);
236 
237  // registration codes
238  if (substr($t_arr[2], 0, 5) == 'rcode' and $ilUser->getId() != ANONYMOUS_USER_ID) {
239  self::$using_code = true;
240  return true;
241  }
242 
243 
244  if ($t_arr[0] != "crs" || ((int) $t_arr[1]) <= 0) {
245  return false;
246  }
247 
248  // checking for read results in endless loop, if read is given
249  // but visible is not given (-> see bug 5323)
250  if ($ilAccess->checkAccess("read", "", $t_arr[1]) ||
251  $ilAccess->checkAccess("visible", "", $t_arr[1])) {
252  //if ($ilAccess->checkAccess("visible", "", $t_arr[1]))
253  return true;
254  }
255  return false;
256  }
257 
264  public static function _lookupViewMode($a_id)
265  {
266  global $DIC;
267 
268  $ilDB = $DIC['ilDB'];
269 
270  $query = "SELECT view_mode FROM crs_settings WHERE obj_id = " . $ilDB->quote($a_id, 'integer') . " ";
271  $res = $ilDB->query($query);
272  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
273  return $row->view_mode;
274  }
275  return false;
276  }
277 
287  public static function _isActivated($a_obj_id, &$a_visible_flag = null, $a_mind_member_view = true)
288  {
289  // #7669
290  if ($a_mind_member_view) {
291  include_once './Services/Container/classes/class.ilMemberViewSettings.php';
292  if (ilMemberViewSettings::getInstance()->isActive()) {
293  $a_visible_flag = true;
294  return true;
295  }
296  }
297 
298  $ref_id = ilObject::_getAllReferences($a_obj_id);
299  $ref_id = array_pop($ref_id);
300 
301  $a_visible_flag = true;
302 
303  include_once './Services/Object/classes/class.ilObjectActivation.php';
304  $item = ilObjectActivation::getItem($ref_id);
305  switch ($item['timing_type']) {
307  if (time() < $item['timing_start'] or
308  time() > $item['timing_end']) {
309  $a_visible_flag = $item['visible'];
310  return false;
311  }
312  // fallthrough
313 
314  // no break
315  default:
316  return true;
317  }
318  }
319 
325  public static function _registrationEnabled($a_obj_id)
326  {
327  global $DIC;
328 
329  $ilDB = $DIC['ilDB'];
330 
331  $query = "SELECT * FROM crs_settings " .
332  "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " ";
333 
334  $res = $ilDB->query($query);
335  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
336  $type = $row->sub_limitation_type;
337  $reg_start = $row->sub_start;
338  $reg_end = $row->sub_end;
339  }
340 
341  switch ($type) {
343  return true;
344 
346  return false;
347 
349  if (time() > $reg_start and
350  time() < $reg_end) {
351  return true;
352  }
353  // no break
354  default:
355  return false;
356  }
357  return false;
358  }
359 
368  public static function lookupRegistrationInfo($a_obj_id)
369  {
370  global $DIC;
371 
372  $ilDB = $DIC['ilDB'];
373  $ilUser = $DIC['ilUser'];
374  $lng = $DIC['lng'];
375 
376  $query = 'SELECT sub_limitation_type, sub_start, sub_end, sub_mem_limit, sub_max_members FROM crs_settings ' .
377  'WHERE obj_id = ' . $ilDB->quote($a_obj_id);
378  $res = $ilDB->query($query);
379 
380  $info = array();
381  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
382  $info['reg_info_start'] = new ilDateTime($row->sub_start, IL_CAL_UNIX);
383  $info['reg_info_end'] = new ilDateTime($row->sub_end, IL_CAL_UNIX);
384  $info['reg_info_type'] = $row->sub_limitation_type;
385  $info['reg_info_max_members'] = $row->sub_max_members;
386  $info['reg_info_mem_limit'] = $row->sub_mem_limit;
387  }
388 
389  $registration_possible = true;
390 
391  // Limited registration
392  if ($info['reg_info_type'] == ilCourseConstants::SUBSCRIPTION_LIMITED) {
393  $dt = new ilDateTime(time(), IL_CAL_UNIX);
394  if (ilDateTime::_before($dt, $info['reg_info_start'])) {
395  $info['reg_info_list_prop']['property'] = $lng->txt('crs_list_reg_start');
396  $info['reg_info_list_prop']['value'] = ilDatePresentation::formatDate($info['reg_info_start']);
397  } elseif (ilDateTime::_before($dt, $info['reg_info_end'])) {
398  $info['reg_info_list_prop']['property'] = $lng->txt('crs_list_reg_end');
399  $info['reg_info_list_prop']['value'] = ilDatePresentation::formatDate($info['reg_info_end']);
400  } else {
401  $registration_possible = false;
402  $info['reg_info_list_prop']['property'] = $lng->txt('crs_list_reg_period');
403  $info['reg_info_list_prop']['value'] = $lng->txt('crs_list_reg_noreg');
404  }
405  } elseif ($info['reg_info_type'] == ilCourseConstants::SUBSCRIPTION_UNLIMITED) {
406  $registration_possible = true;
407  } else {
408  $registration_possible = false;
409  $info['reg_info_list_prop']['property'] = $lng->txt('crs_list_reg');
410  $info['reg_info_list_prop']['value'] = $lng->txt('crs_list_reg_noreg');
411  }
412 
413  if ($info['reg_info_mem_limit'] && $info['reg_info_max_members'] && $registration_possible) {
414  // Check for free places
415  include_once './Modules/Course/classes/class.ilCourseParticipant.php';
416  $part = ilCourseParticipant::_getInstanceByObjId($a_obj_id, $ilUser->getId());
417 
418  include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
419  $info['reg_info_list_size'] = ilCourseWaitingList::lookupListSize($a_obj_id);
420  if ($info['reg_info_list_size']) {
421  $info['reg_info_free_places'] = 0;
422  } else {
423  $info['reg_info_free_places'] = max(0, $info['reg_info_max_members'] - $part->getNumberOfMembers());
424  }
425 
426  if ($info['reg_info_free_places']) {
427  $info['reg_info_list_prop_limit']['property'] = $lng->txt('crs_list_reg_limit_places');
428  $info['reg_info_list_prop_limit']['value'] = $info['reg_info_free_places'];
429  } else {
430  $info['reg_info_list_prop_limit']['property'] = '';
431  $info['reg_info_list_prop_limit']['value'] = $lng->txt('crs_list_reg_limit_full');
432  }
433  }
434 
435  return $info;
436  }
437 
446  public static function _isOffline($a_obj_id)
447  {
448  $dummy = null;
449  return !self::_isActivated($a_obj_id, $dummy, false);
450  }
451 
457  public static function _preloadData($a_obj_ids, $a_ref_ids)
458  {
459  global $DIC;
460 
461  $ilUser = $DIC['ilUser'];
462  $lng = $DIC['lng'];
463 
464  $lng->loadLanguageModule("crs");
465 
466  ilCourseWaitingList::_preloadOnListInfo($ilUser->getId(), $a_obj_ids);
467 
468  $repository = new ilUserCertificateRepository();
469  $coursePreload = new ilCertificateObjectsForUserPreloader($repository);
470  $coursePreload->preLoad($ilUser->getId(), $a_obj_ids);
471 
473  self::$booking_repo = $f->getRepoWithContextObjCache($a_obj_ids);
474  }
475 
480  public static function getBookingInfoRepo()
481  {
482  return self::$booking_repo;
483  }
484 
485 
491  public static function _usingRegistrationCode()
492  {
493  return self::$using_code;
494  }
495 
502  public static function lookupPeriodInfo($a_obj_id)
503  {
504  global $DIC;
505 
506  $ilDB = $DIC['ilDB'];
507  $lng = $DIC['lng'];
508 
509  $start = $end = null;
510  $query = 'SELECT period_start, period_end, period_time_indication FROM crs_settings ' .
511  'WHERE obj_id = ' . $ilDB->quote($a_obj_id);
512 
513  $res = $ilDB->query($query);
514  while ($row = $res->fetchRow(\ilDBConstants::FETCHMODE_OBJECT)) {
515  if (!$row->period_time_indication) {
516  $start = ($row->period_start
517  ? new \ilDate($row->period_start, IL_CAL_DATETIME)
518  : null);
519  $end = ($row->period_end
520  ? new \ilDate($row->period_end, IL_CAL_DATETIME)
521  : null);
522  } else {
523  $start = ($row->period_start
524  ? new \ilDateTime($row->period_start, IL_CAL_DATETIME, \ilTimeZone::UTC)
525  : null);
526  $end = ($row->period_end
527  ? new \ilDateTime($row->period_end, IL_CAL_DATETIME, \ilTimeZone::UTC)
528  : null);
529  }
530  }
531  if ($start && $end) {
532  $lng->loadLanguageModule('crs');
533 
534  return
535  [
536  'crs_start' => $start,
537  'crs_end' => $end,
538  'property' => $lng->txt('crs_period'),
539  'value' => ilDatePresentation::formatPeriod($start, $end)
540  ];
541  }
542  }
543 }
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
const IL_CAL_DATETIME
const ANONYMOUS_USER_ID
Definition: constants.php:25
static getBookingInfoRepo()
Get booking info repo.
_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 getItem($a_ref_id)
Get item data.
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 formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
static _usingRegistrationCode()
Using Registration code.
static _getAllReferences($a_id)
get all reference ids of object
foreach($_POST as $key=> $value) $res
$lng
static _isOffline($a_obj_id)
Type-specific implementation of general status.
global $DIC
Definition: goto.php:24
const IL_CRS_SUBSCRIPTION_UNLIMITED
static lookupRegistrationInfo($a_obj_id)
Lookup registration info ilDB $ilDB ilObjUser $ilUser ilLanguage $lng.
static _hasPassed($a_obj_id, $a_usr_id)
Check if user has passed course.
$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.
static mayLeave($a_course_id, $a_user_id=null, &$a_date=null)
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.
static getInstance()
Get singleton instance.
global $ilDB
$ilUser
Definition: imgupload.php:18
static _isActivated($a_obj_id, &$a_visible_flag=null, $a_mind_member_view=true)
Is activated?
const IL_CRS_SUBSCRIPTION_DEACTIVATED
static _lookupViewMode($a_id)
Lookup view mode.
static _getCommands()
get commands