ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilTestRandomQuestionSetSourcePoolDefinitionList.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetNonAvailablePool.php';
12{
18 protected $db = null;
19
25 protected $testOBJ = null;
26
30 private $sourcePoolDefinitions = array();
31
36
40 protected $lostPools = array();
41
45 protected $trashedPools = array();
46
54 {
55 $this->db = $db;
56 $this->testOBJ = $testOBJ;
57 $this->sourcePoolDefinitionFactory = $sourcePoolDefinitionFactory;
58 }
59
60 public function addDefinition(ilTestRandomQuestionSetSourcePoolDefinition $sourcePoolDefinition)
61 {
62 $this->sourcePoolDefinitions[ $sourcePoolDefinition->getId() ] = $sourcePoolDefinition;
63 }
64
66 {
67 $this->lostPools[$lostPool->getId()] = $lostPool;
68 }
69
70 public function isLostPool($poolId)
71 {
72 return isset($this->lostPools[$poolId]);
73 }
74
75 public function hasLostPool()
76 {
77 return (bool) count($this->lostPools);
78 }
79
80 public function getLostPools()
81 {
82 return $this->lostPools;
83 }
84
85 public function getLostPool($poolId)
86 {
87 if ($this->isLostPool($poolId)) {
88 return $this->lostPools[$poolId];
89 }
90
91 return null;
92 }
93
94 public function isTrashedPool($poolId)
95 {
96 return isset($this->trashedPools[$poolId]);
97 }
98
99 public function hasTrashedPool()
100 {
101 return (bool) count($this->trashedPools);
102 }
103
107 public function getTrashedPools()
108 {
109 return $this->trashedPools;
110 }
111
116 {
117 $this->trashedPools = $trashedPools;
118 }
119
120 // hey: fixRandomTestBuildable - provide single definitions, quantities distribution likes to deal with objects
121
122 public function hasDefinition($sourcePoolDefinitionId)
123 {
124 return $this->getDefinition($sourcePoolDefinitionId) !== null;
125 }
126
127 public function getDefinition($sourcePoolDefinitionId)
128 {
129 if (isset($this->sourcePoolDefinitions[$sourcePoolDefinitionId])) {
130 return $this->sourcePoolDefinitions[$sourcePoolDefinitionId];
131 }
132
133 return null;
134 }
135
136 public function getDefinitionBySourcePoolId($sourcePoolId)
137 {
138 foreach ($this as $definition) {
139 if ($definition->getPoolId() != $sourcePoolId) {
140 continue;
141 }
142
143 return $definition;
144 }
145
146 throw new InvalidArgumentException('invalid source pool id given');
147 }
148
149 public function getDefinitionIds()
150 {
151 return array_keys($this->sourcePoolDefinitions);
152 }
153
154 public function getDefinitionCount()
155 {
156 return count($this->sourcePoolDefinitions);
157 }
158 // hey.
159
160 public function loadDefinitions()
161 {
162 $query = "
163 SELECT tst_rnd_quest_set_qpls.*, odat.obj_id pool_id, odat.title actual_pool_title, tree.child
164 FROM tst_rnd_quest_set_qpls
165 LEFT JOIN object_data odat
166 ON odat.obj_id = pool_fi
167 LEFT JOIN object_reference oref
168 ON oref.obj_id = pool_fi
169 LEFT JOIN tree
170 ON tree = %s
171 AND child = oref.ref_id
172 WHERE test_fi = %s
173 ORDER BY sequence_pos ASC
174 ";
175
176 $res = $this->db->queryF($query, array('integer', 'integer'), array(1, $this->testOBJ->getTestId()));
177
178 $handledDefinitions = array();
179 $trashedPools = array();
180
181 while ($row = $this->db->fetchAssoc($res)) {
182 $sourcePoolDefinition = $this->sourcePoolDefinitionFactory->getEmptySourcePoolDefinition();
183 $sourcePoolDefinition->initFromArray($row);
184
185 if (!isset($handledDefinitions[$sourcePoolDefinition->getId()])) {
186 $this->addDefinition($sourcePoolDefinition);
187 $handledDefinitions[$sourcePoolDefinition->getId()] = $sourcePoolDefinition->getId();
188
189 $trashedPool = new ilTestRandomQuestionSetNonAvailablePool();
190 $trashedPool->assignDbRow($row);
191
192 $trashedPool->setUnavailabilityStatus(
194 );
195
196 $trashedPools[$trashedPool->getId()] = $trashedPool;
197 }
198
199 if (!$this->isLostPool($row['pool_id'])
200 && !$row['pool_id']) {
202 $lostPool->assignDbRow($row);
203
204 $lostPool->setUnavailabilityStatus(
206 );
207
208 $this->addLostPool($lostPool);
209
210 if (isset($trashedPools[$lostPool->getId()])) {
211 unset($trashedPools[$lostPool->getId()]);
212 }
213 }
214
215 if (isset($row['actual_pool_title'])
216 && $sourcePoolDefinition->getPoolTitle() !== $row['actual_pool_title']) {
217 $sourcePoolDefinition->setPoolTitle($row['actual_pool_title']);
218 $sourcePoolDefinition->saveToDb();
219 }
220
221 if ($row['child']) {
222 unset($trashedPools[$row['pool_id']]);
223 }
224 }
225
227 }
228
229 public function saveDefinitions()
230 {
231 foreach ($this as $sourcePoolDefinition) {
233 $sourcePoolDefinition->saveToDb();
234 }
235 }
236
237 public function cloneDefinitionsForTestId($testId)
238 {
239 $definitionIdMap = array();
240
241 foreach ($this as $definition) {
244 $originalId = $definition->getId();
245 $definition->cloneToDbForTestId($testId);
246 $cloneId = $definition->getId();
247
248 $definitionIdMap[$originalId] = $cloneId;
249 }
250
251 return $definitionIdMap;
252 }
253
254 public function deleteDefinitions()
255 {
256 $query = "DELETE FROM tst_rnd_quest_set_qpls WHERE test_fi = %s";
257 $this->db->manipulateF($query, array('integer'), array($this->testOBJ->getTestId()));
258 }
259
260 public function reindexPositions()
261 {
262 $positionIndex = array();
263
264 foreach ($this as $definition) {
266 $positionIndex[ $definition->getId() ] = $definition->getSequencePosition();
267 }
268
269 asort($positionIndex);
270
271 $i = 1;
272
273 foreach ($positionIndex as $definitionId => $definitionPosition) {
274 $positionIndex[$definitionId] = $i++;
275 }
276
277 foreach ($this as $definition) {
278 $definition->setSequencePosition($positionIndex[$definition->getId()]);
279 }
280 }
281
282 public function getNextPosition()
283 {
284 return (count($this->sourcePoolDefinitions) + 1);
285 }
286
287 public function getInvolvedSourcePoolIds()
288 {
289 $involvedSourcePoolIds = array();
290
291 foreach ($this as $definition) {
293 $involvedSourcePoolIds[ $definition->getPoolId() ] = $definition->getPoolId();
294 }
295
296 return array_values($involvedSourcePoolIds);
297 }
298
299 public function getQuestionAmount()
300 {
301 $questionAmount = 0;
302
303 foreach ($this as $definition) {
305 $questionAmount += $definition->getQuestionAmount();
306 }
307
308 return $questionAmount;
309 }
310
314 public function savedDefinitionsExist()
315 {
316 $query = "SELECT COUNT(*) cnt FROM tst_rnd_quest_set_qpls WHERE test_fi = %s";
317 $res = $this->db->queryF($query, array('integer'), array($this->testOBJ->getTestId()));
318
319 $row = $this->db->fetchAssoc($res);
320
321 return $row['cnt'] > 0;
322 }
323
324 public function hasTaxonomyFilters()
325 {
326 foreach ($this as $definition) {
328 // fau: taxFilter/typeFilter - new check for existing taxonomy filter
329 if (count($definition->getMappedTaxonomyFilter())) {
330 return true;
331 }
332 #if( $definition->getMappedFilterTaxId() && $definition->getMappedFilterTaxNodeId() )
333 #{
334 # return true;
335 #}
336 // fau.
337 }
338
339 return false;
340 }
341
342 // fau: taxFilter/typeFilter - check for existing type filters
343 public function hasTypeFilters()
344 {
345 foreach ($this as $definition) {
346 if (count($definition->getTypeFilter())) {
347 return true;
348 }
349 }
350 return false;
351 }
352 // fau.
353
354 public function areAllUsedPoolsAvailable()
355 {
356 if ($this->hasLostPool()) {
357 return false;
358 }
359
360 if ($this->hasTrashedPool()) {
361 return false;
362 }
363
364 return true;
365 }
366
370 public function rewind()
371 {
372 return reset($this->sourcePoolDefinitions);
373 }
374
378 public function current()
379 {
380 return current($this->sourcePoolDefinitions);
381 }
382
386 public function key()
387 {
388 return key($this->sourcePoolDefinitions);
389 }
390
394 public function next()
395 {
396 return next($this->sourcePoolDefinitions);
397 }
398
402 public function valid()
403 {
404 return key($this->sourcePoolDefinitions) !== null;
405 }
406
407 public function getNonAvailablePools()
408 {
409 //echo get_class($this->getTrashedPools()[0]);
410 return array_merge($this->getTrashedPools(), $this->getLostPools());
411 }
412}
An exception for terminatinating execution or to throw for unit testing.
addDefinition(ilTestRandomQuestionSetSourcePoolDefinition $sourcePoolDefinition)
__construct(ilDBInterface $db, ilObjTest $testOBJ, ilTestRandomQuestionSetSourcePoolDefinitionFactory $sourcePoolDefinitionFactory)
Constructor.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$i
Definition: metadata.php:24
$query
foreach($_POST as $key=> $value) $res