ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 $selectionQuestionList = null;
46 
50  private $filteredQuestionList = null;
51 
56 
63  {
64  $this->db = $db;
65  $this->lng = $lng;
66  $this->pluginAdmin = $pluginAdmin;
67  $this->testOBJ = $testOBJ;
68  }
69 
71 
72  public function load(ilObjTestDynamicQuestionSetConfig $dynamicQuestionSetConfig, ilTestDynamicQuestionSetFilterSelection $filterSelection)
73  {
74  $this->completeQuestionList = $this->initCompleteQuestionList(
75  $dynamicQuestionSetConfig, $filterSelection->getAnswerStatusActiveId()
76  );
77 
78  $this->selectionQuestionList = $this->initSelectionQuestionList(
79  $dynamicQuestionSetConfig, $filterSelection
80  );
81 
82  $this->filteredQuestionList = $this->initFilteredQuestionList(
83  $dynamicQuestionSetConfig, $filterSelection
84  );
85 
86  $this->actualQuestionSequence = $this->initActualQuestionSequence(
87  $dynamicQuestionSetConfig, $this->filteredQuestionList
88  );
89  }
90 
92 
93  private function initCompleteQuestionList(ilObjTestDynamicQuestionSetConfig $dynamicQuestionSetConfig, $answerStatusActiveId)
94  {
95  $questionList = $this->buildQuestionList(
96  $dynamicQuestionSetConfig->getSourceQuestionPoolId(), $answerStatusActiveId
97  );
98 
99  $questionList->load();
100 
101  return $questionList;
102  }
103 
104  private function initFilteredQuestionList(ilObjTestDynamicQuestionSetConfig $dynamicQuestionSetConfig, ilTestDynamicQuestionSetFilterSelection $filterSelection)
105  {
106  $questionList = $this->buildQuestionList(
107  $dynamicQuestionSetConfig->getSourceQuestionPoolId(), $filterSelection->getAnswerStatusActiveId()
108  );
109 
110  if( $dynamicQuestionSetConfig->isAnswerStatusFilterEnabled() )
111  {
112  $questionList->setAnswerStatusFilter($filterSelection->getAnswerStatusSelection());
113  }
114 
115  if( $dynamicQuestionSetConfig->isTaxonomyFilterEnabled() )
116  {
117  require_once 'Services/Taxonomy/classes/class.ilObjTaxonomy.php';
118 
119  $questionList->setAvailableTaxonomyIds( ilObjTaxonomy::getUsageOfObject(
120  $dynamicQuestionSetConfig->getSourceQuestionPoolId()
121  ));
122 
123  foreach($filterSelection->getTaxonomySelection() as $taxId => $taxNodes)
124  {
125  $questionList->addTaxonomyFilter(
126  $taxId, $taxNodes, $this->testOBJ->getId(), $this->testOBJ->getType()
127  );
128  }
129  }
130  elseif( $dynamicQuestionSetConfig->getOrderingTaxonomyId() )
131  {
132  $questionList->setAvailableTaxonomyIds( array(
133  $dynamicQuestionSetConfig->getOrderingTaxonomyId()
134  ));
135  }
136 
137  $questionList->setForcedQuestionIds($filterSelection->getForcedQuestionIds());
138 
139  $questionList->load();
140 
141  return $questionList;
142  }
143 
150  {
151  $questionList = $this->buildQuestionList(
152  $dynamicQuestionSetConfig->getSourceQuestionPoolId(), $filterSelection->getAnswerStatusActiveId()
153  );
154 
155  if( $dynamicQuestionSetConfig->isTaxonomyFilterEnabled() )
156  {
157  require_once 'Services/Taxonomy/classes/class.ilObjTaxonomy.php';
158 
159  $questionList->setAvailableTaxonomyIds( ilObjTaxonomy::getUsageOfObject(
160  $dynamicQuestionSetConfig->getSourceQuestionPoolId()
161  ));
162 
163  foreach($filterSelection->getTaxonomySelection() as $taxId => $taxNodes)
164  {
165  $questionList->addTaxonomyFilter(
166  $taxId, $taxNodes, $this->testOBJ->getId(), $this->testOBJ->getType()
167  );
168  }
169  }
170 
171  $questionList->load();
172 
173  return $questionList;
174  }
175 
176  private function initActualQuestionSequence(ilObjTestDynamicQuestionSetConfig $dynamicQuestionSetConfig, ilAssQuestionList $questionList)
177  {
178  if( $dynamicQuestionSetConfig->getOrderingTaxonomyId() )
179  {
181  $questionList, $dynamicQuestionSetConfig->getOrderingTaxonomyId()
182  );
183  }
184 
185  return $this->getQuestionSequenceStructuredByUpdateDate($questionList);
186  }
187 
189 
190  private function getQuestionSequenceStructuredByTaxonomy(ilAssQuestionList $questionList, $orderingTaxId)
191  {
192  require_once 'Services/Taxonomy/classes/class.ilObjTaxonomy.php';
193  $tax = new ilObjTaxonomy($orderingTaxId);
194 
195  require_once 'Modules/Test/classes/class.ilTestTaxonomyTree.php';
196  $tree = new ilTestTaxonomyTree($orderingTaxId);
197  $tree->initOrderedTreeIndex($tax);
198 
199  $questionsByNode = array();
200  $nodelessQuestions = array();
201 
202  foreach($questionList->getQuestionDataArray() as $qId => $qData)
203  {
204  if( isset($qData['taxonomies'][$orderingTaxId]) && count($qData['taxonomies'][$orderingTaxId]) )
205  {
206  foreach($qData['taxonomies'][$orderingTaxId] as $nodeId => $itemData)
207  {
208  $nodeOrderingPath = $tree->getNodeOrderingPathString($itemData['node_id']);
209 
210  if( !isset($questionsByNode[ $nodeOrderingPath ]) )
211  {
212  $questionsByNode[ $nodeOrderingPath ] = array();
213  }
214 
215  if($tax->getItemSorting() == ilObjTaxonomy::SORT_MANUAL)
216  {
217  $questionsByNode[ $nodeOrderingPath ][$itemData['order_nr']] = $qId;
218  }
219  else
220  {
221  $questionsByNode[ $nodeOrderingPath ][$qData['title'].'::'.$qId] = $qId;
222  }
223  }
224  }
225  else
226  {
227  $nodelessQuestions[$qData['tstamp'].'::'.$qId] = $qId;
228  }
229  }
230 
231  foreach($questionsByNode as $path => $questions)
232  {
233  if($tax->getItemSorting() == ilObjTaxonomy::SORT_MANUAL)
234  {
235  ksort($questions, SORT_NUMERIC);
236  }
237  else
238  {
239  ksort($questions, SORT_STRING);
240  }
241 
242  $questionsByNode[$path] = array_values($questions);
243  }
244 
245  ksort($questionsByNode, SORT_STRING);
246  $sequence = array_values($questionsByNode);
247 
248  ksort($nodelessQuestions);
249  $sequence[] = array_values($nodelessQuestions);
250 
251  return $sequence;
252  }
253 
255  {
256  $sequence = array();
257 
258  foreach($questionList->getQuestionDataArray() as $qId => $qData)
259  {
260  $sequence[ $qData['tstamp'].'::'.$qId ] = $qId;
261  }
262 
263  ksort($sequence);
264  $sequence = array_values($sequence);
265 
266  return array($sequence);
267  }
268 
270 
271  public function getActualQuestionSequence()
272  {
274  }
275 
276  public function questionExists($questionId)
277  {
278  $questionData = $this->completeQuestionList->getQuestionDataArray();
279  return isset($questionData[$questionId]);
280  }
281 
282  public function getQuestionData($questionId)
283  {
284  $questionData = $this->completeQuestionList->getQuestionDataArray();
285  return $questionData[$questionId];
286  }
287 
288  public function getAllQuestionsData()
289  {
290  return $this->completeQuestionList->getQuestionDataArray();
291  }
292 
294 
298  public function getCompleteQuestionList()
299  {
301  }
302 
306  public function getSelectionQuestionList()
307  {
309  }
310 
314  public function getFilteredQuestionList()
315  {
317  }
318 
324  private function buildQuestionList($sourceQuestionPoolId, $answerStatusActiveId)
325  {
326  $questionList = new ilAssQuestionList($this->db, $this->lng, $this->pluginAdmin);
327  $questionList->setParentObjId($sourceQuestionPoolId);
328  $questionList->setAnswerStatusActiveId($answerStatusActiveId);
329  return $questionList;
330  }
331 }
332 
__construct(ilDBInterface $db, ilLanguage $lng, ilPluginAdmin $pluginAdmin, ilObjTest $testOBJ)
Constructor.
$path
Definition: aliased.php:25
initFilteredQuestionList(ilObjTestDynamicQuestionSetConfig $dynamicQuestionSetConfig, ilTestDynamicQuestionSetFilterSelection $filterSelection)
getQuestionSequenceStructuredByUpdateDate(ilAssQuestionList $questionList)
static getUsageOfObject($a_obj_id, $a_include_titles=false)
Get usage of object.
isTaxonomyFilterEnabled()
isser for taxonomie filter enabled
Administration class for plugins.
Interface ilDBInterface.
initActualQuestionSequence(ilObjTestDynamicQuestionSetConfig $dynamicQuestionSetConfig, ilAssQuestionList $questionList)
initSelectionQuestionList(ilObjTestDynamicQuestionSetConfig $dynamicQuestionSetConfig, ilTestDynamicQuestionSetFilterSelection $filterSelection)
getQuestionSequenceStructuredByTaxonomy(ilAssQuestionList $questionList, $orderingTaxId)
Create styles array
The data for the language used.
buildQuestionList($sourceQuestionPoolId, $answerStatusActiveId)
language handling
getSourceQuestionPoolId()
getter for source question pool id
initCompleteQuestionList(ilObjTestDynamicQuestionSetConfig $dynamicQuestionSetConfig, $answerStatusActiveId)
load(ilObjTestDynamicQuestionSetConfig $dynamicQuestionSetConfig, ilTestDynamicQuestionSetFilterSelection $filterSelection)