ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
MainSettingsDatabaseRepository.php
Go to the documentation of this file.
1<?php
2
19declare(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 . 'answer_feedback_points,' . PHP_EOL
96 . 'answer_feedback,' . PHP_EOL
97 . 'specific_feedback,' . PHP_EOL
98 . 'instant_verification,' . PHP_EOL
99 . 'force_inst_fb,' . PHP_EOL
100 . 'inst_fb_answer_fixation,' . PHP_EOL
101 . 'follow_qst_answer_fixation,' . PHP_EOL
102 . 'use_previous_answers,' . PHP_EOL
103 . 'suspend_test_allowed,' . PHP_EOL
104 . 'sequence_settings,' . PHP_EOL
105 . 'usr_pass_overview_mode,' . PHP_EOL
106 . 'show_marker,' . PHP_EOL
107 . 'show_questionlist,' . PHP_EOL
108 . 'enable_examview,' . PHP_EOL
109 . 'showfinalstatement,' . PHP_EOL
110 . 'finalstatement,' . PHP_EOL
111 . 'concluding_remarks_page_id,' . PHP_EOL
112 . 'redirection_mode,' . PHP_EOL
113 . 'redirection_url,' . PHP_EOL
114 . 'mailnotification,' . PHP_EOL
115 . 'mailnottype,' . PHP_EOL
116 . 'skill_service' . PHP_EOL
117 . 'FROM ' . self::TABLE_NAME . PHP_EOL
118 . $where_part;
119
120 $res = $this->db->query($query);
121
122 if ($this->db->numRows($res) == 0) {
123 throw new \Exception('Mo main settings for: ' . $where_part);
124 }
125
126 $row = $this->db->fetchAssoc($res);
127
128 $test_id = (int) $row['test_id'];
129
130 $settings = new MainSettings(
131 $test_id,
132 (int) $row['obj_fi'],
133 new SettingsGeneral(
134 $test_id,
135 $row['question_set_type'],
136 (bool) $row['anonymity']
137 ),
139 $test_id,
140 (bool) $row['intro_enabled'],
141 $row['introduction'],
142 $row['introduction_page_id'],
143 (bool) $row['conditions_checkbox_enabled'],
144 ),
145 new SettingsAccess(
146 $test_id,
147 (bool) $row['starting_time_enabled'],
148 $row['starting_time'] !== 0
149 ? \DateTimeImmutable::createFromFormat('U', (string) $row['starting_time'])
150 : null,
151 (bool) $row['ending_time_enabled'],
152 $row['ending_time'] !== 0
153 ? \DateTimeImmutable::createFromFormat('U', (string) $row['ending_time'])
154 : null,
155 (bool) $row['password_enabled'],
156 $row['password'],
157 $row['ip_range_from'],
158 $row['ip_range_to'],
159 (bool) $row['fixed_participants'],
160 ),
162 $test_id,
163 $row['nr_of_tries'],
164 (bool) $row['block_after_passed'],
165 $row['pass_waiting'],
166 (bool) $row['enable_processing_time'],
167 $row['processing_time'],
168 (bool) $row['reset_processing_time'],
169 $row['kiosk'],
170 (bool) $row['examid_in_test_pass']
171 ),
173 $test_id,
174 (int) $row['title_output'],
175 (bool) $row['autosave'],
176 $row['autosave_ival'],
177 (bool) $row['shuffle_questions'],
178 (bool) $row['answer_feedback_points'],
179 (bool) $row['answer_feedback'],
180 (bool) $row['specific_feedback'],
181 (bool) $row['instant_verification'],
182 (bool) $row['force_inst_fb'],
183 (bool) $row['inst_fb_answer_fixation'],
184 (bool) $row['follow_qst_answer_fixation']
185 ),
187 $test_id,
188 (bool) $row['use_previous_answers'],
189 (bool) $row['suspend_test_allowed'],
190 (bool) $row['sequence_settings'],
191 $row['usr_pass_overview_mode'],
192 (bool) $row['show_marker'],
193 (bool) $row['show_questionlist']
194 ),
196 $test_id,
197 (bool) $row['enable_examview'],
198 (bool) $row['showfinalstatement'],
199 $row['finalstatement'],
200 $row['concluding_remarks_page_id'],
201 RedirectionModes::tryFrom($row['redirection_mode']) ?? RedirectionModes::NONE,
202 $row['redirection_url'],
203 $row['mailnotification'],
204 (bool) $row['mailnottype'],
205 ),
207 $test_id,
208 (bool) $row['skill_service'],
209 (bool) $row['hide_info_tab']
210 )
211 );
212
213 return $settings;
214 }
215
216 public function store(MainSettings $settings): void
217 {
218 $values = array_merge(
219 $settings->getGeneralSettings()->toStorage(),
220 $settings->getIntroductionSettings()->toStorage(),
221 $settings->getAccessSettings()->toStorage(),
222 $settings->getTestBehaviourSettings()->toStorage(),
223 $settings->getQuestionBehaviourSettings()->toStorage(),
224 $settings->getParticipantFunctionalitySettings()->toStorage(),
225 $settings->getFinishingSettings()->toStorage(),
226 $settings->getAdditionalSettings()->toStorage()
227 );
228
229 $this->db->update(
230 self::TABLE_NAME,
231 $values,
232 ['test_id' => ['integer', $settings->getTestId()]]
233 );
234 unset($this->instances_by_test_fi[$settings->getTestId()]);
235 unset($this->instances_by_obj_fi[$settings->getObjId()]);
236 }
237}
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...