ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f87
class.ilDynamicTestQuestionChangeListener.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/TestQuestionPool/interfaces/interface.ilQuestionChangeListener.php';
5 
15 {
19  protected $db = null;
20 
24  public function __construct(ilDB $db)
25  {
26  $this->db = $db;
27  }
28 
32  private $testObjIds = array();
33 
37  public function addTestObjId($testObjId)
38  {
39  $this->testObjIds[] = $testObjId;
40  }
41 
45  public function getTestObjIds()
46  {
47  return $this->testObjIds;
48  }
49 
53  public function notifyQuestionCreated(assQuestion $question)
54  {
55  //mail('bheyser@databay.de', __METHOD__, __METHOD__);
56  // nothing to do
57  }
58 
62  public function notifyQuestionEdited(assQuestion $question)
63  {
64  //mail('bheyser@databay.de', __METHOD__, __METHOD__);
65  $this->deleteTestsParticipantsQuestionData($question);
66  }
67 
68  public function notifyQuestionDeleted(assQuestion $question)
69  {
70  //mail('bheyser@databay.de', __METHOD__, __METHOD__);
71  $this->deleteTestsParticipantsQuestionData($question);
72  }
73 
78  {
79  $activeIds = $this->getActiveIds();
80 
81  if( !count($activeIds) )
82  {
83  return null;
84  }
85 
86  $this->deleteTestsParticipantsResultsForQuestion($activeIds, $question->getId());
87  $this->deleteTestsParticipantsTrackingsForQuestion($activeIds, $question->getId());
88 
89  }
90 
91  private function deleteTestsParticipantsResultsForQuestion($activeIds, $questionId)
92  {
93  $inActiveIds = $this->db->in('active_fi', $activeIds, false, 'integer');
94 
95  $this->db->manipulateF(
96  "DELETE FROM tst_solutions WHERE question_fi = %s AND $inActiveIds",
97  array('integer'), array($questionId)
98  );
99 
100  $this->db->manipulateF(
101  "DELETE FROM tst_qst_solved WHERE question_fi = %s AND $inActiveIds",
102  array('integer'), array($questionId)
103  );
104 
105  $this->db->manipulateF(
106  "DELETE FROM tst_test_result WHERE question_fi = %s AND $inActiveIds",
107  array('integer'), array($questionId)
108  );
109 
110  $this->db->manipulate("DELETE FROM tst_pass_result WHERE $inActiveIds");
111 
112  $this->db->manipulate("DELETE FROM tst_result_cache WHERE $inActiveIds");
113  }
114 
115  private function deleteTestsParticipantsTrackingsForQuestion($activeIds, $questionId)
116  {
117  $inActiveIds = $this->db->in('active_fi', $activeIds, false, 'integer');
118 
119  $tables = array(
120  'tst_seq_qst_tracking', 'tst_seq_qst_answstatus', 'tst_seq_qst_postponed', 'tst_seq_qst_checked'
121  );
122 
123  foreach($tables as $table)
124  {
125  $this->db->manipulateF(
126  "DELETE FROM $table WHERE question_fi = %s AND $inActiveIds",
127  array('integer'), array($questionId)
128  );
129  }
130  }
131 
132  private function getActiveIds()
133  {
134  if( !count($this->getTestObjIds()) )
135  {
136  return null;
137  }
138 
139  $inTestObjIds = $this->db->in('obj_fi', $this->getTestObjIds(), false, 'integer');
140 
141  $res = $this->db->query("
142  SELECT active_id
143  FROM tst_tests
144  INNER JOIN tst_active
145  ON test_fi = test_id
146  WHERE $inTestObjIds
147  ");
148 
149  $activeIds = array();
150 
151  while( $row = $this->db->fetchAssoc($res) )
152  {
153  $activeIds[] = $row['active_id'];
154  }
155 
156  return $activeIds;
157  }
158 }
getId()
Gets the id of the assQuestion object.
Abstract basic class which is to be extended by the concrete assessment question type classes...
Database Wrapper.
Definition: class.ilDB.php:28