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