ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilAssQuestionPreviewSession.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4
12{
13 const SESSION_BASEINDEX = 'ilAssQuestionPreviewSessions';
14
15 const SESSION_SUBINDEX_INSTANT_RESPONSE_ACTIVE = 'instantResponseActive';
16 const SESSION_SUBINDEX_PARTICIPANT_SOLUTION = 'participantSolution';
17 const SESSION_SUBINDEX_REQUESTED_HINTS = 'requestedHints';
18 const SESSION_SUBINDEX_RANDOMIZER_SEED = 'randomizerSeed';
19
20 private $userId;
21 private $questionId;
22
24 {
25 $this->userId = $userId;
26 $this->questionId = $questionId;
27 }
28
29 public function init()
30 {
32 }
33
34 public function getUserId()
35 {
36 return $this->userId;
37 }
38
39 public function getQuestionId()
40 {
41 return $this->questionId;
42 }
43
44 private function getSessionContextIndex()
45 {
46 return "u{$this->userId}::q{$this->questionId}";
47 }
48
49 private function saveSessionValue($subIndex, $value)
50 {
51 $_SESSION[self::SESSION_BASEINDEX][$this->getSessionContextIndex()][$subIndex] = $value;
52 }
53
54 private function issetSessionValue($subIndex)
55 {
56 return isset($_SESSION[self::SESSION_BASEINDEX][$this->getSessionContextIndex()][$subIndex]);
57 }
58
59 private function readSessionValue($subIndex)
60 {
61 return $_SESSION[self::SESSION_BASEINDEX][$this->getSessionContextIndex()][$subIndex];
62 }
63
64 public function setInstantResponseActive($instantResponseActive)
65 {
66 $this->saveSessionValue(self::SESSION_SUBINDEX_INSTANT_RESPONSE_ACTIVE, $instantResponseActive);
67 }
68
69 public function isInstantResponseActive()
70 {
71 return $this->readSessionValue(self::SESSION_SUBINDEX_INSTANT_RESPONSE_ACTIVE);
72 }
73
74 public function setParticipantsSolution($participantSolution)
75 {
76 $this->saveSessionValue(self::SESSION_SUBINDEX_PARTICIPANT_SOLUTION, $participantSolution);
77 }
78
79 public function getParticipantsSolution()
80 {
81 return $this->readSessionValue(self::SESSION_SUBINDEX_PARTICIPANT_SOLUTION);
82 }
83
84 public function hasParticipantSolution()
85 {
86 return $this->issetSessionValue(self::SESSION_SUBINDEX_PARTICIPANT_SOLUTION);
87 }
88
89 public function getNumRequestedHints()
90 {
91 $hints = $this->readSessionValue(self::SESSION_SUBINDEX_REQUESTED_HINTS);
92
93 if (!is_array($hints)) {
94 return 0;
95 }
96
97 return count($hints);
98 }
99
100 public function isHintRequested($hintId)
101 {
102 $requestedHints = $this->readSessionValue(self::SESSION_SUBINDEX_REQUESTED_HINTS);
103 return isset($requestedHints[$hintId]);
104 }
105
106 public function addRequestedHint($hintId)
107 {
108 $requestedHints = $this->readSessionValue(self::SESSION_SUBINDEX_REQUESTED_HINTS);
109 $requestedHints[$hintId] = $hintId;
110 $this->saveSessionValue(self::SESSION_SUBINDEX_REQUESTED_HINTS, $requestedHints);
111 }
112
113 public function getRequestedHints()
114 {
115 return $this->readSessionValue(self::SESSION_SUBINDEX_REQUESTED_HINTS);
116 }
117
118 public function resetRequestedHints()
119 {
120 $this->saveSessionValue(self::SESSION_SUBINDEX_REQUESTED_HINTS, array());
121 }
122
123 public function setRandomizerSeed($seed)
124 {
125 $this->saveSessionValue(self::SESSION_SUBINDEX_RANDOMIZER_SEED, $seed);
126 }
127
128 public function getRandomizerSeed()
129 {
130 return $this->readSessionValue(self::SESSION_SUBINDEX_RANDOMIZER_SEED);
131 }
132
133 public function randomizerSeedExists()
134 {
135 return ($this->getRandomizerSeed() !== null);
136 }
137
139 {
140 if (!isset($_SESSION[self::SESSION_BASEINDEX]) || !is_array($_SESSION[self::SESSION_BASEINDEX])) {
142 }
143
144 $baseSession = &$_SESSION[self::SESSION_BASEINDEX];
145
146 if (!isset($baseSession[$this->getSessionContextIndex()])) {
147 $baseSession[$this->getSessionContextIndex()] = array();
148 }
149
150 $contextSession = &$baseSession[$this->getSessionContextIndex()];
151
152 if (!isset($contextSession[self::SESSION_SUBINDEX_INSTANT_RESPONSE_ACTIVE])) {
154 }
155
156 if (!isset($contextSession[self::SESSION_SUBINDEX_PARTICIPANT_SOLUTION])) {
157 $contextSession[self::SESSION_SUBINDEX_PARTICIPANT_SOLUTION] = null;
158 }
159
160 if (!isset($contextSession[self::SESSION_SUBINDEX_RANDOMIZER_SEED])) {
161 $contextSession[self::SESSION_SUBINDEX_RANDOMIZER_SEED] = null;
162 }
163 }
164}
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.