ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f87
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 
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($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  $sourcePoolDefinitionList->cloneDefinitionsForTestId($cloneTestOBJ->getTestId());
395 
396  // build new question stage for cloned test
397 
398  $sourcePoolDefinitionList = $this->buildSourcePoolDefinitionList($cloneTestOBJ);
399  $stagingPool = $this->buildStagingPoolBuilder($cloneTestOBJ);
400 
401  $sourcePoolDefinitionList->loadDefinitions();
402  $stagingPool->rebuild($sourcePoolDefinitionList);
403  $sourcePoolDefinitionList->saveDefinitions();
404 
405  $this->updateLastQuestionSyncTimestampForTestId($cloneTestOBJ->getTestId(), time());
406  }
407 
409  {
410  require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetSourcePoolDefinitionFactory.php';
411  $sourcePoolDefinitionFactory = new ilTestRandomQuestionSetSourcePoolDefinitionFactory(
412  $this->db, $testOBJ
413  );
414 
415  require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetSourcePoolDefinitionList.php';
416  $sourcePoolDefinitionList = new ilTestRandomQuestionSetSourcePoolDefinitionList(
417  $this->db, $testOBJ, $sourcePoolDefinitionFactory
418  );
419 
420  return $sourcePoolDefinitionList;
421  }
422 
424  {
425  require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetStagingPoolBuilder.php';
426  $stagingPool = new ilTestRandomQuestionSetStagingPoolBuilder($this->db, $testOBJ);
427 
428  return $stagingPool;
429  }
430 
431  // -----------------------------------------------------------------------------------------------------------------
432 
434  {
435  $this->db->update('tst_rnd_quest_set_cfg',
436  array(
437  'quest_sync_timestamp' => array('integer', (int)$timestamp)
438  ),
439  array(
440  'test_fi' => array('integer', $testId)
441  )
442  );
443  }
444 
446  {
447  return true;
448  }
449 
450  // -----------------------------------------------------------------------------------------------------------------
451 
452  public function getSelectableQuestionPools()
453  {
454  return $this->testOBJ->getAvailableQuestionpools(
455  true, $this->arePoolsWithHomogeneousScoredQuestionsRequired(), false, true, true
456  );
457  }
458 
460  {
461  return (bool)count($this->getSelectableQuestionPools());
462  }
463 
464  // -----------------------------------------------------------------------------------------------------------------
465 
466  public function areDepenciesBroken()
467  {
468  return (bool)$this->testOBJ->isTestFinalBroken();
469  }
470 
472  {
473  return $lng->txt('tst_old_style_rnd_quest_set_broken');
474  }
475 
477  {
478  //vd($nextClass, $cmd);
479 
480  switch( $nextClass )
481  {
482  case 'ilmdeditorgui':
483  case 'ilpermissiongui':
484 
485  return true;
486 
487  case 'ilobjtestgui':
488  case '':
489 
490  $cmds = array(
491  'infoScreen', 'participants', 'npSetFilter', 'npResetFilter',
492  //'deleteAllUserResults', 'confirmDeleteAllUserResults',
493  //'deleteSingleUserResults', 'confirmDeleteSelectedUserData', 'cancelDeleteSelectedUserData'
494  );
495 
496  if( in_array($cmd, $cmds) )
497  {
498  return true;
499  }
500 
501  break;
502  }
503 
504  return false;
505  }
506 
508  {
509  return array(
510  'assQuestions', 'settings', 'manscoring', 'scoringadjust', 'statistics', 'history', 'export'
511  );
512  }
513 }
insertDbRecord($testId)
inserts a new record for the question set config for the current test into the database ...
setQuestionAmountConfigurationMode($questionAmountConfigurationMode)
static getInstance(ilDB $db, ilObjTest $testOBJ, ilTestRandomQuestionSetConfig $questionSetConfig, ilTestRandomQuestionSetSourcePoolDefinitionList $sourcePoolDefinitionList, ilTestRandomQuestionSetStagingPoolQuestionList $stagingPoolQuestionList)
$cmd
Definition: sahs_server.php:35
loadFromDb()
loads the question set config for current test from the database
Administration class for plugins.
initFromArray($dataArray)
initialises the current object instance with values from matching properties within the passed array ...
cloneToDbForTestId($testId)
saves the question set config for test with given id to the database
setLastQuestionSyncTimestamp($lastQuestionSyncTimestamp)
__construct(ilTree $tree, ilDB $db, ilPluginAdmin $pluginAdmin, ilObjTest $testOBJ)
setPoolsWithHomogeneousScoredQuestionsRequired($requirePoolsWithHomogeneousScoredQuestions)
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...
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 ...
cloneQuestionSetRelatedData($cloneTestOBJ)
removes all question set config related data for cloned/copied test
Database Wrapper.
Definition: class.ilDB.php:28
global $lng
Definition: privfeed.php:40
language handling
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