ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilTestSessionFactory.php
Go to the documentation of this file.
1 <?php
25 {
31  private $testSession = array();
32 
37  private $testOBJ = null;
38 
43  public function __construct(ilObjTest $testOBJ)
44  {
45  $this->testOBJ = $testOBJ;
46  }
47 
53  public function reset()
54  {
55  $this->testSession = array();
56  }
57 
58 
59 
60 
68  public function getSession($activeId = null)
69  {
70  if ($activeId === null || $this->testSession[$activeId] === null) {
72 
73  $testSession->setRefId($this->testOBJ->getRefId());
74  $testSession->setTestId($this->testOBJ->getTestId());
75 
76  if ($activeId) {
77  $testSession->loadFromDb($activeId);
78  $this->testSession[$activeId] = $testSession;
79  } else {
80  global $DIC;
81  $ilUser = $DIC['ilUser'];
82 
83  $testSession->loadTestSession(
84  $this->testOBJ->getTestId(),
85  $ilUser->getId(),
86  $testSession->getAccessCodeFromSession()
87  );
88 
89  return $testSession;
90  }
91  }
92 
93  return $this->testSession[$activeId];
94  }
95 
101  public function getSessionByUserId($userId)
102  {
103  if (!isset($this->testSession[$this->buildCacheKey($userId)])) {
105 
106  $testSession->setRefId($this->testOBJ->getRefId());
107  $testSession->setTestId($this->testOBJ->getTestId());
108 
109  $testSession->loadTestSession($this->testOBJ->getTestId(), $userId);
110 
111  $this->testSession[$this->buildCacheKey($userId)] = $testSession;
112  }
113 
114  return $this->testSession[$this->buildCacheKey($userId)];
115  }
116 
120  private function getNewTestSessionObject()
121  {
122  switch ($this->testOBJ->getQuestionSetType()) {
125 
126  require_once 'Modules/Test/classes/class.ilTestSession.php';
127  $testSession = new ilTestSession();
128  break;
129 
131 
132  require_once 'Modules/Test/classes/class.ilTestSessionDynamicQuestionSet.php';
134  break;
135  }
136 
137  return $testSession;
138  }
139 
144  private function buildCacheKey($userId)
145  {
146  return "{$this->testOBJ->getTestId()}::{$userId}";
147  }
148 }
const QUESTION_SET_TYPE_RANDOM
type setting value for random question set
global $DIC
Definition: goto.php:24
__construct(ilObjTest $testOBJ)
constructor
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 ...
getSession($activeId=null)
Creates and returns an instance of a test sequence that corresponds to the current test mode...
$ilUser
Definition: imgupload.php:18
const QUESTION_SET_TYPE_DYNAMIC
type setting value for dynamic question set (continues testing mode)