ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjSessionAccess.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 include_once './Services/Object/classes/class.ilObjectAccess.php';
25 
35 {
36  protected static $registrations = null;
37  protected static $registered = null;
38 
46  public function _getCommands()
47  {
48  $commands = array
49  (
50  array("permission" => "read", "cmd" => "infoScreen", "lang_var" => "info_short", "default" => true),
51  array("permission" => "read", "cmd" => "register", "lang_var" => "join_session"),
52  array("permission" => "read", "cmd" => "unregister", "lang_var" => "event_unregister"),
53  array("permission" => "write", "cmd" => "edit", "lang_var" => "settings"),
54  array("permission" => "write", "cmd" => "materials", "lang_var" => "crs_objective_add_mat"),
55  array('permission' => 'write', 'cmd' => 'members', 'lang_var' => 'event_edit_members')
56  );
57 
58  return $commands;
59  }
60 
73  public function _checkAccess($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id = "")
74  {
75  global $ilUser, $lng, $rbacsystem, $ilAccess;
76 
77  $a_user_id = $a_user_id ? $a_user_id : $ilUser->getId();
78  switch($a_cmd)
79  {
80  case 'register':
81  if(self::_lookupRegistration($a_obj_id)&& $a_user_id != ANONYMOUS_USER_ID)
82  {
83  return !self::_lookupRegistered($a_user_id,$a_obj_id);
84  }
85  return false;
86 
87  case 'unregister':
88  if(self::_lookupRegistration($a_obj_id) && $a_user_id != ANONYMOUS_USER_ID)
89  {
90  return self::_lookupRegistered($a_user_id,$a_obj_id);
91  }
92  return false;
93  }
94  return true;
95  }
96 
97 
101  public function _checkGoto($a_target)
102  {
103  global $ilAccess;
104 
105  $t_arr = explode("_", $a_target);
106 
107  if ($t_arr[0] != "sess" || ((int) $t_arr[1]) <= 0)
108  {
109  return false;
110  }
111 
112  if($ilAccess->checkAccess("read", "", $t_arr[1]))
113  {
114  return true;
115  }
116  return false;
117  }
118 
127  public static function _lookupRegistration($a_obj_id)
128  {
129  if(!is_null(self::$registrations))
130  {
131  return self::$registrations[$a_obj_id];
132  }
133 
134  global $ilDB;
135 
136  $query = "SELECT registration,obj_id FROM event ";
137  $res = $ilDB->query($query);
138  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
139  {
140  self::$registrations[$row->obj_id] = (bool) $row->registration;
141  }
142  return self::$registrations[$a_obj_id];
143  }
144 
154  public static function _lookupRegistered($a_usr_id,$a_obj_id)
155  {
156  if(isset(self::$registered[$a_usr_id]))
157  {
158  return (bool) self::$registered[$a_usr_id][$a_obj_id];
159  }
160 
161  global $ilDB,$ilUser;
162 
163  $query = "SELECT event_id, registered FROM event_participants WHERE usr_id = ".$ilDB->quote($ilUser->getId(),'integer');
164  $res = $ilDB->query($query);
165  self::$registered[$a_usr_id] = array();
166  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
167  {
168  self::$registered[$a_usr_id][$row->event_id] = (bool) $row->registered;
169  }
170  return (bool) self::$registered[$a_usr_id][$a_obj_id];
171  }
172 
173 }
174 ?>