ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTestSessionDynamicQuestionSet.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.ilTestSession.php';
5 require_once 'Modules/Test/classes/class.ilTestDynamicQuestionSetFilterSelection.php';
6 
7 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionList.php';
8 
18 {
23 
24  public function __construct()
25  {
27 
28  $this->questionSetFilterSelection = new ilTestDynamicQuestionSetFilterSelection();
29  }
30 
35  {
37  }
38 
39  public function loadFromDb($active_id)
40  {
41  global $ilDB;
42  $result = $ilDB->queryF("SELECT * FROM tst_active WHERE active_id = %s",
43  array('integer'),
44  array($active_id)
45  );
46  if ($result->numRows())
47  {
48  $row = $ilDB->fetchAssoc($result);
49  $this->active_id = $row["active_id"];
50  $this->user_id = $row["user_fi"];
51  $this->anonymous_id = $row["anonymous_id"];
52  $this->test_id = $row["test_fi"];
53  $this->lastsequence = $row["lastindex"];
54  $this->pass = $row["tries"];
55  $this->submitted = ($row["submitted"]) ? TRUE : FALSE;
56  $this->submittedTimestamp = $row["submittimestamp"];
57  $this->tstamp = $row["tstamp"];
58 
59  $this->questionSetFilterSelection->setTaxonomySelection(unserialize($row['taxfilter']));
60  $this->questionSetFilterSelection->setAnswerStatusSelection($row['answerstatusfilter']);
61  $this->questionSetFilterSelection->setAnswerStatusActiveId($row['active_id']);
62  }
63  }
64 
66  {
67  global $ilDB;
68  global $ilUser;
69 
70  if (!$user_id)
71  {
72  $user_id = $ilUser->getId();
73  }
74  if (($_SESSION["AccountId"] == ANONYMOUS_USER_ID) && $this->doesAccessCodeInSessionExists())
75  {
76  $result = $ilDB->queryF("SELECT * FROM tst_active WHERE user_fi = %s AND test_fi = %s AND anonymous_id = %s",
77  array('integer','integer','text'),
79  );
80  }
81  else if (strlen($anonymous_id))
82  {
83  $result = $ilDB->queryF("SELECT * FROM tst_active WHERE user_fi = %s AND test_fi = %s AND anonymous_id = %s",
84  array('integer','integer','text'),
86  );
87  }
88  else
89  {
90  if ($_SESSION["AccountId"] == ANONYMOUS_USER_ID)
91  {
92  return NULL;
93  }
94  $result = $ilDB->queryF("SELECT * FROM tst_active WHERE user_fi = %s AND test_fi = %s",
95  array('integer','integer'),
96  array($user_id, $test_id)
97  );
98  }
99  if ($result->numRows())
100  {
101  $row = $ilDB->fetchAssoc($result);
102  $this->active_id = $row["active_id"];
103  $this->user_id = $row["user_fi"];
104  $this->anonymous_id = $row["anonymous_id"];
105  $this->test_id = $row["test_fi"];
106  $this->lastsequence = $row["lastindex"];
107  $this->pass = $row["tries"];
108  $this->submitted = ($row["submitted"]) ? TRUE : FALSE;
109  $this->submittedTimestamp = $row["submittimestamp"];
110  $this->tstamp = $row["tstamp"];
111 
112  $this->questionSetFilterSelection->setTaxonomySelection(unserialize($row['taxfilter']));
113  $this->questionSetFilterSelection->setAnswerStatusSelection($row['answerstatusfilter']);
114  $this->questionSetFilterSelection->setAnswerStatusActiveId($row['active_id']);
115  }
116  elseif( $this->doesAccessCodeInSessionExists() )
117  {
118  $this->unsetAccessCodeInSession();
119  }
120  }
121 
122  function saveToDb()
123  {
124  global $ilDB, $ilLog;
125 
126  $submitted = ($this->isSubmitted()) ? 1 : 0;
127  if ($this->active_id > 0)
128  {
129  $affectedRows = $ilDB->update('tst_active',
130  array(
131  'lastindex' => array('integer', $this->getLastSequence()),
132  'tries' => array('integer', $this->getPass()),
133  'submitted' => array('integer', $submitted),
134  'submittimestamp' => array('timestamp', (strlen($this->getSubmittedTimestamp())) ? $this->getSubmittedTimestamp() : NULL),
135  'tstamp' => array('integer', time()-10),
136  'taxfilter' => array('text', serialize($this->getQuestionSetFilterSelection()->getTaxonomySelection())),
137  'answerstatusfilter' => array('text', $this->getQuestionSetFilterSelection()->getAnswerStatusSelection())
138  ),
139  array(
140  'active_id' => array('integer', $this->getActiveId())
141  )
142  );
143 
144  // update learning progress
145  include_once("./Modules/Test/classes/class.ilObjTestAccess.php");
146  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
149  }
150  else
151  {
152  if (!$this->activeIDExists($this->getUserId(), $this->getTestId()))
153  {
154  $anonymous_id = ($this->getAnonymousId()) ? $this->getAnonymousId() : NULL;
155 
156  $next_id = $ilDB->nextId('tst_active');
157  $affectedRows = $ilDB->insert('tst_active',
158  array(
159  'active_id' => array('integer', $next_id),
160  'user_fi' => array('integer', $this->getUserId()),
161  'anonymous_id' => array('text', $anonymous_id),
162  'test_fi' => array('integer', $this->getTestId()),
163  'lastindex' => array('integer', $this->getLastSequence()),
164  'tries' => array('integer', $this->getPass()),
165  'submitted' => array('integer', $submitted),
166  'submittimestamp' => array('timestamp', (strlen($this->getSubmittedTimestamp())) ? $this->getSubmittedTimestamp() : NULL),
167  'tstamp' => array('integer', time()-10),
168  'taxfilter' => array('text', serialize($this->getQuestionSetFilterSelection()->getTaxonomySelection())),
169  'answerstatusfilter' => array('text', $this->getQuestionSetFilterSelection()->getAnswerStatusSelection())
170  )
171  );
172  $this->active_id = $next_id;
173 
174  // update learning progress
175  include_once("./Modules/Test/classes/class.ilObjTestAccess.php");
176  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
178  $this->getUserId());
179  }
180  }
181 
182  include_once("./Services/Tracking/classes/class.ilLearningProgress.php");
185  $this->getRefId(),
186  'tst');
187  }
188 
189  public function getCurrentQuestionId()
190  {
191  return $this->getLastSequence();
192  }
193 
194  public function setCurrentQuestionId($currentQuestionId)
195  {
196  $this->setLastSequence((int)$currentQuestionId);
197  }
198 
199 }
200