ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilTestSessionFactory.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
11{
17 private $testSession = array();
18
23 private $testOBJ = null;
24
30 {
31 $this->testOBJ = $testOBJ;
32 }
33
39 public function reset()
40 {
41 $this->testSession = array();
42 }
43
44
45
46
54 public function getSession($activeId = null)
55 {
56 if ($activeId === null || $this->testSession[$activeId] === null) {
58
59 $testSession->setRefId($this->testOBJ->getRefId());
60 $testSession->setTestId($this->testOBJ->getTestId());
61
62 if ($activeId) {
63 $testSession->loadFromDb($activeId);
64 $this->testSession[$activeId] = $testSession;
65 } else {
66 global $DIC;
67 $ilUser = $DIC['ilUser'];
68
69 $testSession->loadTestSession(
70 $this->testOBJ->getTestId(),
71 $ilUser->getId(),
72 $testSession->getAccessCodeFromSession()
73 );
74
75 return $testSession;
76 }
77 }
78
79 return $this->testSession[$activeId];
80 }
81
87 public function getSessionByUserId($userId)
88 {
89 if (!isset($this->testSession[$this->buildCacheKey($userId)])) {
91
92 $testSession->setRefId($this->testOBJ->getRefId());
93 $testSession->setTestId($this->testOBJ->getTestId());
94
95 $testSession->loadTestSession($this->testOBJ->getTestId(), $userId);
96
97 $this->testSession[$this->buildCacheKey($userId)] = $testSession;
98 }
99
100 return $this->testSession[$this->buildCacheKey($userId)];
101 }
102
106 private function getNewTestSessionObject()
107 {
108 switch ($this->testOBJ->getQuestionSetType()) {
111
112 require_once 'Modules/Test/classes/class.ilTestSession.php';
114 break;
115
117
118 require_once 'Modules/Test/classes/class.ilTestSessionDynamicQuestionSet.php';
120 break;
121 }
122
123 return $testSession;
124 }
125
130 private function buildCacheKey($userId)
131 {
132 return "{$this->testOBJ->getTestId()}::{$userId}";
133 }
134}
An exception for terminatinating execution or to throw for unit testing.
const QUESTION_SET_TYPE_DYNAMIC
type setting value for dynamic question set (continues testing mode)
const QUESTION_SET_TYPE_RANDOM
type setting value for random question set
const QUESTION_SET_TYPE_FIXED
type setting value for fixed question set
reset()
temporarily bugfix for resetting the state of this singleton smeyer --> BH: not required anymore
__construct(ilObjTest $testOBJ)
constructor
getSession($activeId=null)
Creates and returns an instance of a test sequence that corresponds to the current test mode.
Test session handler.
global $DIC
Definition: saml.php:7
$ilUser
Definition: imgupload.php:18