ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 
46 
47  // settings 5.1
48  private $it_type = self::TYPE_INITIAL_PLACEMENT_ALL;
49  private $qt_type = self::TYPE_QUALIFYING_ALL;
50 
51  private $it_start = FALSE;
52  private $qt_start = FALSE;
53 
54  // end settings 5.1
55 
56  private $container_id = 0;
57  private $type = 0;
58  private $initial_test = 0;
59  private $qualified_test = 0;
60  private $reset_results = true;
61  private $passed_obj_mode = self::HIDE_PASSED_OBJECTIVE_QST;
62 
63 
64  private $entry_exists = false;
65 
66 
71  protected function __construct($a_cont_id)
72  {
73  $this->container_id = $a_cont_id;
74  $this->read();
75  }
76 
82  public static function getInstanceByObjId($a_obj_id)
83  {
84  if(self::$instances[$a_obj_id])
85  {
86  return self::$instances[$a_obj_id];
87  }
88  return self::$instances[$a_obj_id] = new ilLOSettings($a_obj_id);
89  }
90 
95  public function setInitialTestType($a_type)
96  {
97  $this->it_type = $a_type;
98  }
99 
104  public function getInitialTestType()
105  {
106  return $this->it_type;
107  }
108 
112  public function getQualifyingTestType()
113  {
114  return $this->qt_type;
115  }
116 
121  public function setQualifyingTestType($a_type)
122  {
123  $this->qt_type = $a_type;
124  }
125 
130  public function setInitialTestAsStart($a_type)
131  {
132  $this->it_start = $a_type;
133  }
134 
139  public function isInitialTestStart()
140  {
141  return $this->it_start;
142  }
143 
148  public function setQualifyingTestAsStart($a_type)
149  {
150  $this->qt_start = $a_type;
151  }
152 
157  public function isQualifyingTestStart()
158  {
159  return $this->qt_start;
160  }
161 
165  public function hasSeparateInitialTests()
166  {
167  return $this->getInitialTestType() == self::TYPE_INITIAL_PLACEMENT_SELECTED || $this->getInitialTestType() == self::TYPE_INITIAL_QUALIFYING_SELECTED;
168  }
169 
173  public function hasSeparateQualifiedTests()
174  {
175  return $this->getQualifyingTestType() == self::TYPE_QUALIFYING_SELECTED;
176  }
177 
181  public function isInitialTestQualifying()
182  {
183  return $this->getInitialTestType() == self::TYPE_INITIAL_QUALIFYING_ALL || $this->getInitialTestType() == self::TYPE_INITIAL_QUALIFYING_SELECTED;
184  }
185 
190  public static function isObjectiveTest($a_trst_ref_id)
191  {
192  global $ilDB;
193 
194 
195  // Check for direct assignment
196  $query = 'SELECT obj_id FROM loc_settings '.
197  'WHERE itest = '.$ilDB->quote($a_trst_ref_id,'integer').' '.
198  'OR qtest = '.$ilDB->quote($a_trst_ref_id,'integer');
199  $res = $ilDB->query($query);
200  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
201  {
202  return $row->obj_id;
203  }
204 
205  include_once './Modules/Course/classes/Objectives/class.ilLOTestAssignments.php';
206  return ilLOTestAssignments::lookupContainerForTest($a_trst_ref_id);
207  }
208 
215  public static function cloneSettings($a_copy_id, $a_container_id, $a_new_container_id)
216  {
217  include_once './Services/CopyWizard/classes/class.ilCopyWizardOptions.php';
219  $mappings = $options->getMappings();
220 
221  $settings = self::getInstanceByObjId($a_container_id);
222  $new_settings = self::getInstanceByObjId($a_new_container_id);
223 
224  $new_settings->setType($settings->getType());
225  $new_settings->setInitialTestType($settings->getInitialTestType());
226  $new_settings->setQualifyingTestType($settings->getQualifyingTestType());
227  $new_settings->resetResults($settings->isResetResultsEnabled());
228  $new_settings->setPassedObjectiveMode($settings->getPassedObjectiveMode());
229 
230  if($settings->getInitialTest() and array_key_exists($settings->getInitialTest(), $mappings))
231  {
232  $new_settings->setInitialTest($mappings[$settings->getInitialTest()]);
233  $new_settings->setInitialTestAsStart($new_settings->isInitialTestStart());
234  }
235 
236  if($settings->getQualifiedTest() and array_key_exists($settings->getQualifiedTest(), $mappings))
237  {
238  $new_settings->setQualifiedTest($mappings[$settings->getQualifiedTest()]);
239  $new_settings->setQualifyingTestAsStart($settings->isQualifyingTestStart());
240  }
241 
242  // update calls create in case of no entry exists.
243  $new_settings->update();
244  }
245 
249  public function worksWithStartObjects()
250  {
251  return $this->isInitialTestStart() or $this->isQualifyingTestStart();
252  }
253 
254 
258  public function worksWithInitialTest()
259  {
260  return $this->getInitialTestType() != self::TYPE_INITIAL_NONE;
261  }
262 
268  {
269  return $this->getQualifyingTestType() == self::TYPE_QUALIFYING_ALL;
270  }
271 
275  public function setGeneralQualifiedTestVisibility($a_stat)
276  {
277  $this->qt_visible_all = $a_stat;
278  return true;
279  }
280 
282  {
283  return $this->getQualifyingTestType() == self::TYPE_QUALIFYING_SELECTED;
284  }
285 
286  public function setQualifiedTestPerObjectiveVisibility($a_stat)
287  {
288  $this->qt_visible_lo = $a_stat;
289  }
290 
291  public function getPassedObjectiveMode()
292  {
293  return $this->passed_objective_mode;
294  }
295 
296  public function setPassedObjectiveMode($a_mode)
297  {
298  $this->passed_objective_mode = $a_mode;
299  }
300 
305  public function isGeneralInitialTestVisible()
306  {
307  return $this->getInitialTestType() == self::TYPE_INITIAL_PLACEMENT_ALL || $this->getInitialTestType() == self::TYPE_INITIAL_QUALIFYING_ALL;
308  }
309 
314  public function settingsExist()
315  {
316  return $this->entry_exists;
317  }
318 
319  public function getObjId()
320  {
321  return $this->container_id;
322  }
323 
324  public function setType($a_type)
325  {
326  $this->type = $a_type;
327  }
328 
329  public function getType()
330  {
331  return $this->type;
332  }
333 
340  public function getTestByType($a_type)
341  {
342  switch($a_type)
343  {
344  case self::TYPE_TEST_INITIAL:
345  return $this->getInitialTest();
346 
347  case self::TYPE_TEST_QUALIFIED:
348  return $this->getQualifiedTest();
349  }
350  }
351 
357  public function getTests()
358  {
359  $tests = array();
360  if($this->getInitialTest())
361  {
362  $tests[] = $this->getInitialTest();
363  }
364  if($this->getQualifiedTest())
365  {
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 
464 
469  public function update()
470  {
471  global $ilDB;
472 
473  if(!$this->entry_exists)
474  {
475  return $this->create();
476  }
477 
478  $query = 'UPDATE loc_settings '.' '.
479  'SET it_type = '.$ilDB->quote($this->getInitialTestType(),'integer').', '.
480  'itest = '.$ilDB->quote($this->getInitialTest(),'integer').', '.
481  'qtest = '.$ilDB->quote($this->getQualifiedTest(),'integer').', '.
482  'it_start = '.$ilDB->quote($this->isInitialTestStart(),'integer').', '.
483  'qt_type = '.$ilDB->quote($this->getQualifyingTestType(),'integer').', '.
484  'qt_start = '.$ilDB->quote($this->isQualifyingTestStart(),'integer').', '.
485  'reset_results = '.$ilDB->quote($this->isResetResultsEnabled(),'integer').', '.
486  'passed_obj_mode = '.$ilDB->quote($this->getPassedObjectiveMode(),'integer').' '.
487  'WHERE obj_id = '.$ilDB->quote($this->getObjId(),'integer');
488 
489  $ilDB->manipulate($query);
490  }
491 
499  {
500  if($this->getInitialTestType() != self::TYPE_INITIAL_NONE)
501  {
502  if($start->exists($this->getQualifiedTest()))
503  {
504  $start->deleteItem($this->getQualifiedTest());
505  }
506  }
507 
508  switch($this->getInitialTestType())
509  {
510  case self::TYPE_INITIAL_PLACEMENT_ALL:
511  case self::TYPE_INITIAL_QUALIFYING_ALL:
512 
513  if($this->isInitialTestStart())
514  {
515  if(!$start->exists($this->getInitialTest()))
516  {
517  $start->add($this->getInitialTest());
518  }
519  }
520  else
521  {
522  if($start->exists($this->getInitialTest()))
523  {
524  $start->deleteItem($this->getInitialTest());
525  }
526  }
527  break;
528 
529  case self::TYPE_INITIAL_NONE:
530 
531  if($start->exists($this->getInitialTest()))
532  {
533  $start->deleteItem($this->getInitialTest());
534  }
535  break;
536 
537  default:
538 
539  if($start->exists($this->getInitialTest()))
540  {
541  $start->deleteItem($this->getInitialTest());
542  }
543  break;
544  }
545 
546  switch($this->getQualifyingTestType())
547  {
548  case self::TYPE_QUALIFYING_ALL:
549 
550  if($this->isQualifyingTestStart())
551  {
552  if(!$start->exists($this->getQualifiedTest()))
553  {
554  $start->add($this->getQualifiedTest());
555  }
556  }
557  break;
558 
559  default:
560  if($start->exists($this->getQualifiedTest()))
561  {
562  $start->deleteItem($this->getQualifiedTest());
563  }
564  break;
565  }
566  return TRUE;
567  }
568 
569 
573  protected function read()
574  {
575  global $ilDB;
576 
577  $query = 'SELECT * FROM loc_settings '.
578  'WHERE obj_id = '.$ilDB->quote($this->getObjId(),'integer');
579  $res = $ilDB->query($query);
580  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
581  {
582  $this->entry_exists = true;
583 
584  $this->setInitialTestType($row->it_type);
585  $this->setInitialTestAsStart((bool) $row->it_start);
586  $this->setQualifyingTestType($row->qt_type);
587  $this->setQualifyingTestAsStart($row->qt_start);
588 
589  #$this->setType($row->type);
590  $this->setInitialTest($row->itest);
591  $this->setQualifiedTest($row->qtest);
592  #$this->setGeneralQualifiedTestVisibility($row->qt_vis_all);
593  #$this->setQualifiedTestPerObjectiveVisibility($row->qt_vis_obj);
594  $this->resetResults($row->reset_results);
595  $this->setPassedObjectiveMode($row->passed_obj_mode);
596  }
597 
598  if($GLOBALS['tree']->isDeleted($this->getInitialTest()))
599  {
600  $this->setInitialTest(0);
601  }
602  if($GLOBALS['tree']->isDeleted($this->getQualifiedTest()))
603  {
604  $this->setQualifiedTest(0);
605  }
606  }
607 
612  public function toXml(ilXmlWriter $writer)
613  {
614  $writer->xmlElement(
615  'Settings',
616  array(
617  'initialTestType' => (int) $this->getInitialTestType(),
618  'initialTestStart' => (int) $this->isInitialTestStart(),
619  'qualifyingTestType' => (int) $this->getQualifyingTestType(),
620  'qualifyingTestStart' => (int) $this->isQualifyingTestStart(),
621  'resetResults' => (int) $this->isResetResultsEnabled(),
622  'passedObjectivesMode' => (int) $this->getPassedObjectiveMode(),
623  'iTest' => (int) $this->getInitialTest(),
624  'qTest' => (int) $this->getQualifiedTest()
625  )
626  );
627 
628  }
629 }
630 ?>
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.
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.
xmlElement($tag, $attrs=NULL, $data=Null, $encode=TRUE, $escape=TRUE)
Writes a basic element (no children, just textual content)
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
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
deleteItem($a_item_ref_id)
Delete item by ref_id.
isGeneralInitialTestVisible()
Check if initial test for all objectives is visible.
static _getInstance($a_copy_id)
Get instance of copy wizard options.
__construct($a_cont_id)
Constructor.
hasSeparateInitialTests()
Check if separate initial test are configured.
if(!is_array($argv)) $options
setQualifyingTestType($a_type)
Set qualifying test type.
static _lookupObjId($a_id)
const MARK_PASSED_OBJECTIVE_QST
isInitialTestQualifying()
Check if initial test is qualifying*.
setInitialTestType($a_type)
Set Initial test type.
setGeneralQualifiedTestVisibility($a_stat)
getQualifiedTest()
get qualified test
static lookupContainerForTest($a_test_ref_id)
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
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
worksWithStartObjects()
Check if start objects are enabled.
setInitialTestAsStart($a_type)
isRandomTestType($a_type)
Check if test is of type random test.
resetResults($a_status)
reset results
const TYPE_INITIAL_PLACEMENT_SELECTED