ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilLDAPAttributeMapping.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
34{
35 private static $instances = array();
36 private $server_id = null;
37 private $db = null;
38 private $mapping_rules = array();
39 private $rules_for_update = array();
40 private $lng;
41
48 private function __construct($a_server_id)
49 {
50 global $ilDB,$lng;
51
52 $this->db = $ilDB;
53 $this->lng = $lng;
54 $this->server_id = $a_server_id;
55 $this->read();
56 }
57
65 public static function _getInstanceByServerId($a_server_id)
66 {
67 if(array_key_exists($a_server_id,self::$instances) and is_object(self::$instances[$a_server_id]))
68 {
69 return self::$instances[$a_server_id];
70 }
71 return self::$instances[$a_server_id] = new ilLDAPAttributeMapping($a_server_id);
72 }
73
74
82 public static function _delete($a_server_id)
83 {
84 global $ilDB;
85
86 $query = "DELETE FROM ldap_attribute_mapping ".
87 "WHERE server_id =".$ilDB->quote($a_server_id,'integer');
88 $res = $ilDB->manipulate($query);
89 }
90
98 public static function _lookupGlobalRole($a_server_id)
99 {
100 global $ilDB;
101
102 $query = "SELECT value FROM ldap_attribute_mapping ".
103 "WHERE server_id =".$ilDB->quote($a_server_id,'integer')." ".
104 "AND keyword = ".$ilDB->quote('global_role','text');
105
106 $res = $ilDB->query($query);
107 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
108 {
109 return (int) $row->value;
110 }
111 return 0;
112 }
113
120 public static function hasRulesForUpdate($a_server_id)
121 {
122 global $ilDB;
123
124 $query = 'SELECT perform_update FROM ldap_attribute_mapping '.
125 'WHERE server_id = '.$ilDB->quote($a_server_id,'integer').' '.
126 'AND perform_update = 1';
127 $res = $ilDB->query($query);
128 return $res->numRows() ? true : false;
129 }
130
140 public function setRule($a_field_name,$a_ldap_attribute,$a_perform_update)
141 {
142 $this->mapping_rules[$a_field_name]['value'] = $a_ldap_attribute;
143 $this->mapping_rules[$a_field_name]['performUpdate'] = $a_perform_update;
144 }
145
153 public function getRulesForUpdate()
154 {
155 return $this->rules_for_update ? $this->rules_for_update : array();
156 }
157
165 public function getFieldsForUpdate()
166 {
167 foreach($this->rules_for_update as $field => $rule)
168 {
169 if(!strlen($rule['value']))
170 {
171 continue;
172 }
173 if(strpos($rule['value'],',') === false)
174 {
175 $fields[] = strtolower($rule['value']);
176 continue;
177 }
178 $tmp_fields = explode(',',$rule['value']);
179 $value = '';
180 foreach($tmp_fields as $tmp_field)
181 {
182 $fields[] = trim(strtolower($tmp_field));
183 }
184 }
185 return $fields ? $fields : array();
186 }
187
195 public function getFields()
196 {
197 foreach($this->mapping_rules as $field => $rule)
198 {
199 if(!strlen($rule['value']))
200 {
201 continue;
202 }
203 if(strpos($rule['value'],',') === false)
204 {
205 $fields[] = strtolower($rule['value']);
206 continue;
207 }
208 $tmp_fields = explode(',',$rule['value']);
209 $value = '';
210 foreach($tmp_fields as $tmp_field)
211 {
212 $fields[] = trim(strtolower($tmp_field));
213 }
214 }
215 return $fields ? $fields : array();
216 }
217
225 public function getRules()
226 {
228 }
229
236 public function clearRules()
237 {
238 $this->mapping_rules = array();
239 }
240
247 public function save()
248 {
249 global $ilDB;
250
251 $this->delete();
252
253 foreach($this->mapping_rules as $keyword => $options)
254 {
255 $query = "INSERT INTO ldap_attribute_mapping (server_id,keyword,value,perform_update) ".
256 "VALUES( ".
257 $this->db->quote($this->server_id,'integer').", ".
258 $this->db->quote($keyword,'text').", ".
259 $this->db->quote($options['value'],'text').", ".
260 $this->db->quote($options['performUpdate'],'integer').
261 ')';
262 $res = $ilDB->manipulate($query);
263 }
264 }
265
272 public function delete()
273 {
274 self::_delete($this->server_id);
275 }
276
285 public function enabledUpdate($a_field_name)
286 {
287 if(array_key_exists($a_field_name,$this->mapping_rules))
288 {
289 return (bool) $this->mapping_rules[$a_field_name]['performUpdate'];
290 }
291 return false;
292 }
293
301 public function getValue($a_field_name)
302 {
303 if(array_key_exists($a_field_name,$this->mapping_rules))
304 {
305 return $this->mapping_rules[$a_field_name]['value'];
306 }
307 return '';
308 }
309
317 private function read()
318 {
319 global $ilDB;
320
321 $query = "SELECT * FROM ldap_attribute_mapping ".
322 "WHERE server_id =".$this->db->quote($this->server_id,'integer')." ";
323
324 $res = $this->db->query($query);
325 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
326 {
327 $this->mapping_rules[$row->keyword]['value'] = $row->value;
328 $this->mapping_rules[$row->keyword]['performUpdate'] = (bool) $row->perform_update;
329
330 if($row->perform_update)
331 {
332 $this->rules_for_update[$row->keyword]['value'] = $row->value;
333 }
334 }
335 }
336}
337?>
An exception for terminatinating execution or to throw for unit testing.
This class stores the settings that define the mapping between LDAP attribute and user profile fields...
getFields()
Get all mapping fields.
setRule($a_field_name, $a_ldap_attribute, $a_perform_update)
Set mapping rule.
enabledUpdate($a_field_name)
Check whether an update should be performed on a specific user attribute or not.
static hasRulesForUpdate($a_server_id)
Check if there is ldap attribute -> user data mapping which which is updated on login.
getValue($a_field_name)
Get LDAP attribute name by given ILIAS profile field.
__construct($a_server_id)
Private constructor (Singleton for each server_id)
clearRules()
Clear rules => Does not perform an update.
getRulesForUpdate()
Get all mapping rules with option 'update'.
save()
Save mapping rules to db.
static _delete($a_server_id)
Delete mapping rules by server id.
static _lookupGlobalRole($a_server_id)
Lookup global role assignment.
getFieldsForUpdate()
Get field names of all mapping rules with option 'update'.
read()
Read mapping setttings from db.
static _getInstanceByServerId($a_server_id)
Get instance of class.
global $ilDB
if(!is_array($argv)) $options