ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTestDynamicQuestionSet.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/TestQuestionPool/classes/class.ilAssQuestionList.php';
5 
16 {
20  private $db = null;
21 
25  private $lng = null;
26 
30  private $pluginAdmin = null;
31 
35  private $testOBJ = null;
36 
40  private $completeQuestionList = null;
41 
45  private $filteredQuestionList = null;
46 
50  private $actualQuestionSequence = array();
51 
58  {
59  $this->db = $db;
60  $this->lng = $lng;
61  $this->pluginAdmin = $pluginAdmin;
62  $this->testOBJ = $testOBJ;
63  }
64 
66 
67  public function load(ilObjTestDynamicQuestionSetConfig $dynamicQuestionSetConfig, ilTestDynamicQuestionSetFilterSelection $filterSelection)
68  {
69  $this->completeQuestionList = $this->initCompleteQuestionList(
70  $dynamicQuestionSetConfig, $filterSelection->getAnswerStatusActiveId()
71  );
72 
73  $this->filteredQuestionList = $this->initFilteredQuestionList(
74  $dynamicQuestionSetConfig, $filterSelection
75  );
76 
77  $this->actualQuestionSequence = $this->initActualQuestionSequence(
78  $dynamicQuestionSetConfig, $this->filteredQuestionList
79  );
80  }
81 
83 
84  private function initCompleteQuestionList(ilObjTestDynamicQuestionSetConfig $dynamicQuestionSetConfig, $answerStatusActiveId)
85  {
86  $questionList = new ilAssQuestionList(
87  $this->db, $this->lng, $this->pluginAdmin, $dynamicQuestionSetConfig->getSourceQuestionPoolId()
88  );
89 
90  $questionList->setAnswerStatusActiveId($answerStatusActiveId);
91 
92  $questionList->load();
93 
94  return $questionList;
95  }
96 
97  private function initFilteredQuestionList(ilObjTestDynamicQuestionSetConfig $dynamicQuestionSetConfig, ilTestDynamicQuestionSetFilterSelection $filterSelection)
98  {
99  $questionList = new ilAssQuestionList(
100  $this->db, $this->lng, $this->pluginAdmin, $dynamicQuestionSetConfig->getSourceQuestionPoolId()
101  );
102 
103  $questionList->setAnswerStatusActiveId($filterSelection->getAnswerStatusActiveId());
104 
105  if( $dynamicQuestionSetConfig->isAnswerStatusFilterEnabled() )
106  {
107  $questionList->setAnswerStatusFilter($filterSelection->getAnswerStatusSelection());
108  }
109 
110  if( $dynamicQuestionSetConfig->isTaxonomyFilterEnabled() )
111  {
112  require_once 'Services/Taxonomy/classes/class.ilObjTaxonomy.php';
113 
114  $questionList->setAvailableTaxonomyIds( ilObjTaxonomy::getUsageOfObject(
115  $dynamicQuestionSetConfig->getSourceQuestionPoolId()
116  ));
117 
118  foreach($filterSelection->getTaxonomySelection() as $taxId => $taxNodes)
119  {
120  $questionList->addTaxonomyFilter($taxId, $taxNodes);
121  }
122  }
123  elseif( $dynamicQuestionSetConfig->getOrderingTaxonomyId() )
124  {
125  $questionList->setAvailableTaxonomyIds( array(
126  $dynamicQuestionSetConfig->getOrderingTaxonomyId()
127  ));
128  }
129 
130  $questionList->setForcedQuestionIds($filterSelection->getForcedQuestionIds());
131 
132  $questionList->load();
133 
134  return $questionList;
135  }
136 
137  private function initActualQuestionSequence(ilObjTestDynamicQuestionSetConfig $dynamicQuestionSetConfig, ilAssQuestionList $questionList)
138  {
139  if( $dynamicQuestionSetConfig->getOrderingTaxonomyId() )
140  {
142  $questionList, $dynamicQuestionSetConfig->getOrderingTaxonomyId()
143  );
144  }
145 
146  return $this->getQuestionSequenceStructuredByUpdateDate($questionList);
147  }
148 
150 
151  private function getQuestionSequenceStructuredByTaxonomy(ilAssQuestionList $questionList, $orderingTaxId)
152  {
153  $questionsByNode = array();
154  $nodelessQuestions = array();
155 
156  foreach($questionList->getQuestionDataArray() as $qId => $qData)
157  {
158  if( isset($qData['taxonomies'][$orderingTaxId]) && count($qData['taxonomies'][$orderingTaxId]) )
159  {
160  foreach($qData['taxonomies'][$orderingTaxId] as $nodeId => $itemData)
161  {
162  $questionsByNode[ $itemData['node_lft'] ][ $itemData['order_nr'] ] = $qId;
163  break;
164  }
165  }
166  else
167  {
168  $nodelessQuestions[$qData['tstamp'].'::'.$qId] = $qId;
169  }
170  }
171 
172  foreach($questionsByNode as $nodeLft => $questions)
173  {
174  ksort($questions, SORT_NUMERIC);
175  $questionsByNode[$nodeLft] = array_values($questions);
176  }
177 
178  ksort($questionsByNode, SORT_NUMERIC);
179  $sequence = array_values($questionsByNode);
180 
181  ksort($nodelessQuestions);
182  $sequence[] = array_values($nodelessQuestions);
183 
184  return $sequence;
185  }
186 
188  {
189  $sequence = array();
190 
191  foreach($questionList->getQuestionDataArray() as $qId => $qData)
192  {
193  $sequence[ $qData['tstamp'].'::'.$qId ] = $qId;
194  }
195 
196  ksort($sequence);
197  $sequence = array_values($sequence);
198 
199  return array($sequence);
200  }
201 
203 
204  public function getActualQuestionSequence()
205  {
207  }
208 
209  public function questionExists($questionId)
210  {
211  $questionData = $this->completeQuestionList->getQuestionDataArray();
212  return isset($questionData[$questionId]);
213  }
214 
215  public function getQuestionData($questionId)
216  {
217  $questionData = $this->completeQuestionList->getQuestionDataArray();
218  return $questionData[$questionId];
219  }
220 
221  public function getAllQuestionsData()
222  {
223  return $this->completeQuestionList->getQuestionDataArray();
224  }
225 
227 
228  public function getCompleteQuestionList()
229  {
231  }
232 
233  public function getFilteredQuestionList()
234  {
236  }
237 }
238