ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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  $solutions->removeByKey($index);
86  $solutions->addKeyValue($index, $answer->getAnswertext());
87  }
88  } elseif (
89  $rightNode instanceof ilAssLacPercentageResultExpression &&
90  $composite->nodes[0] instanceof ilAssLacResultOfAnswerOfQuestionExpression) {
94  $answers = $gap->getItems();
95  $max_points = 0;
96  foreach ($answers as $answer) {
97  if ($max_points < $answer->getPoints()) {
98  $max_points = $answer->getPoints();
99  }
100  }
101 
102  $item = null;
103  $reached_points = null;
104  // @todo for Thomas J.: Maybe handle identical scoring for every type
105  switch ($gap->getType()) {
106  case CLOZE_TEXT:
107  for ($order = 0; $order < $gap->getItemCount(); $order++) {
108  $answer = $gap->getItem($order);
109  $item_points = $question->getTextgapPoints($answer->getAnswertext(), $result['value'], $answer->getPoints());
110  if ($item_points > $reached_points) {
111  $reached_points = $item_points;
112  }
113  }
114  break;
115 
116  case CLOZE_NUMERIC:
117  for ($order = 0; $order < $gap->getItemCount(); $order++) {
118  $answer = $gap->getItem($order);
119  $item_points = $question->getNumericgapPoints($answer->getAnswertext(), $result["value"], $answer->getPoints(), $answer->getLowerBound(), $answer->getUpperBound());
120  if ($item_points > $reached_points) {
121  $reached_points = $item_points;
122  }
123  }
124  break;
125 
126  case CLOZE_SELECT:
127  if ($result['value'] != null) {
128  $answer = $gap->getItem($result['value'] - 1);
129  $reached_points = $answer->getPoints();
130  }
131  break;
132  }
133 
134  $percentage = 0;
135  if ($max_points != 0 && $reached_points !== null) {
136  $percentage = (int) (($reached_points / $max_points) * 100);
137  }
138  $solutions->setReachedPercentage($percentage);
139  }
140  }
141 
142  if (
143  $question instanceof assFormulaQuestion &&
144  $rightNode instanceof ilAssLacPercentageResultExpression &&
145  $this->isInstanceOfAnswerIndexProvidingExpression($composite->nodes[0])
146  ) {
147  // @todo for Thomas J.: Move to interface / implement in concrete class (req. for future releases)
148  $result = $solutions->getSolutionForKey($index);
149  $answer = $question->getAvailableAnswerOptions($index - 1);
150 
151  $unit = $solutions->getSolutionForKey($index . "_unit");
152  $key = null;
153  if (is_array($unit)) {
154  $key = $unit['value'];
155  }
156 
157  $max_points = $answer->getPoints();
158  $points = $answer->getReachedPoints($question->getVariables(), $question->getResults(), $result["value"], $key, $question->getUnitrepository()->getUnits());
159 
160  $percentage = 0;
161  if ($max_points != 0) {
162  $percentage = (int) (($points / $max_points) * 100);
163  }
164  $solutions->setReachedPercentage($percentage);
165  }
166 
167  $result = $rightNode->checkResult($solutions, $composite->getPattern(), $index);
168  } else {
169  switch ($composite->getPattern()) {
170  case "&":
171  $result = $composite->nodes[0] && $composite->nodes[1];
172  break;
173  case "|":
174  $result = $composite->nodes[0] || $composite->nodes[1];
175  break;
176  default:
177  $result = false;
178  }
179  }
180 
181  if ($composite->isNegated()) {
182  return !$result;
183  }
184  return $result;
185  }
186 
192  {
193  if ($composite->nodes[0] instanceof ilAssLacResultOfAnswerOfQuestionExpression) {
194  return true;
195  }
196 
197  if ($composite->nodes[0] instanceof ilAssLacResultOfAnswerOfCurrentQuestionExpression) {
198  return true;
199  }
200 
201  return false;
202  }
203 }
Class ResultOfAnswerOfCurrentQuestion for the expression R[m].
Class ResultOfAnswerOfQuestion for the expression Qn[m].
Class for cloze tests.
$result
const CLOZE_TEXT
Cloze question constants.
Class StringResultExpression for the expression ~TEXT~.
Class for single choice questions assFormulaQuestion is a class for single choice questions...
$index
Definition: metadata.php:60
__construct($object_loader, $activeId, $pass)
evaluate(ilAssLacAbstractComposite $composite)
const CLOZE_SELECT
const CLOZE_NUMERIC
$key
Definition: croninfo.php:18
Class PercentageResultExpression for the expression n%.
isInstanceOfAnswerIndexProvidingExpression(ilAssLacAbstractComposite $composite)