ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilTestSessionFactory Class Reference
+ Collaboration diagram for ilTestSessionFactory:

Public Member Functions

 __construct (private ilObjTest $test_obj, private ilDBInterface $db, private ilObjUser $user)
 
 reset ()
 temporarily bugfix for resetting the state of this singleton smeyer --> BH: not required anymore More...
 
 getSession (?int $active_id=null)
 Creates and returns an instance of a test sequence that corresponds to the current test mode. More...
 
 getSessionByUserId (int $user_id)
 

Private Member Functions

 getNewTestSessionObject ()
 
 buildCacheKey (int $user_id)
 

Private Attributes

 $testSession = []
 

Detailed Description

Definition at line 27 of file class.ilTestSessionFactory.php.

Constructor & Destructor Documentation

◆ __construct()

ilTestSessionFactory::__construct ( private ilObjTest  $test_obj,
private ilDBInterface  $db,
private ilObjUser  $user 
)

Definition at line 36 of file class.ilTestSessionFactory.php.

40 {
41 }

Member Function Documentation

◆ buildCacheKey()

ilTestSessionFactory::buildCacheKey ( int  $user_id)
private
Parameters
$userId
Returns
string

Definition at line 116 of file class.ilTestSessionFactory.php.

116 : string
117 {
118 $user_id_string = (string) $user_id;
119 return "{$this->test_obj->getTestId()}::{$user_id_string}";
120 }

References $user_id.

Referenced by getSessionByUserId().

+ Here is the caller graph for this function:

◆ getNewTestSessionObject()

ilTestSessionFactory::getNewTestSessionObject ( )
private

Definition at line 107 of file class.ilTestSessionFactory.php.

108 {
109 return new ilTestSession($this->db, $this->user);
110 }
Test session handler.

References ILIAS\Repository\user().

Referenced by getSession(), and getSessionByUserId().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSession()

ilTestSessionFactory::getSession ( ?int  $active_id = null)

Creates and returns an instance of a test sequence that corresponds to the current test mode.

Definition at line 57 of file class.ilTestSessionFactory.php.

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 }

References $testSession, and getNewTestSessionObject().

+ Here is the call graph for this function:

◆ getSessionByUserId()

ilTestSessionFactory::getSessionByUserId ( int  $user_id)
Todo:
: Björn, we also need to handle the anonymous user here
Parameters
integer$userId
Returns
ilTestSession

Definition at line 91 of file class.ilTestSessionFactory.php.

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 }

References $testSession, $user_id, buildCacheKey(), and getNewTestSessionObject().

+ Here is the call graph for this function:

◆ reset()

ilTestSessionFactory::reset ( )

temporarily bugfix for resetting the state of this singleton smeyer --> BH: not required anymore

Definition at line 48 of file class.ilTestSessionFactory.php.

48 : void
49 {
50 $this->testSession = [];
51 }

Field Documentation

◆ $testSession

ilTestSessionFactory::$testSession = []
private

Definition at line 34 of file class.ilTestSessionFactory.php.

Referenced by getSession(), and getSessionByUserId().


The documentation for this class was generated from the following file: