ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 $DIC;
51 
52  $ilDB = $DIC['ilDB'];
53  $lng = $DIC['lng'];
54 
55  $this->db = $ilDB;
56  $this->lng = $lng;
57  $this->server_id = $a_server_id;
58  $this->read();
59  }
60 
68  public static function _getInstanceByServerId($a_server_id)
69  {
70  if (array_key_exists($a_server_id, self::$instances) and is_object(self::$instances[$a_server_id])) {
71  return self::$instances[$a_server_id];
72  }
73  return self::$instances[$a_server_id] = new ilLDAPAttributeMapping($a_server_id);
74  }
75 
76 
84  public static function _delete($a_server_id)
85  {
86  global $DIC;
87 
88  $ilDB = $DIC['ilDB'];
89 
90  $query = "DELETE FROM ldap_attribute_mapping " .
91  "WHERE server_id =" . $ilDB->quote($a_server_id, 'integer');
92  $res = $ilDB->manipulate($query);
93  }
94 
102  public static function _lookupGlobalRole($a_server_id)
103  {
104  global $DIC;
105 
106  $ilDB = $DIC['ilDB'];
107 
108  $query = "SELECT value FROM ldap_attribute_mapping " .
109  "WHERE server_id =" . $ilDB->quote($a_server_id, 'integer') . " " .
110  "AND keyword = " . $ilDB->quote('global_role', 'text');
111 
112  $res = $ilDB->query($query);
113  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
114  return (int) $row->value;
115  }
116  return 0;
117  }
118 
125  public static function hasRulesForUpdate($a_server_id)
126  {
127  global $DIC;
128 
129  $ilDB = $DIC['ilDB'];
130 
131  $query = 'SELECT perform_update FROM ldap_attribute_mapping ' .
132  'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
133  'AND perform_update = 1';
134  $res = $ilDB->query($query);
135  return $res->numRows() ? true : false;
136  }
137 
147  public function setRule($a_field_name, $a_ldap_attribute, $a_perform_update)
148  {
149  $this->mapping_rules[$a_field_name]['value'] = $a_ldap_attribute;
150  $this->mapping_rules[$a_field_name]['performUpdate'] = $a_perform_update;
151  }
152 
160  public function getRulesForUpdate()
161  {
162  return $this->rules_for_update ? $this->rules_for_update : array();
163  }
164 
172  public function getFieldsForUpdate()
173  {
174  foreach ($this->rules_for_update as $field => $rule) {
175  if (!strlen($rule['value'])) {
176  continue;
177  }
178  if (strpos($rule['value'], ',') === false) {
179  $fields[] = strtolower($rule['value']);
180  continue;
181  }
182  $tmp_fields = explode(',', $rule['value']);
183  $value = '';
184  foreach ($tmp_fields as $tmp_field) {
185  $fields[] = trim(strtolower($tmp_field));
186  }
187  }
188  return $fields ? $fields : array();
189  }
190 
198  public function getFields()
199  {
200  foreach ($this->mapping_rules as $field => $rule) {
201  if (!strlen($rule['value'])) {
202  continue;
203  }
204  if (strpos($rule['value'], ',') === false) {
205  $fields[] = strtolower($rule['value']);
206  continue;
207  }
208  $tmp_fields = explode(',', $rule['value']);
209  $value = '';
210  foreach ($tmp_fields as $tmp_field) {
211  $fields[] = trim(strtolower($tmp_field));
212  }
213  }
214  return $fields ? $fields : array();
215  }
216 
224  public function getRules()
225  {
226  return $this->mapping_rules;
227  }
228 
235  public function clearRules()
236  {
237  $this->mapping_rules = array();
238  }
239 
246  public function save()
247  {
248  global $DIC;
249 
250  $ilDB = $DIC['ilDB'];
251 
252  $this->delete();
253 
254  foreach ($this->mapping_rules as $keyword => $options) {
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  return (bool) $this->mapping_rules[$a_field_name]['performUpdate'];
289  }
290  return false;
291  }
292 
300  public function getValue($a_field_name)
301  {
302  if (array_key_exists($a_field_name, $this->mapping_rules)) {
303  return $this->mapping_rules[$a_field_name]['value'];
304  }
305  return '';
306  }
307 
315  private function read()
316  {
317  global $DIC;
318 
319  $ilDB = $DIC['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  $this->mapping_rules[$row->keyword]['value'] = $row->value;
327  $this->mapping_rules[$row->keyword]['performUpdate'] = (bool) $row->perform_update;
328 
329  if ($row->perform_update) {
330  $this->rules_for_update[$row->keyword]['value'] = $row->value;
331  }
332  }
333  }
334 }
clearRules()
Clear rules => Does not perform an update.
static _getInstanceByServerId($a_server_id)
Get instance of class.
setRule($a_field_name, $a_ldap_attribute, $a_perform_update)
Set mapping rule.
static hasRulesForUpdate($a_server_id)
Check if there is ldap attribute -> user data mapping which which is updated on login.
global $DIC
Definition: saml.php:7
enabledUpdate($a_field_name)
Check whether an update should be performed on a specific user attribute or not.
getFieldsForUpdate()
Get field names of all mapping rules with option &#39;update&#39;.
static _lookupGlobalRole($a_server_id)
Lookup global role assignment.
getFields()
Get all mapping fields.
getRulesForUpdate()
Get all mapping rules with option &#39;update&#39;.
if(!file_exists(getcwd() . '/ilias.ini.php'))
registration confirmation script for ilias
Definition: confirmReg.php:12
foreach($_POST as $key=> $value) $res
$rule
Definition: showstats.php:43
static _delete($a_server_id)
Delete mapping rules by server id.
$query
$row
This class stores the settings that define the mapping between LDAP attribute and user profile fields...
read()
Read mapping setttings from db.
global $ilDB
__construct($a_server_id)
Private constructor (Singleton for each server_id)
getValue($a_field_name)
Get LDAP attribute name by given ILIAS profile field.
save()
Save mapping rules to db.