ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilTestRandomQuestionSetConfig.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.ilTestQuestionSetConfig.php';
5
15{
18
23
28
32 private $questionAmountPerTest = null;
33
38
39 //fau: fixRandomTestBuildable - variable for messages
40 private $buildableMessages = array();
41 // fau.
42
50 {
51 parent::__construct($tree, $db, $pluginAdmin, $testOBJ);
52 }
53
58 {
59 $this->requirePoolsWithHomogeneousScoredQuestions = $requirePoolsWithHomogeneousScoredQuestions;
60 }
61
66 {
68 }
69
74 {
75 $this->questionAmountConfigurationMode = $questionAmountConfigurationMode;
76 }
77
82 {
84 }
85
90 {
92 }
93
98 {
100 }
101
102 public function isValidQuestionAmountConfigurationMode($amountMode)
103 {
104 switch ($amountMode) {
107
108 return true;
109 }
110
111 return false;
112 }
113
118 {
119 $this->questionAmountPerTest = $questionAmountPerTest;
120 }
121
125 public function getQuestionAmountPerTest()
126 {
128 }
129
134 {
135 $this->lastQuestionSyncTimestamp = $lastQuestionSyncTimestamp;
136 }
137
142 {
144 }
145
146 //fau: fixRandomTestBuildable - function to get messages
147 public function getBuildableMessages()
148 {
150 }
151 // fau.
152
153 // -----------------------------------------------------------------------------------------------------------------
154
161 public function initFromArray($dataArray)
162 {
163 foreach ($dataArray as $field => $value) {
164 switch ($field) {
165 case 'req_pools_homo_scored': $this->setPoolsWithHomogeneousScoredQuestionsRequired($value); break;
166 case 'quest_amount_cfg_mode': $this->setQuestionAmountConfigurationMode($value); break;
167 case 'quest_amount_per_test': $this->setQuestionAmountPerTest($value); break;
168 case 'quest_sync_timestamp': $this->setLastQuestionSyncTimestamp($value); break;
169 }
170 }
171 }
172
178 public function loadFromDb()
179 {
180 $res = $this->db->queryF(
181 "SELECT * FROM tst_rnd_quest_set_cfg WHERE test_fi = %s",
182 array('integer'),
183 array($this->testOBJ->getTestId())
184 );
185
186 while ($row = $this->db->fetchAssoc($res)) {
187 $this->initFromArray($row);
188
189 return true;
190 }
191
192 return false;
193 }
194
200 public function saveToDb()
201 {
202 if ($this->dbRecordExists($this->testOBJ->getTestId())) {
203 $this->updateDbRecord($this->testOBJ->getTestId());
204 } else {
205 $this->insertDbRecord($this->testOBJ->getTestId());
206 }
207 }
208
214 public function cloneToDbForTestId($testId)
215 {
216 $this->insertDbRecord($testId);
217 }
218
222 public function deleteFromDb()
223 {
224 $this->db->manipulateF(
225 "DELETE FROM tst_rnd_quest_set_cfg WHERE test_fi = %s",
226 array('integer'),
227 array($this->testOBJ->getTestId())
228 );
229 }
230
231 // -----------------------------------------------------------------------------------------------------------------
232
239 private function dbRecordExists($testId)
240 {
241 $res = $this->db->queryF(
242 "SELECT COUNT(*) cnt FROM tst_rnd_quest_set_cfg WHERE test_fi = %s",
243 array('integer'),
244 array($testId)
245 );
246
247 $row = $this->db->fetchAssoc($res);
248
249 return (bool) $row['cnt'];
250 }
251
258 private function updateDbRecord($testId)
259 {
260 $this->db->update(
261 'tst_rnd_quest_set_cfg',
262 array(
263 'req_pools_homo_scored' => array('integer', (int) $this->arePoolsWithHomogeneousScoredQuestionsRequired()),
264 'quest_amount_cfg_mode' => array('text', $this->getQuestionAmountConfigurationMode()),
265 'quest_amount_per_test' => array('integer', (int) $this->getQuestionAmountPerTest()),
266 'quest_sync_timestamp' => array('integer', (int) $this->getLastQuestionSyncTimestamp())
267 ),
268 array(
269 'test_fi' => array('integer', $testId)
270 )
271 );
272 }
273
280 private function insertDbRecord($testId)
281 {
282 $this->db->insert('tst_rnd_quest_set_cfg', array(
283 'test_fi' => array('integer', $testId),
284 'req_pools_homo_scored' => array('integer', (int) $this->arePoolsWithHomogeneousScoredQuestionsRequired()),
285 'quest_amount_cfg_mode' => array('text', $this->getQuestionAmountConfigurationMode()),
286 'quest_amount_per_test' => array('integer', (int) $this->getQuestionAmountPerTest()),
287 'quest_sync_timestamp' => array('integer', (int) $this->getLastQuestionSyncTimestamp())
288 ));
289 }
290
291 // -----------------------------------------------------------------------------------------------------------------
292
293 public function isQuestionSetConfigured()
294 {
295 // fau: delayCopyRandomQuestions - question set is not configured if date of last synchronisation is empty
296 if ($this->getLastQuestionSyncTimestamp() == 0) {
297 return false;
298 }
299 // fau.
300
301 if (!$this->isQuestionAmountConfigComplete()) {
302 return false;
303 }
304
305 if (!$this->hasSourcePoolDefinitions()) {
306 return false;
307 }
308
309 if (!$this->isQuestionSetBuildable()) {
310 return false;
311 }
312
313 return true;
314 }
315
316 public function isQuestionAmountConfigComplete()
317 {
319 $sourcePoolDefinitionList = $this->buildSourcePoolDefinitionList($this->testOBJ);
320
321 $sourcePoolDefinitionList->loadDefinitions();
322
323 foreach ($sourcePoolDefinitionList as $definition) {
326 if ($definition->getQuestionAmount() < 1) {
327 return false;
328 }
329 }
330 } elseif ($this->getQuestionAmountPerTest() < 1) {
331 return false;
332 }
333
334 return true;
335 }
336
337 public function hasSourcePoolDefinitions()
338 {
339 $sourcePoolDefinitionList = $this->buildSourcePoolDefinitionList($this->testOBJ);
340
341 return $sourcePoolDefinitionList->savedDefinitionsExist();
342 }
343
344 public function isQuestionSetBuildable()
345 {
346 $sourcePoolDefinitionList = $this->buildSourcePoolDefinitionList($this->testOBJ);
347 $sourcePoolDefinitionList->loadDefinitions();
348
349 require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetStagingPoolQuestionList.php';
350 $stagingPoolQuestionList = new ilTestRandomQuestionSetStagingPoolQuestionList($this->db, $this->pluginAdmin);
351
352 require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetBuilder.php';
353 $questionSetBuilder = ilTestRandomQuestionSetBuilder::getInstance($this->db, $this->testOBJ, $this, $sourcePoolDefinitionList, $stagingPoolQuestionList);
354
355 //fau: fixRandomTestBuildable - get messages if set is not buildable
356 $buildable = $questionSetBuilder->checkBuildable();
357 $this->buildableMessages = $questionSetBuilder->getCheckMessages();
358 return $buildable;
359 // fau.
360
361 return $questionSetBuilder->checkBuildable();
362 }
363
365 {
366 if ($this->dbRecordExists($this->testOBJ->getTestId())) {
367 return true;
368 }
369
370 $sourcePoolDefinitionList = $this->buildSourcePoolDefinitionList($this->testOBJ);
371
372 if ($sourcePoolDefinitionList->savedDefinitionsExist()) {
373 return true;
374 }
375
376 return false;
377 }
378
380 {
381 $sourcePoolDefinitionList = $this->buildSourcePoolDefinitionList($this->testOBJ);
382 $sourcePoolDefinitionList->deleteDefinitions();
383
384 require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetStagingPoolBuilder.php';
386 $this->db,
387 $this->testOBJ
388 );
389 $stagingPool->reset();
390
392
393 $this->deleteFromDb();
394 }
395
397 {
398 $this->testOBJ->setResultFilterTaxIds(array());
399 $this->testOBJ->saveToDb(true);
400 }
401
407 public function cloneQuestionSetRelatedData(ilObjTest $cloneTestOBJ)
408 {
409 // clone general config
410
411 $this->loadFromDb();
412 $this->cloneToDbForTestId($cloneTestOBJ->getTestId());
413
414 // clone source pool definitions (selection rules)
415
416 $sourcePoolDefinitionList = $this->buildSourcePoolDefinitionList($this->testOBJ);
417 $sourcePoolDefinitionList->loadDefinitions();
418 $definitionIdMap = $sourcePoolDefinitionList->cloneDefinitionsForTestId($cloneTestOBJ->getTestId());
419 $this->registerClonedSourcePoolDefinitionIdMapping($cloneTestOBJ, $definitionIdMap);
420
421 // build new question stage for cloned test
422
423 $sourcePoolDefinitionList = $this->buildSourcePoolDefinitionList($cloneTestOBJ);
424 $stagingPool = $this->buildStagingPoolBuilder($cloneTestOBJ);
425
426 $sourcePoolDefinitionList->loadDefinitions();
427 $stagingPool->rebuild($sourcePoolDefinitionList);
428 $sourcePoolDefinitionList->saveDefinitions();
429
430 $this->updateLastQuestionSyncTimestampForTestId($cloneTestOBJ->getTestId(), time());
431 }
432
433 private function registerClonedSourcePoolDefinitionIdMapping(ilObjTest $cloneTestOBJ, $definitionIdMap)
434 {
435 global $DIC;
436 $ilLog = $DIC['ilLog'];
437
438 require_once 'Services/CopyWizard/classes/class.ilCopyWizardOptions.php';
440
441 foreach ($definitionIdMap as $originalDefinitionId => $cloneDefinitionId) {
442 $originalKey = $this->testOBJ->getRefId() . '_rndSelDef_' . $originalDefinitionId;
443 $mappedKey = $cloneTestOBJ->getRefId() . '_rndSelDef_' . $cloneDefinitionId;
444 $cwo->appendMapping($originalKey, $mappedKey);
445 $ilLog->write(__METHOD__ . ": Added random selection definition id mapping $originalKey <-> $mappedKey");
446 }
447 }
448
450 {
451 require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetSourcePoolDefinitionFactory.php';
452 $sourcePoolDefinitionFactory = new ilTestRandomQuestionSetSourcePoolDefinitionFactory(
453 $this->db,
455 );
456
457 require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetSourcePoolDefinitionList.php';
458 $sourcePoolDefinitionList = new ilTestRandomQuestionSetSourcePoolDefinitionList(
459 $this->db,
460 $testOBJ,
461 $sourcePoolDefinitionFactory
462 );
463
464 return $sourcePoolDefinitionList;
465 }
466
468 {
469 require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetStagingPoolBuilder.php';
470 $stagingPool = new ilTestRandomQuestionSetStagingPoolBuilder($this->db, $testOBJ);
471
472 return $stagingPool;
473 }
474
475 // -----------------------------------------------------------------------------------------------------------------
476
478 {
479 $this->db->update(
480 'tst_rnd_quest_set_cfg',
481 array(
482 'quest_sync_timestamp' => array('integer', (int) $timestamp)
483 ),
484 array(
485 'test_fi' => array('integer', $testId)
486 )
487 );
488 }
489
491 {
492 return true;
493 }
494
495 // -----------------------------------------------------------------------------------------------------------------
496
498 {
499 return $this->testOBJ->getAvailableQuestionpools(
500 true,
502 false,
503 true,
504 true
505 );
506 }
507
509 {
510 return (bool) count($this->getSelectableQuestionPools());
511 }
512
513 // -----------------------------------------------------------------------------------------------------------------
514
515 public function areDepenciesBroken()
516 {
517 return (bool) $this->testOBJ->isTestFinalBroken();
518 }
519
521 {
522 return $lng->txt('tst_old_style_rnd_quest_set_broken');
523 }
524
525 public function isValidRequestOnBrokenQuestionSetDepencies($nextClass, $cmd)
526 {
527 //vd($nextClass, $cmd);
528
529 switch ($nextClass) {
530 case 'ilobjectmetadatagui':
531 case 'ilpermissiongui':
532
533 return true;
534
535 case 'ilobjtestgui':
536 case '':
537
538 $cmds = array(
539 'infoScreen', 'participants', 'npSetFilter', 'npResetFilter',
540 //'deleteAllUserResults', 'confirmDeleteAllUserResults',
541 //'deleteSingleUserResults', 'confirmDeleteSelectedUserData', 'cancelDeleteSelectedUserData'
542 );
543
544 if (in_array($cmd, $cmds)) {
545 return true;
546 }
547
548 break;
549 }
550
551 return false;
552 }
553
555 {
556 return array(
557 'assQuestions', 'settings', 'manscoring', 'scoringadjust', 'statistics', 'history', 'export'
558 );
559 }
560
561 // -----------------------------------------------------------------------------------------------------------------
562
564 {
565 $definitionList = $this->buildSourcePoolDefinitionList($this->testOBJ);
566 $definitionList->loadDefinitions();
567
568 $poolTitles = array();
569
570 foreach ($definitionList as $definition) {
571 /* @var ilTestRandomQuestionSetSourcePoolDefinition $definition */
572
573 $refId = current(ilObject::_getAllReferences($definition->getPoolId()));
574 $href = ilLink::_getLink($refId, 'qpl');
575 $title = $definition->getPoolTitle();
576
577 $poolTitles[$definition->getPoolId()] = "<a href=\"$href\" alt=\"$title\">$title</a>";
578 }
579
580 return implode(', ', $poolTitles);
581 }
582}
foreach($mandatory_scripts as $file) $timestamp
Definition: buildRTE.php:81
An exception for terminatinating execution or to throw for unit testing.
static _getInstance($a_copy_id)
Get instance of copy wizard options.
language handling
getTestId()
Gets the database id of the additional test data.
getRefId()
get reference id @access public
static _getAllReferences($a_id)
get all reference ids of object
Administration class for plugins.
static getInstance(ilDBInterface $db, ilObjTest $testOBJ, ilTestRandomQuestionSetConfig $questionSetConfig, ilTestRandomQuestionSetSourcePoolDefinitionList $sourcePoolDefinitionList, ilTestRandomQuestionSetStagingPoolQuestionList $stagingPoolQuestionList)
cloneToDbForTestId($testId)
saves the question set config for test with given id to the database
initFromArray($dataArray)
initialises the current object instance with values from matching properties within the passed array
dbRecordExists($testId)
checks wether a question set config for current test exists in the database
__construct(ilTree $tree, ilDBInterface $db, ilPluginAdmin $pluginAdmin, ilObjTest $testOBJ)
removeQuestionSetRelatedData()
removes all question set config related data
saveToDb()
saves the question set config for current test to the database
setQuestionAmountConfigurationMode($questionAmountConfigurationMode)
setLastQuestionSyncTimestamp($lastQuestionSyncTimestamp)
cloneQuestionSetRelatedData(ilObjTest $cloneTestOBJ)
removes all question set config related data for cloned/copied test
registerClonedSourcePoolDefinitionIdMapping(ilObjTest $cloneTestOBJ, $definitionIdMap)
loadFromDb()
loads the question set config for current test from the database
doesQuestionSetRelatedDataExist()
checks wether question set config related data exists or not
resetQuestionSetRelatedTestSettings()
resets all test settings that depends on a non changed question set config
deleteFromDb()
deletes the question set config for current test from the database
updateDbRecord($testId)
updates the record in the database that corresponds to the question set config for the current test
setPoolsWithHomogeneousScoredQuestionsRequired($requirePoolsWithHomogeneousScoredQuestions)
insertDbRecord($testId)
inserts a new record for the question set config for the current test into the database
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
Interface ilDBInterface.
$row
global $DIC
Definition: saml.php:7
$lng
foreach($_POST as $key=> $value) $res