ILIAS  Release_4_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 
33 {
34  protected static $registrations = null;
35  protected static $registered = null;
36 
44  public static function _getCommands()
45  {
46  $commands = array
47  (
48  array("permission" => "read", "cmd" => "infoScreen", "lang_var" => "info_short", "default" => true),
49  array("permission" => "read", "cmd" => "register", "lang_var" => "join_session"),
50  array("permission" => "read", "cmd" => "unregister", "lang_var" => "event_unregister"),
51  array("permission" => "write", "cmd" => "edit", "lang_var" => "edit"),
52  array('permission' => 'write', 'cmd' => 'members', 'lang_var' => 'event_edit_members')
53  );
54 
55  return $commands;
56  }
57 
70  public function _checkAccess($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id = "")
71  {
72  global $ilUser, $lng, $rbacsystem, $ilAccess;
73 
74  $a_user_id = $a_user_id ? $a_user_id : $ilUser->getId();
75  switch($a_cmd)
76  {
77  case 'register':
78  if(self::_lookupRegistration($a_obj_id))
79  {
80  return !self::_lookupRegistered($a_user_id,$a_obj_id);
81  }
82  return false;
83 
84  case 'unregister':
85  if(self::_lookupRegistration($a_obj_id))
86  {
87  return self::_lookupRegistered($a_user_id,$a_obj_id);
88  }
89  return false;
90  }
91  return true;
92  }
93 
94 
98  public function _checkGoto($a_target)
99  {
100  global $ilAccess;
101 
102  $t_arr = explode("_", $a_target);
103 
104  if ($t_arr[0] != "sess" || ((int) $t_arr[1]) <= 0)
105  {
106  return false;
107  }
108 
109  if($ilAccess->checkAccess("read", "", $t_arr[1]))
110  {
111  return true;
112  }
113  return false;
114  }
115 
124  public static function _lookupRegistration($a_obj_id)
125  {
126  if(!is_null(self::$registrations))
127  {
128  return self::$registrations[$a_obj_id];
129  }
130 
131  global $ilDB;
132 
133  $query = "SELECT registration,obj_id FROM event ";
134  $res = $ilDB->query($query);
135  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
136  {
137  self::$registrations[$row->obj_id] = (bool) $row->registration;
138  }
139  return self::$registrations[$a_obj_id];
140  }
141 
151  public static function _lookupRegistered($a_usr_id,$a_obj_id)
152  {
153  if(isset(self::$registered[$a_usr_id]))
154  {
155  return (bool) self::$registered[$a_usr_id][$a_obj_id];
156  }
157 
158  global $ilDB,$ilUser;
159 
160  $query = "SELECT event_id, registered FROM event_participants WHERE usr_id = ".$ilDB->quote($ilUser->getId(),'integer');
161  $res = $ilDB->query($query);
162  self::$registered[$a_usr_id] = array();
163  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
164  {
165  self::$registered[$a_usr_id][$row->event_id] = (bool) $row->registered;
166  }
167  return (bool) self::$registered[$a_usr_id][$a_obj_id];
168  }
169 
170 }
171 ?>