ILIAS  release_7 Revision v7.30-3-g800a261c036
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 public $access_limits = array();
41
42 public function __construct()
43 {
44 global $DIC;
45
46 $ilDB = $DIC->database();
47
48 $this->db = $ilDB;
49 $this->__read();
50 }
51
52 // Private
53 public function __read()
54 {
55
56 $query = "SELECT * FROM reg_access_limit ";
57 $res = $this->db->query($query);
58
59 $this->access_limitations = array();
60 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
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]['mode'] = $row->limit_mode;
66 }
67
68 return true;
69 }
70
71 public function save()
72 {
73
74 foreach ($this->access_limitations as $key => $data) {
75 $limit_value = "";
76
77 // Delete old entry
78 $query = "DELETE FROM reg_access_limit " .
79 "WHERE role_id = " . $this->db->quote($key, 'integer');
80 $res = $this->db->manipulate($query);
81
82
83 $query = "INSERT INTO reg_access_limit (role_id,limit_mode,limit_absolute," .
84 "limit_relative_d,limit_relative_m) " .
85 "VALUES( " .
86 $this->db->quote($key, 'integer') . ", " .
87 $this->db->quote($data['mode'], 'text') . ", " .
88 $this->db->quote($data['absolute']) . ", " .
89 $this->db->quote($data['relative_d']) . ", " .
90 $this->db->quote($data['relative_m']) . " " .
91 ")";
92 $res = $this->db->manipulate($query);
93 }
94
95 return true;
96 }
97
98 public function validate()
99 {
100 foreach ($this->access_limitations as $data) {
101 if ($data['mode'] == "null") {
103 }
104
105 if ($data['mode'] == 'absolute' and $data['absolute'] < time()) {
107 }
108
109 if ($data['mode'] == 'relative' and ($data['relative_d'] < 1 and $data['relative_m'] < 1)) {
111 }
112 }
113
114 return 0;
115 }
116
117 public function getMode($a_role_id)
118 {
119 return $this->access_limitations[$a_role_id] ? $this->access_limitations[$a_role_id]['mode'] : 'null';
120 }
121
122 public function setMode($a_mode, $a_role_id)
123 {
124 $this->access_limitations[$a_role_id]['mode'] = $a_mode;
125 }
126
127 public function getAbsolute($a_role_id)
128 {
129 return $this->access_limitations[$a_role_id] ? $this->access_limitations[$a_role_id]['absolute'] : time();
130 }
131
132 public function setAbsolute($date, $a_role_id)
133 {
134 $this->access_limitations[$a_role_id]['absolute'] = strtotime($date);
135 }
136
137 public function getRelative($a_role_id, $a_type)
138 {
139 return $this->access_limitations[$a_role_id] ? $this->access_limitations[$a_role_id]['relative_' . $a_type] : 0;
140 }
141
142 public function setRelative($a_arr, $a_role_id)
143 {
144 $this->access_limitations[$a_role_id]['relative_d'] = $a_arr['dd'];
145 $this->access_limitations[$a_role_id]['relative_m'] = $a_arr['MM'];
146 }
147
151 public function resetAccessLimitations()
152 {
153 $this->access_limitations = array();
154 }
155}
An exception for terminatinating execution or to throw for unit testing.
global $DIC
Definition: goto.php:24
const IL_REG_ACCESS_LIMITATION_MISSING_MODE
Class class.ilRegistrationAccessLimitation.
$query
foreach($_POST as $key=> $value) $res
global $ilDB
$data
Definition: storeScorm.php:23