Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00033 class ilLDAPAttributeMapping
00034 {
00035 private static $instances = array();
00036 private $server_id = null;
00037 private $db = null;
00038 private $mapping_rules = array();
00039 private $rules_for_update = array();
00040 private $lng;
00041
00048 private function __construct($a_server_id)
00049 {
00050 global $ilDB,$lng;
00051
00052 $this->db = $ilDB;
00053 $this->lng = $lng;
00054 $this->server_id = $a_server_id;
00055 $this->read();
00056 }
00057
00065 public static function _getInstanceByServerId($a_server_id)
00066 {
00067 if(array_key_exists($a_server_id,self::$instances) and is_object(self::$instances[$a_server_id]))
00068 {
00069 return self::$instances[$a_server_id];
00070 }
00071 return self::$instances[$a_server_id] = new ilLDAPAttributeMapping($a_server_id);
00072 }
00073
00074
00082 public static function _delete($a_server_id)
00083 {
00084 global $ilDB;
00085
00086 $query = "DELETE FROM ldap_attribute_mapping ".
00087 "WHERE server_id =".$ilDB->quote($a_server_id);
00088 $res = $ilDB->query($query);
00089 }
00090
00098 public static function _lookupGlobalRole($a_server_id)
00099 {
00100 global $ilDB;
00101
00102 $query = "SELECT value FROM ldap_attribute_mapping ".
00103 "WHERE server_id =".$ilDB->quote($a_server_id)." ".
00104 "AND keyword = ".$ilDB->quote('global_role');
00105
00106 $res = $ilDB->query($query);
00107 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00108 {
00109 return (int) $row->value;
00110 }
00111 return 0;
00112 }
00113
00123 public function setRule($a_field_name,$a_ldap_attribute,$a_perform_update)
00124 {
00125 $this->mapping_rules[$a_field_name]['value'] = $a_ldap_attribute;
00126 $this->mapping_rules[$a_field_name]['performUpdate'] = $a_perform_update;
00127 }
00128
00136 public function getRulesForUpdate()
00137 {
00138 return $this->rules_for_update ? $this->rules_for_update : array();
00139 }
00140
00148 public function getFieldsForUpdate()
00149 {
00150 foreach($this->rules_for_update as $field => $rule)
00151 {
00152 if(!strlen($rule['value']))
00153 {
00154 continue;
00155 }
00156 if(strpos($rule['value'],',') === false)
00157 {
00158 $fields[] = strtolower($rule['value']);
00159 continue;
00160 }
00161 $tmp_fields = explode(',',$rule['value']);
00162 $value = '';
00163 foreach($tmp_fields as $tmp_field)
00164 {
00165 $fields[] = trim(strtolower($tmp_field));
00166 }
00167 }
00168 return $fields ? $fields : array();
00169 }
00170
00178 public function getFields()
00179 {
00180 foreach($this->mapping_rules as $field => $rule)
00181 {
00182 if(!strlen($rule['value']))
00183 {
00184 continue;
00185 }
00186 if(strpos($rule['value'],',') === false)
00187 {
00188 $fields[] = strtolower($rule['value']);
00189 continue;
00190 }
00191 $tmp_fields = explode(',',$rule['value']);
00192 $value = '';
00193 foreach($tmp_fields as $tmp_field)
00194 {
00195 $fields[] = trim(strtolower($tmp_field));
00196 }
00197 }
00198 return $fields ? $fields : array();
00199 }
00200
00208 public function getRules()
00209 {
00210 return $this->mapping_rules;
00211 }
00212
00219 public function clearRules()
00220 {
00221 $this->mapping_rules = array();
00222 }
00223
00230 public function save()
00231 {
00232 $this->delete();
00233
00234 foreach($this->mapping_rules as $keyword => $options)
00235 {
00236 $query = "INSERT INTO ldap_attribute_mapping SET ".
00237 "server_id =".$this->db->quote($this->server_id).", ".
00238 "keyword = ".$this->db->quote($keyword).", ".
00239 "value = ".$this->db->quote($options['value']).", ".
00240 "perform_update = ".$this->db->quote($options['performUpdate']);
00241 $this->db->query($query);
00242 }
00243 }
00244
00251 public function delete()
00252 {
00253 self::_delete($this->server_id);
00254 }
00255
00264 public function enabledUpdate($a_field_name)
00265 {
00266 if(array_key_exists($a_field_name,$this->mapping_rules))
00267 {
00268 return (bool) $this->mapping_rules[$a_field_name]['performUpdate'];
00269 }
00270 return false;
00271 }
00272
00280 public function getValue($a_field_name)
00281 {
00282 if(array_key_exists($a_field_name,$this->mapping_rules))
00283 {
00284 return $this->mapping_rules[$a_field_name]['value'];
00285 }
00286 return '';
00287 }
00288
00296 private function read()
00297 {
00298 $query = "SELECT * FROM ldap_attribute_mapping ".
00299 "WHERE server_id =".$this->db->quote($this->server_id)." ";
00300
00301 $res = $this->db->query($query);
00302 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00303 {
00304 $this->mapping_rules[$row->keyword]['value'] = $row->value;
00305 $this->mapping_rules[$row->keyword]['performUpdate'] = (bool) $row->perform_update;
00306
00307 if($row->perform_update)
00308 {
00309 $this->rules_for_update[$row->keyword]['value'] = $row->value;
00310 }
00311 }
00312 }
00313 }
00314 ?>