ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  {
26  parent::__construct();
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'),
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 (($GLOBALS['DIC']['ilUser']->getId() == 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 ($GLOBALS['DIC']['ilUser']->getId() == 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'),
97  );
98  }
99 
100  // TODO bheyser: Refactor
101  $this->user_id = $user_id;
102 
103  if ($result->numRows())
104  {
105  $row = $ilDB->fetchAssoc($result);
106  $this->active_id = $row["active_id"];
107  $this->user_id = $row["user_fi"];
108  $this->anonymous_id = $row["anonymous_id"];
109  $this->test_id = $row["test_fi"];
110  $this->lastsequence = $row["lastindex"];
111  $this->pass = $row["tries"];
112  $this->submitted = ($row["submitted"]) ? TRUE : FALSE;
113  $this->submittedTimestamp = $row["submittimestamp"];
114  $this->tstamp = $row["tstamp"];
115 
116  $this->questionSetFilterSelection->setTaxonomySelection(unserialize($row['taxfilter']));
117  $this->questionSetFilterSelection->setAnswerStatusSelection($row['answerstatusfilter']);
118  $this->questionSetFilterSelection->setAnswerStatusActiveId($row['active_id']);
119  }
120  elseif( $this->doesAccessCodeInSessionExists() )
121  {
122  $this->unsetAccessCodeInSession();
123  }
124  }
125 
126  function saveToDb()
127  {
128  global $ilDB, $ilLog;
129 
130  $submitted = ($this->isSubmitted()) ? 1 : 0;
131  if ($this->active_id > 0)
132  {
133  $affectedRows = $ilDB->update('tst_active',
134  array(
135  'lastindex' => array('integer', $this->getLastSequence()),
136  'tries' => array('integer', $this->getPass()),
137  'submitted' => array('integer', $submitted),
138  'submittimestamp' => array('timestamp', (strlen($this->getSubmittedTimestamp())) ? $this->getSubmittedTimestamp() : NULL),
139  'tstamp' => array('integer', time()-10),
140  'taxfilter' => array('text', serialize($this->getQuestionSetFilterSelection()->getTaxonomySelection())),
141  'answerstatusfilter' => array('text', $this->getQuestionSetFilterSelection()->getAnswerStatusSelection())
142  ),
143  array(
144  'active_id' => array('integer', $this->getActiveId())
145  )
146  );
147 
148  // update learning progress
149  include_once("./Modules/Test/classes/class.ilObjTestAccess.php");
150  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
153  }
154  else
155  {
156  if (!$this->activeIDExists($this->getUserId(), $this->getTestId()))
157  {
158  $anonymous_id = ($this->getAnonymousId()) ? $this->getAnonymousId() : NULL;
159 
160  $next_id = $ilDB->nextId('tst_active');
161  $affectedRows = $ilDB->insert('tst_active',
162  array(
163  'active_id' => array('integer', $next_id),
164  'user_fi' => array('integer', $this->getUserId()),
165  'anonymous_id' => array('text', $anonymous_id),
166  'test_fi' => array('integer', $this->getTestId()),
167  'lastindex' => array('integer', $this->getLastSequence()),
168  'tries' => array('integer', $this->getPass()),
169  'submitted' => array('integer', $submitted),
170  'submittimestamp' => array('timestamp', (strlen($this->getSubmittedTimestamp())) ? $this->getSubmittedTimestamp() : NULL),
171  'tstamp' => array('integer', time()-10),
172  'taxfilter' => array('text', serialize($this->getQuestionSetFilterSelection()->getTaxonomySelection())),
173  'answerstatusfilter' => array('text', $this->getQuestionSetFilterSelection()->getAnswerStatusSelection())
174  )
175  );
176  $this->active_id = $next_id;
177 
178  // update learning progress
179  include_once("./Modules/Test/classes/class.ilObjTestAccess.php");
180  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
182  $this->getUserId());
183  }
184  }
185 
186  include_once("./Services/Tracking/classes/class.ilLearningProgress.php");
189  $this->getRefId(),
190  'tst');
191  }
192 
193  public function getCurrentQuestionId()
194  {
195  return $this->getLastSequence();
196  }
197 
198  public function setCurrentQuestionId($currentQuestionId)
199  {
200  $this->setLastSequence((int)$currentQuestionId);
201  }
202 }
203 
static _getParticipantId($active_id)
Get user id for active id.
$result
static _updateStatus($a_obj_id, $a_usr_id, $a_obj=null, $a_percentage=false, $a_force_raise=false)
Update status.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
static _tracProgress($a_user_id, $a_obj_id, $a_ref_id, $a_obj_type='')
loadTestSession($test_id, $user_id="", $anonymous_id="")
static _lookupObjIdForTestId($a_test_id)
Lookup object id for test id.
getRefId()
Get Ref id.
$ilUser
Definition: imgupload.php:18
Test session handler.
Create styles array
The data for the language used.
global $ilDB
setLastSequence($lastsequence)
activeIDExists($user_id, $test_id)
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.