ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilLDAPAttributeMapping Class Reference

This class stores the settings that define the mapping between LDAP attribute and user profile fields. More...

+ Collaboration diagram for ilLDAPAttributeMapping:

Public Member Functions

 setRule (string $a_field_name, string $a_ldap_attribute, bool $a_perform_update)
 
 getRulesForUpdate ()
 Get all mapping rules with option 'update'. More...
 
 getFieldsForUpdate ()
 Get field names of all mapping rules with option 'update'. More...
 
 getFields ()
 Get all mapping fields. More...
 
 getRules (bool $onlyApplicable=false)
 Get all rules. More...
 
 clearRules ()
 Clear rules => Does not perform an update. More...
 
 save ()
 Save mapping rules to db. More...
 
 delete ()
 Delete all entries. More...
 
 enabledUpdate (string $a_field_name)
 Check whether an update should be performed on a specific user attribute or not. More...
 
 getValue (string $a_field_name)
 Get LDAP attribute name by given ILIAS profile field. More...
 

Static Public Member Functions

static _getInstanceByServerId (int $a_server_id)
 
static _delete (int $a_server_id)
 
static _lookupGlobalRole (int $a_server_id)
 
static hasRulesForUpdate (int $a_server_id)
 Check if there is ldap attribute -> user data mapping which which is updated on login. More...
 

Private Member Functions

 __construct (int $a_server_id)
 
 read ()
 Read mapping settings from db. More...
 

Static Private Member Functions

static getMappedFields (array $rules)
 

Private Attributes

int $server_id
 
ilDBInterface $db
 
array $mapping_rules = []
 
array $rules_for_update = []
 

Static Private Attributes

static array $instances = []
 

Detailed Description

This class stores the settings that define the mapping between LDAP attribute and user profile fields.

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

Definition at line 26 of file class.ilLDAPAttributeMapping.php.

Constructor & Destructor Documentation

◆ __construct()

ilLDAPAttributeMapping::__construct ( int  $a_server_id)
private

Definition at line 35 of file class.ilLDAPAttributeMapping.php.

References $DIC, and read().

36  {
37  global $DIC;
38 
39  $this->db = $DIC->database();
40 
41  $this->server_id = $a_server_id;
42  $this->read();
43  }
global $DIC
Definition: feed.php:28
read()
Read mapping settings from db.
+ Here is the call graph for this function:

Member Function Documentation

◆ _delete()

static ilLDAPAttributeMapping::_delete ( int  $a_server_id)
static

Definition at line 54 of file class.ilLDAPAttributeMapping.php.

References $DIC, $ilDB, and $query.

Referenced by ilLDAPServer\delete().

54  : void
55  {
56  global $DIC;
57 
58  $ilDB = $DIC['ilDB'];
59 
60  $query = "DELETE FROM ldap_attribute_mapping " .
61  "WHERE server_id =" . $ilDB->quote($a_server_id, 'integer');
62  $ilDB->manipulate($query);
63  }
global $DIC
Definition: feed.php:28
$query
+ Here is the caller graph for this function:

◆ _getInstanceByServerId()

static ilLDAPAttributeMapping::_getInstanceByServerId ( int  $a_server_id)
static

Definition at line 45 of file class.ilLDAPAttributeMapping.php.

Referenced by ilLDAPQuery\__construct(), ilLDAPServer\getPearAtributeArray(), ilLDAPSettingsGUI\initAttributeMapping(), and ilLDAPAttributeToUser\initLDAPAttributeMapping().

46  {
47  if (array_key_exists($a_server_id, self::$instances) && is_object(self::$instances[$a_server_id])) {
48  return self::$instances[$a_server_id];
49  }
50 
51  return self::$instances[$a_server_id] = new ilLDAPAttributeMapping($a_server_id);
52  }
This class stores the settings that define the mapping between LDAP attribute and user profile fields...
+ Here is the caller graph for this function:

◆ _lookupGlobalRole()

static ilLDAPAttributeMapping::_lookupGlobalRole ( int  $a_server_id)
static

Definition at line 65 of file class.ilLDAPAttributeMapping.php.

References $DIC, $ilDB, $query, $res, and ilDBConstants\FETCHMODE_OBJECT.

