ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
4 require_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  {
87  return $this->getQuestionAmountConfigurationMode() == self::QUESTION_AMOUNT_CONFIG_MODE_PER_POOL;
88  }
89 
94  {
95  return $this->getQuestionAmountConfigurationMode() == self::QUESTION_AMOUNT_CONFIG_MODE_PER_TEST;
96  }
97 
98  public function isValidQuestionAmountConfigurationMode($amountMode)
99  {
100  switch($amountMode)
101  {
102  case self::QUESTION_AMOUNT_CONFIG_MODE_PER_POOL:
103  case self::QUESTION_AMOUNT_CONFIG_MODE_PER_TEST:
104 
105  return true;
106  }
107 
108  return false;
109  }
110 
115  {
116  $this->questionAmountPerTest = $questionAmountPerTest;
117  }
118 
122  public function getQuestionAmountPerTest()
123  {
125  }
126 
131  {
132  $this->lastQuestionSyncTimestamp = $lastQuestionSyncTimestamp;
133  }
134 
139  {
141  }
142 
143  // -----------------------------------------------------------------------------------------------------------------
144 
151  public function initFromArray($dataArray)
152  {
153  foreach($dataArray as $field => $value)
154  {
155  switch($field)
156  {
157  case 'req_pools_homo_scored': $this->setPoolsWithHomogeneousScoredQuestionsRequired($value); break;
158  case 'quest_amount_cfg_mode': $this->setQuestionAmountConfigurationMode($value); break;
159  case 'quest_amount_per_test': $this->setQuestionAmountPerTest($value); break;
160  case 'quest_sync_timestamp': $this->setLastQuestionSyncTimestamp($value); break;
161  }
162  }
163  }
164 
170  public function loadFromDb()
171  {
172  $res = $this->db->queryF(
173  "SELECT * FROM tst_rnd_quest_set_cfg WHERE test_fi = %s",
174  array('integer'), array($this->testOBJ->getTestId())
175  );
176 
177  while( $row = $this->db->fetchAssoc($res) )
178  {
179  $this->initFromArray($row);
180 
181  return true;
182  }
183 
184  return false;
185  }
186 
192  public function saveToDb()
193  {
194  if( $this->dbRecordExists($this->testOBJ->getTestId()) )
195  {
196  $this->updateDbRecord($this->testOBJ->getTestId());
197  }
198  else
199  {
200  $this->insertDbRecord($this->testOBJ->getTestId());
201  }
202  }
203 
209  public function cloneToDbForTestId($testId)
210  {
211  $this->insertDbRecord($testId);
212  }
213 
217  public function deleteFromDb()
218  {
219  $this->db->manipulateF(
220  "DELETE FROM tst_rnd_quest_set_cfg WHERE test_fi = %s",
221  array('integer'), array($this->testOBJ->getTestId())
222  );
223  }
224 
225  // -----------------------------------------------------------------------------------------------------------------
226 
233  private function dbRecordExists($testId)
234  {
235  $res = $this->db->queryF(
236  "SELECT COUNT(*) cnt FROM tst_rnd_quest_set_cfg WHERE test_fi = %s",
237  array('integer'), array($testId)
238  );
239 
240  $row = $this->db->fetchAssoc($res);
241 
242  return (bool)$row['cnt'];
243  }
244 
251  private function updateDbRecord($testId)
252  {
253  $this->db->update('tst_rnd_quest_set_cfg',
254  array(
255  'req_pools_homo_scored' => array('integer', (int)$this->arePoolsWithHomogeneousScoredQuestionsRequired()),
256  'quest_amount_cfg_mode' => array('text', $this->getQuestionAmountConfigurationMode()),
257  'quest_amount_per_test' => array('integer', (int)$this->getQuestionAmountPerTest()),
258  'quest_sync_timestamp' => array('integer', (int)$this->getLastQuestionSyncTimestamp())
259  ),
260  array(
261  'test_fi' => array('integer', $testId)
262  )
263  );
264  }
265 
272  private function insertDbRecord($testId)
273  {
274  $this->db->insert('tst_rnd_quest_set_cfg', array(
275  'test_fi' => array('integer', $testId),
276  'req_pools_homo_scored' => array('integer', (int)$this->arePoolsWithHomogeneousScoredQuestionsRequired()),
277  'quest_amount_cfg_mode' => array('text', $this->getQuestionAmountConfigurationMode()),
278  'quest_amount_per_test' => array('integer', (int)$this->getQuestionAmountPerTest()),
279  'quest_sync_timestamp' => array('integer', (int)$this->getLastQuestionSyncTimestamp())
280  ));
281  }
282 
283  // -----------------------------------------------------------------------------------------------------------------
284 
285  public function isQuestionSetConfigured()
286  {
287  if( !$this->isQuestionAmountConfigComplete() )
288  {
289  return false;
290  }
291 
292  if( !$this->hasSourcePoolDefinitions() )
293  {
294  return false;
295  }
296 
297  if( !$this->isQuestionSetBuildable() )
298  {
299  return false;
300  }
301 
302  return true;
303  }
304 
305  public function isQuestionAmountConfigComplete()
306  {
308  {
309  $sourcePoolDefinitionList = $this->buildSourcePoolDefinitionList($this->testOBJ);
310 
311  $sourcePoolDefinitionList->loadDefinitions();
312 
313  foreach($sourcePoolDefinitionList as $definition)
314  {
317  if( $definition->getQuestionAmount() < 1 )
318  {
319  return false;
320  }
321  }
322  }
323  elseif( $this->getQuestionAmountPerTest() < 1 )
324  {
325  return false;
326  }
327 
328  return true;
329  }
330 
331  public function hasSourcePoolDefinitions()
332  {
333  $sourcePoolDefinitionList = $this->buildSourcePoolDefinitionList($this->testOBJ);
334 
335  return $sourcePoolDefinitionList->savedDefinitionsExist();
336  }
337 
338  public function isQuestionSetBuildable()
339  {
340  $sourcePoolDefinitionList = $this->buildSourcePoolDefinitionList($this->testOBJ);
341  $sourcePoolDefinitionList->loadDefinitions();
342 
343  require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetStagingPoolQuestionList.php';
344  $stagingPoolQuestionList = new ilTestRandomQuestionSetStagingPoolQuestionList($this->db, $this->pluginAdmin);
345 
346  require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetBuilder.php';
347  $questionSetBuilder = ilTestRandomQuestionSetBuilder::getInstance($this->db, $this->testOBJ, $this, $sourcePoolDefinitionList, $stagingPoolQuestionList);
348 
349  return $questionSetBuilder->checkBuildable();
350  }
351 
353  {
354  if( $this->dbRecordExists($this->testOBJ->getTestId()) )
355  {
356  return true;
357  }
358 
359  $sourcePoolDefinitionList = $this->buildSourcePoolDefinitionList($this->testOBJ);
360 
361  if( $sourcePoolDefinitionList->savedDefinitionsExist() )
362  {
363  return true;
364  }
365 
366  return false;
367  }
368 
370  {
371  $sourcePoolDefinitionList = $this->buildSourcePoolDefinitionList($this->testOBJ);
372  $sourcePoolDefinitionList->deleteDefinitions();
373 
374  require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetStagingPoolBuilder.php';
376  $this->db, $this->testOBJ
377  );
378  $stagingPool->reset();
379 
381 
382  $this->deleteFromDb();
383  }
384 
386  {
387  $this->testOBJ->setResultFilterTaxIds(array());
388  $this->testOBJ->saveToDb(true);
389  }
390 
396  public function cloneQuestionSetRelatedData(ilObjTest $cloneTestOBJ)
397  {
398  // clone general config
399 
400  $this->loadFromDb();
401  $this->cloneToDbForTestId($cloneTestOBJ->getTestId());
402 
403  // clone source pool definitions (selection rules)
404 
405  $sourcePoolDefinitionList = $this->buildSourcePoolDefinitionList($this->testOBJ);
406  $sourcePoolDefinitionList->loadDefinitions();
407  $definitionIdMap = $sourcePoolDefinitionList->cloneDefinitionsForTestId($cloneTestOBJ->getTestId());
408  $this->registerClonedSourcePoolDefinitionIdMapping($cloneTestOBJ, $definitionIdMap);
409 
410  // build new question stage for cloned test
411 
412  $sourcePoolDefinitionList = $this->buildSourcePoolDefinitionList($cloneTestOBJ);
413  $stagingPool = $this->buildStagingPoolBuilder($cloneTestOBJ);
414 
415  $sourcePoolDefinitionList->loadDefinitions();
416  $stagingPool->rebuild($sourcePoolDefinitionList);
417  $sourcePoolDefinitionList->saveDefinitions();
418 
419  $this->updateLastQuestionSyncTimestampForTestId($cloneTestOBJ->getTestId(), time());
420  }
421 
422  private function registerClonedSourcePoolDefinitionIdMapping(ilObjTest $cloneTestOBJ, $definitionIdMap)
423  {
424  global $ilLog;
425 
426  require_once 'Services/CopyWizard/classes/class.ilCopyWizardOptions.php';
428 
429  foreach($definitionIdMap as $originalDefinitionId => $cloneDefinitionId)
430  {
431  $originalKey = $this->testOBJ->getRefId().'_rndSelDef_'.$originalDefinitionId;
432  $mappedKey = $cloneTestOBJ->getRefId().'_rndSelDef_'.$cloneDefinitionId;
433  $cwo->appendMapping($originalKey, $mappedKey);
434  $ilLog->write(__METHOD__.": Added random selection definition id mapping $originalKey <-> $mappedKey");
435  }
436  }
437 
439  {
440  require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetSourcePoolDefinitionFactory.php';
441  $sourcePoolDefinitionFactory = new ilTestRandomQuestionSetSourcePoolDefinitionFactory(
442  $this->db, $testOBJ
443  );
444 
445  require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetSourcePoolDefinitionList.php';
446  $sourcePoolDefinitionList = new ilTestRandomQuestionSetSourcePoolDefinitionList(
447  $this->db, $testOBJ, $sourcePoolDefinitionFactory
448  );
449 
450  return $sourcePoolDefinitionList;
451  }
452 
454  {
455  require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetStagingPoolBuilder.php';
456  $stagingPool = new ilTestRandomQuestionSetStagingPoolBuilder($this->db, $testOBJ);
457 
458  return $stagingPool;
459  }
460 
461  // -----------------------------------------------------------------------------------------------------------------
462 
464  {
465  $this->db->update('tst_rnd_quest_set_cfg',
466  array(
467  'quest_sync_timestamp' => array('integer', (int)$timestamp)
468  ),
469  array(
470  'test_fi' => array('integer', $testId)
471  )
472  );
473  }
474 
476  {
477  return true;
478  }
479 
480  // -----------------------------------------------------------------------------------------------------------------
481 
482  public function getSelectableQuestionPools()
483  {
484  return $this->testOBJ->getAvailableQuestionpools(
485  true, $this->arePoolsWithHomogeneousScoredQuestionsRequired(), false, true, true
486  );
487  }
488 
490  {
491  return (bool)count($this->getSelectableQuestionPools());
492  }
493 
494  // -----------------------------------------------------------------------------------------------------------------
495 
496  public function areDepenciesBroken()
497  {
498  return (bool)$this->testOBJ->isTestFinalBroken();
499  }
500 
502  {
503  return $lng->txt('tst_old_style_rnd_quest_set_broken');
504  }
505 
507  {
508  //vd($nextClass, $cmd);
509 
510  switch( $nextClass )
511  {
512  case 'ilobjectmetadatagui':
513  case 'ilpermissiongui':
514 
515  return true;
516 
517  case 'ilobjtestgui':
518  case '':
519 
520  $cmds = array(
521  'infoScreen', 'participants', 'npSetFilter', 'npResetFilter',
522  //'deleteAllUserResults', 'confirmDeleteAllUserResults',
523  //'deleteSingleUserResults', 'confirmDeleteSelectedUserData', 'cancelDeleteSelectedUserData'
524  );
525 
526  if( in_array($cmd, $cmds) )
527  {
528  return true;
529  }
530 
531  break;
532  }
533 
534  return false;
535  }
536 
538  {
539  return array(
540  'assQuestions', 'settings', 'manscoring', 'scoringadjust', 'statistics', 'history', 'export'
541  );
542  }
543 
544  // -----------------------------------------------------------------------------------------------------------------
545 
547  {
548  $definitionList = $this->buildSourcePoolDefinitionList($this->testOBJ);
549  $definitionList->loadDefinitions();
550 
551  $poolTitles = array();
552 
553  foreach($definitionList as $definition)
554  {
555  /* @var ilTestRandomQuestionSetSourcePoolDefinition $definition */
556 
557  $refId = current(ilObject::_getAllReferences($definition->getPoolId()));
558  $href = ilLink::_getLink($refId, 'qpl');
559  $title = $definition->getPoolTitle();
560 
561  $poolTitles[$definition->getPoolId()] = "<a href=\"$href\" alt=\"$title\">$title</a>";
562  }
563 
564  return implode(', ', $poolTitles);
565  }
566 }
insertDbRecord($testId)
inserts a new record for the question set config for the current test into the database ...
cloneQuestionSetRelatedData(ilObjTest $cloneTestOBJ)
removes all question set config related data for cloned/copied test
setQuestionAmountConfigurationMode($questionAmountConfigurationMode)
getTestId()
Gets the database id of the additional test data.
$cmd
Definition: sahs_server.php:35
registerClonedSourcePoolDefinitionIdMapping(ilObjTest $cloneTestOBJ, $definitionIdMap)
static _getAllReferences($a_id)
get all reference ids of object
$dataArray
loadFromDb()
loads the question set config for current test from the database
Administration class for plugins.
Interface ilDBInterface.
initFromArray($dataArray)
initialises the current object instance with values from matching properties within the passed array ...
static _getInstance($a_copy_id)
Get instance of copy wizard options.
cloneToDbForTestId($testId)
saves the question set config for test with given id to the database
setLastQuestionSyncTimestamp($lastQuestionSyncTimestamp)
setPoolsWithHomogeneousScoredQuestionsRequired($requirePoolsWithHomogeneousScoredQuestions)
static getInstance(ilDBInterface $db, ilObjTest $testOBJ, ilTestRandomQuestionSetConfig $questionSetConfig, ilTestRandomQuestionSetSourcePoolDefinitionList $sourcePoolDefinitionList, ilTestRandomQuestionSetStagingPoolQuestionList $stagingPoolQuestionList)
saveToDb()
saves the question set config for current test to the database
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
Create styles array
The data for the language used.
foreach($mandatory_scripts as $file) $timestamp
Definition: buildRTE.php:81
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 ...
__construct(ilTree $tree, ilDBInterface $db, ilPluginAdmin $pluginAdmin, ilObjTest $testOBJ)
global $lng
Definition: privfeed.php:17
getRefId()
get reference id public
language handling
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
txt($a_topic, $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
dbRecordExists($testId)
checks wether a question set config for current test exists in the database