ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
48  public function getSourceQuestionPoolId()
49  {
51  }
52 
59  {
60  $this->sourceQuestionPoolId = (int) $sourceQuestionPoolId;
61  }
62 
68  public function getSourceQuestionPoolTitle()
69  {
70  return $this->sourceQuestionPoolTitle;
71  }
72 
78  public function setSourceQuestionPoolTitle($sourceQuestionPoolTitle)
79  {
80  $this->sourceQuestionPoolTitle = $sourceQuestionPoolTitle;
81  }
82 
86  public function isAnswerStatusFilterEnabled()
87  {
89  }
90 
95  {
96  $this->answerStatusFilterEnabled = $answerStatusFilterEnabled;
97  }
98 
104  public function isTaxonomyFilterEnabled()
105  {
107  }
108 
115  {
116  $this->taxonomyFilterEnabled = (bool) $taxonomyFilterEnabled;
117  }
118 
124  public function getOrderingTaxonomyId()
125  {
127  }
128 
135  {
136  $this->orderingTaxonomyId = $orderingTaxonomyId;
137  }
138 
145  public function initFromArray($dataArray)
146  {
147  foreach ($dataArray as $field => $value) {
148  switch ($field) {
149  case 'source_qpl_fi': $this->setSourceQuestionPoolId($value); break;
150  case 'source_qpl_title': $this->setSourceQuestionPoolTitle($value); break;
151  case 'answer_filter_enabled': $this->setAnswerStatusFilterEnabled($value); break;
152  case 'tax_filter_enabled': $this->setTaxonomyFilterEnabled($value); break;
153  case 'order_tax': $this->setOrderingTaxonomyId($value); break;
154  }
155  }
156  }
157 
163  public function loadFromDb()
164  {
165  $res = $this->db->queryF(
166  "SELECT * FROM tst_dyn_quest_set_cfg WHERE test_fi = %s",
167  array('integer'),
168  array($this->testOBJ->getTestId())
169  );
170 
171  while ($row = $this->db->fetchAssoc($res)) {
172  $this->initFromArray($row);
173 
174  return true;
175  }
176 
177  return false;
178  }
179 
183  public function saveToDb()
184  {
185  if ($this->dbRecordExists($this->testOBJ->getTestId())) {
186  $this->updateDbRecord($this->testOBJ->getTestId());
187  } else {
188  $this->insertDbRecord($this->testOBJ->getTestId());
189  }
190  }
191 
197  public function cloneToDbForTestId($testId)
198  {
199  $this->insertDbRecord($testId);
200  }
201 
207  public function deleteFromDb()
208  {
209  $aff = $this->db->manipulateF(
210  "DELETE FROM tst_dyn_quest_set_cfg WHERE test_fi = %s",
211  array('integer'),
212  array($this->testOBJ->getTestId())
213  );
214 
215  return (bool) $aff;
216  }
217 
224  private function dbRecordExists($testId)
225  {
226  $res = $this->db->queryF(
227  "SELECT COUNT(*) cnt FROM tst_dyn_quest_set_cfg WHERE test_fi = %s",
228  array('integer'),
229  array($testId)
230  );
231 
232  $row = $this->db->fetchAssoc($res);
233 
234  return (bool) $row['cnt'];
235  }
236 
243  private function updateDbRecord($testId)
244  {
245  $this->db->update(
246  'tst_dyn_quest_set_cfg',
247  array(
248  'source_qpl_fi' => array('integer', $this->getSourceQuestionPoolId()),
249  'source_qpl_title' => array('text', $this->getSourceQuestionPoolTitle()),
250  'answer_filter_enabled' => array('integer', $this->isAnswerStatusFilterEnabled()),
251  'tax_filter_enabled' => array('integer', $this->isTaxonomyFilterEnabled()),
252  'order_tax' => array('integer', $this->getOrderingTaxonomyId())
253  ),
254  array(
255  'test_fi' => array('integer', $testId)
256  )
257  );
258  }
259 
266  private function insertDbRecord($testId)
267  {
268  $this->db->insert('tst_dyn_quest_set_cfg', array(
269  'test_fi' => array('integer', $testId),
270  'source_qpl_fi' => array('integer', $this->getSourceQuestionPoolId()),
271  'source_qpl_title' => array('text', $this->getSourceQuestionPoolTitle()),
272  'answer_filter_enabled' => array('integer', $this->isAnswerStatusFilterEnabled()),
273  'tax_filter_enabled' => array('integer', $this->isTaxonomyFilterEnabled()),
274  'order_tax' => array('integer', $this->getOrderingTaxonomyId())
275  ));
276  }
277 
283  public function isQuestionSetConfigured()
284  {
285  return $this->getSourceQuestionPoolId() > 0;
286  }
287 
294  {
295  return $this->isQuestionSetConfigured();
296  }
297 
303  {
304  $this->deleteFromDb();
305  }
306 
308  {
309  // nothing to do
310  }
311 
317  public function cloneQuestionSetRelatedData(ilObjTest $cloneTestOBJ)
318  {
319  $this->loadFromDb();
320  $this->cloneToDbForTestId($cloneTestOBJ->getTestId());
321  }
322 
329  {
330  $poolRefs = $this->getSourceQuestionPoolRefIds();
331 
332  if (!count($poolRefs)) {
333  $sourceQuestionPoolSummaryString = sprintf(
334  $lng->txt('tst_dyn_quest_set_src_qpl_summary_string_deleted'),
336  );
337 
338  return $sourceQuestionPoolSummaryString;
339  }
340 
341  foreach ($poolRefs as $refId) {
342  if (!$this->tree->isDeleted($refId)) {
343  $sourceQuestionPoolSummaryString = sprintf(
344  $lng->txt('tst_dynamic_question_set_source_questionpool_summary_string'),
348  );
349 
350  return $sourceQuestionPoolSummaryString;
351  }
352  }
353 
354  $sourceQuestionPoolSummaryString = sprintf(
355  $lng->txt('tst_dyn_quest_set_src_qpl_summary_string_trashed'),
358  );
359 
360  return $sourceQuestionPoolSummaryString;
361  }
362 
367  {
368  $query = "
369  SELECT COUNT(*) num from qpl_questions
370  WHERE obj_fi = %s AND original_id IS NULL
371  ";
372 
373  $res = $this->db->queryF(
374  $query,
375  array('integer'),
377  );
378 
379  $row = $this->db->fetchAssoc($res);
380 
381  return $row['num'];
382  }
383 
385  {
386  if (!$this->getSourceQuestionPoolId()) {
387  return false;
388  }
389 
390  $poolRefs = $this->getSourceQuestionPoolRefIds();
391 
392  foreach ($poolRefs as $refId) {
393  if (!$this->tree->isDeleted($refId)) {
394  return false;
395  }
396  }
397 
398  return true;
399  }
400 
402  {
403  $msg = sprintf(
404  $lng->txt('tst_dyn_quest_set_pool_trashed'),
406  );
407 
408  return $msg;
409  }
410 
411  public function areDepenciesBroken()
412  {
413  if (!$this->getSourceQuestionPoolId()) {
414  return false;
415  }
416 
417  $poolRefs = $this->getSourceQuestionPoolRefIds();
418 
419  if (count($poolRefs)) {
420  return false;
421  }
422 
423  return true;
424  }
425 
427  {
428  $msg = sprintf(
429  $lng->txt('tst_dyn_quest_set_pool_deleted'),
431  );
432 
433  return $msg;
434  }
435 
436  public function isValidRequestOnBrokenQuestionSetDepencies($nextClass, $cmd)
437  {
438  //vd($nextClass, $cmd);
439 
440  if (!$this->testOBJ->participantDataExist()) {
441  return true;
442  }
443 
444  switch ($nextClass) {
445  case 'ilobjtestdynamicquestionsetconfiggui':
446 
447  case 'ilobjectmetadatagui':
448  case 'ilpermissiongui':
449 
450  return true;
451 
452  case 'ilobjtestgui':
453  case '':
454 
455  $cmds = array(
456  'infoScreen', 'participants', 'npSetFilter', 'npResetFilter',
457  'deleteAllUserResults', 'confirmDeleteAllUserResults',
458  'deleteSingleUserResults', 'confirmDeleteSelectedUserData', 'cancelDeleteSelectedUserData'
459  );
460 
461  if (in_array($cmd, $cmds)) {
462  return true;
463  }
464 
465  break;
466  }
467 
468  return false;
469  }
470 
472  {
473  return array(
474  'settings', 'manscoring', 'scoringadjust', 'statistics', 'history', 'export'
475  );
476  }
477 
479 
480  public function getSourceQuestionPoolRefIds()
481  {
482  if ($this->sourceQuestionPoolRefIds === null) {
483  $this->sourceQuestionPoolRefIds = ilObject::_getAllReferences($this->getSourceQuestionPoolId());
484  }
485 
487  }
488 
493  public static function getPoolQuestionChangeListener(ilDBInterface $db, $poolObjId)
494  {
495  $query = "
496  SELECT obj_fi
497  FROM tst_dyn_quest_set_cfg
498  INNER JOIN tst_tests
499  ON tst_tests.test_id = tst_dyn_quest_set_cfg.test_fi
500  WHERE source_qpl_fi = %s
501  ";
502 
503  $res = $db->queryF($query, array('integer'), array($poolObjId));
504 
505  require_once 'Modules/Test/classes/class.ilDynamicTestQuestionChangeListener.php';
506  $questionChangeListener = new ilDynamicTestQuestionChangeListener($db);
507 
508  while ($row = $db->fetchAssoc($res)) {
509  $questionChangeListener->addTestObjId($row['obj_fi']);
510  }
511 
512  return $questionChangeListener;
513  }
514 
516  {
517  return false;
518  }
519 
520  public function isAnyQuestionFilterEnabled()
521  {
522  if ($this->isTaxonomyFilterEnabled()) {
523  return true;
524  }
525 
526  if ($this->isAnswerStatusFilterEnabled()) {
527  return true;
528  }
529 
530  return false;
531  }
532 
533  public function getSourceQuestionPoolLink()
534  {
535  $refId = current(ilObject::_getAllReferences($this->getSourceQuestionPoolId()));
536  $href = ilLink::_getLink($refId, 'qpl');
538 
539  return "<a href=\"$href\" alt=\"$title\">$title</a>";
540  }
541 }
saveToDb()
saves the question set config for current test to the database
initFromArray($dataArray)
initialises the current object instance with values from matching properties within the passed array ...
loadFromDb()
loads the question set config for current test from the database
getTestId()
Gets the database id of the additional test data.
cloneQuestionSetRelatedData(ilObjTest $cloneTestOBJ)
removes all question set config related data for cloned/copied test
static getPoolQuestionChangeListener(ilDBInterface $db, $poolObjId)
isTaxonomyFilterEnabled()
isser for taxonomie filter enabled
setTaxonomyFilterEnabled($taxonomyFilterEnabled)
setter for taxonomie filter enabled
setOrderingTaxonomyId($orderingTaxonomyId)
getter for ordering taxonomy id
static _getAllReferences($a_id)
get all reference ids of object
$dataArray
deleteFromDb()
deletes the question set config for current test from the database
Interface ilDBInterface.
isQuestionSetConfigured()
returns the fact wether a useable question set config exists or not
getSourceQuestionPoolTitle()
getter for source question pool title
foreach($_POST as $key=> $value) $res
setSourceQuestionPoolId($sourceQuestionPoolId)
getter for source question pool id
queryF($query, $types, $values)
$query
Create styles array
The data for the language used.
updateDbRecord($testId)
updates the record in the database that corresponds to the question set config for the current test ...
global $lng
Definition: privfeed.php:17
fetchAssoc($query_result)
insertDbRecord($testId)
inserts a new record for the question set config for the current test into the database ...
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...
setSourceQuestionPoolTitle($sourceQuestionPoolTitle)
getter for source question pool title
getSourceQuestionPoolId()
getter for source question pool id
dbRecordExists($testId)
checks wether a question set config for current test exists in the database
removeQuestionSetRelatedData()
removes all question set config related data (in this case it&#39;s only the config itself) ...
doesQuestionSetRelatedDataExist()
returns the fact wether a useable question set config exists or not
cloneToDbForTestId($testId)
saves the question set config for test with given id to the database