ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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  include_once './Services/WebServices/FileManager/classes/class.ilFMSettings.php';
127  if (ilFMSettings::getInstance()->isEnabled()) {
128  $commands[] = array(
129  'permission' => 'read',
130  'cmd' => 'fileManagerLaunch',
131  'lang_var' => 'fm_start',
132  'enable_anonymous' => false
133  );
134  }
135 
136  $commands[] = array("permission" => "join", "cmd" => "join", "lang_var" => "join");
137 
138  // on waiting list
139  $commands[] = array('permission' => "join", "cmd" => "leave", "lang_var" => "leave_waiting_list");
140 
141  // regualar users
142  $commands[] = array('permission' => "leave", "cmd" => "leave", "lang_var" => "grp_btn_unsubscribe");
143 
144  include_once('Services/WebDAV/classes/class.ilDAVActivationChecker.php');
146  include_once './Services/WebDAV/classes/class.ilWebDAVUtil.php';
147  if (ilWebDAVUtil::getInstance()->isLocalPasswordInstructionRequired()) {
148  $commands[] = array('permission' => 'read', 'cmd' => 'showPasswordInstruction', 'lang_var' => 'mount_webfolder', 'enable_anonymous' => 'false');
149  } else {
150  $commands[] = array("permission" => "read", "cmd" => "mount_webfolder", "lang_var" => "mount_webfolder", "enable_anonymous" => "false");
151  }
152  }
153 
154  $commands[] = array("permission" => "write", "cmd" => "enableAdministrationPanel", "lang_var" => "edit_content");
155  $commands[] = array("permission" => "write", "cmd" => "edit", "lang_var" => "settings");
156 
157  return $commands;
158  }
159 
163  public static function _checkGoto($a_target)
164  {
165  global $DIC;
166 
167  $ilAccess = $DIC['ilAccess'];
168  $ilUser = $DIC['ilUser'];
169 
170  $t_arr = explode("_", $a_target);
171  // registration codes
172  if (substr($t_arr[2], 0, 5) == 'rcode' and $ilUser->getId() != ANONYMOUS_USER_ID) {
173  self::$using_code = true;
174  return true;
175  }
176 
177  if ($t_arr[0] != "grp" || ((int) $t_arr[1]) <= 0) {
178  return false;
179  }
180 
181  if ($ilAccess->checkAccess("read", "", $t_arr[1]) ||
182  $ilAccess->checkAccess("visible", "", $t_arr[1])) {
183  return true;
184  }
185  return false;
186  }
187 
193  public static function _registrationEnabled($a_obj_id)
194  {
195  global $DIC;
196 
197  $ilDB = $DIC['ilDB'];
198 
199  $query = "SELECT * FROM grp_settings " .
200  "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " ";
201 
202  $res = $ilDB->query($query);
203 
204  $enabled = $unlimited = false;
205  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
206  $enabled = $row->registration_enabled;
207  $unlimited = $row->registration_unlimited;
208  $start = $row->registration_start;
209  $end = $row->registration_end;
210  }
211 
212  if (!$enabled) {
213  return false;
214  }
215  if ($unlimited) {
216  return true;
217  }
218 
219  if (!$unlimited) {
222  $time = new ilDateTime(time(), IL_CAL_UNIX);
223 
225  }
226  return false;
227  }
228 
229 
235  public static function _preloadData($a_obj_ids, $a_ref_ids)
236  {
237  global $DIC;
238 
239  $ilDB = $DIC['ilDB'];
240  $ilUser = $DIC['ilUser'];
241 
242  include_once("./Modules/Group/classes/class.ilGroupWaitingList.php");
243  ilGroupWaitingList::_preloadOnListInfo($ilUser->getId(), $a_obj_ids);
244  }
245 
254  public static function lookupRegistrationInfo($a_obj_id)
255  {
256  global $DIC;
257 
258  $ilDB = $DIC['ilDB'];
259  $ilUser = $DIC['ilUser'];
260  $lng = $DIC['lng'];
261 
262  $query = 'SELECT registration_type, registration_enabled, registration_unlimited, registration_start, ' .
263  'registration_end, registration_mem_limit, registration_max_members FROM grp_settings ' .
264  'WHERE obj_id = ' . $ilDB->quote($a_obj_id);
265  $res = $ilDB->query($query);
266 
267  $info = array();
268  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
269  $info['reg_info_start'] = new ilDateTime($row->registration_start, IL_CAL_DATETIME);
270  $info['reg_info_end'] = new ilDateTime($row->registration_end, IL_CAL_DATETIME);
271  $info['reg_info_type'] = $row->registration_type;
272  $info['reg_info_max_members'] = $row->registration_max_members;
273  $info['reg_info_mem_limit'] = $row->registration_mem_limit;
274  $info['reg_info_unlimited'] = $row->registration_unlimited;
275 
276  $info['reg_info_max_members'] = 0;
277  if ($info['reg_info_mem_limit']) {
278  $info['reg_info_max_members'] = $row->registration_max_members;
279  }
280 
281  $info['reg_info_enabled'] = $row->registration_enabled;
282  }
283 
284  $registration_possible = $info['reg_info_enabled'];
285 
286  // Limited registration (added $registration_possible, see bug 0010157)
287  if (!$info['reg_info_unlimited'] && $registration_possible) {
288  $dt = new ilDateTime(time(), IL_CAL_UNIX);
289  if (ilDateTime::_before($dt, $info['reg_info_start'])) {
290  $info['reg_info_list_prop']['property'] = $lng->txt('grp_list_reg_start');
291  $info['reg_info_list_prop']['value'] = ilDatePresentation::formatDate($info['reg_info_start']);
292  } elseif (ilDateTime::_before($dt, $info['reg_info_end'])) {
293  $info['reg_info_list_prop']['property'] = $lng->txt('grp_list_reg_end');
294  $info['reg_info_list_prop']['value'] = ilDatePresentation::formatDate($info['reg_info_end']);
295  } else {
296  $registration_possible = false;
297  $info['reg_info_list_prop']['property'] = $lng->txt('grp_list_reg_period');
298  $info['reg_info_list_prop']['value'] = $lng->txt('grp_list_reg_noreg');
299  }
300  } else {
301  // added !$registration_possible, see bug 0010157
302  if (!$registration_possible) {
303  $registration_possible = false;
304  $info['reg_info_list_prop']['property'] = $lng->txt('grp_list_reg');
305  $info['reg_info_list_prop']['value'] = $lng->txt('grp_list_reg_noreg');
306  }
307  }
308 
309  if ($info['reg_info_mem_limit'] && $info['reg_info_max_members'] && $registration_possible) {
310  // Check for free places
311  include_once './Modules/Group/classes/class.ilGroupParticipants.php';
312  $part = ilGroupParticipants::_getInstanceByObjId($a_obj_id);
313 
314  include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
315  $info['reg_info_list_size'] = ilCourseWaitingList::lookupListSize($a_obj_id);
316  if ($info['reg_info_list_size']) {
317  $info['reg_info_free_places'] = 0;
318  } else {
319  $info['reg_info_free_places'] = max(0, $info['reg_info_max_members'] - $part->getCountMembers());
320  }
321 
322  if ($info['reg_info_free_places']) {
323  $info['reg_info_list_prop_limit']['property'] = $lng->txt('grp_list_reg_limit_places');
324  $info['reg_info_list_prop_limit']['value'] = $info['reg_info_free_places'];
325  } else {
326  $info['reg_info_list_prop_limit']['property'] = '';
327  $info['reg_info_list_prop_limit']['value'] = $lng->txt('grp_list_reg_limit_full');
328  }
329  }
330 
331  return $info;
332  }
333 
340  public static function lookupPeriodInfo($a_obj_id)
341  {
342  global $DIC;
343 
344  $ilDB = $DIC['ilDB'];
345  $lng = $DIC['lng'];
346 
347  $start = $end = null;
348 
349  $query = 'SELECT grp_start, grp_end FROM grp_settings' .
350  ' WHERE obj_id = ' . $ilDB->quote($a_obj_id);
351  $set = $ilDB->query($query);
352  while ($row = $ilDB->fetchAssoc($set)) {
353  $start = $row['grp_start']
354  ? new ilDate($row['grp_start'], IL_CAL_UNIX)
355  : null;
356  $end = $row['grp_end']
357  ? new ilDate($row['grp_end'], IL_CAL_UNIX)
358  : null;
359  }
360 
361  if ($start && $end) {
362  $lng->loadLanguageModule('grp');
363 
364  return array(
365  'property' => $lng->txt('grp_period'),
367  );
368  }
369  }
370 
371 
377  public static function _usingRegistrationCode()
378  {
379  return self::$using_code;
380  }
381 }
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
global $DIC
Definition: saml.php:7
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...
$start
Definition: bench.php:8
$time
Definition: cron.php:21
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.
Class for single dates.
foreach($_POST as $key=> $value) $res
$lng
static _usingRegistrationCode()
Using Registration code.
Date and time handling
$ilUser
Definition: imgupload.php:18
$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.
$row
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.
static getInstance()
Get singleton instance.
Class ilObjectAccess.
global $ilDB
static _checkGoto($a_target)
check whether goto script will succeed
$info
Definition: index.php:5