19 declare(strict_types=1);
83 $result = $this->db->queryF(
84 "SELECT * FROM tst_active WHERE user_fi = %s AND test_fi = %s",
85 [
'integer',
'integer'],
88 if ($result->numRows()) {
89 $row = $this->db->fetchAssoc($result);
90 $this->active_id = (
int) $row[
"active_id"];
91 $this->user_id = (
int) $row[
"user_fi"];
92 $this->anonymous_id = $row[
"anonymous_id"] ??
'';
93 $this->test_id = (
int) $row[
"test_fi"];
94 $this->lastsequence = (
int) $row[
"lastindex"];
95 $this->pass = (
int) $row[
"tries"];
96 $this->submitted = ($row[
"submitted"]) ?
true :
false;
97 $this->submittedTimestamp = (string) $row[
"submittimestamp"];
98 $this->tstamp = (
int) $row[
"tstamp"];
100 $this->lastStartedPass = $row[
'last_started_pass'];
101 $this->lastFinishedPass = $row[
'last_finished_pass'];
102 $this->objectiveOrientedContainerId = $row[
'objective_container'];
111 if (!$this->active_id) {
119 if (!isset($active[
'tst_last_increase_pass']) || $active[
'tst_last_increase_pass'] !==
null) {
120 $active[
'tst_last_increase_pass'] = 0;
124 if (time() - $active[
'tst_last_increase_pass'] > 10) {
125 $active[
'tst_last_increase_pass'] = time();
126 $this->tstamp = time();
132 'tries' => [
'integer', $this->
getPass()],
133 'submitted' => [
'integer', $submitted],
134 'submittimestamp' => [
'timestamp', $submittedtimestamp],
135 'tstamp' => [
'integer', time()],
151 if ($this->active_id > 0) {
156 'tries' => [
'integer', $this->
getPass()],
157 'submitted' => [
'integer', $submitted],
158 'submittimestamp' => [
'timestamp', $submittedtimestamp],
159 'tstamp' => [
'integer', time() - 10],
161 'last_started_pass' => [
'integer', $this->
getPass()],
174 $next_id = $this->db->nextId(
'tst_active');
178 'active_id' => [
'integer', $next_id],
179 'user_fi' => [
'integer', $this->
getUserId()],
180 'anonymous_id' => [
'text', $anonymous_id],
181 'test_fi' => [
'integer', $this->
getTestId()],
183 'tries' => [
'integer', $this->
getPass()],
184 'submitted' => [
'integer', $submitted],
186 'tstamp' => [
'integer', time() - 10],
188 'last_started_pass' => [
'integer', $this->
getPass()],
192 $this->active_id = $next_id;
198 if ($user_id === 0) {
199 $user_id = $this->
user->getId();
202 $result = $this->db->queryF(
203 "SELECT * FROM tst_active WHERE user_fi = %s AND test_fi = %s AND anonymous_id = %s",
204 [
'integer',
'integer',
'text'],
207 } elseif ($anonymous_id !==
null) {
208 $result = $this->db->queryF(
209 "SELECT * FROM tst_active WHERE user_fi = %s AND test_fi = %s AND anonymous_id = %s",
210 [
'integer',
'integer',
'text'],
211 [$user_id, $test_id, $anonymous_id]
217 $result = $this->db->queryF(
218 "SELECT * FROM tst_active WHERE user_fi = %s AND test_fi = %s",
219 [
'integer',
'integer'],
227 if ($result->numRows()) {
228 $row = $this->db->fetchAssoc($result);
229 $this->active_id = $row[
"active_id"];
230 $this->user_id = $row[
"user_fi"];
231 $this->anonymous_id = $row[
"anonymous_id"] ??
'';
232 $this->test_id = $row[
"test_fi"];
233 $this->lastsequence = $row[
"lastindex"];
234 $this->pass = $row[
"tries"];
235 $this->submitted = ($row[
"submitted"]) ?
true :
false;
236 $this->submittedTimestamp = $row[
"submittimestamp"] ??
'';
237 $this->tstamp = $row[
"tstamp"];
238 $this->lastStartedPass = $row[
'last_started_pass'];
239 $this->lastFinishedPass = $row[
'last_finished_pass'];
248 $result = $this->db->queryF(
249 "SELECT * FROM tst_active WHERE active_id = %s",
253 if ($result->numRows()) {
254 $row = $this->db->fetchAssoc($result);
255 $this->active_id = $row[
"active_id"];
256 $this->user_id = $row[
"user_fi"];
257 $this->anonymous_id = $row[
"anonymous_id"] ??
'';
258 $this->test_id = $row[
"test_fi"];
259 $this->lastsequence = $row[
"lastindex"];
260 $this->pass = $row[
"tries"];
261 $this->submitted = ($row[
"submitted"]) ?
true :
false;
262 $this->submittedTimestamp = $row[
"submittimestamp"] ??
'';
263 $this->tstamp = $row[
"tstamp"];
265 $this->lastStartedPass = $row[
'last_started_pass'];
266 $this->lastFinishedPass = $row[
'last_finished_pass'];
338 $this->submitted =
true;
348 $this->submittedTimestamp = date(
'Y-m-d H:i:s');
363 $this->objectiveOrientedContainerId = $objectiveOriented;
368 return $this->objectiveOrientedContainerId ?? 0;
393 [
'start_lock' => [
'text', $testStartLock]],
400 $res = $this->db->queryF(
401 "SELECT start_lock FROM tst_active WHERE active_id = %s",
406 while ($row = $this->db->fetchAssoc(
$res)) {
407 return $row[
'start_lock'];
419 $session_code[$this->
getTestId()] = $access_code;
426 unset($session_code[$this->
getTestId()]);
436 if (!isset($session_code[$this->
getTestId()])) {
440 return $session_code[$this->
getTestId()];
459 $query =
"SELECT anonymous_id FROM tst_active WHERE test_fi = %s AND anonymous_id = %s";
461 $result = $this->db->queryF(
467 return ($result->numRows() > 0);
473 $codestring = self::ACCESS_CODE_CHAR_DOMAIN;
479 for ($i = 1; $i <= self::ACCESS_CODE_LENGTH; $i++) {
480 $index = mt_rand(0, strlen($codestring) - 1);
481 $code .= substr($codestring, $index, 1);
509 if ($this->reportable_results_available ===
null) {
510 $this->reportable_results_available =
true;
513 $this->reportable_results_available =
false;
517 $this->reportable_results_available =
false;
527 $test_passes_selector->setActiveId($this->
getActiveId());
530 if (count($test_passes_selector->getReportablePasses()) == 1) {
const ACCESS_CODE_CHAR_DOMAIN
static get(string $a_var)
setPasswordChecked(bool $value)
loadTestSession(int $test_id, int $user_id=0, ?string $anonymous_id=null)
getAccessCodeFromSession()
persistTestStartLock(string $testStartLock)
isAccessCodeUsed(string $code)
doesAccessCodeInSessionExists()
setLastSequence(int $lastsequence)
getObjectiveOrientedContainerId()
int $objectiveOrientedContainerId
Base Exception for all Exceptions relating to Modules/Test.
reportableResultsAvailable(ilObjTest $test_obj)
const ACCESS_CODE_SESSION_INDEX
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
setLastFinishedPass(int $lastFinishedPass)
unsetAccessCodeInSession()
hasSinglePassReportable(ilObjTest $testObj)
canShowTestResults(ilTestSession $test_session)
activeIDExists(int $user_id, int $test_id)
__construct(protected ilDBInterface $db, protected ilObjUser $user)
ilTestSession constructor
loadFromDb(int $active_id)
setAnonymousId(string $anonymous_id)
setLastStartedPass(int $lastStartedPass)
string $lastPresentationMode
bool $reportable_results_available
static set(string $a_var, $a_val)
Set a value.
setAccessCodeToSession(string $access_code)
setObjectiveOrientedContainerId(int $objectiveOriented)
string $submittedTimestamp