ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilExternalAuthUserAttributeMapping.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2016 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Services/Authentication/classes/External/UserAttributeMapping/class.ilExternalAuthUserAttributeMappingRule.php';
5 
11 {
15  protected $db;
16 
20  protected $authMode = '';
21 
25  protected $authSourceId;
26 
30  protected $mapping = array();
31 
37  public function __construct($authMode, $authSourceId = 0)
38  {
39  assert(is_string($authMode));
40  assert(is_numeric($authSourceId));
41 
42  $this->db = $GLOBALS['DIC']->database();
43 
44  $this->setAuthMode($authMode);
46 
47  $this->read();
48  }
49 
53  public function getAuthSourceId()
54  {
55  return $this->authSourceId;
56  }
57 
61  public function setAuthSourceId($authSourceId)
62  {
63  $this->authSourceId = $authSourceId;
64  }
65 
69  public function getAuthMode()
70  {
71  return $this->authMode;
72  }
73 
77  public function setAuthMode($authMode)
78  {
79  $this->authMode = $authMode;
80  }
81 
85  public function getEmptyRule()
86  {
88  }
89 
93  public function offsetExists($offset)
94  {
95  return isset($this->mapping[$offset]);
96  }
97 
101  public function offsetGet($offset)
102  {
103  return $this->offsetExists($offset) ? $this->mapping[$offset] : null;
104  }
105 
109  public function offsetSet($offset, $value)
110  {
111  if (is_null($offset)) {
112  $this->mapping[] = $value;
113  } else {
114  $this->mapping[$offset] = $value;
115  }
116  }
117 
121  public function offsetUnset($offset)
122  {
123  unset($this->mapping[$offset]);
124  }
125 
129  public function count()
130  {
131  return count($this->mapping);
132  }
133 
137  public function current()
138  {
139  return current($this->mapping);
140  }
141 
145  public function next()
146  {
147  next($this->mapping);
148  }
149 
153  public function key()
154  {
155  return key($this->mapping);
156  }
157 
161  public function valid()
162  {
163  return current($this->mapping);
164  }
165 
166  public function rewind()
167  {
168  reset($this->mapping);
169  }
170 
174  protected function read()
175  {
176  $this->mapping = array();
177 
178  $res = $this->db->queryF(
179  'SELECT * FROM auth_ext_attr_mapping WHERE auth_mode = %s AND auth_src_id = %s',
180  array('text', 'integer'),
181  array($this->getAuthMode(), $this->getAuthSourceId())
182  );
183  while ($row = $this->db->fetchAssoc($res)) {
184  $rule = $this->getEmptyRule();
185  $rule->setAttribute($row['attribute']);
186  $rule->setExternalAttribute($row['ext_attribute']);
187  $rule->updateAutomatically((bool) $row['update_automatically']);
188 
189  $this->mapping[$rule->getAttribute()] = $rule;
190  }
191  }
192 
196  public function save()
197  {
198  foreach ($this->mapping as $rule) {
199  $this->db->replace(
200  'auth_ext_attr_mapping',
201  array(
202  'auth_mode' => array('text', $this->getAuthMode()),
203  'auth_src_id' => array('integer', $this->getAuthSourceId()),
204  'attribute' => array('text', $rule->getAttribute())
205  ),
206  array(
207  'ext_attribute' => array('text', $rule->getExternalAttribute()),
208  'update_automatically' => array('integer', (int) $rule->isAutomaticallyUpdated())
209  )
210  );
211  }
212  }
213 
217  public function delete()
218  {
219  $this->mapping = array();
220  $this->db->manipulateF(
221  'DELETE FROM auth_ext_attr_mapping WHERE auth_mode = %s AND auth_src_id = %s',
222  array('text', 'integer'),
223  array($this->getAuthMode(), $this->getAuthSourceId())
224  );
225  }
226 }
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
Class ilExternalAuthUserAttributeMapping.
foreach($_POST as $key=> $value) $res
$rule
Definition: showstats.php:43
Create styles array
The data for the language used.
__construct($authMode, $authSourceId=0)
ilExternalAuthUserAttributeMapping constructor.