ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilTestVirtualSequence.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Modules/Test/interfaces/interface.ilTestQuestionSequence.php';
5 
13 {
17  protected $db;
18 
22  protected $testOBJ;
23 
28 
32  protected $activeId;
33 
37  protected $questionsPassMap;
38 
40  {
41  $this->db = $db;
42  $this->testOBJ = $testOBJ;
43  $this->testSequenceFactory = $testSequenceFactory;
44 
45  $this->activeId = null;
46 
47  $this->questionsPassMap = array();
48  }
49 
50  public function getActiveId()
51  {
52  return $this->activeId;
53  }
54 
55  public function setActiveId($activeId)
56  {
57  $this->activeId = $activeId;
58  }
59 
60  public function getQuestionIds()
61  {
62  return array_keys($this->questionsPassMap);
63  }
64 
65  public function getQuestionsPassMap()
66  {
68  }
69 
70  public function getUniquePasses()
71  {
72  return array_unique(array_values($this->questionsPassMap));
73  }
74 
75  public function init()
76  {
77  $passes = $this->getExistingPassesDescendent($this->getActiveId());
78  $this->fetchQuestionsFromPasses($this->getActiveId(), $passes);
79  }
80 
82  {
83  require_once 'Modules/Test/classes/class.ilTestPassesSelector.php';
84  $passesSelector = new ilTestPassesSelector($this->db, $this->testOBJ);
85  $passesSelector->setActiveId($activeId);
86 
87  $passes = $passesSelector->getExistingPasses();
88 
89  rsort($passes, SORT_NUMERIC);
90 
91  return $passes;
92  }
93 
94  protected function getTestSequence($activeId, $pass)
95  {
96  $testSequence = $this->testSequenceFactory->getSequenceByActiveIdAndPass($activeId, $pass);
97 
98  $testSequence->loadFromDb();
99  $testSequence->loadQuestions();
100 
101  $testSequence->setConsiderHiddenQuestionsEnabled(true);
102  $testSequence->setConsiderOptionalQuestionsEnabled(true);
103  return $testSequence;
104  }
105 
106  protected function wasAnsweredInThisPass(ilTestSequence $testSequence, $questionId)
107  {
108  if( $testSequence->isHiddenQuestion($questionId) )
109  {
110  return false;
111  }
112 
113  if( !$testSequence->isQuestionOptional($questionId) )
114  {
115  return true;
116  }
117 
118  if( $testSequence->isAnsweringOptionalQuestionsConfirmed() )
119  {
120  return true;
121  }
122 
123  return false;
124  }
125 
126  protected function fetchQuestionsFromPasses($activeId, $passes)
127  {
128  $this->questionsPassMap = array();
129 
130  foreach($passes as $pass)
131  {
132  $testSequence = $this->getTestSequence($activeId, $pass);
133 
134  foreach($testSequence->getOrderedSequenceQuestions() as $questionId)
135  {
136  if(isset($this->questionsPassMap[$questionId]))
137  {
138  continue;
139  }
140 
141  if($this->wasAnsweredInThisPass($testSequence, $questionId))
142  {
143  $this->questionsPassMap[$questionId] = $pass;
144  }
145  }
146  }
147  }
148 }
isQuestionOptional($questionId)
fetchQuestionsFromPasses($activeId, $passes)
Test sequence handler.
Interface ilDBInterface.
Create styles array
The data for the language used.
isHiddenQuestion($question_id)
wasAnsweredInThisPass(ilTestSequence $testSequence, $questionId)
__construct(ilDBInterface $db, ilObjTest $testOBJ, ilTestSequenceFactory $testSequenceFactory)