ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
20  const TYPE_INITIAL_NONE = 5;
21 
24 
25  // end new settings
26 
28  const TYPE_TEST_INITIAL = 1;
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
53  private $it_type = self::TYPE_INITIAL_PLACEMENT_ALL;
54  private $qt_type = self::TYPE_QUALIFYING_ALL;
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;
66  private $passed_obj_mode = self::HIDE_PASSED_OBJECTIVE_QST;
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  return self::$instances[$a_obj_id];
93  }
94  return self::$instances[$a_obj_id] = new ilLOSettings($a_obj_id);
95  }
96 
101  public function setInitialTestType($a_type)
102  {
103  $this->it_type = $a_type;
104  }
105 
110  public function getInitialTestType()
111  {
112  return $this->it_type;
113  }
114 
118  public function getQualifyingTestType()
119  {
120  return $this->qt_type;
121  }
122 
128  {
129  $this->qt_type = $a_type;
130  }
131 
137  {
138  $this->it_start = $a_type;
139  }
140 
145  public function isInitialTestStart()
146  {
147  return $this->it_start;
148  }
149 
155  {
156  $this->qt_start = $a_type;
157  }
158 
163  public function isQualifyingTestStart()
164  {
165  return $this->qt_start;
166  }
167 
171  public function hasSeparateInitialTests()
172  {
173  return $this->getInitialTestType() == self::TYPE_INITIAL_PLACEMENT_SELECTED || $this->getInitialTestType() == self::TYPE_INITIAL_QUALIFYING_SELECTED;
174  }
175 
179  public function hasSeparateQualifiedTests()
180  {
181  return $this->getQualifyingTestType() == self::TYPE_QUALIFYING_SELECTED;
182  }
183 
187  public function isInitialTestQualifying()
188  {
189  return $this->getInitialTestType() == self::TYPE_INITIAL_QUALIFYING_ALL || $this->getInitialTestType() == self::TYPE_INITIAL_QUALIFYING_SELECTED;
190  }
191 
196  public static function isObjectiveTest($a_trst_ref_id)
197  {
198  global $ilDB;
199 
200 
201  // Check for direct assignment
202  $query = 'SELECT obj_id FROM loc_settings ' .
203  'WHERE itest = ' . $ilDB->quote($a_trst_ref_id, 'integer') . ' ' .
204  'OR qtest = ' . $ilDB->quote($a_trst_ref_id, 'integer');
205  $res = $ilDB->query($query);
206  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
207  return $row->obj_id;
208  }
209 
210  include_once './Modules/Course/classes/Objectives/class.ilLOTestAssignments.php';
211  return ilLOTestAssignments::lookupContainerForTest($a_trst_ref_id);
212  }
213 
220  public static function cloneSettings($a_copy_id, $a_container_id, $a_new_container_id)
221  {
222  include_once './Services/CopyWizard/classes/class.ilCopyWizardOptions.php';
224  $mappings = $options->getMappings();
225 
226  $settings = self::getInstanceByObjId($a_container_id);
227  $new_settings = self::getInstanceByObjId($a_new_container_id);
228 
229  $new_settings->setType($settings->getType());
230  $new_settings->setInitialTestType($settings->getInitialTestType());
231  $new_settings->setQualifyingTestType($settings->getQualifyingTestType());
232  $new_settings->resetResults($settings->isResetResultsEnabled());
233  $new_settings->setPassedObjectiveMode($settings->getPassedObjectiveMode());
234 
235  if ($settings->getInitialTest() and array_key_exists($settings->getInitialTest(), $mappings)) {
236  $new_settings->setInitialTest($mappings[$settings->getInitialTest()]);
237  $new_settings->setInitialTestAsStart($new_settings->isInitialTestStart());
238  }
239 
240  if ($settings->getQualifiedTest() and array_key_exists($settings->getQualifiedTest(), $mappings)) {
241  $new_settings->setQualifiedTest($mappings[$settings->getQualifiedTest()]);
242  $new_settings->setQualifyingTestAsStart($settings->isQualifyingTestStart());
243  }
244 
245  // update calls create in case of no entry exists.
246  $new_settings->update();
247  }
248 
252  public function worksWithStartObjects()
253  {
254  return $this->isInitialTestStart() or $this->isQualifyingTestStart();
255  }
256 
257 
261  public function worksWithInitialTest()
262  {
263  return $this->getInitialTestType() != self::TYPE_INITIAL_NONE;
264  }
265 
271  {
272  return $this->getQualifyingTestType() == self::TYPE_QUALIFYING_ALL;
273  }
274 
278  public function setGeneralQualifiedTestVisibility($a_stat)
279  {
280  $this->qt_visible_all = $a_stat;
281  return true;
282  }
283 
285  {
286  return $this->getQualifyingTestType() == self::TYPE_QUALIFYING_SELECTED;
287  }
288 
289  public function setQualifiedTestPerObjectiveVisibility($a_stat)
290  {
291  $this->qt_visible_lo = $a_stat;
292  }
293 
294  public function getPassedObjectiveMode()
295  {
296  return $this->passed_objective_mode;
297  }
298 
299  public function setPassedObjectiveMode($a_mode)
300  {
301  $this->passed_objective_mode = $a_mode;
302  }
303 
308  public function isGeneralInitialTestVisible()
309  {
310  return $this->getInitialTestType() == self::TYPE_INITIAL_PLACEMENT_ALL || $this->getInitialTestType() == self::TYPE_INITIAL_QUALIFYING_ALL;
311  }
312 
317  public function settingsExist()
318  {
319  return $this->entry_exists;
320  }
321 
322  public function getObjId()
323  {
324  return $this->container_id;
325  }
326 
327  public function setType($a_type)
328  {
329  $this->type = $a_type;
330  }
331 
332  public function getType()
333  {
334  return $this->type;
335  }
336 
343  public function getTestByType($a_type)
344  {
345  switch ($a_type) {
346  case self::TYPE_TEST_INITIAL:
347  return $this->getInitialTest();
348 
349  case self::TYPE_TEST_QUALIFIED:
350  return $this->getQualifiedTest();
351  }
352  }
353 
359  public function getTests()
360  {
361  $tests = array();
362  if ($this->getInitialTest()) {
363  $tests[] = $this->getInitialTest();
364  }
365  if ($this->getQualifiedTest()) {
366  $tests[] = $this->getQualifiedTest();
367  }
368  return $tests;
369  }
370 
377  public function isRandomTestType($a_type)
378  {
379  $tst = $this->getTestByType($a_type);
380  include_once './Modules/Test/classes/class.ilObjTest.php';
382  }
383 
389  public function setInitialTest($a_id)
390  {
391  $this->initial_test = $a_id;
392  }
393 
399  public function getInitialTest()
400  {
401  return $this->initial_test;
402  }
403 
409  public function setQualifiedTest($a_id)
410  {
411  $this->qualified_test = $a_id;
412  }
413 
419  public function getQualifiedTest()
420  {
421  return $this->qualified_test;
422  }
423 
428  public function resetResults($a_status)
429  {
430  $this->reset_results = $a_status;
431  }
432 
437  public function isResetResultsEnabled()
438  {
439  return (bool) $this->reset_results;
440  }
441 
445  public function create()
446  {
447  global $ilDB;
448 
449  $query = 'INSERT INTO loc_settings ' .
450  '(obj_id, it_type,itest,qtest,it_start,qt_type,qt_start,reset_results,passed_obj_mode) VALUES ( ' .
451  $ilDB->quote($this->getObjId(), 'integer') . ', ' .
452  $ilDB->quote($this->getInitialTestType(), 'integer') . ', ' .
453  $ilDB->quote($this->getInitialTest(), 'integer') . ', ' .
454  $ilDB->quote($this->getQualifiedTest(), 'integer') . ', ' .
455  $ilDB->quote($this->isInitialTestStart(), 'integer') . ', ' .
456  $ilDB->quote($this->getQualifyingTestType(), 'integer') . ', ' .
457  $ilDB->quote($this->isQualifyingTestStart(), 'integer') . ', ' .
458  $ilDB->quote($this->isResetResultsEnabled(), 'integer') . ', ' .
459  $ilDB->quote($this->getPassedObjectiveMode(), 'integer') . ' ' .
460  ') ';
461  $ilDB->manipulate($query);
462 
463  $this->entry_exists = true;
464  }
465 
466 
471  public function update()
472  {
473  global $ilDB;
474 
475  if (!$this->entry_exists) {
476  return $this->create();
477  }
478 
479  $query = 'UPDATE loc_settings ' . ' ' .
480  'SET it_type = ' . $ilDB->quote($this->getInitialTestType(), 'integer') . ', ' .
481  'itest = ' . $ilDB->quote($this->getInitialTest(), 'integer') . ', ' .
482  'qtest = ' . $ilDB->quote($this->getQualifiedTest(), 'integer') . ', ' .
483  'it_start = ' . $ilDB->quote($this->isInitialTestStart(), 'integer') . ', ' .
484  'qt_type = ' . $ilDB->quote($this->getQualifyingTestType(), 'integer') . ', ' .
485  'qt_start = ' . $ilDB->quote($this->isQualifyingTestStart(), 'integer') . ', ' .
486  'reset_results = ' . $ilDB->quote($this->isResetResultsEnabled(), 'integer') . ', ' .
487  'passed_obj_mode = ' . $ilDB->quote($this->getPassedObjectiveMode(), 'integer') . ' ' .
488  'WHERE obj_id = ' . $ilDB->quote($this->getObjId(), 'integer');
489 
490  $ilDB->manipulate($query);
491  }
492 
500  {
501  if ($this->getInitialTestType() != self::TYPE_INITIAL_NONE) {
502  if ($start->exists($this->getQualifiedTest())) {
503  $start->deleteItem($this->getQualifiedTest());
504  }
505  }
506 
507  switch ($this->getInitialTestType()) {
508  case self::TYPE_INITIAL_PLACEMENT_ALL:
509  case self::TYPE_INITIAL_QUALIFYING_ALL:
510 
511  if ($this->isInitialTestStart()) {
512  if (!$start->exists($this->getInitialTest())) {
513  $start->add($this->getInitialTest());
514  }
515  } else {
516  if ($start->exists($this->getInitialTest())) {
517  $start->deleteItem($this->getInitialTest());
518  }
519  }
520  break;
521 
522  case self::TYPE_INITIAL_NONE:
523 
524  if ($start->exists($this->getInitialTest())) {
525  $start->deleteItem($this->getInitialTest());
526  }
527  break;
528 
529  default:
530 
531  $this->logger->debug('Type initial default');
532  if ($start->exists($this->getInitialTest())) {
533  $this->logger->debug('Old start object exists. Trying to delete');
534  $start->deleteItem($this->getInitialTest());
535  }
536  break;
537  }
538 
539  switch ($this->getQualifyingTestType()) {
540  case self::TYPE_QUALIFYING_ALL:
541 
542  if ($this->isQualifyingTestStart()) {
543  if (!$start->exists($this->getQualifiedTest())) {
544  $start->add($this->getQualifiedTest());
545  }
546  }
547  break;
548 
549  default:
550  if ($start->exists($this->getQualifiedTest())) {
551  $start->deleteItem($this->getQualifiedTest());
552  }
553  break;
554  }
555  return true;
556  }
557 
558 
562  protected function read()
563  {
564  global $ilDB;
565 
566  $query = 'SELECT * FROM loc_settings ' .
567  'WHERE obj_id = ' . $ilDB->quote($this->getObjId(), 'integer');
568  $res = $ilDB->query($query);
569  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
570  $this->entry_exists = true;
571 
572  $this->setInitialTestType($row->it_type);
573  $this->setInitialTestAsStart((bool) $row->it_start);
574  $this->setQualifyingTestType($row->qt_type);
575  $this->setQualifyingTestAsStart($row->qt_start);
576 
577  #$this->setType($row->type);
578  $this->setInitialTest($row->itest);
579  $this->setQualifiedTest($row->qtest);
580  #$this->setGeneralQualifiedTestVisibility($row->qt_vis_all);
581  #$this->setQualifiedTestPerObjectiveVisibility($row->qt_vis_obj);
582  $this->resetResults($row->reset_results);
583  $this->setPassedObjectiveMode($row->passed_obj_mode);
584  }
585 
586  if ($GLOBALS['tree']->isDeleted($this->getInitialTest())) {
587  $this->setInitialTest(0);
588  }
589  if ($GLOBALS['tree']->isDeleted($this->getQualifiedTest())) {
590  $this->setQualifiedTest(0);
591  }
592  }
593 
598  public function toXml(ilXmlWriter $writer)
599  {
600  $writer->xmlElement(
601  'Settings',
602  array(
603  'initialTestType' => (int) $this->getInitialTestType(),
604  'initialTestStart' => (int) $this->isInitialTestStart(),
605  'qualifyingTestType' => (int) $this->getQualifyingTestType(),
606  'qualifyingTestStart' => (int) $this->isQualifyingTestStart(),
607  'resetResults' => (int) $this->isResetResultsEnabled(),
608  'passedObjectivesMode' => (int) $this->getPassedObjectiveMode(),
609  'iTest' => (int) $this->getInitialTest(),
610  'qTest' => (int) $this->getQualifiedTest()
611  )
612  );
613  }
614 }
static getInstanceByObjId($a_obj_id)
get singleton instance
update()
update settings type $ilDB
toXml(ilXmlWriter $writer)
export to xml
worksWithInitialTest()
Check if the loc is configured for initial tests.
getTests()
Get assigned tests.
const TYPE_INITIAL_QUALIFYING_SELECTED
static cloneSettings($a_copy_id, $a_container_id, $a_new_container_id)
Clone settings.
isGeneralQualifiedTestVisible()
Check if qualified test for all objectives is visible.
static _lookupRandomTest($a_obj_id)
Returns the fact wether the test with passed obj id is a random questions test or not...
setInitialTest($a_id)
set initial test id
isQualifyingTestStart()
Is qt start object.
getInitialTestType()
Get initial test type.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
updateStartObjects(ilContainerStartObjects $start)
Update start objects Depends on course objective settings.
Settings for LO courses.
static isObjectiveTest($a_trst_ref_id)
Check if test ref_id is used in an objective course.
XML writer class.
setQualifiedTestPerObjectiveVisibility($a_stat)
create()
Create new entry.
setPassedObjectiveMode($a_mode)
isResetResultsEnabled()
check if reset result is enabled
setQualifiedTest($a_id)
set qualified test
const HIDE_PASSED_OBJECTIVE_QST
deleteItem($a_item_ref_id)
Delete item by ref_id.
isGeneralInitialTestVisible()
Check if initial test for all objectives is visible.
$a_type
Definition: workflow.php:92
static _getInstance($a_copy_id)
Get instance of copy wizard options.
__construct($a_cont_id)
Constructor.
foreach($_POST as $key=> $value) $res
hasSeparateInitialTests()
Check if separate initial test are configured.
setQualifyingTestType($a_type)
Set qualifying test type.
static _lookupObjId($a_id)
const MARK_PASSED_OBJECTIVE_QST
isInitialTestQualifying()
Check if initial test is qualifying*.
$query
setInitialTestType($a_type)
Set Initial test type.
setGeneralQualifiedTestVisibility($a_stat)
getQualifiedTest()
get qualified test
Create styles array
The data for the language used.
static lookupContainerForTest($a_test_ref_id)
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
getQualifyingTestType()
Get qualifying test type.
getInitialTest()
get initial test
hasSeparateQualifiedTests()
Check if separate qualified tests are configured.
global $ilDB
isInitialTestStart()
Get initial test start.
setQualifyingTestAsStart($a_type)
Set qt as start object.
const TYPE_INITIAL_QUALIFYING_ALL
const TYPE_INITIAL_PLACEMENT_ALL
const TYPE_QUALIFYING_SELECTED
worksWithStartObjects()
Check if start objects are enabled.
setInitialTestAsStart($a_type)
isRandomTestType($a_type)
Check if test is of type random test.
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
resetResults($a_status)
reset results
const TYPE_INITIAL_PLACEMENT_SELECTED