ILIAS  release_8 Revision v8.24
class.ilTestSessionFactory.php
Go to the documentation of this file.
1<?php
25{
31 private $testSession = array();
32
37 private $testOBJ = null;
38
44 {
45 $this->testOBJ = $testOBJ;
46 }
47
53 public function reset()
54 {
55 $this->testSession = array();
56 }
57
65 public function getSession($activeId = null)
66 {
67 if ($activeId === null ||
68 $this->testSession === array() ||
69 !array_key_exists($activeId, $this->testSession) ||
70 $this->testSession[$activeId] === null
71 ) {
73
74 $testSession->setRefId($this->testOBJ->getRefId());
75 $testSession->setTestId($this->testOBJ->getTestId());
76
77 if ($activeId) {
78 $testSession->loadFromDb($activeId);
79 $this->testSession[$activeId] = $testSession;
80 } else {
81 global $DIC;
82 $ilUser = $DIC['ilUser'];
83
84 $testSession->loadTestSession(
85 $this->testOBJ->getTestId(),
86 $ilUser->getId(),
87 $testSession->getAccessCodeFromSession()
88 );
89
90 return $testSession;
91 }
92 }
93
94 return $this->testSession[$activeId];
95 }
96
102 public function getSessionByUserId($userId)
103 {
104 if (!isset($this->testSession[$this->buildCacheKey($userId)])) {
106
107 $testSession->setRefId($this->testOBJ->getRefId());
108 $testSession->setTestId($this->testOBJ->getTestId());
109
110 $testSession->loadTestSession($this->testOBJ->getTestId(), $userId);
111
112 $this->testSession[$this->buildCacheKey($userId)] = $testSession;
113 }
114
115 return $this->testSession[$this->buildCacheKey($userId)];
116 }
117
121 private function getNewTestSessionObject()
122 {
123 if ($this->testOBJ->isDynamicTest()) {
125 }
126 return new ilTestSession();
127 }
128
133 private function buildCacheKey($userId): string
134 {
135 return "{$this->testOBJ->getTestId()}::{$userId}";
136 }
137}
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
$ilUser
Definition: imgupload.php:34