ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
4require_once 'Modules/Test/classes/class.ilTestSession.php';
5require_once 'Modules/Test/classes/class.ilTestDynamicQuestionSetFilterSelection.php';
6
7require_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(
43 "SELECT * FROM tst_active WHERE active_id = %s",
44 array('integer'),
45 array($active_id)
46 );
47 if ($result->numRows()) {
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
65 public function loadTestSession($test_id, $user_id = "", $anonymous_id = "")
66 {
67 global $ilDB;
68 global $ilUser;
69
70 if (!$user_id) {
71 $user_id = $ilUser->getId();
72 }
73 if (($GLOBALS['DIC']['ilUser']->getId() == ANONYMOUS_USER_ID) && $this->doesAccessCodeInSessionExists()) {
74 $result = $ilDB->queryF(
75 "SELECT * FROM tst_active WHERE user_fi = %s AND test_fi = %s AND anonymous_id = %s",
76 array('integer','integer','text'),
78 );
79 } elseif (strlen($anonymous_id)) {
80 $result = $ilDB->queryF(
81 "SELECT * FROM tst_active WHERE user_fi = %s AND test_fi = %s AND anonymous_id = %s",
82 array('integer','integer','text'),
84 );
85 } else {
86 if ($GLOBALS['DIC']['ilUser']->getId() == ANONYMOUS_USER_ID) {
87 return null;
88 }
89 $result = $ilDB->queryF(
90 "SELECT * FROM tst_active WHERE user_fi = %s AND test_fi = %s",
91 array('integer','integer'),
92 array($user_id, $test_id)
93 );
94 }
95
96 // TODO bheyser: Refactor
97 $this->user_id = $user_id;
98
99 if ($result->numRows()) {
100 $row = $ilDB->fetchAssoc($result);
101 $this->active_id = $row["active_id"];
102 $this->user_id = $row["user_fi"];
103 $this->anonymous_id = $row["anonymous_id"];
104 $this->test_id = $row["test_fi"];
105 $this->lastsequence = $row["lastindex"];
106 $this->pass = $row["tries"];
107 $this->submitted = ($row["submitted"]) ? true : false;
108 $this->submittedTimestamp = $row["submittimestamp"];
109 $this->tstamp = $row["tstamp"];
110
111 $this->questionSetFilterSelection->setTaxonomySelection(unserialize($row['taxfilter']));
112 $this->questionSetFilterSelection->setAnswerStatusSelection($row['answerstatusfilter']);
113 $this->questionSetFilterSelection->setAnswerStatusActiveId($row['active_id']);
114 } elseif ($this->doesAccessCodeInSessionExists()) {
116 }
117 }
118
119 public function saveToDb()
120 {
121 global $ilDB, $ilLog;
122
123 $submitted = ($this->isSubmitted()) ? 1 : 0;
124 if ($this->active_id > 0) {
125 $affectedRows = $ilDB->update(
126 'tst_active',
127 array(
128 'lastindex' => array('integer', $this->getLastSequence()),
129 'tries' => array('integer', $this->getPass()),
130 'submitted' => array('integer', $submitted),
131 'submittimestamp' => array('timestamp', (strlen($this->getSubmittedTimestamp())) ? $this->getSubmittedTimestamp() : null),
132 'tstamp' => array('integer', time()-10),
133 'taxfilter' => array('text', serialize($this->getQuestionSetFilterSelection()->getTaxonomySelection())),
134 'answerstatusfilter' => array('text', $this->getQuestionSetFilterSelection()->getAnswerStatusSelection())
135 ),
136 array(
137 'active_id' => array('integer', $this->getActiveId())
138 )
139 );
140
141 // update learning progress
142 include_once("./Modules/Test/classes/class.ilObjTestAccess.php");
143 include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
147 );
148 } else {
149 if (!$this->activeIDExists($this->getUserId(), $this->getTestId())) {
150 $anonymous_id = ($this->getAnonymousId()) ? $this->getAnonymousId() : null;
151
152 $next_id = $ilDB->nextId('tst_active');
153 $affectedRows = $ilDB->insert(
154 'tst_active',
155 array(
156 'active_id' => array('integer', $next_id),
157 'user_fi' => array('integer', $this->getUserId()),
158 'anonymous_id' => array('text', $anonymous_id),
159 'test_fi' => array('integer', $this->getTestId()),
160 'lastindex' => array('integer', $this->getLastSequence()),
161 'tries' => array('integer', $this->getPass()),
162 'submitted' => array('integer', $submitted),
163 'submittimestamp' => array('timestamp', (strlen($this->getSubmittedTimestamp())) ? $this->getSubmittedTimestamp() : null),
164 'tstamp' => array('integer', time()-10),
165 'taxfilter' => array('text', serialize($this->getQuestionSetFilterSelection()->getTaxonomySelection())),
166 'answerstatusfilter' => array('text', $this->getQuestionSetFilterSelection()->getAnswerStatusSelection())
167 )
168 );
169 $this->active_id = $next_id;
170
171 // update learning progress
172 include_once("./Modules/Test/classes/class.ilObjTestAccess.php");
173 include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
176 $this->getUserId()
177 );
178 }
179 }
180
181 include_once("./Services/Tracking/classes/class.ilLearningProgress.php");
183 $this->getUserId(),
185 $this->getRefId(),
186 'tst'
187 );
188 }
189
190 public function getCurrentQuestionId()
191 {
192 return $this->getLastSequence();
193 }
194
195 public function setCurrentQuestionId($currentQuestionId)
196 {
197 $this->setLastSequence((int) $currentQuestionId);
198 }
199}
$result
An exception for terminatinating execution or to throw for unit testing.
static _updateStatus($a_obj_id, $a_usr_id, $a_obj=null, $a_percentage=false, $a_force_raise=false)
Update status.
static _tracProgress($a_user_id, $a_obj_id, $a_ref_id, $a_obj_type='')
static _getParticipantId($active_id)
Get user id for active id.
static _lookupObjIdForTestId($a_test_id)
Lookup object id for test id.
loadTestSession($test_id, $user_id="", $anonymous_id="")
loadFromDb($active_id)
Loads the session data for a given active id.
Test session handler.
activeIDExists($user_id, $test_id)
getRefId()
Get Ref id.
setLastSequence($lastsequence)
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
global $ilDB
$ilUser
Definition: imgupload.php:18