ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilRegistrationEmailRoleAssignments.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_MISSING_DOMAIN', 1);
34define('IL_REG_MISSING_ROLE', 2);
35
37{
38 public $assignments = array();
39 public $default_role = 0;
40
41 public function __construct()
42 {
43 global $ilDB;
44
45 $this->db = $ilDB;
46 $this->__read();
47 }
48
49 public function getRoleByEmail($a_email)
50 {
51 global $ilObjDataCache;
52
53 foreach ($this->assignments as $assignment) {
54 if (!$assignment['domain'] or !$assignment['role']) {
55 continue;
56 }
57 if (stristr($a_email, $assignment['domain'])) {
58 // check if role exists
59 if (!$ilObjDataCache->lookupType($assignment['role'])) {
60 continue;
61 }
62 return $assignment['role'];
63 }
64 }
65 // return default
66 return $this->getDefaultRole();
67 }
68
69 public function getAssignments()
70 {
71 return $this->assignments ? $this->assignments : array();
72 }
73
74 public function setDomain($a_id, $a_domain)
75 {
76 $this->assignments[$a_id]['domain'] = $a_domain;
77 }
78 public function setRole($a_id, $a_role)
79 {
80 $this->assignments[$a_id]['role'] = $a_role;
81 }
82
83 public function getDefaultRole()
84 {
86 }
87 public function setDefaultRole($a_role_id)
88 {
89 $this->default_role = $a_role_id;
90 }
91
92 public function delete($a_id)
93 {
94 global $ilDB;
95
96 $query = "DELETE FROM reg_er_assignments " .
97 "WHERE assignment_id = " . $ilDB->quote($a_id, 'integer');
98 $res = $ilDB->manipulate($query);
99 $this->__read();
100 return true;
101 }
102
103 public function add()
104 {
105 global $ilDB;
106
107 $next_id = $ilDB->nextId('reg_er_assignments');
108 $query = "INSERT INTO reg_er_assignments (assignment_id,domain,role) " .
109 "VALUES( " .
110 $ilDB->quote($next_id, 'integer') . ', ' .
111 $ilDB->quote('', 'text') . ", " .
112 $ilDB->quote(0, 'integer') .
113 ")";
114 $res = $ilDB->manipulate($query);
115 $this->__read();
116 return true;
117 }
118
119 public function save()
120 {
121 global $ilias, $ilDB;
122
123 // Save default role
124 $ilias->setSetting('reg_default_role', $this->getDefaultRole());
125
126 foreach ($this->assignments as $assignment) {
127 $query = "UPDATE reg_er_assignments " .
128 "SET domain = " . $ilDB->quote($assignment['domain'], 'text') . ", " .
129 "role = " . $ilDB->quote($assignment['role'], 'integer') . " " .
130 "WHERE assignment_id = " . $ilDB->quote($assignment['id'], 'integer');
131 $res = $ilDB->manipulate($query);
132 }
133 return true;
134 }
135
136 public function validate()
137 {
138 foreach ($this->assignments as $assignment) {
139 if (!strlen($assignment['domain'])) {
141 }
142 if (!$assignment['role']) {
143 return IL_REG_MISSING_ROLE;
144 }
145 }
146 if (!$this->getDefaultRole()) {
147 return IL_REG_MISSING_ROLE;
148 }
149 return 0;
150 }
151
152
153
154
155 // Private
156 public function __read()
157 {
158 global $ilias, $ilDB;
159
160 $query = "SELECT * FROM reg_er_assignments ";
161 $res = $this->db->query($query);
162
163 $this->assignments = array();
164 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
165 $this->assignments[$row->assignment_id]['id'] = $row->assignment_id;
166 $this->assignments[$row->assignment_id]['role'] = $row->role;
167 $this->assignments[$row->assignment_id]['domain'] = $row->domain;
168 }
169
170 $this->default_role = $ilias->getSetting('reg_default_role');
171
172 return true;
173 }
174}
An exception for terminatinating execution or to throw for unit testing.
const IL_REG_MISSING_DOMAIN
Class class.ilregistrationEmailRoleAssignments.
$query
foreach($_POST as $key=> $value) $res
global $ilDB