ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
46 {
47 parent::__construct($tree, $db, $pluginAdmin, $testOBJ);
48 }
49
54 {
55 $this->requirePoolsWithHomogeneousScoredQuestions = $requirePoolsWithHomogeneousScoredQuestions;
56 }
57
62 {
64 }
65
70 {
71 $this->questionAmountConfigurationMode = $questionAmountConfigurationMode;
72 }
73
78 {
80 }
81
86 {
88 }
89
94 {
96 }
97
102 {
103 $this->questionAmountPerTest = $questionAmountPerTest;
104 }
105
109 public function getQuestionAmountPerTest()
110 {
112 }
113
118 {
119 $this->lastQuestionSyncTimestamp = $lastQuestionSyncTimestamp;
120 }
121
126 {
128 }
129
130 // -----------------------------------------------------------------------------------------------------------------
131
138 public function initFromArray($dataArray)
139 {
140 foreach($dataArray as $field => $value)
141 {
142 switch($field)
143 {
144 case 'req_pools_homo_scored': $this->setPoolsWithHomogeneousScoredQuestionsRequired($value); break;
145 case 'quest_amount_cfg_mode': $this->setQuestionAmountConfigurationMode($value); break;
146 case 'quest_amount_per_test': $this->setQuestionAmountPerTest($value); break;
147 case 'quest_sync_timestamp': $this->setLastQuestionSyncTimestamp($value); break;
148 }
149 }
150 }
151
157 public function loadFromDb()
158 {
159 $res = $this->db->queryF(
160 "SELECT * FROM tst_rnd_quest_set_cfg WHERE test_fi = %s",
161 array('integer'), array($this->testOBJ->getTestId())
162 );
163
164 while( $row = $this->db->fetchAssoc($res) )
165 {
166 $this->initFromArray($row);
167
168 return true;
169 }
170
171 return false;
172 }
173
179 public function saveToDb()
180 {
181 if( $this->dbRecordExists($this->testOBJ->getTestId()) )
182 {
183 $this->updateDbRecord($this->testOBJ->getTestId());
184 }
185 else
186 {
187 $this->insertDbRecord($this->testOBJ->getTestId());
188 }
189 }
190
196 public function cloneToDbForTestId($testId)
197 {
198 $this->insertDbRecord($testId);
199 }
200
204 public function deleteFromDb()
205 {
206 $this->db->manipulateF(
207 "DELETE FROM tst_rnd_quest_set_cfg WHERE test_fi = %s",
208 array('integer'), array($this->testOBJ->getTestId())
209 );
210 }
211
212 // -----------------------------------------------------------------------------------------------------------------
213
220 private function dbRecordExists($testId)
221 {
222 $res = $this->db->queryF(
223 "SELECT COUNT(*) cnt FROM tst_rnd_quest_set_cfg WHERE test_fi = %s",
224 array('integer'), array($testId)
225 );
226
227 $row = $this->db->fetchAssoc($res);
228
229 return (bool)$row['cnt'];
230 }
231
238 private function updateDbRecord($testId)
239 {
240 $this->db->update('tst_rnd_quest_set_cfg',
241 array(
242 'req_pools_homo_scored' => array('integer', (int)$this->arePoolsWithHomogeneousScoredQuestionsRequired()),
243 'quest_amount_cfg_mode' => array('text', $this->getQuestionAmountConfigurationMode()),
244 'quest_amount_per_test' => array('integer', (int)$this->getQuestionAmountPerTest()),
245 'quest_sync_timestamp' => array('integer', (int)$this->getLastQuestionSyncTimestamp())
246 ),
247 array(
248 'test_fi' => array('integer', $testId)
249 )
250 );
251 }
252
259 private function insertDbRecord($testId)
260 {
261 $this->db->insert('tst_rnd_quest_set_cfg', array(
262 'test_fi' => array('integer', $testId),
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 }
269
270 // -----------------------------------------------------------------------------------------------------------------
271
272 public function isQuestionSetConfigured()
273 {
274 if( !$this->isQuestionAmountConfigComplete() )
275 {
276 return false;
277 }
278
279 if( !$this->hasSourcePoolDefinitions() )
280 {
281 return false;
282 }
283
284 if( !$this->isQuestionSetBuildable() )
285 {
286 return false;
287 }
288
289 return true;
290 }
291
292 public function isQuestionAmountConfigComplete()
293 {
295 {
296 $sourcePoolDefinitionList = $this->buildSourcePoolDefinitionList($this->testOBJ);
297
298 $sourcePoolDefinitionList->loadDefinitions();
299
300 foreach($sourcePoolDefinitionList as $definition)
301 {
304 if( $definition->getQuestionAmount() < 1 )
305 {
306 return false;
307 }
308 }
309 }
310 elseif( $this->getQuestionAmountPerTest() < 1 )
311 {
312 return false;
313 }
314
315 return true;
316 }
317
318 public function hasSourcePoolDefinitions()
319 {
320 $sourcePoolDefinitionList = $this->buildSourcePoolDefinitionList($this->testOBJ);
321
322 return $sourcePoolDefinitionList->savedDefinitionsExist();
323 }
324
325 public function isQuestionSetBuildable()
326 {
327 $sourcePoolDefinitionList = $this->buildSourcePoolDefinitionList($this->testOBJ);
328 $sourcePoolDefinitionList->loadDefinitions();
329
330 require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetStagingPoolQuestionList.php';
331 $stagingPoolQuestionList = new ilTestRandomQuestionSetStagingPoolQuestionList($this->db, $this->pluginAdmin);
332
333 require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetBuilder.php';
334 $questionSetBuilder = ilTestRandomQuestionSetBuilder::getInstance($this->db, $this->testOBJ, $this, $sourcePoolDefinitionList, $stagingPoolQuestionList);
335
336 return $questionSetBuilder->checkBuildable();
337 }
338
340 {
341 if( $this->dbRecordExists($this->testOBJ->getTestId()) )
342 {
343 return true;
344 }
345
346 $sourcePoolDefinitionList = $this->buildSourcePoolDefinitionList($this->testOBJ);
347
348 if( $sourcePoolDefinitionList->savedDefinitionsExist() )
349 {
350 return true;
351 }
352
353 return false;
354 }
355
357 {
358 $sourcePoolDefinitionList = $this->buildSourcePoolDefinitionList($this->testOBJ);
359 $sourcePoolDefinitionList->deleteDefinitions();
360
361 require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetStagingPoolBuilder.php';
363 $this->db, $this->testOBJ
364 );
365 $stagingPool->reset();
366
368
369 $this->deleteFromDb();
370 }
371
373 {
374 $this->testOBJ->setResultFilterTaxIds(array());
375 $this->testOBJ->saveToDb(true);
376 }
377
383 public function cloneQuestionSetRelatedData(ilObjTest $cloneTestOBJ)
384 {
385 // clone general config
386
387 $this->loadFromDb();
388 $this->cloneToDbForTestId($cloneTestOBJ->getTestId());
389
390 // clone source pool definitions (selection rules)
391
392 $sourcePoolDefinitionList = $this->buildSourcePoolDefinitionList($this->testOBJ);
393 $sourcePoolDefinitionList->loadDefinitions();
394 $definitionIdMap = $sourcePoolDefinitionList->cloneDefinitionsForTestId($cloneTestOBJ->getTestId());
395 $this->registerClonedSourcePoolDefinitionIdMapping($cloneTestOBJ, $definitionIdMap);
396
397 // build new question stage for cloned test
398
399 $sourcePoolDefinitionList = $this->buildSourcePoolDefinitionList($cloneTestOBJ);
400 $stagingPool = $this->buildStagingPoolBuilder($cloneTestOBJ);
401
402 $sourcePoolDefinitionList->loadDefinitions();
403 $stagingPool->rebuild($sourcePoolDefinitionList);
404 $sourcePoolDefinitionList->saveDefinitions();
405
406 $this->updateLastQuestionSyncTimestampForTestId($cloneTestOBJ->getTestId(), time());
407 }
408
409 private function registerClonedSourcePoolDefinitionIdMapping(ilObjTest $cloneTestOBJ, $definitionIdMap)
410 {
411 global $ilLog;
412
413 require_once 'Services/CopyWizard/classes/class.ilCopyWizardOptions.php';
415
416 foreach($definitionIdMap as $originalDefinitionId => $cloneDefinitionId)
417 {
418 $originalKey = $this->testOBJ->getRefId().'_rndSelDef_'.$originalDefinitionId;
419 $mappedKey = $cloneTestOBJ->getRefId().'_rndSelDef_'.$cloneDefinitionId;
420 $cwo->appendMapping($originalKey, $mappedKey);
421 $ilLog->write(__METHOD__.": Added random selection definition id mapping $originalKey <-> $mappedKey");
422 }
423 }
424
426 {
427 require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetSourcePoolDefinitionFactory.php';
428 $sourcePoolDefinitionFactory = new ilTestRandomQuestionSetSourcePoolDefinitionFactory(
429 $this->db, $testOBJ
430 );
431
432 require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetSourcePoolDefinitionList.php';
433 $sourcePoolDefinitionList = new ilTestRandomQuestionSetSourcePoolDefinitionList(
434 $this->db, $testOBJ, $sourcePoolDefinitionFactory
435 );
436
437 return $sourcePoolDefinitionList;
438 }
439
441 {
442 require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetStagingPoolBuilder.php';
443 $stagingPool = new ilTestRandomQuestionSetStagingPoolBuilder($this->db, $testOBJ);
444
445 return $stagingPool;
446 }
447
448 // -----------------------------------------------------------------------------------------------------------------
449
451 {
452 $this->db->update('tst_rnd_quest_set_cfg',
453 array(
454 'quest_sync_timestamp' => array('integer', (int)$timestamp)
455 ),
456 array(
457 'test_fi' => array('integer', $testId)
458 )
459 );
460 }
461
463 {
464 return true;
465 }
466
467 // -----------------------------------------------------------------------------------------------------------------
468
470 {
471 return $this->testOBJ->getAvailableQuestionpools(
472 true, $this->arePoolsWithHomogeneousScoredQuestionsRequired(), false, true, true
473 );
474 }
475
477 {
478 return (bool)count($this->getSelectableQuestionPools());
479 }
480
481 // -----------------------------------------------------------------------------------------------------------------
482
483 public function areDepenciesBroken()
484 {
485 return (bool)$this->testOBJ->isTestFinalBroken();
486 }
487
489 {
490 return $lng->txt('tst_old_style_rnd_quest_set_broken');
491 }
492
494 {
495 //vd($nextClass, $cmd);
496
497 switch( $nextClass )
498 {
499 case 'ilobjectmetadatagui':
500 case 'ilpermissiongui':
501
502 return true;
503
504 case 'ilobjtestgui':
505 case '':
506
507 $cmds = array(
508 'infoScreen', 'participants', 'npSetFilter', 'npResetFilter',
509 //'deleteAllUserResults', 'confirmDeleteAllUserResults',
510 //'deleteSingleUserResults', 'confirmDeleteSelectedUserData', 'cancelDeleteSelectedUserData'
511 );
512
513 if( in_array($cmd, $cmds) )
514 {
515 return true;
516 }
517
518 break;
519 }
520
521 return false;
522 }
523
525 {
526 return array(
527 'assQuestions', 'settings', 'manscoring', 'scoringadjust', 'statistics', 'history', 'export'
528 );
529 }
530
531 // -----------------------------------------------------------------------------------------------------------------
532
534 {
535 $definitionList = $this->buildSourcePoolDefinitionList($this->testOBJ);
536 $definitionList->loadDefinitions();
537
538 $poolTitles = array();
539
540 foreach($definitionList as $definition)
541 {
542 /* @var ilTestRandomQuestionSetSourcePoolDefinition $definition */
543
544 $refId = current(ilObject::_getAllReferences($definition->getPoolId()));
545 $href = ilLink::_getLink($refId, 'qpl');
546 $title = $definition->getPoolTitle();
547
548 $poolTitles[$definition->getPoolId()] = "<a href=\"$href\" alt=\"$title\">$title</a>";
549 }
550
551 return implode(', ', $poolTitles);
552 }
553}
foreach($mandatory_scripts as $file) $timestamp
Definition: buildRTE.php:81
static _getInstance($a_copy_id)
Get instance of copy wizard options.
Database Wrapper.
Definition: class.ilDB.php:29
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(ilDB $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
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
__construct(ilTree $tree, ilDB $db, ilPluginAdmin $pluginAdmin, ilObjTest $testOBJ)
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
global $lng
Definition: privfeed.php:40
$cmd
Definition: sahs_server.php:35