ILIAS  release_8 Revision v8.24
class.ilAssQuestionUserSolutionAdopter.php
Go to the documentation of this file.
1<?php
2
26{
28
30
32
33 protected static $preparedDeleteResultRecordStatement = null;
34
35 protected static $preparedSelectResultRecordStatement = null;
36
37 protected static $preparedInsertResultRecordStatement = null;
38
42 protected $db;
43
48
52 protected $userId;
53
57 protected $activeId;
58
62 protected $targetPass;
63
67 protected $questionIds;
68
74 public function __construct(ilDBInterface $db, ilSetting $assSettings, $isAssessmentLogEnabled)
75 {
76 $this->db = $db;
77
78 $this->userId = null;
79 $this->activeId = null;
80 $this->targetPass = null;
81 $this->questionIds = array();
82
83 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionProcessLockerFactory.php';
84 $this->processLockerFactory = new ilAssQuestionProcessLockerFactory($assSettings, $db);
85 $this->processLockerFactory->setAssessmentLogEnabled($isAssessmentLogEnabled);
86 }
87
91 public function getUserId(): ?int
92 {
93 return $this->userId;
94 }
95
99 public function setUserId($userId): void
100 {
101 $this->userId = $userId;
102 }
103
107 public function getActiveId(): ?int
108 {
109 return $this->activeId;
110 }
111
115 public function setActiveId($activeId): void
116 {
117 $this->activeId = $activeId;
118 }
119
123 public function getTargetPass(): ?int
124 {
125 return $this->targetPass;
126 }
127
131 public function setTargetPass($targetPass): void
132 {
133 $this->targetPass = $targetPass;
134 }
135
139 public function getQuestionIds(): array
140 {
141 return $this->questionIds;
142 }
143
147 public function setQuestionIds($questionIds): void
148 {
149 $this->questionIds = $questionIds;
150 }
151
152 public function perform(): void
153 {
154 $this->processLockerFactory->setUserId($this->getUserId());
155
156 foreach ($this->getQuestionIds() as $questionId) {
157 $this->processLockerFactory->setQuestionId($questionId);
158 $processLocker = $this->processLockerFactory->getLocker();
159
160 $processLocker->executeUserTestResultUpdateLockOperation(function () use ($questionId) {
161 $this->adoptQuestionAnswer($questionId);
162 });
163 }
164 }
165
166 protected function adoptQuestionAnswer($questionId): void
167 {
168 $this->resetTargetSolution($questionId);
169 $this->resetTargetResult($questionId);
170
171 $sourcePass = $this->adoptSourceSolution($questionId);
172
173 if ($sourcePass !== null) {
174 $this->adoptSourceResult($questionId, $sourcePass);
175 }
176 }
177
178 protected function resetTargetSolution($questionId): void
179 {
180 $this->db->execute(
182 array($this->getActiveId(), $questionId, $this->getTargetPass())
183 );
184 }
185
186 protected function resetTargetResult($questionId): void
187 {
188 $this->db->execute(
190 array($this->getActiveId(), $questionId, $this->getTargetPass())
191 );
192 }
193
194 protected function adoptSourceSolution($questionId)
195 {
196 $res = $this->db->execute(
198 array($this->getActiveId(), $questionId, $this->getTargetPass())
199 );
200
201 $sourcePass = null;
202
203 while ($row = $this->db->fetchAssoc($res)) {
204 if ($sourcePass === null) {
205 $sourcePass = $row['pass'];
206 } elseif ($row['pass'] < $sourcePass) {
207 break;
208 }
209
210 $solutionId = $this->db->nextId('tst_solutions');
211
212 $this->db->execute($this->getPreparedInsertSolutionRecordStatement(), array(
213 $solutionId, $this->getActiveId(), $questionId, $this->getTargetPass(), time(),
214 $row['points'], $row['value1'], $row['value2']
215 ));
216 }
217
218 return $sourcePass;
219 }
220
221 protected function adoptSourceResult($questionId, $sourcePass): void
222 {
223 $res = $this->db->execute(
225 array($this->getActiveId(), $questionId, $sourcePass)
226 );
227
228 $row = $this->db->fetchAssoc($res);
229
230 $resultId = $this->db->nextId('tst_test_result');
231
232 $this->db->execute($this->getPreparedInsertResultRecordStatement(), array(
233 $resultId, $this->getActiveId(), $questionId, $this->getTargetPass(), time(),
234 $row['points'], $row['manual'], $row['hint_count'], $row['hint_points'], $row['answered']
235 ));
236 }
237
239 {
240 if (self::$preparedDeleteSolutionRecordsStatement === null) {
241 self::$preparedDeleteSolutionRecordsStatement = $this->db->prepareManip(
242 "DELETE FROM tst_solutions WHERE active_fi = ? AND question_fi = ? AND pass = ?",
243 array('integer', 'integer', 'integer')
244 );
245 }
246
248 }
249
251 {
252 if (self::$preparedSelectSolutionRecordsStatement === null) {
253 $query = "
254 SELECT pass, points, value1, value2 FROM tst_solutions
255 WHERE active_fi = ? AND question_fi = ? AND pass < ? ORDER BY pass DESC
256 ";
257
258 self::$preparedSelectSolutionRecordsStatement = $this->db->prepare(
259 $query,
260 array('integer', 'integer', 'integer')
261 );
262 }
263
265 }
266
268 {
269 if (self::$preparedInsertSolutionRecordStatement === null) {
270 $query = "
271 INSERT INTO tst_solutions (
272 solution_id, active_fi, question_fi, pass, tstamp, points, value1, value2
273 ) VALUES (
274 ?, ?, ?, ?, ?, ?, ?, ?
275 )
276 ";
277
278 self::$preparedInsertSolutionRecordStatement = $this->db->prepareManip(
279 $query,
280 array('integer', 'integer', 'integer', 'integer', 'integer', 'integer', 'text', 'text')
281 );
282 }
283
285 }
286
288 {
289 if (self::$preparedDeleteResultRecordStatement === null) {
290 self::$preparedDeleteResultRecordStatement = $this->db->prepareManip(
291 "DELETE FROM tst_test_result WHERE active_fi = ? AND question_fi = ? AND pass = ?",
292 array('integer', 'integer', 'integer')
293 );
294 }
295
297 }
298
300 {
301 if (self::$preparedSelectResultRecordStatement === null) {
302 $query = "
303 SELECT points, manual, hint_count, hint_points, answered FROM tst_test_result
304 WHERE active_fi = ? AND question_fi = ? AND pass = ?
305 ";
306
307 self::$preparedSelectResultRecordStatement = $this->db->prepare(
308 $query,
309 array('integer', 'integer', 'integer')
310 );
311 }
312
314 }
315
317 {
318 if (self::$preparedInsertResultRecordStatement === null) {
319 $query = "
320 INSERT INTO tst_test_result (
321 test_result_id, active_fi, question_fi, pass, tstamp,
322 points, manual, hint_count, hint_points, answered
323 ) VALUES (
324 ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
325 )
326 ";
327
328 self::$preparedInsertResultRecordStatement = $this->db->prepareManip(
329 $query,
330 array('integer', 'integer', 'integer', 'integer', 'integer', 'integer', 'integer', 'integer', 'integer', 'integer')
331 );
332 }
333
335 }
336}
__construct(ilDBInterface $db, ilSetting $assSettings, $isAssessmentLogEnabled)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface ilDBInterface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$res
Definition: ltiservices.php:69
$query