ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilRegistrationRoleAccessLimitations.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2001 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
33define('IL_REG_ACCESS_LIMITATION_MISSING_MODE',1);
34define('IL_REG_ACCESS_LIMITATION_OUT_OF_DATE',2);
35
37{
38 private $access_limitations = array();
39
40 var $access_limits = array();
41
42 function __construct()
43 {
44 global $ilDB;
45
46 $this->db = $ilDB;
47 $this->__read();
48 }
49
50 // Private
51 function __read()
52 {
53 global $ilias;
54
55 $query = "SELECT * FROM reg_access_limit ";
56 $res = $this->db->query($query);
57
58 $this->access_limitations = array();
59 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
60 {
61 $this->access_limitations[$row->role_id]['id'] = $row->role_id;
62 $this->access_limitations[$row->role_id]['absolute'] = $row->limit_absolute;
63 $this->access_limitations[$row->role_id]['relative_d'] = $row->limit_relative_d;
64 $this->access_limitations[$row->role_id]['relative_m'] = $row->limit_relative_m;
65 $this->access_limitations[$row->role_id]['relative_y'] = $row->limit_relative_y;
66 $this->access_limitations[$row->role_id]['mode'] = $row->limit_mode;
67 }
68
69 return true;
70 }
71
72 function save()
73 {
74 global $ilias, $ilDB;
75
76 foreach($this->access_limitations as $key => $data)
77 {
78 $limit_value = "";
79
80 // Delete old entry
81 $query = "DELETE FROM reg_access_limit ".
82 "WHERE role_id = ".$ilDB->quote($key,'integer');
83 $res = $ilDB->manipulate($query);
84
85
86 $query = "INSERT INTO reg_access_limit (role_id,limit_mode,limit_absolute,".
87 "limit_relative_d,limit_relative_m,limit_relative_y) ".
88 "VALUES( ".
89 $ilDB->quote($key,'integer').", ".
90 $ilDB->quote($data['mode'] ,'text').", ".
91 $ilDB->quote($data['absolute']).", ".
92 $ilDB->quote($data['relative_d']).", ".
93 $ilDB->quote($data['relative_m']).", ".
94 $ilDB->quote($data['relative_y'])." ".
95 ")";
96 $res = $ilDB->manipulate($query);
97 }
98
99 return true;
100 }
101
102 function validate()
103 {
104 foreach ($this->access_limitations as $data)
105 {
106 if ($data['mode'] == "null")
107 {
109 }
110
111 if ($data['mode'] == 'absolute' and $data['absolute'] < time())
112 {
114 }
115
116 if ($data['mode'] == 'relative' and ($data['relative_d'] < 1 and $data['relative_m'] < 1 and $data['relative_y'] < 1))
117 {
119 }
120 }
121
122 return 0;
123 }
124
125 function getMode($a_role_id)
126 {
127 return $this->access_limitations[$a_role_id] ? $this->access_limitations[$a_role_id]['mode'] : 'null';
128 }
129
130 function setMode($a_mode,$a_role_id)
131 {
132 $this->access_limitations[$a_role_id]['mode'] = $a_mode;
133 }
134
135 function getAbsolute($a_role_id)
136 {
137 return $this->access_limitations[$a_role_id] ? $this->access_limitations[$a_role_id]['absolute'] : time();
138 }
139
140 function setAbsolute($a_arr,$a_role_id)
141 {
142 $this->access_limitations[$a_role_id]['absolute'] = mktime(23,59,59,$a_arr['m'],$a_arr['d'],$a_arr['y']);
143 }
144
145 function getRelative($a_role_id,$a_type)
146 {
147 return $this->access_limitations[$a_role_id] ? $this->access_limitations[$a_role_id]['relative_'.$a_type] : 0;
148 }
149
150 function setRelative($a_arr,$a_role_id)
151 {
152 $this->access_limitations[$a_role_id]['relative_d'] = $a_arr['d'];
153 $this->access_limitations[$a_role_id]['relative_m'] = $a_arr['m'];
154 $this->access_limitations[$a_role_id]['relative_y'] = $a_arr['y'];
155 }
156
160 public function resetAccessLimitations()
161 {
162 $this->access_limitations = array();
163 }
164}
165?>
An exception for terminatinating execution or to throw for unit testing.
const IL_REG_ACCESS_LIMITATION_MISSING_MODE
Class class.ilRegistrationAccessLimitation.
global $ilDB
$a_type
Definition: workflow.php:93