ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules Pages
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 {
16  private $testSession = array();
17 
22  private $testOBJ = null;
23 
28  public function __construct(ilObjTest $testOBJ)
29  {
30  $this->testOBJ = $testOBJ;
31  }
32 
37  public function reset()
38  {
39  $this->testSession = array();
40  }
41 
48  public function getSession($activeId = null)
49  {
50  if($activeId === null || $this->testSession[$activeId] === null)
51  {
53 
54  $testSession->setRefId($this->testOBJ->getRefId());
55  $testSession->setTestId($this->testOBJ->getTestId());
56 
57  if($activeId)
58  {
59  $testSession->loadFromDb($activeId);
60  $this->testSession[$activeId] = $testSession;
61  }
62  else
63  {
64  global $ilUser;
65 
66  $testSession->loadTestSession(
67  $this->testOBJ->getTestId(), $ilUser->getId(), $testSession->getAccessCodeFromSession()
68  );
69 
70  return $testSession;
71  }
72  }
73 
74  return $this->testSession[$activeId];
75  }
76 
82  public function getSessionByUserId($userId)
83  {
84  if(!isset($this->testSession[$this->buildCacheKey($userId)]))
85  {
87 
88  $testSession->setRefId($this->testOBJ->getRefId());
89  $testSession->setTestId($this->testOBJ->getTestId());
90 
91  $testSession->loadTestSession($this->testOBJ->getTestId(), $userId);
92 
93  $this->testSession[$this->buildCacheKey($userId)] = $testSession;
94  }
95 
96  return $this->testSession[$this->buildCacheKey($userId)];
97  }
98 
102  private function getNewTestSessionObject()
103  {
104  switch($this->testOBJ->getQuestionSetType())
105  {
108 
109  require_once 'Modules/Test/classes/class.ilTestSession.php';
110  $testSession = new ilTestSession();
111  break;
112 
114 
115  require_once 'Modules/Test/classes/class.ilTestSessionDynamicQuestionSet.php';
117  break;
118  }
119 
120  return $testSession;
121  }
122 
127  private function buildCacheKey($userId)
128  {
129  return "{$this->testOBJ->getTestId()}::{$userId}";
130  }
131 }
const QUESTION_SET_TYPE_RANDOM
type setting value for random question set
Test session handler.
__construct(ilObjTest $testOBJ)
constructor
global $ilUser
Definition: imgupload.php:15
const QUESTION_SET_TYPE_FIXED
type setting value for fixed question set
reset()
temporarily bugfix for resetting the state of this singleton smeyer
getSession($activeId=null)
Creates and returns an instance of a test sequence that corresponds to the current test mode...
const QUESTION_SET_TYPE_DYNAMIC
type setting value for dynamic question set (continues testing mode)