ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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 
5 include_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 $DIC;
33 
34  $ilUser = $DIC['ilUser'];
35  $lng = $DIC['lng'];
36  $rbacsystem = $DIC['rbacsystem'];
37  $ilAccess = $DIC['ilAccess'];
38 
39  if ($a_user_id == "") {
40  $a_user_id = $ilUser->getId();
41  }
42 
43  switch ($a_cmd) {
44  case "info":
45 
46  include_once './Modules/Group/classes/class.ilGroupParticipants.php';
47  if (ilGroupParticipants::_isParticipant($a_ref_id, $a_user_id)) {
48  $ilAccess->addInfoItem(ilAccessInfo::IL_STATUS_INFO, $lng->txt("info_is_member"));
49  } else {
50  $ilAccess->addInfoItem(ilAccessInfo::IL_STATUS_INFO, $lng->txt("info_is_not_member"));
51  }
52  break;
53 
54  case "join":
55 
56  if (!self::_registrationEnabled($a_obj_id)) {
57  return false;
58  }
59 
60  include_once './Modules/Group/classes/class.ilGroupWaitingList.php';
61  if (ilGroupWaitingList::_isOnList($ilUser->getId(), $a_obj_id)) {
62  return false;
63  }
64 
65  include_once './Modules/Group/classes/class.ilGroupParticipants.php';
66  if (ilGroupParticipants::_isParticipant($a_ref_id, $a_user_id)) {
67  return false;
68  }
69  break;
70 
71  case 'leave':
72 
73  // Regular member
74  if ($a_permission == 'leave') {
75  include_once './Modules/Group/classes/class.ilObjGroup.php';
76  $limit = null;
77  if (!ilObjGroup::mayLeave($a_obj_id, $a_user_id, $limit)) {
78  $ilAccess->addInfoItem(
80  sprintf($lng->txt("grp_cancellation_end_rbac_info"), ilDatePresentation::formatDate($limit))
81  );
82  return false;
83  }
84 
85  include_once './Modules/Group/classes/class.ilGroupParticipants.php';
86  if (!ilGroupParticipants::_isParticipant($a_ref_id, $a_user_id)) {
87  return false;
88  }
89  }
90  // Waiting list
91  if ($a_permission == 'join') {
92  include_once './Modules/Group/classes/class.ilGroupWaitingList.php';
93  if (!ilGroupWaitingList::_isOnList($ilUser->getId(), $a_obj_id)) {
94  return false;
95  }
96  }
97  break;
98 
99  }
100 
101  switch ($a_permission) {
102  case 'leave':
103  include_once './Modules/Group/classes/class.ilObjGroup.php';
104  return ilObjGroup::mayLeave($a_obj_id, $a_user_id);
105  }
106  return true;
107  }
108 
121  public static function _getCommands()
122  {
123  $commands = array();
124  $commands[] = array("permission" => "grp_linked", "cmd" => "", "lang_var" => "show", "default" => true);
125 
126  $commands[] = array("permission" => "join", "cmd" => "join", "lang_var" => "join");
127 
128  // on waiting list
129  $commands[] = array('permission' => "join", "cmd" => "leave", "lang_var" => "leave_waiting_list");
130 
131  // regualar users
132  $commands[] = array('permission' => "leave", "cmd" => "leave", "lang_var" => "grp_btn_unsubscribe");
133 
134  include_once('Services/WebDAV/classes/class.ilDAVActivationChecker.php');
136  include_once './Services/WebDAV/classes/class.ilWebDAVUtil.php';
137  if (ilWebDAVUtil::getInstance()->isLocalPasswordInstructionRequired()) {
138  $commands[] = array('permission' => 'read', 'cmd' => 'showPasswordInstruction', 'lang_var' => 'mount_webfolder', 'enable_anonymous' => 'false');
139  } else {
140  $commands[] = array("permission" => "read", "cmd" => "mount_webfolder", "lang_var" => "mount_webfolder", "enable_anonymous" => "false");
141  }
142  }
143 
144  $commands[] = array("permission" => "write", "cmd" => "enableAdministrationPanel", "lang_var" => "edit_content");
145  $commands[] = array("permission" => "write", "cmd" => "edit", "lang_var" => "settings");
146 
147  return $commands;
148  }
149 
153  public static function _checkGoto($a_target)
154  {
155  global $DIC;
156 
157  $ilAccess = $DIC['ilAccess'];
158  $ilUser = $DIC['ilUser'];
159 
160  $t_arr = explode("_", $a_target);
161  // registration codes
162  if (substr($t_arr[2], 0, 5) == 'rcode' and $ilUser->getId() != ANONYMOUS_USER_ID) {
163  self::$using_code = true;
164  return true;
165  }
166 
167  if ($t_arr[0] != "grp" || ((int) $t_arr[1]) <= 0) {
168  return false;
169  }
170 
171  if ($ilAccess->checkAccess("read", "", $t_arr[1]) ||
172  $ilAccess->checkAccess("visible", "", $t_arr[1])) {
173  return true;
174  }
175  return false;
176  }
177 
183  public static function _registrationEnabled($a_obj_id)
184  {
185  global $DIC;
186 
187  $ilDB = $DIC['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);
211  $end = new ilDateTime($end, IL_CAL_DATETIME);
212  $time = new ilDateTime(time(), IL_CAL_UNIX);
213 
214  return ilDateTime::_after($time, $start) and ilDateTime::_before($time, $end);
215  }
216  return false;
217  }
218 
219 
225  public static function _preloadData($a_obj_ids, $a_ref_ids)
226  {
227  global $DIC;
228 
229  $ilDB = $DIC['ilDB'];
230  $ilUser = $DIC['ilUser'];
231 
232  include_once("./Modules/Group/classes/class.ilGroupWaitingList.php");
233  ilGroupWaitingList::_preloadOnListInfo($ilUser->getId(), $a_obj_ids);
234  }
235 
244  public static function lookupRegistrationInfo($a_obj_id)
245  {
246  global $DIC;
247 
248  $ilDB = $DIC['ilDB'];
249  $ilUser = $DIC['ilUser'];
250  $lng = $DIC['lng'];
251 
252  $query = 'SELECT registration_type, registration_enabled, registration_unlimited, registration_start, ' .
253  'registration_end, registration_mem_limit, registration_max_members FROM grp_settings ' .
254  'WHERE obj_id = ' . $ilDB->quote($a_obj_id);
255  $res = $ilDB->query($query);
256 
257  $info = array();
258  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
259  $info['reg_info_start'] = new ilDateTime($row->registration_start, IL_CAL_DATETIME);
260  $info['reg_info_end'] = new ilDateTime($row->registration_end, IL_CAL_DATETIME);
261  $info['reg_info_type'] = $row->registration_type;
262  $info['reg_info_max_members'] = $row->registration_max_members;
263  $info['reg_info_mem_limit'] = $row->registration_mem_limit;
264  $info['reg_info_unlimited'] = $row->registration_unlimited;
265 
266  $info['reg_info_max_members'] = 0;
267  if ($info['reg_info_mem_limit']) {
268  $info['reg_info_max_members'] = $row->registration_max_members;
269  }
270 
271  $info['reg_info_enabled'] = $row->registration_enabled;
272  }
273 
274  $registration_possible = $info['reg_info_enabled'];
275 
276  // Limited registration (added $registration_possible, see bug 0010157)
277  if (!$info['reg_info_unlimited'] && $registration_possible) {
278  $dt = new ilDateTime(time(), IL_CAL_UNIX);
279  if (ilDateTime::_before($dt, $info['reg_info_start'])) {
280  $info['reg_info_list_prop']['property'] = $lng->txt('grp_list_reg_start');
281  $info['reg_info_list_prop']['value'] = ilDatePresentation::formatDate($info['reg_info_start']);
282  } elseif (ilDateTime::_before($dt, $info['reg_info_end'])) {
283  $info['reg_info_list_prop']['property'] = $lng->txt('grp_list_reg_end');
284  $info['reg_info_list_prop']['value'] = ilDatePresentation::formatDate($info['reg_info_end']);
285  } else {
286  $registration_possible = false;
287  $info['reg_info_list_prop']['property'] = $lng->txt('grp_list_reg_period');
288  $info['reg_info_list_prop']['value'] = $lng->txt('grp_list_reg_noreg');
289  }
290  } else {
291  // added !$registration_possible, see bug 0010157
292  if (!$registration_possible) {
293  $registration_possible = false;
294  $info['reg_info_list_prop']['property'] = $lng->txt('grp_list_reg');
295  $info['reg_info_list_prop']['value'] = $lng->txt('grp_list_reg_noreg');
296  }
297  }
298 
299  if ($info['reg_info_mem_limit'] && $info['reg_info_max_members'] && $registration_possible) {
300  // Check for free places
301  include_once './Modules/Group/classes/class.ilGroupParticipants.php';
302  $part = ilGroupParticipants::_getInstanceByObjId($a_obj_id);
303 
304  include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
305  $info['reg_info_list_size'] = ilCourseWaitingList::lookupListSize($a_obj_id);
306  if ($info['reg_info_list_size']) {
307  $info['reg_info_free_places'] = 0;
308  } else {
309  $info['reg_info_free_places'] = max(0, $info['reg_info_max_members'] - $part->getCountMembers());
310  }
311 
312  if ($info['reg_info_free_places']) {
313  $info['reg_info_list_prop_limit']['property'] = $lng->txt('grp_list_reg_limit_places');
314  $info['reg_info_list_prop_limit']['value'] = $info['reg_info_free_places'];
315  } else {
316  $info['reg_info_list_prop_limit']['property'] = '';
317  $info['reg_info_list_prop_limit']['value'] = $lng->txt('grp_list_reg_limit_full');
318  }
319  }
320 
321  return $info;
322  }
323 
330  public static function lookupPeriodInfo($a_obj_id)
331  {
332  global $DIC;
333 
334  $ilDB = $DIC['ilDB'];
335  $lng = $DIC['lng'];
336 
337  $start = $end = null;
338  $query = 'SELECT period_start, period_end, period_time_indication FROM grp_settings ' .
339  'WHERE obj_id = ' . $ilDB->quote($a_obj_id);
340 
341  $res = $ilDB->query($query);
342  while ($row = $res->fetchRow(\ilDBConstants::FETCHMODE_OBJECT)) {
343  if (!$row->period_time_indication) {
344  $start = ($row->period_start
345  ? new \ilDate($row->period_start, IL_CAL_DATETIME)
346  : null);
347  $end = ($row->period_end
348  ? new \ilDate($row->period_end, IL_CAL_DATETIME)
349  : null);
350  } else {
351  $start = ($row->period_start
352  ? new \ilDateTime($row->period_start, IL_CAL_DATETIME, \ilTimeZone::UTC)
353  : null);
354  $end = ($row->period_end
355  ? new \ilDateTime($row->period_end, IL_CAL_DATETIME, \ilTimeZone::UTC)
356  : null);
357  }
358  }
359  if ($start && $end) {
360  $lng->loadLanguageModule('grp');
361 
362  return
363  [
364  'property' => $lng->txt('grp_period'),
365  'value' => ilDatePresentation::formatPeriod($start, $end)
366  ];
367  }
368  }
374  public static function _usingRegistrationCode()
375  {
376  return self::$using_code;
377  }
378 }
static mayLeave($a_group_id, $a_user_id=null, &$a_date=null)
static _registrationEnabled($a_obj_id)
static _isParticipant($a_ref_id, $a_usr_id)
Static function to check if a user is a participant of the container object.
const IL_CAL_DATETIME
const ANONYMOUS_USER_ID
Definition: constants.php:25
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 _preloadOnListInfo($a_usr_ids, $a_obj_ids)
Preload on list info.
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 _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 _preloadData($a_obj_ids, $a_ref_ids)
Preload data.
_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 _getCommands()
get commands
static lookupRegistrationInfo($a_obj_id)
Lookup registration info ilDB $ilDB ilObjUser $ilUser ilLanguage $lng.
Class ilObjGroupAccess.
static lookupPeriodInfo($a_obj_id)
Lookup course period info.
foreach($_POST as $key=> $value) $res
$lng
static _usingRegistrationCode()
Using Registration code.
global $DIC
Definition: goto.php:24
$query
static _isOnList($a_usr_id, $a_obj_id)
Check if a user on the waiting list.
static _getInstanceByObjId($a_obj_id)
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.
static getInstance()
Get singleton instance.
global $ilDB
static _checkGoto($a_target)
check whether goto script will succeed
$ilUser
Definition: imgupload.php:18