ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjTestDynamicQuestionSetConfig.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 {
21  private $sourceQuestionPoolId = null;
22 
27 
34  private $taxonomyFilterEnabled = null;
35 
41  private $orderingTaxonomyId = null;
42 
47 
53  public function getSourceQuestionPoolId()
54  {
56  }
57 
64  {
65  $this->sourceQuestionPoolId = (int)$sourceQuestionPoolId;
66  }
67 
73  public function getSourceQuestionPoolTitle()
74  {
75  return $this->sourceQuestionPoolTitle;
76  }
77 
83  public function setSourceQuestionPoolTitle($sourceQuestionPoolTitle)
84  {
85  $this->sourceQuestionPoolTitle = $sourceQuestionPoolTitle;
86  }
87 
91  public function isAnswerStatusFilterEnabled()
92  {
94  }
95 
100  {
101  $this->answerStatusFilterEnabled = $answerStatusFilterEnabled;
102  }
103 
109  public function isTaxonomyFilterEnabled()
110  {
112  }
113 
120  {
121  $this->taxonomyFilterEnabled = (bool)$taxonomyFilterEnabled;
122  }
123 
129  public function getOrderingTaxonomyId()
130  {
132  }
133 
140  {
141  $this->orderingTaxonomyId = $orderingTaxonomyId;
142  }
143 
148  {
150  }
151 
156  {
157  $this->previousQuestionsListEnabled = $previousQuestionsListEnabled;
158  }
159 
166  public function initFromArray($dataArray)
167  {
168  foreach($dataArray as $field => $value)
169  {
170  switch($field)
171  {
172  case 'source_qpl_fi': $this->setSourceQuestionPoolId($value); break;
173  case 'source_qpl_title': $this->setSourceQuestionPoolTitle($value); break;
174  case 'answer_filter_enabled': $this->setAnswerStatusFilterEnabled($value); break;
175  case 'tax_filter_enabled': $this->setTaxonomyFilterEnabled($value); break;
176  case 'order_tax': $this->setOrderingTaxonomyId($value); break;
177  case 'prev_quest_list_enabled': $this->setPreviousQuestionsListEnabled($value); break;
178  }
179  }
180  }
181 
187  public function loadFromDb()
188  {
189  $res = $this->db->queryF(
190  "SELECT * FROM tst_dyn_quest_set_cfg WHERE test_fi = %s",
191  array('integer'), array($this->testOBJ->getTestId())
192  );
193 
194  while( $row = $this->db->fetchAssoc($res) )
195  {
196  $this->initFromArray($row);
197 
198  return true;
199  }
200 
201  return false;
202  }
203 
207  public function saveToDb()
208  {
209  if( $this->dbRecordExists($this->testOBJ->getTestId()) )
210  {
211  $this->updateDbRecord($this->testOBJ->getTestId());
212  }
213  else
214  {
215  $this->insertDbRecord($this->testOBJ->getTestId());
216  }
217  }
218 
224  public function cloneToDbForTestId($testId)
225  {
226  $this->insertDbRecord($testId);
227  }
228 
234  public function deleteFromDb()
235  {
236  $aff = $this->db->manipulateF(
237  "DELETE FROM tst_dyn_quest_set_cfg WHERE test_fi = %s",
238  array('integer'), array($this->testOBJ->getTestId())
239  );
240 
241  return (bool)$aff;
242  }
243 
250  private function dbRecordExists($testId)
251  {
252  $res = $this->db->queryF(
253  "SELECT COUNT(*) cnt FROM tst_dyn_quest_set_cfg WHERE test_fi = %s",
254  array('integer'), array($testId)
255  );
256 
257  $row = $this->db->fetchAssoc($res);
258 
259  return (bool)$row['cnt'];
260  }
261 
268  private function updateDbRecord($testId)
269  {
270  $this->db->update('tst_dyn_quest_set_cfg',
271  array(
272  'source_qpl_fi' => array('integer', $this->getSourceQuestionPoolId()),
273  'source_qpl_title' => array('text', $this->getSourceQuestionPoolTitle()),
274  'answer_filter_enabled' => array('integer', $this->isAnswerStatusFilterEnabled()),
275  'tax_filter_enabled' => array('integer', $this->isTaxonomyFilterEnabled()),
276  'order_tax' => array('integer', $this->getOrderingTaxonomyId()),
277  'prev_quest_list_enabled' => array('integer', $this->isPreviousQuestionsListEnabled())
278  ),
279  array(
280  'test_fi' => array('integer', $testId)
281  )
282  );
283  }
284 
291  private function insertDbRecord($testId)
292  {
293  $this->db->insert('tst_dyn_quest_set_cfg', array(
294  'test_fi' => array('integer', $testId),
295  'source_qpl_fi' => array('integer', $this->getSourceQuestionPoolId()),
296  'source_qpl_title' => array('text', $this->getSourceQuestionPoolTitle()),
297  'answer_filter_enabled' => array('integer', $this->isAnswerStatusFilterEnabled()),
298  'tax_filter_enabled' => array('integer', $this->isTaxonomyFilterEnabled()),
299  'order_tax' => array('integer', $this->getOrderingTaxonomyId()),
300  'prev_quest_list_enabled' => array('integer', $this->isPreviousQuestionsListEnabled())
301  ));
302  }
303 
309  public function isQuestionSetConfigured()
310  {
311  return $this->getSourceQuestionPoolId() > 0;
312  }
313 
320  {
321  return $this->isQuestionSetConfigured();
322  }
323 
329  {
330  $this->deleteFromDb();
331  }
332 
338  public function cloneQuestionSetRelatedData($cloneTestOBJ)
339  {
340  $this->loadFromDb();
341  $this->cloneToDbForTestId($cloneTestOBJ->getTestId());
342  }
343 
350  {
351  $poolRefs = $this->getSourceQuestionPoolRefIds();
352 
353  if( !count($poolRefs) )
354  {
355  $sourceQuestionPoolSummaryString = sprintf(
356  $lng->txt('tst_dyn_quest_set_src_qpl_summary_string_deleted'),
358  );
359 
360  return $sourceQuestionPoolSummaryString;
361  }
362 
363  foreach($poolRefs as $refId)
364  {
365  if( !$this->tree->isDeleted($refId) )
366  {
367  $sourceQuestionPoolSummaryString = sprintf(
368  $lng->txt('tst_dynamic_question_set_source_questionpool_summary_string'),
372  );
373 
374  return $sourceQuestionPoolSummaryString;
375  }
376  }
377 
378  $sourceQuestionPoolSummaryString = sprintf(
379  $lng->txt('tst_dyn_quest_set_src_qpl_summary_string_trashed'),
382  );
383 
384  return $sourceQuestionPoolSummaryString;
385  }
386 
391  {
392  $query = "
393  SELECT COUNT(*) num from qpl_questions
394  WHERE obj_fi = %s AND original_id IS NULL
395  ";
396 
397  $res = $this->db->queryF(
398  $query, array('integer'), array($this->getSourceQuestionPoolId())
399  );
400 
401  $row = $this->db->fetchAssoc($res);
402 
403  return $row['num'];
404  }
405 
407  {
408  if( !$this->getSourceQuestionPoolId() )
409  {
410  return false;
411  }
412 
413  $poolRefs = $this->getSourceQuestionPoolRefIds();
414 
415  foreach( $poolRefs as $refId )
416  {
417  if( !$this->tree->isDeleted($refId) )
418  {
419  return false;
420  }
421  }
422 
423  return true;
424  }
425 
427  {
428  $msg = sprintf(
429  $lng->txt('tst_dyn_quest_set_pool_trashed'), $this->getSourceQuestionPoolTitle()
430  );
431 
432  return $msg;
433  }
434 
435  public function areDepenciesBroken()
436  {
437  if( !$this->getSourceQuestionPoolId() )
438  {
439  return false;
440  }
441 
442  $poolRefs = $this->getSourceQuestionPoolRefIds();
443 
444  if( count($poolRefs) )
445  {
446  return false;
447  }
448 
449  return true;
450  }
451 
453  {
454  $msg = sprintf(
455  $lng->txt('tst_dyn_quest_set_pool_deleted'), $this->getSourceQuestionPoolTitle()
456  );
457 
458  return $msg;
459  }
460 
462  {
463  //vd($nextClass, $cmd);
464 
465  if( !$this->testOBJ->participantDataExist() )
466  {
467  return true;
468  }
469 
470  switch( $nextClass )
471  {
472  case 'ilobjtestdynamicquestionsetconfiggui':
473 
474  case 'ilmdeditorgui':
475  case 'ilpermissiongui':
476 
477  return true;
478 
479  case 'ilobjtestgui':
480  case '':
481 
482  $cmds = array(
483  'infoScreen', 'participants', 'npSetFilter', 'npResetFilter',
484  'deleteAllUserResults', 'confirmDeleteAllUserResults',
485  'deleteSingleUserResults', 'confirmDeleteSelectedUserData', 'cancelDeleteSelectedUserData'
486  );
487 
488  if( in_array($cmd, $cmds) )
489  {
490  return true;
491  }
492 
493  break;
494  }
495 
496  return false;
497  }
498 
500  {
501  return array(
502  'settings', 'manscoring', 'scoringadjust', 'statistics', 'history', 'export'
503  );
504  }
505 
507 
508  public function getSourceQuestionPoolRefIds()
509  {
510  if( $this->sourceQuestionPoolRefIds === null )
511  {
512  $this->sourceQuestionPoolRefIds = ilObject::_getAllReferences($this->getSourceQuestionPoolId());
513  }
514 
516  }
517 
522  public static function getPoolQuestionChangeListener(ilDB $db, $poolObjId)
523  {
524  $query = "
525  SELECT obj_fi
526  FROM tst_dyn_quest_set_cfg
527  INNER JOIN tst_tests
528  ON tst_tests.test_id = tst_dyn_quest_set_cfg.test_fi
529  WHERE source_qpl_fi = %s
530  ";
531 
532  $res = $db->queryF($query, array('integer'), array($poolObjId));
533 
534  require_once 'Modules/Test/classes/class.ilDynamicTestQuestionChangeListener.php';
535  $questionChangeListener = new ilDynamicTestQuestionChangeListener($db);
536 
537  while( $row = $db->fetchAssoc($res) )
538  {
539  $questionChangeListener->addTestObjId( $row['obj_fi'] );
540  }
541 
542  return $questionChangeListener;
543  }
544 }