ILIAS  release_8 Revision v8.24
ilAssLacCompositeEvaluator.php
Go to the documentation of this file.
1<?php
26{
30 protected $object_loader;
31
35 protected $activeId;
36
40 protected $pass;
41
48 {
49 $this->object_loader = $object_loader;
50 $this->activeId = $activeId;
51 $this->pass = $pass;
52 }
53
59 public function evaluate(ilAssLacAbstractComposite $composite)
60 {
61 if (count($composite->nodes) > 0) {
62 $composite->nodes[0] = $this->evaluate($composite->nodes[0]);
63 $composite->nodes[1] = $this->evaluate($composite->nodes[1]);
64 $composite = $this->evaluateSubTree($composite);
65 }
66 return $composite;
67 }
68
74 private function evaluateSubTree(ilAssLacAbstractComposite $composite): bool
75 {
76 $result = false;
77 if ($composite->nodes[0] instanceof ilAssLacExpressionInterface &&
78 $composite->nodes[1] instanceof ilAssLacExpressionInterface
79 ) {
80 $question = $this->object_loader->getQuestion($composite->nodes[0]->getQuestionIndex());
81 $rightNode = $composite->nodes[1];
82
83 $index = $this->isInstanceOfAnswerIndexProvidingExpression($composite) ? $composite->nodes[0]->getAnswerIndex() : null;
84
85 $solutions = $question->getUserQuestionResult($this->activeId, $this->pass);
86
87 if ($question instanceof assClozeTest) {
88 // @todo for Thomas J.: Move to interface / implement in concrete class (req. for future releases)
93 $result = $solutions->getSolutionForKey($index);
94 $gap = $question->getAvailableAnswerOptions($index - 1);
95
96 if ($rightNode instanceof ilAssLacStringResultExpression) {
97 if ($gap->getType() == 1) {
98 $answer = $gap->getItem($result['value'] - 1);
99 if ($answer) {
100 $solutions->removeByKey($index);
101 $solutions->addKeyValue($index, $answer->getAnswertext());
102 }
103 }
104 } elseif (
105 $rightNode instanceof ilAssLacPercentageResultExpression &&
106 $composite->nodes[0] instanceof ilAssLacResultOfAnswerOfQuestionExpression) {
107
111 $answers = $gap->getItems($question->getShuffler());
112 $max_points = 0;
113 foreach ($answers as $answer) {
114 if ($max_points < $answer->getPoints()) {
115 $max_points = $answer->getPoints();
116 }
117 }
118
119 $item = null;
120 $reached_points = null;
121 // @todo for Thomas J.: Maybe handle identical scoring for every type
122 switch ($gap->getType()) {
123 case CLOZE_TEXT:
124 for ($order = 0; $order < $gap->getItemCount(); $order++) {
125 $answer = $gap->getItem($order);
126 $item_points = $question->getTextgapPoints($answer->getAnswertext(), $result['value'], $answer->getPoints());
127 if ($item_points > $reached_points) {
128 $reached_points = $item_points;
129 }
130 }
131 break;
132
133 case CLOZE_NUMERIC:
134 for ($order = 0; $order < $gap->getItemCount(); $order++) {
135 $answer = $gap->getItem($order);
136 $item_points = $question->getNumericgapPoints($answer->getAnswertext(), $result["value"], $answer->getPoints(), $answer->getLowerBound(), $answer->getUpperBound());
137 if ($item_points > $reached_points) {
138 $reached_points = $item_points;
139 }
140 }
141 break;
142
143 case CLOZE_SELECT:
144 if ($result['value'] != null) {
145 $answer = $gap->getItem($result['value'] - 1);
146 $reached_points = $answer->getPoints();
147 }
148 break;
149 }
150
151 $percentage = 0;
152 if ($max_points != 0 && $reached_points !== null) {
153 $percentage = (int) (($reached_points / $max_points) * 100);
154 }
155 $solutions->setReachedPercentage($percentage);
156 }
157 }
158
159 if (
160 $question instanceof assFormulaQuestion &&
161 $rightNode instanceof ilAssLacPercentageResultExpression &&
162 $this->isInstanceOfAnswerIndexProvidingExpression($composite->nodes[0])
163 ) {
164 // @todo for Thomas J.: Move to interface / implement in concrete class (req. for future releases)
165 $result = $solutions->getSolutionForKey($index);
166 $answer = $question->getAvailableAnswerOptions($index - 1);
167
168 $unit = $solutions->getSolutionForKey($index . "_unit");
169 $key = null;
170 if (is_array($unit)) {
171 $key = $unit['value'];
172 }
173
174 $max_points = $answer->getPoints();
175 // @PHP8-CR
176 // I have the feeling that $question could be meant, but lacking deeper insight, I like to postpone this
177 // to a later date and eventually task this to T&A TechSquad for analysis.
178 // Candidate:
179 //$points = $question->getReachedPoints($question->getVariables(), $question->getResults(), $result["value"], $key, $question->getUnitrepository()->getUnits());
180 $points = $answer->getReachedPoints($question->getVariables(), $question->getResults(), $result["value"], $key, $question->getUnitrepository()->getUnits());
181
182 $percentage = 0;
183 if ($max_points != 0) {
184 $percentage = (int) (($points / $max_points) * 100);
185 }
186 $solutions->setReachedPercentage($percentage);
187 }
188
189 $result = $rightNode->checkResult($solutions, $composite->getPattern(), $index);
190 } else {
191 switch ($composite->getPattern()) {
192 case "&":
193 $result = $composite->nodes[0] && $composite->nodes[1];
194 break;
195 case "|":
196 $result = $composite->nodes[0] || $composite->nodes[1];
197 break;
198 default:
199 $result = false;
200 }
201 }
202
203 if ($composite->isNegated()) {
204 return !$result;
205 }
206 return $result;
207 }
208
214 {
215 if ($composite->nodes[0] instanceof ilAssLacResultOfAnswerOfQuestionExpression) {
216 return true;
217 }
218
219 if ($composite->nodes[0] instanceof ilAssLacResultOfAnswerOfCurrentQuestionExpression) {
220 return true;
221 }
222
223 return false;
224 }
225}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
isInstanceOfAnswerIndexProvidingExpression(ilAssLacAbstractComposite $composite)
evaluate(ilAssLacAbstractComposite $composite)
__construct($object_loader, $activeId, $pass)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const CLOZE_NUMERIC
const CLOZE_SELECT
const CLOZE_TEXT
Cloze question constants.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$index
Definition: metadata.php:145
string $key
Consumer key/client ID value.
Definition: System.php:193