ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilLOSettings.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
11{
12 // new settings 5.1
13 const QST_PASSED_FLAG = 1;
14 const QST_PASSED_HIDE = 2;
15
21
24
25 // end new settings
26
30
31 const QT_VISIBLE_ALL = 0;
33
34
35 const LOC_INITIAL_ALL = 1;
36 const LOC_INITIAL_SEL = 2;
37 const LOC_QUALIFIED = 3;
38 const LOC_PRACTISE = 4;
39
42
43
44 private static $instances = array();
45
49 private $logger = null;
50
51
52 // settings 5.1
55
56 private $it_start = FALSE;
57 private $qt_start = FALSE;
58
59 // end settings 5.1
60
61 private $container_id = 0;
62 private $type = 0;
63 private $initial_test = 0;
64 private $qualified_test = 0;
65 private $reset_results = true;
67
68
69 private $entry_exists = false;
70
71
76 protected function __construct($a_cont_id)
77 {
78 $this->logger = $GLOBALS['DIC']->logger()->crs();
79
80 $this->container_id = $a_cont_id;
81 $this->read();
82 }
83
89 public static function getInstanceByObjId($a_obj_id)
90 {
91 if(self::$instances[$a_obj_id])
92 {
93 return self::$instances[$a_obj_id];
94 }
95 return self::$instances[$a_obj_id] = new ilLOSettings($a_obj_id);
96 }
97
103 {
104 $this->it_type = $a_type;
105 }
106
111 public function getInitialTestType()
112 {
113 return $this->it_type;
114 }
115
119 public function getQualifyingTestType()
120 {
121 return $this->qt_type;
122 }
123
129 {
130 $this->qt_type = $a_type;
131 }
132
138 {
139 $this->it_start = $a_type;
140 }
141
146 public function isInitialTestStart()
147 {
148 return $this->it_start;
149 }
150
156 {
157 $this->qt_start = $a_type;
158 }
159
164 public function isQualifyingTestStart()
165 {
166 return $this->qt_start;
167 }
168
172 public function hasSeparateInitialTests()
173 {
174 return $this->getInitialTestType() == self::TYPE_INITIAL_PLACEMENT_SELECTED || $this->getInitialTestType() == self::TYPE_INITIAL_QUALIFYING_SELECTED;
175 }
176
181 {
183 }
184
188 public function isInitialTestQualifying()
189 {
190 return $this->getInitialTestType() == self::TYPE_INITIAL_QUALIFYING_ALL || $this->getInitialTestType() == self::TYPE_INITIAL_QUALIFYING_SELECTED;
191 }
192
197 public static function isObjectiveTest($a_trst_ref_id)
198 {
199 global $ilDB;
200
201
202 // Check for direct assignment
203 $query = 'SELECT obj_id FROM loc_settings '.
204 'WHERE itest = '.$ilDB->quote($a_trst_ref_id,'integer').' '.
205 'OR qtest = '.$ilDB->quote($a_trst_ref_id,'integer');
206 $res = $ilDB->query($query);
207 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
208 {
209 return $row->obj_id;
210 }
211
212 include_once './Modules/Course/classes/Objectives/class.ilLOTestAssignments.php';
213 return ilLOTestAssignments::lookupContainerForTest($a_trst_ref_id);
214 }
215
222 public static function cloneSettings($a_copy_id, $a_container_id, $a_new_container_id)
223 {
224 include_once './Services/CopyWizard/classes/class.ilCopyWizardOptions.php';
226 $mappings = $options->getMappings();
227
228 $settings = self::getInstanceByObjId($a_container_id);
229 $new_settings = self::getInstanceByObjId($a_new_container_id);
230
231 $new_settings->setType($settings->getType());
232 $new_settings->setInitialTestType($settings->getInitialTestType());
233 $new_settings->setQualifyingTestType($settings->getQualifyingTestType());
234 $new_settings->resetResults($settings->isResetResultsEnabled());
235 $new_settings->setPassedObjectiveMode($settings->getPassedObjectiveMode());
236
237 if($settings->getInitialTest() and array_key_exists($settings->getInitialTest(), $mappings))
238 {
239 $new_settings->setInitialTest($mappings[$settings->getInitialTest()]);
240 $new_settings->setInitialTestAsStart($new_settings->isInitialTestStart());
241 }
242
243 if($settings->getQualifiedTest() and array_key_exists($settings->getQualifiedTest(), $mappings))
244 {
245 $new_settings->setQualifiedTest($mappings[$settings->getQualifiedTest()]);
246 $new_settings->setQualifyingTestAsStart($settings->isQualifyingTestStart());
247 }
248
249 // update calls create in case of no entry exists.
250 $new_settings->update();
251 }
252
256 public function worksWithStartObjects()
257 {
258 return $this->isInitialTestStart() or $this->isQualifyingTestStart();
259 }
260
261
265 public function worksWithInitialTest()
266 {
268 }
269
275 {
277 }
278
282 public function setGeneralQualifiedTestVisibility($a_stat)
283 {
284 $this->qt_visible_all = $a_stat;
285 return true;
286 }
287
289 {
291 }
292
294 {
295 $this->qt_visible_lo = $a_stat;
296 }
297
298 public function getPassedObjectiveMode()
299 {
300 return $this->passed_objective_mode;
301 }
302
303 public function setPassedObjectiveMode($a_mode)
304 {
305 $this->passed_objective_mode = $a_mode;
306 }
307
313 {
314 return $this->getInitialTestType() == self::TYPE_INITIAL_PLACEMENT_ALL || $this->getInitialTestType() == self::TYPE_INITIAL_QUALIFYING_ALL;
315 }
316
321 public function settingsExist()
322 {
323 return $this->entry_exists;
324 }
325
326 public function getObjId()
327 {
328 return $this->container_id;
329 }
330
331 public function setType($a_type)
332 {
333 $this->type = $a_type;
334 }
335
336 public function getType()
337 {
338 return $this->type;
339 }
340
347 public function getTestByType($a_type)
348 {
349 switch($a_type)
350 {
352 return $this->getInitialTest();
353
355 return $this->getQualifiedTest();
356 }
357 }
358
364 public function getTests()
365 {
366 $tests = array();
367 if($this->getInitialTest())
368 {
369 $tests[] = $this->getInitialTest();
370 }
371 if($this->getQualifiedTest())
372 {
373 $tests[] = $this->getQualifiedTest();
374 }
375 return $tests;
376 }
377
384 public function isRandomTestType($a_type)
385 {
386 $tst = $this->getTestByType($a_type);
387 include_once './Modules/Test/classes/class.ilObjTest.php';
389 }
390
396 public function setInitialTest($a_id)
397 {
398 $this->initial_test = $a_id;
399 }
400
406 public function getInitialTest()
407 {
408 return $this->initial_test;
409 }
410
416 public function setQualifiedTest($a_id)
417 {
418 $this->qualified_test = $a_id;
419 }
420
426 public function getQualifiedTest()
427 {
429 }
430
435 public function resetResults($a_status)
436 {
437 $this->reset_results = $a_status;
438 }
439
444 public function isResetResultsEnabled()
445 {
446 return (bool) $this->reset_results;
447 }
448
452 public function create()
453 {
454 global $ilDB;
455
456 $query = 'INSERT INTO loc_settings '.
457 '(obj_id, it_type,itest,qtest,it_start,qt_type,qt_start,reset_results,passed_obj_mode) VALUES ( '.
458 $ilDB->quote($this->getObjId(),'integer').', '.
459 $ilDB->quote($this->getInitialTestType(),'integer').', '.
460 $ilDB->quote($this->getInitialTest(),'integer').', '.
461 $ilDB->quote($this->getQualifiedTest(),'integer').', '.
462 $ilDB->quote($this->isInitialTestStart(),'integer').', '.
463 $ilDB->quote($this->getQualifyingTestType(),'integer').', '.
464 $ilDB->quote($this->isQualifyingTestStart(),'integer').', '.
465 $ilDB->quote($this->isResetResultsEnabled(),'integer').', '.
466 $ilDB->quote($this->getPassedObjectiveMode(),'integer').' '.
467 ') ';
468 $ilDB->manipulate($query);
469
470 $this->entry_exists = true;
471 }
472
473
478 public function update()
479 {
480 global $ilDB;
481
482 if(!$this->entry_exists)
483 {
484 return $this->create();
485 }
486
487 $query = 'UPDATE loc_settings '.' '.
488 'SET it_type = '.$ilDB->quote($this->getInitialTestType(),'integer').', '.
489 'itest = '.$ilDB->quote($this->getInitialTest(),'integer').', '.
490 'qtest = '.$ilDB->quote($this->getQualifiedTest(),'integer').', '.
491 'it_start = '.$ilDB->quote($this->isInitialTestStart(),'integer').', '.
492 'qt_type = '.$ilDB->quote($this->getQualifyingTestType(),'integer').', '.
493 'qt_start = '.$ilDB->quote($this->isQualifyingTestStart(),'integer').', '.
494 'reset_results = '.$ilDB->quote($this->isResetResultsEnabled(),'integer').', '.
495 'passed_obj_mode = '.$ilDB->quote($this->getPassedObjectiveMode(),'integer').' '.
496 'WHERE obj_id = '.$ilDB->quote($this->getObjId(),'integer');
497
498 $ilDB->manipulate($query);
499 }
500
508 {
509 if($this->getInitialTestType() != self::TYPE_INITIAL_NONE)
510 {
511 if($start->exists($this->getQualifiedTest()))
512 {
513 $start->deleteItem($this->getQualifiedTest());
514 }
515 }
516
517 switch($this->getInitialTestType())
518 {
521
522 if($this->isInitialTestStart())
523 {
524 if(!$start->exists($this->getInitialTest()))
525 {
526 $start->add($this->getInitialTest());
527 }
528 }
529 else
530 {
531 if($start->exists($this->getInitialTest()))
532 {
533 $start->deleteItem($this->getInitialTest());
534 }
535 }
536 break;
537
539
540 if($start->exists($this->getInitialTest()))
541 {
542 $start->deleteItem($this->getInitialTest());
543 }
544 break;
545
546 default:
547
548 $this->logger->debug('Type initial default');
549 if($start->exists($this->getInitialTest()))
550 {
551 $this->logger->debug('Old start object exists. Trying to delete');
552 $start->deleteItem($this->getInitialTest());
553 }
554 break;
555 }
556
557 switch($this->getQualifyingTestType())
558 {
560
561 if($this->isQualifyingTestStart())
562 {
563 if(!$start->exists($this->getQualifiedTest()))
564 {
565 $start->add($this->getQualifiedTest());
566 }
567 }
568 break;
569
570 default:
571 if($start->exists($this->getQualifiedTest()))
572 {
573 $start->deleteItem($this->getQualifiedTest());
574 }
575 break;
576 }
577 return TRUE;
578 }
579
580
584 protected function read()
585 {
586 global $ilDB;
587
588 $query = 'SELECT * FROM loc_settings '.
589 'WHERE obj_id = '.$ilDB->quote($this->getObjId(),'integer');
590 $res = $ilDB->query($query);
591 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
592 {
593 $this->entry_exists = true;
594
595 $this->setInitialTestType($row->it_type);
596 $this->setInitialTestAsStart((bool) $row->it_start);
597 $this->setQualifyingTestType($row->qt_type);
598 $this->setQualifyingTestAsStart($row->qt_start);
599
600 #$this->setType($row->type);
601 $this->setInitialTest($row->itest);
602 $this->setQualifiedTest($row->qtest);
603 #$this->setGeneralQualifiedTestVisibility($row->qt_vis_all);
604 #$this->setQualifiedTestPerObjectiveVisibility($row->qt_vis_obj);
605 $this->resetResults($row->reset_results);
606 $this->setPassedObjectiveMode($row->passed_obj_mode);
607 }
608
609 if($GLOBALS['tree']->isDeleted($this->getInitialTest()))
610 {
611 $this->setInitialTest(0);
612 }
613 if($GLOBALS['tree']->isDeleted($this->getQualifiedTest()))
614 {
615 $this->setQualifiedTest(0);
616 }
617 }
618
623 public function toXml(ilXmlWriter $writer)
624 {
625 $writer->xmlElement(
626 'Settings',
627 array(
628 'initialTestType' => (int) $this->getInitialTestType(),
629 'initialTestStart' => (int) $this->isInitialTestStart(),
630 'qualifyingTestType' => (int) $this->getQualifyingTestType(),
631 'qualifyingTestStart' => (int) $this->isQualifyingTestStart(),
632 'resetResults' => (int) $this->isResetResultsEnabled(),
633 'passedObjectivesMode' => (int) $this->getPassedObjectiveMode(),
634 'iTest' => (int) $this->getInitialTest(),
635 'qTest' => (int) $this->getQualifiedTest()
636 )
637 );
638
639 }
640}
641?>
An exception for terminatinating execution or to throw for unit testing.
static _getInstance($a_copy_id)
Get instance of copy wizard options.
Settings for LO courses.
getTests()
Get assigned tests.
const TYPE_INITIAL_QUALIFYING_ALL
setQualifiedTestPerObjectiveVisibility($a_stat)
update()
update settings @global type $ilDB
setQualifyingTestType($a_type)
Set qualifying test type.
const TYPE_INITIAL_PLACEMENT_SELECTED
hasSeparateQualifiedTests()
Check if separate qualified tests are configured.
getInitialTestType()
Get initial test type.
const HIDE_PASSED_OBJECTIVE_QST
isInitialTestQualifying()
Check if initial test is qualifying*.
isInitialTestStart()
Get initial test start.
const TYPE_INITIAL_PLACEMENT_ALL
setGeneralQualifiedTestVisibility($a_stat)
worksWithStartObjects()
Check if start objects are enabled.
isRandomTestType($a_type)
Check if test is of type random test.
setInitialTestType($a_type)
Set Initial test type.
getInitialTest()
get initial test
setInitialTestAsStart($a_type)
const MARK_PASSED_OBJECTIVE_QST
setInitialTest($a_id)
set initial test id
updateStartObjects(ilContainerStartObjects $start)
Update start objects Depends on course objective settings.
resetResults($a_status)
reset results
worksWithInitialTest()
Check if the loc is configured for initial tests.
setPassedObjectiveMode($a_mode)
__construct($a_cont_id)
Constructor.
const TYPE_QUALIFYING_SELECTED
static cloneSettings($a_copy_id, $a_container_id, $a_new_container_id)
Clone settings.
const TYPE_INITIAL_QUALIFYING_SELECTED
isGeneralInitialTestVisible()
Check if initial test for all objectives is visible.
static isObjectiveTest($a_trst_ref_id)
Check if test ref_id is used in an objective course.
isResetResultsEnabled()
check if reset result is enabled
setQualifyingTestAsStart($a_type)
Set qt as start object.
static getInstanceByObjId($a_obj_id)
get singleton instance
isQualifyingTestStart()
Is qt start object.
create()
Create new entry.
hasSeparateInitialTests()
Check if separate initial test are configured.
toXml(ilXmlWriter $writer)
export to xml
setQualifiedTest($a_id)
set qualified test
isGeneralQualifiedTestVisible()
Check if qualified test for all objectives is visible.
getQualifiedTest()
get qualified test
getQualifyingTestType()
Get qualifying test type.
static lookupContainerForTest($a_test_ref_id)
static _lookupRandomTest($a_obj_id)
Returns the fact wether the test with passed obj id is a random questions test or not.
static _lookupObjId($a_id)
XML writer class.
xmlElement($tag, $attrs=NULL, $data=Null, $encode=TRUE, $escape=TRUE)
Writes a basic element (no children, just textual content)
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
global $ilDB
if(!is_array($argv)) $options
$a_type
Definition: workflow.php:93