ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
19  private $userId;
20  private $questionId;
21 
22  public function __construct($userId, $questionId)
23  {
24  $this->userId = $userId;
25  $this->questionId = $questionId;
26  }
27 
28  public function init()
29  {
30  if( !isset($_SESSION[self::SESSION_BASEINDEX]) || !is_array($_SESSION[self::SESSION_BASEINDEX]) )
31  {
33  }
34 
35  $baseSession = &$_SESSION[self::SESSION_BASEINDEX];
36 
37  if( !isset($baseSession[$this->getSessionContextIndex()]) )
38  {
39  $baseSession[$this->getSessionContextIndex()] = array();
40  }
41 
42  $contextSession = &$baseSession[$this->getSessionContextIndex()];
43 
44  if( !isset($contextSession[self::SESSION_SUBINDEX_INSTANT_RESPONSE_ACTIVE]) )
45  {
47  }
48 
49  if( !isset($contextSession[self::SESSION_SUBINDEX_PARTICIPANT_SOLUTION]) )
50  {
51  $contextSession[self::SESSION_SUBINDEX_PARTICIPANT_SOLUTION] = null;
52  }
53  }
54 
55  public function getUserId()
56  {
57  return $this->userId;
58  }
59 
60  public function getQuestionId()
61  {
62  return $this->questionId;
63  }
64 
65  private function getSessionContextIndex()
66  {
67  return "u{$this->userId}::q{$this->questionId}";
68  }
69 
70  private function saveSessionValue($subIndex, $value)
71  {
72  $_SESSION[self::SESSION_BASEINDEX][$this->getSessionContextIndex()][$subIndex] = $value;
73  }
74 
75  private function readSessionValue($subIndex)
76  {
77  return $_SESSION[self::SESSION_BASEINDEX][$this->getSessionContextIndex()][$subIndex];
78  }
79 
80  public function setInstantResponseActive($instantResponseActive)
81  {
82  $this->saveSessionValue(self::SESSION_SUBINDEX_INSTANT_RESPONSE_ACTIVE, $instantResponseActive);
83  }
84 
85  public function isInstantResponseActive()
86  {
87  return $this->readSessionValue(self::SESSION_SUBINDEX_INSTANT_RESPONSE_ACTIVE);
88  }
89 
90  public function setParticipantsSolution($participantSolution)
91  {
92  $this->saveSessionValue(self::SESSION_SUBINDEX_PARTICIPANT_SOLUTION, $participantSolution);
93  }
94 
95  public function getParticipantsSolution()
96  {
97  return $this->readSessionValue(self::SESSION_SUBINDEX_PARTICIPANT_SOLUTION);
98  }
99 
100  public function getNumRequestedHints()
101  {
102  return count($this->readSessionValue(self::SESSION_SUBINDEX_REQUESTED_HINTS));
103  }
104 
105  public function isHintRequested($hintId)
106  {
107  $requestedHints = $this->readSessionValue(self::SESSION_SUBINDEX_REQUESTED_HINTS);
108  return isset($requestedHints[$hintId]);
109  }
110 
111  public function addRequestedHint($hintId)
112  {
113  $requestedHints = $this->readSessionValue(self::SESSION_SUBINDEX_REQUESTED_HINTS);
114  $requestedHints[$hintId] = $hintId;
115  $this->saveSessionValue(self::SESSION_SUBINDEX_REQUESTED_HINTS, $requestedHints);
116  }
117 
118  public function getRequestedHints()
119  {
120  return $this->readSessionValue(self::SESSION_SUBINDEX_REQUESTED_HINTS);
121  }
122 
123  public function resetRequestedHints()
124  {
125  $this->saveSessionValue(self::SESSION_SUBINDEX_REQUESTED_HINTS, array());
126  }
127 }