ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
class.ilLOSettings.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
20
27{
28 // new settings 5.1
29 public const QST_PASSED_FLAG = 1;
30 public const QST_PASSED_HIDE = 2;
31
36 public const TYPE_INITIAL_NONE = 5;
37
38 public const TYPE_QUALIFYING_ALL = 1;
39 public const TYPE_QUALIFYING_SELECTED = 2;
40
41 // end new settings
42
43 public const TYPE_TEST_UNDEFINED = 0;
44 public const TYPE_TEST_INITIAL = 1;
45 public const TYPE_TEST_QUALIFIED = 2;
46
47 public const QT_VISIBLE_ALL = 0;
48 public const QT_VISIBLE_OBJECTIVE = 1;
49
50 public const LOC_INITIAL_ALL = 1;
51 public const LOC_INITIAL_SEL = 2;
52 public const LOC_QUALIFIED = 3;
53 public const LOC_PRACTISE = 4;
54
55 public const HIDE_PASSED_OBJECTIVE_QST = 1;
56 public const MARK_PASSED_OBJECTIVE_QST = 2;
57
58 private static array $instances = [];
59
62
63 private bool $it_start = false;
64 private bool $qt_start = false;
65 private int $container_id = 0;
66 private int $type = 0;
67 private int $initial_test = 0;
68 private int $qualified_test = 0;
69 private bool $reset_results = true;
71
72 private bool $entry_exists = false;
73
75 protected ilDBInterface $db;
76 protected ilTree $tree;
77
78 protected function __construct(int $a_cont_id)
79 {
80 global $DIC;
81
82 $this->logger = $DIC->logger()->crs();
83 $this->db = $DIC->database();
84 $this->tree = $DIC->repositoryTree();
85 $this->container_id = $a_cont_id;
86 $this->read();
87 }
88
89 public static function getInstanceByObjId(int $a_obj_id): self
90 {
91 if (isset(self::$instances[$a_obj_id])) {
92 return self::$instances[$a_obj_id];
93 }
94 return self::$instances[$a_obj_id] = new ilLOSettings($a_obj_id);
95 }
96
97 public function setInitialTestType(int $a_type): void
98 {
99 $this->it_type = $a_type;
100 }
101
102 public function getInitialTestType(): int
103 {
104 return $this->it_type;
105 }
106
107 public function getQualifyingTestType(): int
108 {
109 return $this->qt_type;
110 }
111
112 public function setQualifyingTestType(int $a_type): void
113 {
114 $this->qt_type = $a_type;
115 }
116
117 public function setInitialTestAsStart(bool $a_type): void
118 {
119 $this->it_start = $a_type;
120 }
121
122 public function isInitialTestStart(): bool
123 {
124 return $this->it_start;
125 }
126
127 public function setQualifyingTestAsStart(bool $a_type): void
128 {
129 $this->qt_start = $a_type;
130 }
131
132 public function isQualifyingTestStart(): bool
133 {
134 return $this->qt_start;
135 }
136
140 public function hasSeparateInitialTests(): bool
141 {
142 return $this->getInitialTestType() == self::TYPE_INITIAL_PLACEMENT_SELECTED || $this->getInitialTestType() == self::TYPE_INITIAL_QUALIFYING_SELECTED;
143 }
144
148 public function hasSeparateQualifiedTests(): bool
149 {
151 }
152
156 public function isInitialTestQualifying(): bool
157 {
158 return $this->getInitialTestType() == self::TYPE_INITIAL_QUALIFYING_ALL || $this->getInitialTestType() == self::TYPE_INITIAL_QUALIFYING_SELECTED;
159 }
160
164 public static function isObjectiveTest(int $a_trst_ref_id): bool
165 {
166 global $DIC;
167
168 $ilDB = $DIC->database();
169 // Check for direct assignment
170 $query = 'SELECT obj_id FROM loc_settings ' .
171 'WHERE itest = ' . $ilDB->quote($a_trst_ref_id, 'integer') . ' ' .
172 'OR qtest = ' . $ilDB->quote($a_trst_ref_id, 'integer');
173 $res = $ilDB->query($query);
174 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
175 return $row->obj_id;
176 }
177 return (bool) ilLOTestAssignments::lookupContainerForTest($a_trst_ref_id);
178 }
179
180 public static function cloneSettings(int $a_copy_id, int $a_container_id, int $a_new_container_id): void
181 {
183 $mappings = $options->getMappings();
184
185 $settings = self::getInstanceByObjId($a_container_id);
186 $new_settings = self::getInstanceByObjId($a_new_container_id);
187
188 $new_settings->setType($settings->getType());
189 $new_settings->setInitialTestType($settings->getInitialTestType());
190 $new_settings->setQualifyingTestType($settings->getQualifyingTestType());
191 $new_settings->resetResults($settings->isResetResultsEnabled());
192 $new_settings->setPassedObjectiveMode($settings->getPassedObjectiveMode());
193
194 if ($settings->getInitialTest() && array_key_exists($settings->getInitialTest(), $mappings)) {
195 $new_settings->setInitialTest($mappings[$settings->getInitialTest()]);
196 $new_settings->setInitialTestAsStart($new_settings->isInitialTestStart());
197 }
198
199 if ($settings->getQualifiedTest() && array_key_exists($settings->getQualifiedTest(), $mappings)) {
200 $new_settings->setQualifiedTest($mappings[$settings->getQualifiedTest()]);
201 $new_settings->setQualifyingTestAsStart($settings->isQualifyingTestStart());
202 }
203
204 // update calls create in case of no entry exists.
205 $new_settings->update();
206 }
207
211 public function worksWithStartObjects(): bool
212 {
213 return $this->isInitialTestStart() || $this->isQualifyingTestStart();
214 }
215
219 public function worksWithInitialTest(): bool
220 {
222 }
223
224 public function isGeneralQualifiedTestVisible(): bool
225 {
227 }
228
229 public function getPassedObjectiveMode(): int
230 {
232 }
233
234 public function setPassedObjectiveMode(int $a_mode): void
235 {
236 $this->passed_objective_mode = $a_mode;
237 }
238
239 public function isGeneralInitialTestVisible(): bool
240 {
241 return
242 $this->getInitialTestType() === self::TYPE_INITIAL_PLACEMENT_ALL ||
244 }
245
246 public function settingsExist(): bool
247 {
248 return $this->entry_exists;
249 }
250
251 public function getObjId(): int
252 {
253 return $this->container_id;
254 }
255
256 public function setType(int $a_type): void
257 {
258 $this->type = $a_type;
259 }
260
261 public function getType(): int
262 {
263 return $this->type;
264 }
265
266 public function getTestByType(int $a_type): int
267 {
268 switch ($a_type) {
270 return $this->getInitialTest();
271
273 return $this->getQualifiedTest();
274 }
275 return 0;
276 }
277
278 public function getTests(): array
279 {
280 $tests = array();
281 if ($this->getInitialTest()) {
282 $tests[] = $this->getInitialTest();
283 }
284 if ($this->getQualifiedTest()) {
285 $tests[] = $this->getQualifiedTest();
286 }
287 return $tests;
288 }
289
290 public function isRandomTestType(int $a_type): bool
291 {
292 $tst = $this->getTestByType($a_type);
294 }
295
296 public function setInitialTest(int $a_id): void
297 {
298 $this->initial_test = $a_id;
299 }
300
301 public function getInitialTest(): int
302 {
303 return $this->initial_test;
304 }
305
306 public function setQualifiedTest(int $a_id): void
307 {
308 $this->qualified_test = $a_id;
309 }
310
311 public function getQualifiedTest(): int
312 {
314 }
315
316 public function resetResults(bool $a_status): void
317 {
318 $this->reset_results = $a_status;
319 }
320
321 public function isResetResultsEnabled(): bool
322 {
324 }
325
326 public function create(): void
327 {
328 $query = 'INSERT INTO loc_settings ' .
329 '(obj_id, it_type,itest,qtest,it_start,qt_type,qt_start,reset_results,passed_obj_mode) VALUES ( ' .
330 $this->db->quote($this->getObjId(), 'integer') . ', ' .
331 $this->db->quote($this->getInitialTestType(), 'integer') . ', ' .
332 $this->db->quote($this->getInitialTest(), 'integer') . ', ' .
333 $this->db->quote($this->getQualifiedTest(), 'integer') . ', ' .
334 $this->db->quote($this->isInitialTestStart(), 'integer') . ', ' .
335 $this->db->quote($this->getQualifyingTestType(), 'integer') . ', ' .
336 $this->db->quote($this->isQualifyingTestStart(), 'integer') . ', ' .
337 $this->db->quote($this->isResetResultsEnabled(), 'integer') . ', ' .
338 $this->db->quote($this->getPassedObjectiveMode(), 'integer') . ' ' .
339 ') ';
340 $this->db->manipulate($query);
341 $this->entry_exists = true;
342 }
343
344 public function update(): void
345 {
346 if (!$this->entry_exists) {
347 $this->create();
348 return;
349 }
350
351 $query = 'UPDATE loc_settings ' . ' ' .
352 'SET it_type = ' . $this->db->quote($this->getInitialTestType(), 'integer') . ', ' .
353 'itest = ' . $this->db->quote($this->getInitialTest(), 'integer') . ', ' .
354 'qtest = ' . $this->db->quote($this->getQualifiedTest(), 'integer') . ', ' .
355 'it_start = ' . $this->db->quote($this->isInitialTestStart(), 'integer') . ', ' .
356 'qt_type = ' . $this->db->quote($this->getQualifyingTestType(), 'integer') . ', ' .
357 'qt_start = ' . $this->db->quote($this->isQualifyingTestStart(), 'integer') . ', ' .
358 'reset_results = ' . $this->db->quote($this->isResetResultsEnabled(), 'integer') . ', ' .
359 'passed_obj_mode = ' . $this->db->quote($this->getPassedObjectiveMode(), 'integer') . ' ' .
360 'WHERE obj_id = ' . $this->db->quote($this->getObjId(), 'integer');
361
362 $this->db->manipulate($query);
363 }
364
370 public function updateStartObjects(ilContainerStartObjects $start): void
371 {
372 if ($this->getInitialTestType() != self::TYPE_INITIAL_NONE) {
373 if ($start->exists($this->getQualifiedTest())) {
374 $start->deleteItem($this->getQualifiedTest());
375 }
376 }
377
378 switch ($this->getInitialTestType()) {
381
382 if ($this->isInitialTestStart()) {
383 if (!$start->exists($this->getInitialTest())) {
384 $start->add($this->getInitialTest());
385 }
386 } else {
387 if ($start->exists($this->getInitialTest())) {
388 $start->deleteItem($this->getInitialTest());
389 }
390 }
391 break;
392
394
395 if ($start->exists($this->getInitialTest())) {
396 $start->deleteItem($this->getInitialTest());
397 }
398 break;
399
400 default:
401
402 $this->logger->debug('Type initial default');
403 if ($start->exists($this->getInitialTest())) {
404 $this->logger->debug('Old start object exists. Trying to delete');
405 $start->deleteItem($this->getInitialTest());
406 }
407 break;
408 }
409
410 switch ($this->getQualifyingTestType()) {
412
413 if ($this->isQualifyingTestStart()) {
414 if (!$start->exists($this->getQualifiedTest())) {
415 $start->add($this->getQualifiedTest());
416 }
417 }
418 break;
419
420 default:
421 if ($start->exists($this->getQualifiedTest())) {
422 $start->deleteItem($this->getQualifiedTest());
423 }
424 break;
425 }
426 }
427
431 protected function read(): void
432 {
433 $query = 'SELECT * FROM loc_settings ' .
434 'WHERE obj_id = ' . $this->db->quote($this->getObjId(), 'integer');
435 $res = $this->db->query($query);
436 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
437 $this->entry_exists = true;
438
439 $this->setInitialTestType((int) $row->it_type);
440 $this->setInitialTestAsStart((bool) $row->it_start);
441 $this->setQualifyingTestType((int) $row->qt_type);
442 $this->setQualifyingTestAsStart((bool) $row->qt_start);
443 $this->setInitialTest((int) $row->itest);
444 $this->setQualifiedTest((int) $row->qtest);
445 $this->resetResults((bool) $row->reset_results);
446 $this->setPassedObjectiveMode((int) $row->passed_obj_mode);
447 }
448
449 if ($this->tree->isDeleted($this->getInitialTest())) {
450 $this->setInitialTest(0);
451 }
452 if ($this->tree->isDeleted($this->getQualifiedTest())) {
453 $this->setQualifiedTest(0);
454 }
455 $this->purgeReferences();
456 }
457
458 protected function purgeReferences(): void
459 {
460 if ($this->getInitialTest() > 0) {
462 if (!$obj instanceof ilObjTest) {
463 $this->setInitialTest(0);
464 $this->update();
465 }
466 }
467 if ($this->getQualifiedTest() > 0) {
469 if (!$obj instanceof ilObjTest) {
470 $this->setQualifiedTest(0);
471 $this->update();
472 }
473 }
474 }
475
476
477 public function toXml(ilXmlWriter $writer): void
478 {
479 $writer->xmlElement(
480 'Settings',
481 array(
482 'initialTestType' => $this->getInitialTestType(),
483 'initialTestStart' => (int) $this->isInitialTestStart(),
484 'qualifyingTestType' => $this->getQualifyingTestType(),
485 'qualifyingTestStart' => (int) $this->isQualifyingTestStart(),
486 'resetResults' => (int) $this->isResetResultsEnabled(),
487 'passedObjectivesMode' => $this->getPassedObjectiveMode(),
488 'iTest' => $this->getInitialTest(),
489 'qTest' => $this->getQualifiedTest()
490 )
491 );
492 }
493}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getInstance(int $a_copy_id)
const FETCHMODE_OBJECT
Settings for LO courses.
const TYPE_INITIAL_QUALIFYING_ALL
setType(int $a_type)
const TYPE_INITIAL_PLACEMENT_SELECTED
hasSeparateQualifiedTests()
Check if separate qualified tests are configured.
static getInstanceByObjId(int $a_obj_id)
const HIDE_PASSED_OBJECTIVE_QST
isInitialTestQualifying()
Check if initial test is qualifying*.
isRandomTestType(int $a_type)
setQualifyingTestAsStart(bool $a_type)
setQualifyingTestType(int $a_type)
const TYPE_INITIAL_PLACEMENT_ALL
worksWithStartObjects()
Check if start objects are enabled.
getTestByType(int $a_type)
const MARK_PASSED_OBJECTIVE_QST
updateStartObjects(ilContainerStartObjects $start)
Update start objects Depends on course objective settings.
resetResults(bool $a_status)
static cloneSettings(int $a_copy_id, int $a_container_id, int $a_new_container_id)
__construct(int $a_cont_id)
worksWithInitialTest()
Check if the loc is configured for initial tests.
setInitialTest(int $a_id)
setQualifiedTest(int $a_id)
const TYPE_QUALIFYING_SELECTED
const TYPE_INITIAL_QUALIFYING_SELECTED
ilDBInterface $db
hasSeparateInitialTests()
Check if separate initial test are configured.
toXml(ilXmlWriter $writer)
setInitialTestType(int $a_type)
static array $instances
static isObjectiveTest(int $a_trst_ref_id)
Check if test ref_id is used in an objective course.
setInitialTestAsStart(bool $a_type)
setPassedObjectiveMode(int $a_mode)
static lookupContainerForTest(int $a_test_ref_id)
Component logger with individual log levels by component id.
static _lookupRandomTest(int $obj_id)
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
static _lookupObjId(int $ref_id)
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26