ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 readSessionValue($subIndex)
55 {
56 return $_SESSION[self::SESSION_BASEINDEX][$this->getSessionContextIndex()][$subIndex];
57 }
58
59 public function setInstantResponseActive($instantResponseActive)
60 {
61 $this->saveSessionValue(self::SESSION_SUBINDEX_INSTANT_RESPONSE_ACTIVE, $instantResponseActive);
62 }
63
64 public function isInstantResponseActive()
65 {
66 return $this->readSessionValue(self::SESSION_SUBINDEX_INSTANT_RESPONSE_ACTIVE);
67 }
68
69 public function setParticipantsSolution($participantSolution)
70 {
71 $this->saveSessionValue(self::SESSION_SUBINDEX_PARTICIPANT_SOLUTION, $participantSolution);
72 }
73
74 public function getParticipantsSolution()
75 {
76 return $this->readSessionValue(self::SESSION_SUBINDEX_PARTICIPANT_SOLUTION);
77 }
78
79 public function getNumRequestedHints()
80 {
81 return count($this->readSessionValue(self::SESSION_SUBINDEX_REQUESTED_HINTS));
82 }
83
84 public function isHintRequested($hintId)
85 {
86 $requestedHints = $this->readSessionValue(self::SESSION_SUBINDEX_REQUESTED_HINTS);
87 return isset($requestedHints[$hintId]);
88 }
89
90 public function addRequestedHint($hintId)
91 {
92 $requestedHints = $this->readSessionValue(self::SESSION_SUBINDEX_REQUESTED_HINTS);
93 $requestedHints[$hintId] = $hintId;
94 $this->saveSessionValue(self::SESSION_SUBINDEX_REQUESTED_HINTS, $requestedHints);
95 }
96
97 public function getRequestedHints()
98 {
99 return $this->readSessionValue(self::SESSION_SUBINDEX_REQUESTED_HINTS);
100 }
101
102 public function resetRequestedHints()
103 {
104 $this->saveSessionValue(self::SESSION_SUBINDEX_REQUESTED_HINTS, array());
105 }
106
107 public function setRandomizerSeed($seed)
108 {
109 $this->saveSessionValue(self::SESSION_SUBINDEX_RANDOMIZER_SEED, $seed);
110 }
111
112 public function getRandomizerSeed()
113 {
114 return $this->readSessionValue(self::SESSION_SUBINDEX_RANDOMIZER_SEED);
115 }
116
117 public function randomizerSeedExists()
118 {
119 return ($this->getRandomizerSeed() !== null);
120 }
121
123 {
124 if(!isset($_SESSION[self::SESSION_BASEINDEX]) || !is_array($_SESSION[self::SESSION_BASEINDEX]))
125 {
127 }
128
129 $baseSession = &$_SESSION[self::SESSION_BASEINDEX];
130
131 if(!isset($baseSession[$this->getSessionContextIndex()]))
132 {
133 $baseSession[$this->getSessionContextIndex()] = array();
134 }
135
136 $contextSession = &$baseSession[$this->getSessionContextIndex()];
137
138 if(!isset($contextSession[self::SESSION_SUBINDEX_INSTANT_RESPONSE_ACTIVE]))
139 {
141 }
142
143 if(!isset($contextSession[self::SESSION_SUBINDEX_PARTICIPANT_SOLUTION]))
144 {
145 $contextSession[self::SESSION_SUBINDEX_PARTICIPANT_SOLUTION] = null;
146 }
147
148 if(!isset($contextSession[self::SESSION_SUBINDEX_RANDOMIZER_SEED]))
149 {
150 $contextSession[self::SESSION_SUBINDEX_RANDOMIZER_SEED] = null;
151 }
152 }
153}
$_SESSION["AccountId"]