ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
MainSettingsDatabaseRepository.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
24 
26 {
27  public const TABLE_NAME = 'tst_tests';
28  public const STORAGE_DATE_FORMAT = 'YmdHis';
29 
30  private array $instances_by_obj_fi = [];
31  private array $instances_by_test_fi = [];
32 
33  protected \ilDBInterface $db;
34 
35  public function __construct(\ilDBInterface $db)
36  {
37  $this->db = $db;
38  }
39 
40  public function getForObjFi(int $obj_fi): MainSettings
41  {
42  if (!isset($this->instances_by_obj_fi[$obj_fi])) {
43  $where_part = 'WHERE obj_fi = ' . $this->db->quote($obj_fi, 'integer');
44  $this->instances_by_obj_fi[$obj_fi] = $this->doSelect($where_part);
45  $test_id = $this->instances_by_obj_fi[$obj_fi]->getTestId();
46  $this->instances_by_test_fi[$test_id] = $this->instances_by_obj_fi[$obj_fi];
47  }
48  return $this->instances_by_obj_fi[$obj_fi];
49  }
50 
51  public function getFor(int $test_id): MainSettings
52  {
53  if (!isset(self::$instances_by_test_fi[$test_id])) {
54  $where_part = 'WHERE test_id = ' . $this->db->quote($test_id, 'integer');
55  $this->instances_by_test_fi[$test_id] = $this->doSelect($where_part);
56  $obj_id = $this->instances_by_test_fi[$test_id]->getObjId();
57  $this->instances_by_obj_fi[$obj_id] = $this->instances_by_test_fi[$test_id];
58  }
59  return $this->instances_by_test_fi[$test_id];
60  }
61 
62  protected function doSelect(string $where_part): MainSettings
63  {
64  $query = 'SELECT ' . PHP_EOL
65  . 'test_id,' . PHP_EOL
66  . 'obj_fi,' . PHP_EOL
67  . 'question_set_type,' . PHP_EOL
68  . 'anonymity,' . PHP_EOL
69  . 'intro_enabled,' . PHP_EOL
70  . 'hide_info_tab,' . PHP_EOL
71  . 'conditions_checkbox_enabled,' . PHP_EOL
72  . 'introduction,' . PHP_EOL
73  . 'introduction_page_id,' . PHP_EOL
74  . 'starting_time_enabled,' . PHP_EOL
75  . 'starting_time,' . PHP_EOL
76  . 'ending_time_enabled,' . PHP_EOL
77  . 'ending_time,' . PHP_EOL
78  . 'password_enabled,' . PHP_EOL
79  . 'password,' . PHP_EOL
80  . 'ip_range_from,' . PHP_EOL
81  . 'ip_range_to,' . PHP_EOL
82  . 'fixed_participants,' . PHP_EOL
83  . 'nr_of_tries,' . PHP_EOL
84  . 'block_after_passed,' . PHP_EOL
85  . 'pass_waiting,' . PHP_EOL
86  . 'enable_processing_time,' . PHP_EOL
87  . 'processing_time,' . PHP_EOL
88  . 'reset_processing_time,' . PHP_EOL
89  . 'kiosk,' . PHP_EOL
90  . 'examid_in_test_pass,' . PHP_EOL
91  . 'title_output,' . PHP_EOL
92  . 'autosave,' . PHP_EOL
93  . 'autosave_ival,' . PHP_EOL
94  . 'shuffle_questions,' . PHP_EOL
95  . 'offer_question_hints,' . PHP_EOL
96  . 'answer_feedback_points,' . PHP_EOL
97  . 'answer_feedback,' . PHP_EOL
98  . 'specific_feedback,' . PHP_EOL
99  . 'instant_verification,' . PHP_EOL
100  . 'force_inst_fb,' . PHP_EOL
101  . 'inst_fb_answer_fixation,' . PHP_EOL
102  . 'follow_qst_answer_fixation,' . PHP_EOL
103  . 'use_previous_answers,' . PHP_EOL
104  . 'suspend_test_allowed,' . PHP_EOL
105  . 'sequence_settings,' . PHP_EOL
106  . 'usr_pass_overview_mode,' . PHP_EOL
107  . 'show_marker,' . PHP_EOL
108  . 'show_questionlist,' . PHP_EOL
109  . 'enable_examview,' . PHP_EOL
110  . 'showfinalstatement,' . PHP_EOL
111  . 'finalstatement,' . PHP_EOL
112  . 'concluding_remarks_page_id,' . PHP_EOL
113  . 'redirection_mode,' . PHP_EOL
114  . 'redirection_url,' . PHP_EOL
115  . 'mailnotification,' . PHP_EOL
116  . 'mailnottype,' . PHP_EOL
117  . 'skill_service' . PHP_EOL
118  . 'FROM ' . self::TABLE_NAME . PHP_EOL
119  . $where_part;
120 
121  $res = $this->db->query($query);
122 
123  if ($this->db->numRows($res) == 0) {
124  throw new \Exception('Mo main settings for: ' . $where_part);
125  }
126 
127  $row = $this->db->fetchAssoc($res);
128 
129  $test_id = (int) $row['test_id'];
130 
131  $settings = new MainSettings(
132  $test_id,
133  (int) $row['obj_fi'],
134  new SettingsGeneral(
135  $test_id,
136  $row['question_set_type'],
137  (bool) $row['anonymity']
138  ),
140  $test_id,
141  (bool) $row['intro_enabled'],
142  $row['introduction'],
143  $row['introduction_page_id'],
144  (bool) $row['conditions_checkbox_enabled'],
145  ),
146  new SettingsAccess(
147  $test_id,
148  (bool) $row['starting_time_enabled'],
149  $row['starting_time'] !== 0
150  ? \DateTimeImmutable::createFromFormat('U', (string) $row['starting_time'])
151  : null,
152  (bool) $row['ending_time_enabled'],
153  $row['ending_time'] !== 0
154  ? \DateTimeImmutable::createFromFormat('U', (string) $row['ending_time'])
155  : null,
156  (bool) $row['password_enabled'],
157  $row['password'],
158  $row['ip_range_from'],
159  $row['ip_range_to'],
160  (bool) $row['fixed_participants'],
161  ),
163  $test_id,
164  $row['nr_of_tries'],
165  (bool) $row['block_after_passed'],
166  $row['pass_waiting'],
167  (bool) $row['enable_processing_time'],
168  $row['processing_time'],
169  (bool) $row['reset_processing_time'],
170  $row['kiosk'],
171  (bool) $row['examid_in_test_pass']
172  ),
174  $test_id,
175  (int) $row['title_output'],
176  (bool) $row['autosave'],
177  $row['autosave_ival'],
178  (bool) $row['shuffle_questions'],
179  (bool) $row['offer_question_hints'],
180  (bool) $row['answer_feedback_points'],
181  (bool) $row['answer_feedback'],
182  (bool) $row['specific_feedback'],
183  (bool) $row['instant_verification'],
184  (bool) $row['force_inst_fb'],
185  (bool) $row['inst_fb_answer_fixation'],
186  (bool) $row['follow_qst_answer_fixation']
187  ),
189  $test_id,
190  (bool) $row['use_previous_answers'],
191  (bool) $row['suspend_test_allowed'],
192  (bool) $row['sequence_settings'],
193  $row['usr_pass_overview_mode'],
194  (bool) $row['show_marker'],
195  (bool) $row['show_questionlist']
196  ),
197  new SettingsFinishing(
198  $test_id,
199  (bool) $row['enable_examview'],
200  (bool) $row['showfinalstatement'],
201  $row['finalstatement'],
202  $row['concluding_remarks_page_id'],
203  $row['redirection_mode'],
204  $row['redirection_url'],
205  $row['mailnotification'],
206  (bool) $row['mailnottype'],
207  ),
208  new SettingsAdditional(
209  $test_id,
210  (bool) $row['skill_service'],
211  (bool) $row['hide_info_tab']
212  )
213  );
214 
215  return $settings;
216  }
217 
218  public function store(MainSettings $settings): void
219  {
220  $values = array_merge(
221  $settings->getGeneralSettings()->toStorage(),
222  $settings->getIntroductionSettings()->toStorage(),
223  $settings->getAccessSettings()->toStorage(),
224  $settings->getTestBehaviourSettings()->toStorage(),
225  $settings->getQuestionBehaviourSettings()->toStorage(),
226  $settings->getParticipantFunctionalitySettings()->toStorage(),
227  $settings->getFinishingSettings()->toStorage(),
228  $settings->getAdditionalSettings()->toStorage()
229  );
230 
231  $this->db->update(
232  self::TABLE_NAME,
233  $values,
234  ['test_id' => ['integer', $settings->getTestId()]]
235  );
236  unset($this->instances_by_test_fi[$settings->getTestId()]);
237  unset($this->instances_by_obj_fi[$settings->getObjId()]);
238  }
239 }
$res
Definition: ltiservices.php:69
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...