ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $ilLog;
436
437 require_once 'Services/CopyWizard/classes/class.ilCopyWizardOptions.php';
439
440 foreach ($definitionIdMap as $originalDefinitionId => $cloneDefinitionId) {
441 $originalKey = $this->testOBJ->getRefId() . '_rndSelDef_' . $originalDefinitionId;
442 $mappedKey = $cloneTestOBJ->getRefId() . '_rndSelDef_' . $cloneDefinitionId;
443 $cwo->appendMapping($originalKey, $mappedKey);
444 $ilLog->write(__METHOD__ . ": Added random selection definition id mapping $originalKey <-> $mappedKey");
445 }
446 }
447
449 {
450 require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetSourcePoolDefinitionFactory.php';
451 $sourcePoolDefinitionFactory = new ilTestRandomQuestionSetSourcePoolDefinitionFactory(
452 $this->db,
454 );
455
456 require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetSourcePoolDefinitionList.php';
457 $sourcePoolDefinitionList = new ilTestRandomQuestionSetSourcePoolDefinitionList(
458 $this->db,
459 $testOBJ,
460 $sourcePoolDefinitionFactory
461 );
462
463 return $sourcePoolDefinitionList;
464 }
465
467 {
468 require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetStagingPoolBuilder.php';
469 $stagingPool = new ilTestRandomQuestionSetStagingPoolBuilder($this->db, $testOBJ);
470
471 return $stagingPool;
472 }
473
474 // -----------------------------------------------------------------------------------------------------------------
475
477 {
478 $this->db->update(
479 'tst_rnd_quest_set_cfg',
480 array(
481 'quest_sync_timestamp' => array('integer', (int) $timestamp)
482 ),
483 array(
484 'test_fi' => array('integer', $testId)
485 )
486 );
487 }
488
490 {
491 return true;
492 }
493
494 // -----------------------------------------------------------------------------------------------------------------
495
497 {
498 return $this->testOBJ->getAvailableQuestionpools(
499 true,
501 false,
502 true,
503 true
504 );
505 }
506
508 {
509 return (bool) count($this->getSelectableQuestionPools());
510 }
511
512 // -----------------------------------------------------------------------------------------------------------------
513
514 public function areDepenciesBroken()
515 {
516 return (bool) $this->testOBJ->isTestFinalBroken();
517 }
518
520 {
521 return $lng->txt('tst_old_style_rnd_quest_set_broken');
522 }
523
524 public function isValidRequestOnBrokenQuestionSetDepencies($nextClass, $cmd)
525 {
526 //vd($nextClass, $cmd);
527
528 switch ($nextClass) {
529 case 'ilobjectmetadatagui':
530 case 'ilpermissiongui':
531
532 return true;
533
534 case 'ilobjtestgui':
535 case '':
536
537 $cmds = array(
538 'infoScreen', 'participants', 'npSetFilter', 'npResetFilter',
539 //'deleteAllUserResults', 'confirmDeleteAllUserResults',
540 //'deleteSingleUserResults', 'confirmDeleteSelectedUserData', 'cancelDeleteSelectedUserData'
541 );
542
543 if (in_array($cmd, $cmds)) {
544 return true;
545 }
546
547 break;
548 }
549
550 return false;
551 }
552
554 {
555 return array(
556 'assQuestions', 'settings', 'manscoring', 'scoringadjust', 'statistics', 'history', 'export'
557 );
558 }
559
560 // -----------------------------------------------------------------------------------------------------------------
561
563 {
564 $definitionList = $this->buildSourcePoolDefinitionList($this->testOBJ);
565 $definitionList->loadDefinitions();
566
567 $poolTitles = array();
568
569 foreach ($definitionList as $definition) {
570 /* @var ilTestRandomQuestionSetSourcePoolDefinition $definition */
571
572 $refId = current(ilObject::_getAllReferences($definition->getPoolId()));
573 $href = ilLink::_getLink($refId, 'qpl');
574 $title = $definition->getPoolTitle();
575
576 $poolTitles[$definition->getPoolId()] = "<a href=\"$href\" alt=\"$title\">$title</a>";
577 }
578
579 return implode(', ', $poolTitles);
580 }
581}
$dataArray
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.
global $lng
Definition: privfeed.php:17
foreach($_POST as $key=> $value) $res