ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  {
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 
366  $stagingPool->reset();
367 
368  $this->deleteFromDb();
369  }
370 
376  public function cloneQuestionSetRelatedData($cloneTestOBJ)
377  {
378  // clone general config
379 
380  $this->loadFromDb();
381  $this->cloneToDbForTestId($cloneTestOBJ->getTestId());
382 
383  // clone source pool definitions (selection rules)
384 
385  $sourcePoolDefinitionList = $this->buildSourcePoolDefinitionList($this->testOBJ);
386  $sourcePoolDefinitionList->loadDefinitions();
387  $sourcePoolDefinitionList->cloneDefinitionsForTestId($cloneTestOBJ->getTestId());
388 
389  // build new question stage for cloned test
390 
391  $sourcePoolDefinitionList = $this->buildSourcePoolDefinitionList($cloneTestOBJ);
392  $stagingPool = $this->buildStagingPoolBuilder($cloneTestOBJ);
393 
394  $sourcePoolDefinitionList->loadDefinitions();
395  $stagingPool->rebuild($sourcePoolDefinitionList);
396  $sourcePoolDefinitionList->saveDefinitions();
397 
398  $this->updateLastQuestionSyncTimestampForTestId($cloneTestOBJ->getTestId(), time());
399  }
400 
402  {
403  require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetSourcePoolDefinitionFactory.php';
404  $sourcePoolDefinitionFactory = new ilTestRandomQuestionSetSourcePoolDefinitionFactory(
405  $this->db, $testOBJ
406  );
407 
408  require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetSourcePoolDefinitionList.php';
409  $sourcePoolDefinitionList = new ilTestRandomQuestionSetSourcePoolDefinitionList(
410  $this->db, $testOBJ, $sourcePoolDefinitionFactory
411  );
412 
413  return $sourcePoolDefinitionList;
414  }
415 
417  {
418  require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetStagingPoolBuilder.php';
419  $stagingPool = new ilTestRandomQuestionSetStagingPoolBuilder($this->db, $testOBJ);
420 
421  return $stagingPool;
422  }
423 
424  // -----------------------------------------------------------------------------------------------------------------
425 
427  {
428  $this->db->update('tst_rnd_quest_set_cfg',
429  array(
430  'quest_sync_timestamp' => array('integer', (int)$timestamp)
431  ),
432  array(
433  'test_fi' => array('integer', $testId)
434  )
435  );
436  }
437 
438  // -----------------------------------------------------------------------------------------------------------------
439 
440  public function getSelectableQuestionPools()
441  {
442  return $this->testOBJ->getAvailableQuestionpools(
443  true, $this->arePoolsWithHomogeneousScoredQuestionsRequired(), false, true, true
444  );
445  }
446 
448  {
449  return (bool)count($this->getSelectableQuestionPools());
450  }
451 
452  // -----------------------------------------------------------------------------------------------------------------
453 
454  public function areDepenciesBroken()
455  {
456  return (bool)$this->testOBJ->isTestFinalBroken();
457  }
458 
460  {
461  return $lng->txt('tst_old_style_rnd_quest_set_broken');
462  }
463 
465  {
466  //vd($nextClass, $cmd);
467 
468  switch( $nextClass )
469  {
470  case 'ilmdeditorgui':
471  case 'ilpermissiongui':
472 
473  return true;
474 
475  case 'ilobjtestgui':
476  case '':
477 
478  $cmds = array(
479  'infoScreen', 'participants', 'npSetFilter', 'npResetFilter',
480  //'deleteAllUserResults', 'confirmDeleteAllUserResults',
481  //'deleteSingleUserResults', 'confirmDeleteSelectedUserData', 'cancelDeleteSelectedUserData'
482  );
483 
484  if( in_array($cmd, $cmds) )
485  {
486  return true;
487  }
488 
489  break;
490  }
491 
492  return false;
493  }
494 
496  {
497  return array(
498  'assQuestions', 'settings', 'manscoring', 'scoringadjust', 'statistics', 'history', 'export'
499  );
500  }
501 }