ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilPageQuestionProcessor Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilPageQuestionProcessor:

Public Member Functions

 __construct ()
 

Static Public Member Functions

static saveQuestionAnswer (string $a_type, int $a_id, string $a_answer)
 
static getQuestionStatistics (int $a_q_id)
 
static calculatePoints (string $a_type, int $a_id, array $a_choice)
 Calculate points. More...
 
static getAnswerStatus ( $a_q_id, int $a_user_id=0)
 
static resetTries (int $a_q_id, int $a_user_id)
 Reset tries for user and question. More...
 
static unlock (int $a_q_id, int $a_user_id)
 Unlock question for user. More...
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Page question processor

Author
Alexander Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

Definition at line 24 of file class.ilPageQuestionProcessor.php.

Constructor & Destructor Documentation

◆ __construct()

ilPageQuestionProcessor::__construct ( )

Definition at line 26 of file class.ilPageQuestionProcessor.php.

27 {
28 }

Member Function Documentation

◆ calculatePoints()

static ilPageQuestionProcessor::calculatePoints ( string  $a_type,
int  $a_id,
array  $a_choice 
)
static

Calculate points.

This function calculates the points for a given answer. Better would be to re-use from T&A here in the future. When this code has been written this has not been possible yet.

Definition at line 138 of file class.ilPageQuestionProcessor.php.

