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