ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.ilECSParticipantSetting.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25{
26 public const AUTH_VERSION_4 = 1;
27 public const AUTH_VERSION_5 = 2;
28
29 public const PERSON_EPPN = 1;
30 public const PERSON_LUID = 2;
31 public const PERSON_LOGIN = 3;
32 public const PERSON_UID = 4;
33
34 public const LOGIN_PLACEHOLDER = '[LOGIN]';
35 public const EXTERNAL_ACCOUNT_PLACEHOLDER = '[EXTERNAL_ACCOUNT]';
36
40 public const INCOMING_AUTH_TYPE_OIDC = 3;
41
42 public const OUTGOING_AUTH_MODE_DEFAULT = 'default';
43
44 public const VALIDATION_OK = 0;
46
47
48 protected static array $instances = [];
49
50
51 // :TODO: what types are needed?
52 public const IMPORT_UNCHANGED = 0;
53 public const IMPORT_RCRS = 1;
54 public const IMPORT_CRS = 2;
55 public const IMPORT_CMS = 3;
56
57 private int $server_id;
58 private int $mid;
59 private bool $export = false;
60 private bool $import = false;
61 private int $import_type = 1;
62 private string $title = '';
63 private string $cname = '';
64 private bool $token = true;
65 private bool $dtoken = true;
66
69
70
71 private array $export_types = array();
72 private array $import_types = array();
73 private array $username_placeholders = [];
74 private bool $incoming_local_accounts = true;
79 private array $outgoing_auth_modes = [];
80
81 private bool $exists = false;
82
84
85 public function __construct(int $a_server_id, int $mid)
86 {
87 global $DIC;
88
89 $this->db = $DIC->database();
90
91 $this->server_id = $a_server_id;
92 $this->mid = $mid;
93 $this->read();
94 }
95
102 public static function getInstance(int $a_server_id, int $mid): ilECSParticipantSetting
103 {
104 if (!isset(self::$instances[$a_server_id . '_' . $mid])) {
105 return self::$instances[$a_server_id . '_' . $mid] = new self($a_server_id, $mid);
106 }
107 return self::$instances[$a_server_id . '_' . $mid];
108 }
109
110
114 public function getServerId(): int
115 {
116 return $this->server_id;
117 }
118
119 public function setMid(int $a_mid): void
120 {
121 $this->mid = $a_mid;
122 }
123
124 public function getMid(): int
125 {
126 return $this->mid;
127 }
128
129 public function enableExport(bool $a_status): void
130 {
131 $this->export = $a_status;
132 }
133
134 public function isExportEnabled(): bool
135 {
136 return $this->export;
137 }
138
139 public function enableImport(bool $a_status): void
140 {
141 $this->import = $a_status;
142 }
143
144 public function isImportEnabled(): bool
145 {
146 return $this->import;
147 }
148
149 public function setImportType(int $a_type): void
150 {
151 if ($a_type !== self::IMPORT_UNCHANGED) {
152 $this->import_type = $a_type;
153 }
154 }
155
156 public function getImportType(): int
157 {
158 return $this->import_type;
159 }
160
161 public function setTitle(string $a_title): void
162 {
163 $this->title = $a_title;
164 }
165
166 public function getTitle(): string
167 {
168 return $this->title;
169 }
170
171 public function getCommunityName(): string
172 {
173 return $this->cname;
174 }
175
176 public function setCommunityName(string $a_name): void
177 {
178 $this->cname = $a_name;
179 }
180
181 public function isTokenEnabled(): bool
182 {
183 return $this->token;
184 }
185
186 public function enableToken(bool $a_stat): void
187 {
188 $this->token = $a_stat;
189 }
190
191 public function setExportTypes(array $a_types): void
192 {
193 $this->export_types = $a_types;
194 }
195
196 public function getExportTypes(): array
197 {
198 return $this->export_types;
199 }
200
201 public function getOutgoingUsernamePlaceholders(): array
202 {
204 }
205
206 public function setOutgoingUsernamePlaceholders(array $a_username_placeholders): void
207 {
208 $this->username_placeholders = $a_username_placeholders;
209 }
210
211 public function getOutgoingUsernamePlaceholderByAuthMode(string $auth_mode): string
212 {
213 return $this->getOutgoingUsernamePlaceholders()[$auth_mode] ?? '';
214 }
215
216 public function areIncomingLocalAccountsSupported(): bool
217 {
219 }
220
221 public function enableIncomingLocalAccounts(bool $a_status): void
222 {
223 $this->incoming_local_accounts = $a_status;
224 }
225
226 public function setIncomingAuthType(int $incoming_auth_type): void
227 {
228 $this->incoming_auth_type = $incoming_auth_type;
229 }
230
231 public function getIncomingAuthType(): int
232 {
234 }
235
236 public function setOutgoingAuthModes(array $auth_modes): void
237 {
238 $this->outgoing_auth_modes = $auth_modes;
239 }
240
241 public function getOutgoingAuthModes(): array
242 {
244 }
245
249 public function getOutgoingExternalAuthModes(): array
250 {
251 return array_filter(
252 $this->getOutgoingAuthModes(),
253 static function (string $auth_mode): bool {
254 return $auth_mode !== self::OUTGOING_AUTH_MODE_DEFAULT;
255 }
256 );
257 }
258
259 public function isOutgoingAuthModeEnabled(string $auth_mode): bool
260 {
261 return (bool) ($this->getOutgoingAuthModes()[$auth_mode] ?? false);
262 }
263
264
265 public function setImportTypes(array $a_types): void
266 {
267 $this->import_types = $a_types;
268 }
269
270 public function getImportTypes(): array
271 {
272 return $this->import_types;
273 }
274
275 private function exists(): bool
276 {
277 return $this->exists;
278 }
279
280 public function validate(): int
281 {
282 foreach ($this->getOutgoingAuthModes() as $auth_mode) {
283 if ($auth_mode === self::OUTGOING_AUTH_MODE_DEFAULT) {
284 continue;
285 }
286 $placeholder = $this->getOutgoingUsernamePlaceholderByAuthMode($auth_mode);
287 if (
288 !stristr($placeholder, self::LOGIN_PLACEHOLDER) &&
289 !stristr($placeholder, self::EXTERNAL_ACCOUNT_PLACEHOLDER)
290 ) {
292 }
293 }
294 return self::VALIDATION_OK;
295 }
296
301 public function update(): bool
302 {
303 if (!$this->exists()) {
304 return $this->create();
305 }
306 $query = 'UPDATE ecs_part_settings ' .
307 'SET ' .
308 'sid = ' . $this->db->quote($this->getServerId(), 'integer') . ', ' .
309 'mid = ' . $this->db->quote($this->getMid(), 'integer') . ', ' .
310 'export = ' . $this->db->quote((int) $this->isExportEnabled(), 'integer') . ', ' .
311 'import = ' . $this->db->quote((int) $this->isImportEnabled(), 'integer') . ', ' .
312 'import_type = ' . $this->db->quote($this->getImportType(), 'integer') . ', ' .
313 'title = ' . $this->db->quote($this->getTitle(), 'text') . ', ' .
314 'cname = ' . $this->db->quote($this->getCommunityName(), 'text') . ', ' .
315 'token = ' . $this->db->quote($this->isTokenEnabled(), 'integer') . ', ' .
316 'export_types = ' . $this->db->quote(serialize($this->getExportTypes()), 'text') . ', ' .
317 'import_types = ' . $this->db->quote(serialize($this->getImportTypes()), ilDBConstants::T_TEXT) . ', ' .
318 'username_placeholders = ' . $this->db->quote(serialize($this->getOutgoingUsernamePlaceholders()), ilDBConstants::T_TEXT) . ', ' .
319 'incoming_local_accounts = ' . $this->db->quote($this->areIncomingLocalAccountsSupported(), ilDBConstants::T_INTEGER) . ', ' .
320 'incoming_auth_type = ' . $this->db->quote($this->getIncomingAuthType(), ilDBConstants::T_INTEGER) . ', ' .
321 'outgoing_auth_modes = ' . $this->db->quote(serialize($this->getOutgoingAuthModes()), ilDBConstants::T_TEXT) . ' ' .
322 'WHERE sid = ' . $this->db->quote($this->getServerId(), 'integer') . ' ' .
323 'AND mid = ' . $this->db->quote($this->getMid(), 'integer');
324 $this->db->manipulate($query);
325 return true;
326 }
327
328 private function create(): bool
329 {
330 $query = 'INSERT INTO ecs_part_settings ' .
331 '(sid,mid,export,import,import_type,title,cname,token,export_types, import_types, username_placeholders, incoming_auth_type, incoming_local_accounts, outgoing_auth_modes) ' .
332 'VALUES( ' .
333 $this->db->quote($this->getServerId(), 'integer') . ', ' .
334 $this->db->quote($this->getMid(), 'integer') . ', ' .
335 $this->db->quote((int) $this->isExportEnabled(), 'integer') . ', ' .
336 $this->db->quote((int) $this->isImportEnabled(), 'integer') . ', ' .
337 $this->db->quote($this->getImportType(), 'integer') . ', ' .
338 $this->db->quote($this->getTitle(), 'text') . ', ' .
339 $this->db->quote($this->getCommunityName(), 'text') . ', ' .
340 $this->db->quote($this->isTokenEnabled(), 'integer') . ', ' .
341 $this->db->quote(serialize($this->getExportTypes()), 'text') . ', ' .
342 $this->db->quote(serialize($this->getImportTypes()), 'text') . ', ' .
343 $this->db->quote(serialize($this->getOutgoingUsernamePlaceholders()), ilDBConstants::T_TEXT) . ', ' .
344 $this->db->quote($this->areIncomingLocalAccountsSupported(), ilDBConstants::T_INTEGER) . ', ' .
345 $this->db->quote($this->getIncomingAuthType(), ilDBConstants::T_INTEGER) . ', ' .
346 $this->db->quote(serialize($this->getOutgoingAuthModes()), ilDBConstants::T_TEXT) . ' ' .
347 ')';
348 $this->db->manipulate($query);
349 return true;
350 }
351
355 public function delete(): bool
356 {
357 $query = 'DELETE FROM ecs_part_settings ' .
358 'WHERE sid = ' . $this->db->quote($this->getServerId(), 'integer') . ' ' .
359 'AND mid = ' . $this->db->quote($this->getMid(), 'integer');
360 $this->db->manipulate($query);
361 return true;
362 }
363
367 private function read(): void
368 {
369 $query = 'SELECT * FROM ecs_part_settings ' .
370 'WHERE sid = ' . $this->db->quote($this->getServerId(), 'integer') . ' ' .
371 'AND mid = ' . $this->db->quote($this->getMid(), 'integer');
372
373 $res = $this->db->query($query);
374
375 $this->exists = ($res->numRows() ? true : false);
376
377 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
378 $this->enableExport((bool) $row->export);
379 $this->enableImport((bool) $row->import);
380 $this->setImportType((int) $row->import_type);
381 $this->setTitle($row->title);
382 $this->setCommunityName($row->cname);
383 $this->enableToken((bool) $row->token);
384 $this->setExportTypes((array) unserialize($row->export_types, ['allowed_classes' => true]));
385 $this->setImportTypes((array) unserialize($row->import_types, ['allowed_classes' => true]));
386 $this->setOutgoingUsernamePlaceholders((array) unserialize((string) $row->username_placeholders, ['allowed_classes' => true]));
387 $this->setIncomingAuthType((int) $row->incoming_auth_type);
388 $this->enableIncomingLocalAccounts((bool) $row->incoming_local_accounts);
389 $this->setOutgoingAuthModes((array) unserialize((string) $row->outgoing_auth_modes, ['allowed_classes' => true]));
390 }
391 }
392}
return true
getOutgoingUsernamePlaceholderByAuthMode(string $auth_mode)
setOutgoingUsernamePlaceholders(array $a_username_placeholders)
setIncomingAuthType(int $incoming_auth_type)
update()
Update Calls create automatically when no entry exists.
__construct(int $a_server_id, int $mid)
static getInstance(int $a_server_id, int $mid)
Get instance by server id and mid.
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26