ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilAssLacCompositeEvaluator.php
Go to the documentation of this file.
1<?php
2
27{
31 protected $object_loader;
32
36 protected $activeId;
37
41 protected $pass;
42
49 {
50 $this->object_loader = $object_loader;
51 $this->activeId = $activeId;
52 $this->pass = $pass;
53 }
54
60 public function evaluate(ilAssLacAbstractComposite $composite)
61 {
62 if (count($composite->nodes) > 0) {
63 $composite->nodes[0] = $this->evaluate($composite->nodes[0]);
64 $composite->nodes[1] = $this->evaluate($composite->nodes[1]);
65 $composite = $this->evaluateSubTree($composite);
66 }
67 return $composite;
68 }
69
75 private function evaluateSubTree(ilAssLacAbstractComposite $composite): bool
76 {
77 $result = false;
78 if ($composite->nodes[0] instanceof ilAssLacExpressionInterface &&
79 $composite->nodes[1] instanceof ilAssLacExpressionInterface
80 ) {
81 $question = $this->object_loader->getQuestion($composite->nodes[0]->getQuestionIndex());
82 $rightNode = $composite->nodes[1];
83
84 $index = $this->isInstanceOfAnswerIndexProvidingExpression($composite) ? $composite->nodes[0]->getAnswerIndex() : null;
85
86 $solutions = $question->getUserQuestionResult($this->activeId, $this->pass);
87
88 if ($question instanceof assClozeTest) {
89 // @todo for Thomas J.: Move to interface / implement in concrete class (req. for future releases)
94 $result = $solutions->getSolutionForKey($index);
95 $gap = $question->getAvailableAnswerOptions($index - 1);
96
97 if ($rightNode instanceof ilAssLacStringResultExpression) {
98 if ($gap->getType() == 1 && is_array($result) && isset($result['value'])) {
99 $answer = $gap->getItem($result['value'] - 1);
100 if ($answer) {
101 $solutions->removeByKey($index);
102 $solutions->addKeyValue($index, $answer->getAnswertext());
103 }
104 }
105 } elseif (
106 $rightNode instanceof ilAssLacPercentageResultExpression &&
107 $composite->nodes[0] instanceof ilAssLacResultOfAnswerOfQuestionExpression) {
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()) {
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
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
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_repository = $question->getUnitrepository();
169 $unit = $solutions->getSolutionForKey($index . "_unit");
170 $key = isset($unit["value"])
171 ? $unit_repository->getUnit((int) $unit["value"])
172 : null;
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(
181 $question->getVariables(),
182 $question->getResults(),
183 $result["value"] ?? "",
184 $key,
185 $unit_repository->getUnits()
186 );
187
188 $percentage = 0;
189 if ($max_points != 0) {
190 $percentage = (int) (($points / $max_points) * 100);
191 }
192 $solutions->setReachedPercentage($percentage);
193 }
194
195 $result = $rightNode->checkResult($solutions, $composite->getPattern(), $index);
196 } else {
197 switch ($composite->getPattern()) {
198 case "&":
199 $result = $composite->nodes[0] && $composite->nodes[1];
200 break;
201 case "|":
202 $result = $composite->nodes[0] || $composite->nodes[1];
203 break;
204 default:
205 $result = false;
206 }
207 }
208
209 if ($composite->isNegated()) {
210 return !$result;
211 }
212 return $result;
213 }
214
220 {
221 if ($composite->nodes[0] instanceof ilAssLacResultOfAnswerOfQuestionExpression) {
222 return true;
223 }
224
225 if ($composite->nodes[0] instanceof ilAssLacResultOfAnswerOfCurrentQuestionExpression) {
226 return true;
227 }
228
229 return false;
230 }
231}
Class for cloze tests.
Class for single choice questions assFormulaQuestion is a class for single choice questions.
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...