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