ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilAssLacCompositeEvaluator.php
Go to the documentation of this file.
1 <?php
2 
11 
15  protected $object_loader;
16 
20  protected $activeId;
21 
25  protected $pass;
26 
33  {
34  $this->object_loader = $object_loader;
35  $this->activeId = $activeId;
36  $this->pass = $pass;
37  }
38 
44  public function evaluate(ilAssLacAbstractComposite $composite)
45  {
46  if(count($composite->nodes) > 0)
47  {
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  {
75  // @todo for Thomas J.: Move to interface / implement in concrete class (req. for future releases)
80  $result = $solutions->getSolutionForKey($index);
81  $gap = $question->getAvailableAnswerOptions($index-1);
82 
83  if($rightNode instanceof ilAssLacStringResultExpression)
84  {
85  if($gap->getType() == 1)
86  {
87  $answer = $gap->getItem($result['value'] - 1);
88  $solutions->removeByKey($index);
89  $solutions->addKeyValue($index, $answer->getAnswertext());
90  }
91  }
92  else if(
93  $rightNode instanceof ilAssLacPercentageResultExpression &&
94  $composite->nodes[0] instanceof ilAssLacResultOfAnswerOfQuestionExpression)
95  {
99  $answers = $gap->getItems();
100  $max_points = 0;
101  foreach($answers as $answer)
102  {
103  if($max_points < $answer->getPoints())
104  {
105  $max_points = $answer->getPoints();
106  }
107  }
108 
109  $item = null;
110  $reached_points = null;
111  // @todo for Thomas J.: Maybe handle identical scoring for every type
112  switch($gap->getType())
113  {
114  case CLOZE_TEXT:
115  for($order = 0; $order < $gap->getItemCount(); $order++)
116  {
117  $answer = $gap->getItem($order);
118  $item_points = $question->getTextgapPoints($answer->getAnswertext(), $result['value'], $answer->getPoints());
119  if($item_points > $reached_points) $reached_points = $item_points;
120  }
121  break;
122 
123  case CLOZE_NUMERIC:
124  for($order = 0; $order < $gap->getItemCount(); $order++)
125  {
126  $answer = $gap->getItem($order);
127  $item_points = $question->getNumericgapPoints($answer->getAnswertext(), $result["value"], $answer->getPoints(), $answer->getLowerBound(), $answer->getUpperBound());
128  if($item_points > $reached_points) $reached_points = $item_points;
129  }
130  break;
131 
132  case CLOZE_SELECT:
133  if($result['value'] != null)
134  {
135  $answer = $gap->getItem($result['value'] - 1);
136  $reached_points = $answer->getPoints();
137  }
138  break;
139  }
140 
141  $percentage = 0;
142  if($max_points != 0 && $reached_points !== null)
143  {
144  $percentage = (int)(($reached_points / $max_points) * 100);
145  }
146  $solutions->setReachedPercentage($percentage);
147  }
148  }
149 
150  if(
151  $question instanceof assFormulaQuestion &&
152  $rightNode instanceof ilAssLacPercentageResultExpression &&
153  $this->isInstanceOfAnswerIndexProvidingExpression($composite->nodes[0])
154  )
155  {
156  // @todo for Thomas J.: Move to interface / implement in concrete class (req. for future releases)
157  $result = $solutions->getSolutionForKey($index);
158  $answer = $question->getAvailableAnswerOptions($index-1);
159 
160  $unit = $solutions->getSolutionForKey($index . "_unit");
161  $key = null;
162  if(is_array($unit))
163  {
164  $key = $unit['value'];
165  }
166 
167  $max_points = $answer->getPoints();
168  $points = $answer->getReachedPoints($question->getVariables(), $question->getResults(), $result["value"], $key, $question->getUnitrepository()->getUnits());
169 
170  $percentage = 0;
171  if($max_points != 0)
172  {
173  $percentage = (int)(($points/$max_points)*100);
174  }
175  $solutions->setReachedPercentage($percentage);
176  }
177 
178  $result = $rightNode->checkResult($solutions,$composite->getPattern(),$index);
179  }
180  else
181  {
182  switch($composite->getPattern())
183  {
184  case "&":
185  $result = $composite->nodes[0] && $composite->nodes[1];
186  break;
187  case "|":
188  $result = $composite->nodes[0] || $composite->nodes[1];
189  break;
190  default:
191  $result = false;
192  }
193  }
194 
195  if($composite->isNegated())
196  {
197  return !$result;
198  }
199  return $result;
200  }
201 
207  {
208  if($composite->nodes[0] instanceof ilAssLacResultOfAnswerOfQuestionExpression)
209  {
210  return true;
211  }
212 
213  if($composite->nodes[0] instanceof ilAssLacResultOfAnswerOfCurrentQuestionExpression)
214  {
215  return true;
216  }
217 
218  return false;
219  }
220 }
221 
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...
__construct($object_loader, $activeId, $pass)
evaluate(ilAssLacAbstractComposite $composite)
const CLOZE_SELECT
const CLOZE_NUMERIC
Class PercentageResultExpression for the expression n%.
isInstanceOfAnswerIndexProvidingExpression(ilAssLacAbstractComposite $composite)