142 : int {
143 $points = 0;
144
145 switch ($a_type) {
146 case "assSingleChoice":
147 $q = new assSingleChoice();
148 $q->loadFromDb($a_id);
149 $points = 0;
150 foreach ($q->getAnswers() as $key => $answer) {
151 if (isset($a_choice[0]) && $key == $a_choice[0]) {
152 $points += $answer->getPoints();
153 }
154 }
155 break;
156
157 case "assMultipleChoice":
158 $q = new assMultipleChoice();
159 $q->loadFromDb($a_id);
160 $points = 0;
161 foreach ($q->getAnswers() as $key => $answer) {
162 if (is_array($a_choice) && in_array($key, $a_choice)) {
163 $points += $answer->getPoints();
164 } else {
165 $points += $answer->getPointsUnchecked();
166 }
167 }
168 break;
169
170 case "assClozeTest":
171 $q = new assClozeTest();
172 $q->loadFromDb($a_id);
173 $points = 0;
174 foreach ($q->getGaps() as $id => $gap) {
175 $choice = $a_choice[$id];
176 switch ($gap->getType()) {
178 $gappoints = 0;
179 for ($order = 0; $order < $gap->getItemCount(); $order++) {
180 $answer = $gap->getItem($order);
181 $gotpoints = $q->getTextgapPoints(
182 $answer->getAnswertext(),
183 $choice,
184 $answer->getPoints()
185 );
186 if ($gotpoints > $gappoints) {
187 $gappoints = $gotpoints;
188 }
189 }
190 $points += $gappoints;
191 //$ilLog->write("ct: ".$gappoints);
192 break;
193
195 $gappoints = 0;
196 for ($order = 0; $order < $gap->getItemCount(); $order++) {
197 $answer = $gap->getItem($order);
198 $gotpoints = $q->getNumericgapPoints(
199 $answer->getAnswertext(),
200 $choice,
201 $answer->getPoints(),
202 $answer->getLowerBound(),
203 $answer->getUpperBound()
204 );
205 if ($gotpoints > $gappoints) {
206 $gappoints = $gotpoints;
207 }
208 }
209 $points += $gappoints;
210 //$ilLog->write("cn: ".$gappoints);
211 break;
212
214 for ($order = 0; $order < $gap->getItemCount(); $order++) {
215 $answer = $gap->getItem($order);
216 if ($choice == $answer->getOrder()) {
217 $answerpoints = $answer->getPoints();
218 $points += $answerpoints;
219 //$ilLog->write("cs: ".$answerpoints);
220 }
221 }
222 break;
223 }
224 }
225 break;
226
227 case "assMatchingQuestion":
228 $q = new assMatchingQuestion();
229 $q->loadFromDb($a_id);
230 $points = 0;
231 for ($i = 0; $i < $q->getMatchingPairCount(); $i++) {
232 $pair = $q->getMatchingPair($i);
233 if (is_array($a_choice) && in_array($pair->getDefinition()->getIdentifier() . "-" . $pair->getTerm()->getIdentifier(), $a_choice)) {
234 $points += $pair->points;
235 }
236 }
237 break;
238
239 case "assOrderingQuestion":
240
241 // TODO-LSD: change calculation strategy according to lsd cleanup changes
242
243 $q = new assOrderingQuestion();
244 $q->loadFromDb($a_id);
245 $points = 0;
246 $cnt = 1;
247 $right = true;
248 foreach ($q->getOrderElements() as $answer) {
249 if ($a_choice[$cnt - 1] != $cnt) {
250 $right = false;
251 }
252 $cnt++;
253 }
254 if ($right) {
255 $points = $q->getPoints();
256 }
257 break;
258
259 case "assImagemapQuestion":
260 $q = new assImagemapQuestion();
261 $q->loadFromDb($a_id);
262 $points = 0;
263
264 foreach ($q->getAnswers() as $key => $answer) {
265 if (is_array($a_choice) && in_array($key, $a_choice)) {
266 $points += $answer->getPoints();
267 }
268 }
269 break;
270 }
271
272 if ($points < 0) {
273 $points = 0;
274 }
275
276 return (int) $points;
277 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Class for cloze tests.
Class for image map questions.
Class for matching questions.
Class for multiple choice tests.
Class for ordering questions.
Class for single choice questions.
$q
Definition: shib_logout.php:23

References $id, $q, assClozeGap\TYPE_NUMERIC, assClozeGap\TYPE_SELECT, and assClozeGap\TYPE_TEXT.

◆ getAnswerStatus()

static ilPageQuestionProcessor::getAnswerStatus (   $a_q_id,
int  $a_user_id = 0 
)
static
Parameters
int | array$a_q_id

Definition at line 282 of file class.ilPageQuestionProcessor.php.

285 : array {
286 global $DIC;
287
288 $ilDB = $DIC->database();
289
290 $qst = (is_array($a_q_id))
291 ? $ilDB->in("qst_id", $a_q_id, false, "integer")
292 : " qst_id = " . $ilDB->quote($a_q_id, "integer");
293
294 $and = ($a_user_id > 0)
295 ? " AND user_id = " . $ilDB->quote($a_user_id, "integer")
296 : "";
297
298 $set = $ilDB->query(
299 "SELECT * FROM page_qst_answer WHERE " .
300 $qst .
301 $and
302 );
303
304 if (is_array($a_q_id) || $a_user_id == 0) {
305 $recs = array();
306 while ($rec = $ilDB->fetchAssoc($set)) {
307 $key = ($a_user_id == 0)
308 ? $rec["qst_id"] . ":" . $rec["user_id"]
309 : $rec["qst_id"];
310 $recs[$key] = $rec;
311 }
312 return $recs;
313 }
314
315 if ($rec = $ilDB->fetchAssoc($set)) {
316 return $rec;
317 }
318 return [
319 "try" => 0,
320 "passed" => false
321 ];
322 }
global $DIC
Definition: shib_login.php:26

References $ilDB.

Referenced by ilLMTracker\getBlockedUsersInformation(), ilPCQuestion\getOnloadCode(), ilLMTracker\loadLMTrackingData(), and ilLMPageGUI\processAnswer().

+ Here is the caller graph for this function:

◆ getQuestionStatistics()

static ilPageQuestionProcessor::getQuestionStatistics ( int  $a_q_id)
static

Definition at line 81 of file class.ilPageQuestionProcessor.php.

83 : array {
84 global $DIC;
85
86 $ilDB = $DIC->database();
87
88 $set = $ilDB->query(
89 "SELECT count(user_id) usr_cnt FROM page_qst_answer WHERE " .
90 " qst_id = " . $ilDB->quote($a_q_id, "integer")
91 );
92 $rec = $ilDB->fetchAssoc($set);
93 $all = $rec["usr_cnt"];
94
95 $first = false;
96 $second = false;
97 $third_or_more = false;
98
99 if ($all > 0) {
100 $set = $ilDB->query(
101 "SELECT count(user_id) usr_cnt FROM page_qst_answer WHERE " .
102 " qst_id = " . $ilDB->quote($a_q_id, "integer") . " AND " .
103 " passed = " . $ilDB->quote(1, "integer") . " AND " .
104 " try = " . $ilDB->quote(1, "integer")
105 );
106 $rec = $ilDB->fetchAssoc($set);
107 $first = $rec["usr_cnt"];
108
109 $set = $ilDB->query(
110 "SELECT count(user_id) usr_cnt FROM page_qst_answer WHERE " .
111 " qst_id = " . $ilDB->quote($a_q_id, "integer") . " AND " .
112 " passed = " . $ilDB->quote(1, "integer") . " AND " .
113 " try = " . $ilDB->quote(2, "integer")
114 );
115 $rec = $ilDB->fetchAssoc($set);
116 $second = $rec["usr_cnt"];
117
118 $set = $ilDB->query(
119 $q = "SELECT count(user_id) usr_cnt FROM page_qst_answer WHERE " .
120 " qst_id = " . $ilDB->quote($a_q_id, "integer") . " AND " .
121 " passed = " . $ilDB->quote(1, "integer") . " AND " .
122 " try >= " . $ilDB->quote(3, "integer")
123 );
124 $rec = $ilDB->fetchAssoc($set);
125 $third_or_more = $rec["usr_cnt"];
126 }
127
128 return array("all" => $all, "first" => $first, "second" => $second, "third_or_more" => $third_or_more);
129 }

References $ilDB, and $q.

Referenced by ilLMQuestionListTableGUI\fillRow().

+ Here is the caller graph for this function:

◆ resetTries()

static ilPageQuestionProcessor::resetTries ( int  $a_q_id,
int  $a_user_id 
)
static

Reset tries for user and question.

Definition at line 327 of file class.ilPageQuestionProcessor.php.

330 : void {
331 global $DIC;
332
333 $ilDB = $DIC->database();
334
335 $ilDB->manipulate(
336 $q = "UPDATE page_qst_answer SET " .
337 " try = " . $ilDB->quote(0, "integer") . "," .
338 " passed = " . $ilDB->quote(0, "integer") . "," .
339 " points = " . $ilDB->quote(0, "integer") . "," .
340 " unlocked = " . $ilDB->quote(0, "integer") .
341 " WHERE qst_id = " . $ilDB->quote($a_q_id, "integer") .
342 " AND user_id = " . $ilDB->quote($a_user_id, "integer")
343 );
344 }

Referenced by ilObjContentObjectGUI\resetNumberOfTries().

+ Here is the caller graph for this function:

◆ saveQuestionAnswer()

static ilPageQuestionProcessor::saveQuestionAnswer ( string  $a_type,
int  $a_id,
string  $a_answer 
)
static

Definition at line 30 of file class.ilPageQuestionProcessor.php.

34 : void {
35 global $DIC;
36
37 $ilUser = $DIC->user();
38 $ilLog = $DIC["ilLog"];
39 $ilDB = $DIC->database();
40 $ilLog->write($a_type);
41 $ilLog->write($a_id);
42 $ilLog->write($a_answer);
43 $answer = json_decode($a_answer, false, 512, JSON_THROW_ON_ERROR);
44 $passed = $answer->passed;
45 $choice = $answer->choice ?? [];
46 $points = self::calculatePoints($a_type, $a_id, $choice);
47 $ilLog->write("Points: " . $points);
48
49 $set = $ilDB->query(
50 "SELECT * FROM page_qst_answer WHERE " .
51 " qst_id = " . $ilDB->quote($a_id, "integer") . " AND " .
52 " user_id = " . $ilDB->quote($ilUser->getId(), "integer")
53 );
54
55 // #15146
56 if (!$ilDB->fetchAssoc($set)) {
57 $ilDB->replace(
58 "page_qst_answer",
59 array(
60 "qst_id" => array("integer", $a_id),
61 "user_id" => array("integer", $ilUser->getId())
62 ),
63 array(
64 "try" => array("integer", 1),
65 "passed" => array("integer", $passed),
66 "points" => array("float", $points)
67 )
68 );
69 } else {
70 $ilDB->manipulate(
71 "UPDATE page_qst_answer SET " .
72 " try = try + 1," .
73 " passed = " . $ilDB->quote($passed, "integer") . "," .
74 " points = " . $ilDB->quote($points, "float") .
75 " WHERE qst_id = " . $ilDB->quote($a_id, "integer") .
76 " AND user_id = " . $ilDB->quote($ilUser->getId(), "integer")
77 );
78 }
79 }
static calculatePoints(string $a_type, int $a_id, array $a_choice)
Calculate points.

Referenced by ilPageObjectGUI\processAnswer().

+ Here is the caller graph for this function:

◆ unlock()

static ilPageQuestionProcessor::unlock ( int  $a_q_id,
int  $a_user_id 
)
static

Unlock question for user.

Definition at line 349 of file class.ilPageQuestionProcessor.php.

352 : void {
353 global $DIC;
354
355 $ilDB = $DIC->database();
356
357 $ilDB->manipulate(
358 $q = "UPDATE page_qst_answer SET " .
359 " unlocked = " . $ilDB->quote(1, "integer") .
360 " WHERE qst_id = " . $ilDB->quote($a_q_id, "integer") .
361 " AND user_id = " . $ilDB->quote($a_user_id, "integer")
362 );
363 }

Referenced by ilObjContentObjectGUI\unlockQuestion().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: