ILIAS  release_7 Revision v7.30-3-g800a261c036
ilAssLacCompositeEvaluator.php
Go to the documentation of this file.
1<?php
2
11{
12
16 protected $object_loader;
17
21 protected $activeId;
22
26 protected $pass;
27
34 {
35 $this->object_loader = $object_loader;
36 $this->activeId = $activeId;
37 $this->pass = $pass;
38 }
39
45 public function evaluate(ilAssLacAbstractComposite $composite)
46 {
47 if (count($composite->nodes) > 0) {
48 $composite->nodes[0] = $this->evaluate($composite->nodes[0]);
49 $composite->nodes[1] = $this->evaluate($composite->nodes[1]);
50 $composite = $this->evaluateSubTree($composite);
51 }
52 return $composite;
53 }
54
60 private function evaluateSubTree(ilAssLacAbstractComposite $composite)
61 {
62 $result = false;
63 if ($composite->nodes[0] instanceof ilAssLacExpressionInterface &&
64 $composite->nodes[1] instanceof ilAssLacExpressionInterface
65 ) {
66 $question = $this->object_loader->getQuestion($composite->nodes[0]->getQuestionIndex());
67 $rightNode = $composite->nodes[1];
68
69 $index = $this->isInstanceOfAnswerIndexProvidingExpression($composite) ? $composite->nodes[0]->getAnswerIndex(): null;
70
71 $solutions = $question->getUserQuestionResult($this->activeId, $this->pass);
72
73 if ($question instanceof assClozeTest) {
74 // @todo for Thomas J.: Move to interface / implement in concrete class (req. for future releases)
79 $result = $solutions->getSolutionForKey($index);
80 $gap = $question->getAvailableAnswerOptions($index - 1);
81
82 if ($rightNode instanceof ilAssLacStringResultExpression) {
83 if ($gap->getType() == 1) {
84 $answer = $gap->getItem($result['value'] - 1);
85 if ($answer) {
86 $solutions->removeByKey($index);
87 $solutions->addKeyValue($index, $answer->getAnswertext());
88 }
89 }
90 } elseif (
91 $rightNode instanceof ilAssLacPercentageResultExpression &&
92 $composite->nodes[0] instanceof ilAssLacResultOfAnswerOfQuestionExpression) {
96 $answers = $gap->getItems();
97 $max_points = 0;
98 foreach ($answers as $answer) {
99 if ($max_points < $answer->getPoints()) {
100 $max_points = $answer->getPoints();
101 }
102 }
103
104 $item = null;
105 $reached_points = null;
106 // @todo for Thomas J.: Maybe handle identical scoring for every type
107 switch ($gap->getType()) {
108 case CLOZE_TEXT:
109 for ($order = 0; $order < $gap->getItemCount(); $order++) {
110 $answer = $gap->getItem($order);
111 $item_points = $question->getTextgapPoints($answer->getAnswertext(), $result['value'], $answer->getPoints());
112 if ($item_points > $reached_points) {
113 $reached_points = $item_points;
114 }
115 }
116 break;
117
118 case CLOZE_NUMERIC:
119 for ($order = 0; $order < $gap->getItemCount(); $order++) {
120 $answer = $gap->getItem($order);
121 $item_points = $question->getNumericgapPoints($answer->getAnswertext(), $result["value"], $answer->getPoints(), $answer->getLowerBound(), $answer->getUpperBound());
122 if ($item_points > $reached_points) {
123 $reached_points = $item_points;
124 }
125 }
126 break;
127
128 case CLOZE_SELECT:
129 if ($result['value'] != null) {
130 $answer = $gap->getItem($result['value'] - 1);
131 $reached_points = $answer->getPoints();
132 }
133 break;
134 }
135
136 $percentage = 0;
137 if ($max_points != 0 && $reached_points !== null) {
138 $percentage = (int) (($reached_points / $max_points) * 100);
139 }
140 $solutions->setReachedPercentage($percentage);
141 }
142 }
143
144 if (
145 $question instanceof assFormulaQuestion &&
146 $rightNode instanceof ilAssLacPercentageResultExpression &&
147 $this->isInstanceOfAnswerIndexProvidingExpression($composite->nodes[0])
148 ) {
149 // @todo for Thomas J.: Move to interface / implement in concrete class (req. for future releases)
150 $result = $solutions->getSolutionForKey($index);
151 $answer = $question->getAvailableAnswerOptions($index - 1);
152
153 $unit = $solutions->getSolutionForKey($index . "_unit");
154 $key = null;
155 if (is_array($unit)) {
156 $key = $unit['value'];
157 }
158
159 $max_points = $answer->getPoints();
160 $points = $answer->getReachedPoints($question->getVariables(), $question->getResults(), $result["value"], $key, $question->getUnitrepository()->getUnits());
161
162 $percentage = 0;
163 if ($max_points != 0) {
164 $percentage = (int) (($points / $max_points) * 100);
165 }
166 $solutions->setReachedPercentage($percentage);
167 }
168
169 $result = $rightNode->checkResult($solutions, $composite->getPattern(), $index);
170 } else {
171 switch ($composite->getPattern()) {
172 case "&":
173 $result = $composite->nodes[0] && $composite->nodes[1];
174 break;
175 case "|":
176 $result = $composite->nodes[0] || $composite->nodes[1];
177 break;
178 default:
179 $result = false;
180 }
181 }
182
183 if ($composite->isNegated()) {
184 return !$result;
185 }
186 return $result;
187 }
188
194 {
195 if ($composite->nodes[0] instanceof ilAssLacResultOfAnswerOfQuestionExpression) {
196 return true;
197 }
198
199 if ($composite->nodes[0] instanceof ilAssLacResultOfAnswerOfCurrentQuestionExpression) {
200 return true;
201 }
202
203 return false;
204 }
205}
$result
An exception for terminatinating execution or to throw for unit testing.
Class for cloze tests.
Class for single choice questions assFormulaQuestion is a class for single choice questions.
isInstanceOfAnswerIndexProvidingExpression(ilAssLacAbstractComposite $composite)
evaluate(ilAssLacAbstractComposite $composite)
__construct($object_loader, $activeId, $pass)
Class PercentageResultExpression for the expression n%.
Class ResultOfAnswerOfCurrentQuestion for the expression R[m].
Class ResultOfAnswerOfQuestion for the expression Qn[m].
Class StringResultExpression for the expression ~TEXT~.
const CLOZE_NUMERIC
const CLOZE_SELECT
const CLOZE_TEXT
Cloze question constants.
$index
Definition: metadata.php:128