ILIAS  release_8 Revision v8.24
class.ilECSParticipantSetting.php
Go to the documentation of this file.
1<?php
2
18declare(strict_types=1);
19
24{
25 public const AUTH_VERSION_4 = 1;
26 public const AUTH_VERSION_5 = 2;
27
28 public const PERSON_EPPN = 1;
29 public const PERSON_LUID = 2;
30 public const PERSON_LOGIN = 3;
31 public const PERSON_UID = 4;
32
33 public const LOGIN_PLACEHOLDER = '[LOGIN]';
34 public const EXTERNAL_ACCOUNT_PLACEHOLDER = '[EXTERNAL_ACCOUNT]';
35
39
40 public const OUTGOING_AUTH_MODE_DEFAULT = 'default';
41
42 public const VALIDATION_OK = 0;
44
45
46 protected static array $instances = [];
47
48
49 // :TODO: what types are needed?
50 public const IMPORT_UNCHANGED = 0;
51 public const IMPORT_RCRS = 1;
52 public const IMPORT_CRS = 2;
53 public const IMPORT_CMS = 3;
54
55 private int $server_id;
56 private int $mid;
57 private bool $export = false;
58 private bool $import = false;
59 private int $import_type = 1;
60 private string $title = '';
61 private string $cname = '';
62 private bool $token = true;
63 private bool $dtoken = true;
64
67
68
69 private array $export_types = array();
70 private array $import_types = array();
71 private array $username_placeholders = [];
72 private bool $incoming_local_accounts = true;
77 private array $outgoing_auth_modes = [];
78
79 private bool $exists = false;
80
82
83 public function __construct(int $a_server_id, int $mid)
84 {
85 global $DIC;
86
87 $this->db = $DIC->database();
88
89 $this->server_id = $a_server_id;
90 $this->mid = $mid;
91 $this->read();
92 }
93
100 public static function getInstance(int $a_server_id, int $mid): ilECSParticipantSetting
101 {
102 if (!isset(self::$instances[$a_server_id . '_' . $mid])) {
103 return self::$instances[$a_server_id . '_' . $mid] = new self($a_server_id, $mid);
104 }
105 return self::$instances[$a_server_id . '_' . $mid];
106 }
107
108
112 public function getServerId(): int
113 {
114 return $this->server_id;
115 }
116
117 public function setMid(int $a_mid): void
118 {
119 $this->mid = $a_mid;
120 }
121
122 public function getMid(): int
123 {
124 return $this->mid;
125 }
126
127 public function enableExport(bool $a_status): void
128 {
129 $this->export = $a_status;
130 }
131
132 public function isExportEnabled(): bool
133 {
134 return $this->export;
135 }
136
137 public function enableImport(bool $a_status): void
138 {
139 $this->import = $a_status;
140 }
141
142 public function isImportEnabled(): bool
143 {
144 return $this->import;
145 }
146
147 public function setImportType(int $a_type): void
148 {
149 if ($a_type !== self::IMPORT_UNCHANGED) {
150 $this->import_type = $a_type;
151 }
152 }
153
154 public function getImportType(): int
155 {
156 return $this->import_type;
157 }
158
159 public function setTitle(string $a_title): void
160 {
161 $this->title = $a_title;
162 }
163
164 public function getTitle(): string
165 {
166 return $this->title;
167 }
168
169 public function getCommunityName(): string
170 {
171 return $this->cname;
172 }
173
174 public function setCommunityName(string $a_name): void
175 {
176 $this->cname = $a_name;
177 }
178
179 public function isTokenEnabled(): bool
180 {
181 return $this->token;
182 }
183
184 public function enableToken(bool $a_stat): void
185 {
186 $this->token = $a_stat;
187 }
188
189 public function setExportTypes(array $a_types): void
190 {
191 $this->export_types = $a_types;
192 }
193
194 public function getExportTypes(): array
195 {
196 return $this->export_types;
197 }
198
199 public function getOutgoingUsernamePlaceholders(): array
200 {
202 }
203
204 public function setOutgoingUsernamePlaceholders(array $a_username_placeholders): void
205 {
206 $this->username_placeholders = $a_username_placeholders;
207 }
208
209 public function getOutgoingUsernamePlaceholderByAuthMode(string $auth_mode): string
210 {
211 return $this->getOutgoingUsernamePlaceholders()[$auth_mode] ?? '';
212 }
213
214 public function areIncomingLocalAccountsSupported(): bool
215 {
217 }
218
219 public function enableIncomingLocalAccounts(bool $a_status): void
220 {
221 $this->incoming_local_accounts = $a_status;
222 }
223
224 public function setIncomingAuthType(int $incoming_auth_type): void
225 {
226 $this->incoming_auth_type = $incoming_auth_type;
227 }
228
229 public function getIncomingAuthType(): int
230 {
232 }
233
234 public function setOutgoingAuthModes(array $auth_modes): void
235 {
236 $this->outgoing_auth_modes = $auth_modes;
237 }
238
239 public function getOutgoingAuthModes(): array
240 {
242 }
243
247 public function getOutgoingExternalAuthModes(): array
248 {
249 return array_filter(
250 $this->getOutgoingAuthModes(),
251 static function (string $auth_mode): bool {
252 return $auth_mode !== self::OUTGOING_AUTH_MODE_DEFAULT;
253 }
254 );
255 }
256
257 public function isOutgoingAuthModeEnabled(string $auth_mode): bool
258 {
259 return (bool) ($this->getOutgoingAuthModes()[$auth_mode] ?? false);
260 }
261
262
263 public function setImportTypes(array $a_types): void
264 {
265 $this->import_types = $a_types;
266 }
267
268 public function getImportTypes(): array
269 {
270 return $this->import_types;
271 }
272
273 private function exists(): bool
274 {
275 return $this->exists;
276 }
277
278 public function validate(): int
279 {
280 foreach ($this->getOutgoingAuthModes() as $auth_mode) {
281 if ($auth_mode === self::OUTGOING_AUTH_MODE_DEFAULT) {
282 continue;
283 }
284 $placeholder = $this->getOutgoingUsernamePlaceholderByAuthMode($auth_mode);
285 if (
286 !stristr($placeholder, self::LOGIN_PLACEHOLDER) &&
287 !stristr($placeholder, self::EXTERNAL_ACCOUNT_PLACEHOLDER)
288 ) {
290 }
291 }
292 return self::VALIDATION_OK;
293 }
294
299 public function update(): bool
300 {
301 if (!$this->exists()) {
302 return $this->create();
303 }
304 $query = 'UPDATE ecs_part_settings ' .
305 'SET ' .
306 'sid = ' . $this->db->quote($this->getServerId(), 'integer') . ', ' .
307 'mid = ' . $this->db->quote($this->getMid(), 'integer') . ', ' .
308 'export = ' . $this->db->quote((int) $this->isExportEnabled(), 'integer') . ', ' .
309 'import = ' . $this->db->quote((int) $this->isImportEnabled(), 'integer') . ', ' .
310 'import_type = ' . $this->db->quote($this->getImportType(), 'integer') . ', ' .
311 'title = ' . $this->db->quote($this->getTitle(), 'text') . ', ' .
312 'cname = ' . $this->db->quote($this->getCommunityName(), 'text') . ', ' .
313 'token = ' . $this->db->quote($this->isTokenEnabled(), 'integer') . ', ' .
314 'export_types = ' . $this->db->quote(serialize($this->getExportTypes()), 'text') . ', ' .
315 'import_types = ' . $this->db->quote(serialize($this->getImportTypes()), ilDBConstants::T_TEXT) . ', ' .
316 'username_placeholders = ' . $this->db->quote(serialize($this->getOutgoingUsernamePlaceholders()), ilDBConstants::T_TEXT) . ', ' .
317 'incoming_local_accounts = ' . $this->db->quote($this->areIncomingLocalAccountsSupported(), ilDBConstants::T_INTEGER) . ', ' .
318 'incoming_auth_type = ' . $this->db->quote($this->getIncomingAuthType(), ilDBConstants::T_INTEGER) . ', ' .
319 'outgoing_auth_modes = ' . $this->db->quote(serialize($this->getOutgoingAuthModes()), ilDBConstants::T_TEXT) . ' ' .
320 'WHERE sid = ' . $this->db->quote($this->getServerId(), 'integer') . ' ' .
321 'AND mid = ' . $this->db->quote($this->getMid(), 'integer');
322 $this->db->manipulate($query);
323 return true;
324 }
325
326 private function create(): bool
327 {
328 $query = 'INSERT INTO ecs_part_settings ' .
329 '(sid,mid,export,import,import_type,title,cname,token,export_types, import_types, username_placeholders, incoming_auth_type, incoming_local_accounts, outgoing_auth_modes) ' .
330 'VALUES( ' .
331 $this->db->quote($this->getServerId(), 'integer') . ', ' .
332 $this->db->quote($this->getMid(), 'integer') . ', ' .
333 $this->db->quote((int) $this->isExportEnabled(), 'integer') . ', ' .
334 $this->db->quote((int) $this->isImportEnabled(), 'integer') . ', ' .
335 $this->db->quote($this->getImportType(), 'integer') . ', ' .
336 $this->db->quote($this->getTitle(), 'text') . ', ' .
337 $this->db->quote($this->getCommunityName(), 'text') . ', ' .
338 $this->db->quote($this->isTokenEnabled(), 'integer') . ', ' .
339 $this->db->quote(serialize($this->getExportTypes()), 'text') . ', ' .
340 $this->db->quote(serialize($this->getImportTypes()), '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.
global $DIC
Definition: feed.php:28
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
$query