ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.RunSessionRepo.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
21 namespace ILIAS\Survey\Execution;
22 
28 {
29  protected const KEY_BASE = "svy_run_";
30  protected const KEY_ANONYM = self::KEY_BASE . "anonymous_id_";
31  protected const KEY_EXTRT = self::KEY_BASE . "extrt_";
32  protected const KEY_PAGE_ENTER = self::KEY_BASE . "enter_page";
33  protected const KEY_PREVIEW_DATA = self::KEY_BASE . "preview_data";
34  protected const KEY_ERRORS = self::KEY_BASE . "errors";
35  protected const KEY_POST_DATA = self::KEY_BASE . "post_data";
36 
37  public function __construct()
38  {
39  }
40 
41  protected function getAnonymKey(int $survey_id): string
42  {
43  return self::KEY_ANONYM . $survey_id;
44  }
45 
46  public function issetCode(int $survey_id): bool
47  {
48  return (
49  \ilSession::has($this->getAnonymKey($survey_id)) &&
50  is_string(\ilSession::get($this->getAnonymKey($survey_id))) &&
51  \ilSession::get($this->getAnonymKey($survey_id)) !== ""
52  );
53  }
54 
55  public function setCode(int $survey_id, string $code): void
56  {
57  \ilSession::set($this->getAnonymKey($survey_id), $code);
58  }
59 
60  public function getCode(int $survey_id): string
61  {
62  if (\ilSession::has($this->getAnonymKey($survey_id))) {
63  return \ilSession::get($this->getAnonymKey($survey_id));
64  }
65  return "";
66  }
67 
68  public function clearCode(int $survey_id): void
69  {
70  \ilSession::clear($this->getAnonymKey($survey_id));
71  }
72 
73  public function isExternalRaterValidated(int $ref_id): bool
74  {
75  if (\ilSession::has(self::KEY_EXTRT . $ref_id)) {
76  return (bool) \ilSession::get(self::KEY_EXTRT . $ref_id);
77  }
78  return false;
79  }
80 
81  public function setExternalRaterValidation(int $ref_id, bool $valid): void
82  {
83  \ilSession::set(self::KEY_EXTRT . $ref_id, $valid);
84  }
85 
86  public function setPageEnter(int $time): void
87  {
88  \ilSession::set(self::KEY_PAGE_ENTER, $time);
89  }
90 
91  public function getPageEnter(): int
92  {
93  return \ilSession::get(self::KEY_PAGE_ENTER) ?? 0;
94  }
95 
96  public function clearPageEnter(): void
97  {
98  \ilSession::clear(self::KEY_PAGE_ENTER);
99  }
100 
101  protected function getPreviewDataKey(int $survey_id): string
102  {
103  return self::KEY_PREVIEW_DATA . "_" . $survey_id;
104  }
105 
106  public function setPreviewData(int $survey_id, int $question_id, array $data): void
107  {
108  $all_data = $this->getAllPreviewData($survey_id);
109  $all_data[$question_id] = $data;
110  \ilSession::set($this->getPreviewDataKey($survey_id), $all_data);
111  }
112 
113  protected function getAllPreviewData(int $survey_id): array
114  {
115  if (\ilSession::has($this->getPreviewDataKey($survey_id))) {
116  return \ilSession::get($this->getPreviewDataKey($survey_id));
117  }
118  return [];
119  }
120 
121  public function getPreviewData(int $survey_id, int $question_id): array
122  {
123  if (\ilSession::has($this->getPreviewDataKey($survey_id))) {
124  $data = \ilSession::get($this->getPreviewDataKey($survey_id));
125  return $data[$question_id] ?? [];
126  }
127  return [];
128  }
129 
130  public function clearPreviewData(int $survey_id, int $question_id): void
131  {
132  if (\ilSession::has($this->getPreviewDataKey($survey_id))) {
133  $data = \ilSession::get($this->getPreviewDataKey($survey_id));
134  unset($data[$question_id]);
135  \ilSession::set($this->getPreviewDataKey($survey_id), $data);
136  }
137  }
138 
139  public function clearAllPreviewData(int $survey_id): void
140  {
141  \ilSession::clear($this->getPreviewDataKey($survey_id));
142  }
143 
144  public function setErrors(array $errors): void
145  {
146  \ilSession::set(self::KEY_ERRORS, $errors);
147  }
148 
149  public function getErrors(): array
150  {
151  return \ilSession::get(self::KEY_ERRORS) ?? [];
152  }
153 
154  public function clearErrors(): void
155  {
156  \ilSession::clear(self::KEY_ERRORS);
157  }
158 
159  public function setPostData(array $data): void
160  {
161  \ilSession::set(self::KEY_POST_DATA, $data);
162  }
163 
164  public function getPostData(): array
165  {
166  return \ilSession::get(self::KEY_POST_DATA);
167  }
168 
169  public function clearPostData(): void
170  {
171  \ilSession::clear(self::KEY_POST_DATA);
172  }
173 }
static get(string $a_var)
setPreviewData(int $survey_id, int $question_id, array $data)
$errors
Definition: imgupload.php:65
getPreviewData(int $survey_id, int $question_id)
$valid
Stores access codes of anonymous session.
$ref_id
Definition: ltiauth.php:67
setCode(int $survey_id, string $code)
static has($a_var)
clearPreviewData(int $survey_id, int $question_id)
get(string $key, Refinery\Transformation $t)
Get passed parameter, if not data passed, get key from http request.
setExternalRaterValidation(int $ref_id, bool $valid)
static clear(string $a_var)
static set(string $a_var, $a_val)
Set a value.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...