ILIAS  release_8 Revision v8.24
class.ilExternalAuthUserAttributeMapping.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25class ilExternalAuthUserAttributeMapping implements ArrayAccess, Countable, Iterator
26{
27 protected ilDBInterface $db;
28 protected string $authMode;
29 protected int $authSourceId;
31 protected array $mapping = [];
32
33 public function __construct(string $authMode, int $authSourceId = 0)
34 {
35 global $DIC;
36 $this->db = $DIC->database();
37
38 $this->setAuthMode($authMode);
39 $this->setAuthSourceId($authSourceId);
40
41 $this->read();
42 }
43
44 public function getAuthSourceId(): int
45 {
47 }
48
49 public function setAuthSourceId(int $authSourceId): void
50 {
51 $this->authSourceId = $authSourceId;
52 }
53
54 public function getAuthMode(): string
55 {
56 return $this->authMode;
57 }
58
59 public function setAuthMode(string $authMode): void
60 {
61 $this->authMode = $authMode;
62 }
63
65 {
67 }
68
69 public function offsetExists($offset): bool
70 {
71 return isset($this->mapping[$offset]);
72 }
73
74 public function offsetGet($offset)
75 {
76 return $this->offsetExists($offset) ? $this->mapping[$offset] : null;
77 }
78
79 public function offsetSet($offset, $value): void
80 {
81 if (is_null($offset)) {
82 $this->mapping[] = $value;
83 } else {
84 $this->mapping[$offset] = $value;
85 }
86 }
87
88 public function offsetUnset($offset): void
89 {
90 unset($this->mapping[$offset]);
91 }
92
93 public function count(): int
94 {
95 return count($this->mapping);
96 }
97
99 {
100 return current($this->mapping);
101 }
102
103 public function next(): void
104 {
105 next($this->mapping);
106 }
107
108 public function key()
109 {
110 return key($this->mapping);
111 }
112
113 public function valid()
114 {
115 return current($this->mapping);
116 }
117
118 public function rewind(): void
119 {
120 reset($this->mapping);
121 }
122
123 protected function read(): void
124 {
125 $this->mapping = [];
126
127 $res = $this->db->queryF(
128 'SELECT * FROM auth_ext_attr_mapping WHERE auth_mode = %s AND auth_src_id = %s',
129 ['text', 'integer'],
130 [$this->getAuthMode(), $this->getAuthSourceId()]
131 );
132 while ($row = $this->db->fetchAssoc($res)) {
133 $rule = $this->getEmptyRule();
134 $rule->setAttribute($row['attribute']);
135 $rule->setExternalAttribute($row['ext_attribute']);
136 $rule->updateAutomatically((bool) $row['update_automatically']);
137
138 $this->mapping[$rule->getAttribute()] = $rule;
139 }
140 }
141
142 public function save(): void
143 {
144 foreach ($this->mapping as $rule) {
145 $this->db->replace(
146 'auth_ext_attr_mapping',
147 [
148 'auth_mode' => ['text', $this->getAuthMode()],
149 'auth_src_id' => ['integer', $this->getAuthSourceId()],
150 'attribute' => ['text', $rule->getAttribute()]
151 ],
152 [
153 'ext_attribute' => ['text', $rule->getExternalAttribute()],
154 'update_automatically' => ['integer', (int) $rule->isAutomaticallyUpdated()]
155 ]
156 );
157 }
158 }
159
160 public function delete(): void
161 {
162 $this->mapping = [];
163 $this->db->manipulateF(
164 'DELETE FROM auth_ext_attr_mapping WHERE auth_mode = %s AND auth_src_id = %s',
165 ['text', 'integer'],
166 [$this->getAuthMode(), $this->getAuthSourceId()]
167 );
168 }
169}
__construct(string $authMode, int $authSourceId=0)
global $DIC
Definition: feed.php:28
Interface ilDBInterface.
$res
Definition: ltiservices.php:69