1<?php 2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */ 3 4/** 5 * Factory for test question set config 6 * 7 * @author Björn Heyser <bheyser@databay.de> 8 * @version $Id$ 9 * 10 * @package Modules/Test 11 */ 12class ilTestQuestionSetConfigFactory 13{ 14 /** 15 * singleton instance of test question set config 16 * 17 * @var ilTestQuestionSetConfig 18 */ 19 private $testQuestionSetConfig = null; 20 21 /** 22 * global $tree object instance 23 * 24 * @var ilTree 25 */ 26 private $tree = null; 27 28 /** 29 * object instance of $ilDB 30 * 31 * @var ilDBInterface 32 */ 33 private $db = null; 34 35 /** 36 * object instance of $ilPluginAdmin 37 * 38 * @var ilPluginAdmin 39 */ 40 private $pluginAdmin = null; 41 42 /** 43 * object instance of current test 44 * 45 * @var ilObjTest 46 */ 47 private $testOBJ = null; 48 49 /** 50 * constructor 51 * 52 * @param ilObjTest $testOBJ 53 */ 54 public function __construct(ilTree $tree, ilDBInterface $db, ilPluginAdmin $pluginAdmin, ilObjTest $testOBJ) 55 { 56 $this->tree = $tree; 57 $this->db = $db; 58 $this->pluginAdmin = $pluginAdmin; 59 $this->testOBJ = $testOBJ; 60 } 61 62 /** 63 * creates and returns an instance of a test question set config 64 * that corresponds to the test's current question set type (test mode) 65 * 66 * @return ilTestQuestionSetConfig 67 */ 68 public function getQuestionSetConfig() 69 { 70 return $this->getQuestionSetConfigByType($this->testOBJ->getQuestionSetType()); 71 } 72 73 /** 74 * creates and returns an instance of a test question set config 75 * that corresponds to the passed question set type (test mode) 76 * 77 * @return ilTestQuestionSetConfig 78 */ 79 public function getQuestionSetConfigByType($questionSetType) 80 { 81 if ($this->testQuestionSetConfig === null) { 82 switch ($questionSetType) { 83 case ilObjTest::QUESTION_SET_TYPE_FIXED: 84 85 require_once 'Modules/Test/classes/class.ilTestFixedQuestionSetConfig.php'; 86 $this->testQuestionSetConfig = new ilTestFixedQuestionSetConfig( 87 $this->tree, 88 $this->db, 89 $this->pluginAdmin, 90 $this->testOBJ 91 ); 92 break; 93 94 case ilObjTest::QUESTION_SET_TYPE_RANDOM: 95 96 require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetConfig.php'; 97 $this->testQuestionSetConfig = new ilTestRandomQuestionSetConfig( 98 $this->tree, 99 $this->db, 100 $this->pluginAdmin, 101 $this->testOBJ 102 ); 103 break; 104 105 case ilObjTest::QUESTION_SET_TYPE_DYNAMIC: 106 107 require_once 'Modules/Test/classes/class.ilObjTestDynamicQuestionSetConfig.php'; 108 $this->testQuestionSetConfig = new ilObjTestDynamicQuestionSetConfig( 109 $this->tree, 110 $this->db, 111 $this->pluginAdmin, 112 $this->testOBJ 113 ); 114 break; 115 } 116 117 $this->testQuestionSetConfig->loadFromDb(); 118 } 119 120 return $this->testQuestionSetConfig; 121 } 122} 123