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