Referenced by ilLDAPRoleAssignmentRules\getDefaultRole(), and ilLDAPSettingsGUI\setServerFormValues().

65  : int
66  {
67  global $DIC;
68 
69  $ilDB = $DIC['ilDB'];
70 
71  $query = "SELECT value FROM ldap_attribute_mapping " .
72  "WHERE server_id =" . $ilDB->quote($a_server_id, 'integer') . " " .
73  "AND keyword = " . $ilDB->quote('global_role', 'text');
74 
75  $res = $ilDB->query($query);
76  if ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
77  return (int) $row->value;
78  }
79 
80  return 0;
81  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: feed.php:28
$query
+ Here is the caller graph for this function:

◆ clearRules()

ilLDAPAttributeMapping::clearRules ( )

Clear rules => Does not perform an update.

Definition at line 169 of file class.ilLDAPAttributeMapping.php.

169  : void
170  {
171  $this->mapping_rules = array();
172  }

◆ delete()

ilLDAPAttributeMapping::delete ( )

Delete all entries.

Definition at line 196 of file class.ilLDAPAttributeMapping.php.

196  : void
197  {
198  self::_delete($this->server_id);
199  }

◆ enabledUpdate()

ilLDAPAttributeMapping::enabledUpdate ( string  $a_field_name)

Check whether an update should be performed on a specific user attribute or not.

Parameters
stringILIAS user attribute

Definition at line 206 of file class.ilLDAPAttributeMapping.php.

206  : bool
207  {
208  if (array_key_exists($a_field_name, $this->mapping_rules)) {
209  return (bool) $this->mapping_rules[$a_field_name]['performUpdate'];
210  }
211 
212  return false;
213  }

◆ getFields()

ilLDAPAttributeMapping::getFields ( )

Get all mapping fields.

Definition at line 127 of file class.ilLDAPAttributeMapping.php.

127  : array
128  {
129  return self::getMappedFields($this->mapping_rules);
130  }

◆ getFieldsForUpdate()

ilLDAPAttributeMapping::getFieldsForUpdate ( )

Get field names of all mapping rules with option 'update'.

Definition at line 119 of file class.ilLDAPAttributeMapping.php.

119  : array
120  {
121  return self::getMappedFields($this->rules_for_update);
122  }

◆ getMappedFields()

static ilLDAPAttributeMapping::getMappedFields ( array  $rules)
staticprivate

Definition at line 132 of file class.ilLDAPAttributeMapping.php.

132  : array
133  {
134  $fields = [];
135  foreach ($rules as $rule) {
136  if (!$rule['value']) {
137  continue;
138  }
139  if (strpos($rule['value'], ',') === false) {
140  $fields[] = strtolower($rule['value']);
141  continue;
142  }
143  $tmp_fields = explode(',', $rule['value']);
144  foreach ($tmp_fields as $tmp_field) {
145  $fields[] = strtolower(trim($tmp_field));
146  }
147  }
148  return $fields;
149  }

◆ getRules()

ilLDAPAttributeMapping::getRules ( bool  $onlyApplicable = false)

Get all rules.

Returns
array mapping rules. E.g. array('firstname' => 'name',...)

Definition at line 156 of file class.ilLDAPAttributeMapping.php.

References $mapping_rules.

156  : array
157  {
158  if (!$onlyApplicable) {
159  return $this->mapping_rules;
160  }
161  return array_filter($this->mapping_rules, static function (array $rule): bool {
162  return $rule['value'] !== '';
163  });
164  }

◆ getRulesForUpdate()

ilLDAPAttributeMapping::getRulesForUpdate ( )

Get all mapping rules with option 'update'.

Returns
array mapping rules. E.g. array('firstname' => 'name',...)

Definition at line 110 of file class.ilLDAPAttributeMapping.php.

References $rules_for_update.

110  : array
111  {
113  }

◆ getValue()

ilLDAPAttributeMapping::getValue ( string  $a_field_name)

Get LDAP attribute name by given ILIAS profile field.

Parameters
stringILIAS user attribute
Returns
string LDAP attribute name

Definition at line 221 of file class.ilLDAPAttributeMapping.php.

221  : string
222  {
223  if (array_key_exists($a_field_name, $this->mapping_rules)) {
224  return $this->mapping_rules[$a_field_name]['value'];
225  }
226 
227  return '';
228  }

