ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilAssQuestionUserSolutionAdopter.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4
12{
17
22
27
31 protected static $preparedDeleteResultRecordStatement = null;
32
36 protected static $preparedSelectResultRecordStatement = null;
37
41 protected static $preparedInsertResultRecordStatement = null;
42
46 protected $db;
47
52
56 protected $userId;
57
61 protected $activeId;
62
66 protected $targetPass;
67
71 protected $questionIds;
72
78 public function __construct(ilDB $db, ilSetting $assSettings, $isAssessmentLogEnabled)
79 {
80 $this->db = $db;
81
82 $this->userId = null;
83 $this->activeId = null;
84 $this->targetPass = null;
85 $this->questionIds = array();
86
87 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionProcessLockerFactory.php';
88 $this->processLockerFactory = new ilAssQuestionProcessLockerFactory($assSettings, $db);
89 $this->processLockerFactory->setAssessmentLogEnabled($isAssessmentLogEnabled);
90 }
91
95 public function getUserId()
96 {
97 return $this->userId;
98 }
99
103 public function setUserId($userId)
104 {
105 $this->userId = $userId;
106 }
107
111 public function getActiveId()
112 {
113 return $this->activeId;
114 }
115
119 public function setActiveId($activeId)
120 {
121 $this->activeId = $activeId;
122 }
123
127 public function getTargetPass()
128 {
129 return $this->targetPass;
130 }
131
135 public function setTargetPass($targetPass)
136 {
137 $this->targetPass = $targetPass;
138 }
139
143 public function getQuestionIds()
144 {
145 return $this->questionIds;
146 }
147
152 {
153 $this->questionIds = $questionIds;
154 }
155
156 public function perform()
157 {
158 $this->processLockerFactory->setUserId($this->getUserId());
159
160 foreach($this->getQuestionIds() as $questionId)
161 {
162 $this->processLockerFactory->setQuestionId($questionId);
163 $processLocker = $this->processLockerFactory->getLocker();
164
165 $processLocker->requestUserSolutionAdoptLock();
166 $this->adoptQuestionAnswer($questionId);
167 $processLocker->releaseUserSolutionAdoptLock();
168 }
169 }
170
171 protected function adoptQuestionAnswer($questionId)
172 {
173 $this->resetTargetSolution($questionId);
174 $this->resetTargetResult($questionId);
175
176 $sourcePass = $this->adoptSourceSolution($questionId);
177
178 if( $sourcePass !== null )
179 {
180 $this->adoptSourceResult($questionId, $sourcePass);
181 }
182 }
183
184 protected function resetTargetSolution($questionId)
185 {
186 $this->db->execute(
188 array($this->getActiveId(), $questionId, $this->getTargetPass())
189 );
190 }
191
192 protected function resetTargetResult($questionId)
193 {
194 $this->db->execute(
196 array($this->getActiveId(), $questionId, $this->getTargetPass())
197 );
198 }
199
200 protected function adoptSourceSolution($questionId)
201 {
202 $res = $this->db->execute(
204 array($this->getActiveId(), $questionId, $this->getTargetPass())
205 );
206
207 $sourcePass = null;
208
209 while($row = $this->db->fetchAssoc($res))
210 {
211 if($sourcePass === null)
212 {
213 $sourcePass = $row['pass'];
214 }
215 elseif($row['pass'] < $sourcePass)
216 {
217 break;
218 }
219
220 $solutionId = $this->db->nextId('tst_solutions');
221
222 $this->db->execute($this->getPreparedInsertSolutionRecordStatement(), array(
223 $solutionId, $this->getActiveId(), $questionId, $this->getTargetPass(), time(),
224 $row['points'], $row['value1'], $row['value2']
225 ));
226 }
227
228 return $sourcePass;
229 }
230
231 protected function adoptSourceResult($questionId, $sourcePass)
232 {
233 $res = $this->db->execute(
235 array($this->getActiveId(), $questionId, $sourcePass)
236 );
237
238 $row = $this->db->fetchAssoc($res);
239
240 $resultId = $this->db->nextId('tst_test_result');
241
242 $this->db->execute($this->getPreparedInsertResultRecordStatement(), array(
243 $resultId, $this->getActiveId(), $questionId, $this->getTargetPass(), time(),
244 $row['points'], $row['manual'], $row['hint_count'], $row['hint_points'], $row['answered']
245 ));
246 }
247
249 {
250 if( self::$preparedDeleteSolutionRecordsStatement === null )
251 {
252 self::$preparedDeleteSolutionRecordsStatement = $this->db->prepareManip(
253 "DELETE FROM tst_solutions WHERE active_fi = ? AND question_fi = ? AND pass = ?",
254 array('integer', 'integer', 'integer')
255 );
256 }
257
259 }
260
262 {
263 if( self::$preparedSelectSolutionRecordsStatement === null )
264 {
265 $query = "
266 SELECT pass, points, value1, value2 FROM tst_solutions
267 WHERE active_fi = ? AND question_fi = ? AND pass < ? ORDER BY pass DESC
268 ";
269
270 self::$preparedSelectSolutionRecordsStatement = $this->db->prepare(
271 $query, array('integer', 'integer', 'integer')
272 );
273 }
274
276 }
277
279 {
280 if( self::$preparedInsertSolutionRecordStatement === null )
281 {
282 $query = "
283 INSERT INTO tst_solutions (
284 solution_id, active_fi, question_fi, pass, tstamp, points, value1, value2
285 ) VALUES (
286 ?, ?, ?, ?, ?, ?, ?, ?
287 )
288 ";
289
290 self::$preparedInsertSolutionRecordStatement = $this->db->prepareManip(
291 $query, array('integer', 'integer', 'integer', 'integer', 'integer', 'integer', 'text', 'text')
292 );
293 }
294
296 }
297
299 {
300 if( self::$preparedDeleteResultRecordStatement === null )
301 {
302 self::$preparedDeleteResultRecordStatement = $this->db->prepareManip(
303 "DELETE FROM tst_test_result WHERE active_fi = ? AND question_fi = ? AND pass = ?",
304 array('integer', 'integer', 'integer')
305 );
306 }
307
309 }
310
312 {
313 if( self::$preparedSelectResultRecordStatement === null )
314 {
315 $query = "
316 SELECT points, manual, hint_count, hint_points, answered FROM tst_test_result
317 WHERE active_fi = ? AND question_fi = ? AND pass = ?
318 ";
319
320 self::$preparedSelectResultRecordStatement = $this->db->prepare(
321 $query, array('integer', 'integer', 'integer')
322 );
323 }
324
326 }
327
329 {
330 if( self::$preparedInsertResultRecordStatement === null )
331 {
332 $query = "
333 INSERT INTO tst_test_result (
334 test_result_id, active_fi, question_fi, pass, tstamp,
335 points, manual, hint_count, hint_points, answered
336 ) VALUES (
337 ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
338 )
339 ";
340
341 self::$preparedInsertResultRecordStatement = $this->db->prepareManip(
342 $query, array('integer', 'integer', 'integer', 'integer', 'integer', 'integer', 'integer', 'integer', 'integer', 'integer')
343 );
344 }
345
347 }
348}
__construct(ilDB $db, ilSetting $assSettings, $isAssessmentLogEnabled)
Database Wrapper.
Definition: class.ilDB.php:29
ILIAS Setting Class.