ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilTestSessionFactory.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
28{
34 private $testSession = [];
35
36 public function __construct(
37 private ilObjTest $test_obj,
38 private ilDBInterface $db,
39 private ilObjUser $user
40 ) {
41 }
42
48 public function reset(): void
49 {
50 $this->testSession = [];
51 }
52
57 public function getSession(?int $active_id = null): ilTestSession
58 {
59 if ($active_id === null ||
60 $this->testSession === [] ||
61 !array_key_exists($active_id, $this->testSession) ||
62 $this->testSession[$active_id] === null
63 ) {
65
66 $testSession->setRefId($this->test_obj->getRefId());
67 $testSession->setTestId($this->test_obj->getTestId());
68
69 if ($active_id) {
70 $testSession->loadFromDb($active_id);
71 $this->testSession[$active_id] = $testSession;
72 } else {
73 $testSession->loadTestSession(
74 $this->test_obj->getTestId(),
75 $this->user->getId(),
76 $testSession->getAccessCodeFromSession()
77 );
78
79 return $testSession;
80 }
81 }
82
83 return $this->testSession[$active_id];
84 }
85
92 {
93 if (!isset($this->testSession[$this->buildCacheKey($user_id)])) {
95
96 $testSession->setRefId($this->test_obj->getRefId());
97 $testSession->setTestId($this->test_obj->getTestId());
98
99 $testSession->loadTestSession($this->test_obj->getTestId(), $user_id);
100
101 $this->testSession[$this->buildCacheKey($user_id)] = $testSession;
102 }
103
104 return $this->testSession[$this->buildCacheKey($user_id)];
105 }
106
108 {
109 return new ilTestSession($this->db, $this->user);
110 }
111
116 private function buildCacheKey(int $user_id): string
117 {
118 $user_id_string = (string) $user_id;
119 return "{$this->test_obj->getTestId()}::{$user_id_string}";
120 }
121}
User class.
reset()
temporarily bugfix for resetting the state of this singleton smeyer --> BH: not required anymore
getSession(?int $active_id=null)
Creates and returns an instance of a test sequence that corresponds to the current test mode.
__construct(private ilObjTest $test_obj, private ilDBInterface $db, private ilObjUser $user)
Test session handler.
Interface ilDBInterface.