◆ hasRulesForUpdate()

static ilLDAPAttributeMapping::hasRulesForUpdate ( int  $a_server_id)
static

Check if there is ldap attribute -> user data mapping which which is updated on login.

Definition at line 87 of file class.ilLDAPAttributeMapping.php.

References $DIC, $ilDB, $query, and $res.

Referenced by ilLDAPUserSynchronisation\isUpdateRequired().

87  : bool
88  {
89  global $DIC;
90 
91  $ilDB = $DIC['ilDB'];
92 
93  $query = 'SELECT perform_update FROM ldap_attribute_mapping ' .
94  'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
95  'AND perform_update = 1';
96  $res = $ilDB->query($query);
97  return $res->numRows() > 0;
98  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: feed.php:28
$query
+ Here is the caller graph for this function:

◆ read()

ilLDAPAttributeMapping::read ( )
private

Read mapping settings from db.

Definition at line 233 of file class.ilLDAPAttributeMapping.php.

References $query, $res, ilDBConstants\FETCHMODE_OBJECT, and if.

Referenced by __construct(), ilLDAPSettingsGUI\addRoleMapping(), ilLDAPSettingsGUI\confirmDeleteRoleMapping(), and ilLDAPSettingsGUI\editRoleMapping().

233  : void
234  {
235  $query = "SELECT * FROM ldap_attribute_mapping " .
236  "WHERE server_id =" . $this->db->quote($this->server_id, 'integer');
237 
238  $res = $this->db->query($query);
239  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
240  if (!is_null($row->value)) {
241  $this->mapping_rules[$row->keyword]['value'] = $row->value;
242  $this->mapping_rules[$row->keyword]['performUpdate'] = (bool) $row->perform_update;
243 
244  if ($row->perform_update) {
245  $this->rules_for_update[$row->keyword]['value'] = $row->value;
246  }
247  }
248  }
249  }
$res
Definition: ltiservices.php:69
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
$query
+ Here is the caller graph for this function:

◆ save()

ilLDAPAttributeMapping::save ( )

Save mapping rules to db.

Definition at line 177 of file class.ilLDAPAttributeMapping.php.

References $query.

Referenced by ilLDAPSettingsGUI\createRoleMapping().

177  : void
178  {
179  $this->delete();
180 
181  foreach ($this->mapping_rules as $keyword => $options) {
182  $query = "INSERT INTO ldap_attribute_mapping (server_id,keyword,value,perform_update) " .
183  "VALUES( " .
184  $this->db->quote($this->server_id, 'integer') . ", " .
185  $this->db->quote($keyword, 'text') . ", " .
186  $this->db->quote($options['value'], 'text') . ", " .
187  $this->db->quote($options['performUpdate'], 'integer') .
188  ')';
189  $this->db->manipulate($query);
190  }
191  }
$query
+ Here is the caller graph for this function:

◆ setRule()

ilLDAPAttributeMapping::setRule ( string  $a_field_name,
string  $a_ldap_attribute,
bool  $a_perform_update 
)

Definition at line 100 of file class.ilLDAPAttributeMapping.php.

100  : void
101  {
102  $this->mapping_rules[$a_field_name]['value'] = $a_ldap_attribute;
103  $this->mapping_rules[$a_field_name]['performUpdate'] = $a_perform_update;
104  }

Field Documentation

◆ $db

ilDBInterface ilLDAPAttributeMapping::$db
private

Definition at line 30 of file class.ilLDAPAttributeMapping.php.

◆ $instances

array ilLDAPAttributeMapping::$instances = []
staticprivate

Definition at line 28 of file class.ilLDAPAttributeMapping.php.

◆ $mapping_rules

array ilLDAPAttributeMapping::$mapping_rules = []
private

Definition at line 32 of file class.ilLDAPAttributeMapping.php.

Referenced by getRules().

◆ $rules_for_update

array ilLDAPAttributeMapping::$rules_for_update = []
private

Definition at line 33 of file class.ilLDAPAttributeMapping.php.

Referenced by getRulesForUpdate().

◆ $server_id

int ilLDAPAttributeMapping::$server_id
private

Definition at line 29 of file class.ilLDAPAttributeMapping.php.


The documentation for this class was generated from the following file: