ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilTestDynamicQuestionSet.php
Go to the documentation of this file.
1 <?php
2 
20 
28 {
29  private ilDBInterface $db;
30  private ilLanguage $lng;
37  private array $actualQuestionSequence = [];
38 
39  public function __construct(ilDBInterface $db, ilLanguage $lng, Refinery $refinery, ilComponentRepository $component_repository, ilObjTest $testOBJ)
40  {
41  $this->db = $db;
42  $this->lng = $lng;
43  $this->refinery = $refinery;
44  $this->component_repository = $component_repository;
45  $this->testOBJ = $testOBJ;
46  }
47 
49 
50  public function load(ilObjTestDynamicQuestionSetConfig $dynamicQuestionSetConfig, ilTestDynamicQuestionSetFilterSelection $filterSelection): void
51  {
52  $this->completeQuestionList = $this->initCompleteQuestionList(
53  $dynamicQuestionSetConfig,
54  $filterSelection->getAnswerStatusActiveId()
55  );
56 
57  $this->selectionQuestionList = $this->initSelectionQuestionList(
58  $dynamicQuestionSetConfig,
59  $filterSelection
60  );
61 
62  $this->filteredQuestionList = $this->initFilteredQuestionList(
63  $dynamicQuestionSetConfig,
64  $filterSelection
65  );
66 
67  $this->actualQuestionSequence = $this->initActualQuestionSequence(
68  $dynamicQuestionSetConfig,
69  $this->filteredQuestionList
70  );
71  }
72 
74 
75  private function initCompleteQuestionList(ilObjTestDynamicQuestionSetConfig $dynamicQuestionSetConfig, $answerStatusActiveId): ilAssQuestionList
76  {
77  $questionList = $this->buildQuestionList(
78  $dynamicQuestionSetConfig->getSourceQuestionPoolId(),
79  $answerStatusActiveId
80  );
81 
82  $questionList->load();
83 
84  return $questionList;
85  }
86 
88  {
89  $questionList = $this->buildQuestionList(
90  $dynamicQuestionSetConfig->getSourceQuestionPoolId(),
91  $filterSelection->getAnswerStatusActiveId()
92  );
93 
94  if ($dynamicQuestionSetConfig->isAnswerStatusFilterEnabled()) {
95  $questionList->setAnswerStatusFilter($filterSelection->getAnswerStatusSelection());
96  }
97 
98  if ($dynamicQuestionSetConfig->isTaxonomyFilterEnabled()) {
99  require_once 'Services/Taxonomy/classes/class.ilObjTaxonomy.php';
100 
101  $questionList->setAvailableTaxonomyIds(ilObjTaxonomy::getUsageOfObject(
102  $dynamicQuestionSetConfig->getSourceQuestionPoolId()
103  ));
104 
105  foreach ($filterSelection->getTaxonomySelection() as $taxId => $taxNodes) {
106  $questionList->addTaxonomyFilter(
107  $taxId,
108  $taxNodes,
109  $this->testOBJ->getId(),
110  $this->testOBJ->getType()
111  );
112  }
113  } elseif ($dynamicQuestionSetConfig->getOrderingTaxonomyId()) {
114  $questionList->setAvailableTaxonomyIds(array(
115  $dynamicQuestionSetConfig->getOrderingTaxonomyId()
116  ));
117  }
118 
119  $questionList->setForcedQuestionIds($filterSelection->getForcedQuestionIds());
120 
121  $questionList->load();
122 
123  return $questionList;
124  }
125 
132  {
133  $questionList = $this->buildQuestionList(
134  $dynamicQuestionSetConfig->getSourceQuestionPoolId(),
135  $filterSelection->getAnswerStatusActiveId()
136  );
137 
138  if ($dynamicQuestionSetConfig->isTaxonomyFilterEnabled()) {
139  require_once 'Services/Taxonomy/classes/class.ilObjTaxonomy.php';
140 
141  $questionList->setAvailableTaxonomyIds(ilObjTaxonomy::getUsageOfObject(
142  $dynamicQuestionSetConfig->getSourceQuestionPoolId()
143  ));
144 
145  foreach ($filterSelection->getTaxonomySelection() as $taxId => $taxNodes) {
146  $questionList->addTaxonomyFilter(
147  $taxId,
148  $taxNodes,
149  $this->testOBJ->getId(),
150  $this->testOBJ->getType()
151  );
152  }
153  }
154 
155  $questionList->load();
156 
157  return $questionList;
158  }
159 
160  private function initActualQuestionSequence(ilObjTestDynamicQuestionSetConfig $dynamicQuestionSetConfig, ilAssQuestionList $questionList): array
161  {
162  if ($dynamicQuestionSetConfig->getOrderingTaxonomyId()) {
164  $questionList,
165  $dynamicQuestionSetConfig->getOrderingTaxonomyId()
166  );
167  }
168 
169  return $this->getQuestionSequenceStructuredByUpdateDate($questionList);
170  }
171 
173 
174  private function getQuestionSequenceStructuredByTaxonomy(ilAssQuestionList $questionList, $orderingTaxId): array
175  {
176  require_once 'Services/Taxonomy/classes/class.ilObjTaxonomy.php';
177  $tax = new ilObjTaxonomy($orderingTaxId);
178 
179  require_once 'Modules/Test/classes/class.ilTestTaxonomyTree.php';
180  $tree = new ilTestTaxonomyTree($orderingTaxId);
181  $tree->initOrderedTreeIndex($tax);
182 
183  $questionsByNode = array();
184  $nodelessQuestions = array();
185 
186  foreach ($questionList->getQuestionDataArray() as $qId => $qData) {
187  if (isset($qData['taxonomies'][$orderingTaxId]) && count($qData['taxonomies'][$orderingTaxId])) {
188  foreach ($qData['taxonomies'][$orderingTaxId] as $nodeId => $itemData) {
189  $nodeOrderingPath = $tree->getNodeOrderingPathString($itemData['node_id']);
190 
191  if (!isset($questionsByNode[ $nodeOrderingPath ])) {
192  $questionsByNode[ $nodeOrderingPath ] = array();
193  }
194 
195  if ($tax->getItemSorting() == ilObjTaxonomy::SORT_MANUAL) {
196  $questionsByNode[ $nodeOrderingPath ][$itemData['order_nr']] = $qId;
197  } else {
198  $questionsByNode[ $nodeOrderingPath ][$qData['title'] . '::' . $qId] = $qId;
199  }
200  }
201  } else {
202  $nodelessQuestions[$qData['tstamp'] . '::' . $qId] = $qId;
203  }
204  }
205 
206  foreach ($questionsByNode as $path => $questions) {
207  if ($tax->getItemSorting() == ilObjTaxonomy::SORT_MANUAL) {
208  ksort($questions, SORT_NUMERIC);
209  } else {
210  ksort($questions, SORT_STRING);
211  }
212 
213  $questionsByNode[$path] = array_values($questions);
214  }
215 
216  ksort($questionsByNode, SORT_STRING);
217  $sequence = array_values($questionsByNode);
218 
219  ksort($nodelessQuestions);
220  $sequence[] = array_values($nodelessQuestions);
221 
222  return $sequence;
223  }
224 
225  private function getQuestionSequenceStructuredByUpdateDate(ilAssQuestionList $questionList): array
226  {
227  $sequence = array();
228 
229  foreach ($questionList->getQuestionDataArray() as $qId => $qData) {
230  $sequence[ $qData['tstamp'] . '::' . $qId ] = $qId;
231  }
232 
233  ksort($sequence);
234  $sequence = array_values($sequence);
235 
236  return array($sequence);
237  }
238 
240 
241  public function getActualQuestionSequence(): array
242  {
244  }
245 
246  public function questionExists($questionId): bool
247  {
248  $questionData = $this->completeQuestionList->getQuestionDataArray();
249  return isset($questionData[$questionId]);
250  }
251 
252  public function getQuestionData($questionId)
253  {
254  $questionData = $this->completeQuestionList->getQuestionDataArray();
255  return $questionData[$questionId];
256  }
257 
258  public function getAllQuestionsData(): array
259  {
260  return $this->completeQuestionList->getQuestionDataArray();
261  }
262 
264 
269  {
271  }
272 
277  {
279  }
280 
285  {
287  }
288 
294  private function buildQuestionList($sourceQuestionPoolId, $answerStatusActiveId): ilAssQuestionList
295  {
296  $questionList = new ilAssQuestionList($this->db, $this->lng, $this->refinery, $this->component_repository);
297  $questionList->setParentObjId($sourceQuestionPoolId);
298  $questionList->setAnswerStatusActiveId($answerStatusActiveId);
299  return $questionList;
300  }
301 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(ilDBInterface $db, ilLanguage $lng, Refinery $refinery, ilComponentRepository $component_repository, ilObjTest $testOBJ)
Readable part of repository interface to ilComponentDataDB.
initFilteredQuestionList(ilObjTestDynamicQuestionSetConfig $dynamicQuestionSetConfig, ilTestDynamicQuestionSetFilterSelection $filterSelection)
getQuestionSequenceStructuredByUpdateDate(ilAssQuestionList $questionList)
isTaxonomyFilterEnabled()
isser for taxonomie filter enabled
static getUsageOfObject(int $a_obj_id, bool $a_include_titles=false)
$path
Definition: ltiservices.php:32
initActualQuestionSequence(ilObjTestDynamicQuestionSetConfig $dynamicQuestionSetConfig, ilAssQuestionList $questionList)
initSelectionQuestionList(ilObjTestDynamicQuestionSetConfig $dynamicQuestionSetConfig, ilTestDynamicQuestionSetFilterSelection $filterSelection)
getQuestionSequenceStructuredByTaxonomy(ilAssQuestionList $questionList, $orderingTaxId)
buildQuestionList($sourceQuestionPoolId, $answerStatusActiveId)
getSourceQuestionPoolId()
getter for source question pool id
initCompleteQuestionList(ilObjTestDynamicQuestionSetConfig $dynamicQuestionSetConfig, $answerStatusActiveId)
load(ilObjTestDynamicQuestionSetConfig $dynamicQuestionSetConfig, ilTestDynamicQuestionSetFilterSelection $filterSelection)