1<?php 2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */ 3 4require_once 'Modules/Test/classes/class.ilTestQuestionSetConfig.php'; 5 6/** 7 * class that manages/holds the data for a question set configuration for continues tests 8 * 9 * @author Björn Heyser <bheyser@databay.de> 10 * @version $Id$ 11 * 12 * @package Modules/Test 13 */ 14class ilTestFixedQuestionSetConfig extends ilTestQuestionSetConfig 15{ 16 /** 17 * returns the fact wether a useable question set config exists or not 18 * 19 * @return boolean 20 */ 21 public function isQuestionSetConfigured() 22 { 23 if (count($this->testOBJ->questions)) { 24 return true; 25 } 26 27 return false; 28 } 29 30 /** 31 * returns the fact wether a useable question set config exists or not 32 * 33 * @return boolean 34 */ 35 public function doesQuestionSetRelatedDataExist() 36 { 37 return $this->isQuestionSetConfigured(); 38 } 39 40 /** 41 * removes all question set config related data 42 */ 43 public function removeQuestionSetRelatedData() 44 { 45 $res = $this->db->queryF( 46 "SELECT question_fi FROM tst_test_question WHERE test_fi = %s", 47 array('integer'), 48 array($this->testOBJ->getTestId()) 49 ); 50 51 while ($row = $this->db->fetchAssoc($res)) { 52 $this->testOBJ->removeQuestion($row["question_fi"]); 53 } 54 55 $this->db->manipulateF( 56 "DELETE FROM tst_test_question WHERE test_fi = %s", 57 array('integer'), 58 array($this->testOBJ->getTestId()) 59 ); 60 61 $this->testOBJ->questions = array(); 62 63 $this->testOBJ->saveCompleteStatus($this); 64 } 65 66 public function resetQuestionSetRelatedTestSettings() 67 { 68 // nothing to do 69 } 70 71 /** 72 * removes all question set config related data for cloned/copied test 73 * 74 * @param ilObjTest $cloneTestOBJ 75 */ 76 public function cloneQuestionSetRelatedData(ilObjTest $cloneTestOBJ) 77 { 78 global $DIC; 79 $ilLog = $DIC['ilLog']; 80 81 require_once 'Services/CopyWizard/classes/class.ilCopyWizardOptions.php'; 82 require_once 'Modules/TestQuestionPool/classes/class.assQuestion.php'; 83 84 $cwo = ilCopyWizardOptions::_getInstance($cloneTestOBJ->getTmpCopyWizardCopyId()); 85 86 foreach ($this->testOBJ->questions as $key => $question_id) { 87 $question = assQuestion::_instanciateQuestion($question_id); 88 $cloneTestOBJ->questions[$key] = $question->duplicate(true, null, null, null, $cloneTestOBJ->getId()); 89 90 $original_id = assQuestion::_getOriginalId($question_id); 91 92 $question = assQuestion::_instanciateQuestion($cloneTestOBJ->questions[$key]); 93 $question->saveToDb($original_id); 94 95 // Save the mapping of old question id <-> new question id 96 // This will be used in class.ilObjCourse::cloneDependencies to copy learning objectives 97 $originalKey = $this->testOBJ->getRefId() . '_question_' . $question_id; 98 $mappedKey = $cloneTestOBJ->getRefId() . '_question_' . $cloneTestOBJ->questions[$key]; 99 $cwo->appendMapping($originalKey, $mappedKey); 100 $ilLog->write(__METHOD__ . ": Added question id mapping $originalKey <-> $mappedKey"); 101 } 102 } 103 104 /** 105 * loads the question set config for current test from the database 106 */ 107 public function loadFromDb() 108 { 109 // TODO: Implement loadFromDb() method. 110 } 111 112 /** 113 * saves the question set config for current test to the database 114 */ 115 public function saveToDb() 116 { 117 // TODO: Implement saveToDb() method. 118 } 119 120 /** 121 * @return ilTestReindexedSequencePositionMap 122 */ 123 public function reindexQuestionOrdering() 124 { 125 $query = " 126 SELECT question_fi, sequence FROM tst_test_question 127 WHERE test_fi = %s 128 ORDER BY sequence ASC 129 "; 130 131 $res = $this->db->queryF( 132 $query, 133 array('integer'), 134 array($this->testOBJ->getTestId()) 135 ); 136 137 $sequenceIndex = 0; 138 139 require_once 'Modules/Test/classes/class.ilTestReindexedSequencePositionMap.php'; 140 $reindexedSequencePositionMap = new ilTestReindexedSequencePositionMap(); 141 142 while ($row = $this->db->fetchAssoc($res)) { 143 $sequenceIndex++; // start with 1 144 145 $reindexedSequencePositionMap->addPositionMapping($row['sequence'], $sequenceIndex); 146 147 $this->db->update( 148 'tst_test_question', 149 array('sequence' => array('integer', $sequenceIndex)), 150 array('question_fi' => array('integer', $row['question_fi'])) 151 ); 152 } 153 154 return $reindexedSequencePositionMap; 155 } 156 157 /** 158 * saves the question set config for test with given id to the database 159 * 160 * @param $testId 161 */ 162 public function cloneToDbForTestId($testId) 163 { 164 // TODO: Implement saveToDbByTestId() method. 165 } 166 167 /** 168 * deletes the question set config for current test from the database 169 */ 170 public function deleteFromDb() 171 { 172 // TODO: Implement deleteFromDb() method. 173 } 174 175 public function isResultTaxonomyFilterSupported() 176 { 177 return false; 178 } 179} 180