ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilAssLacNumberOfResultExpression.php
Go to the documentation of this file.
1 <?php
2 
3 include_once "Modules/TestQuestionPool/classes/questions/LogicalAnswerCompare/Expressions/ilAssLacAbstractExpression.php";
4 include_once "Modules/TestQuestionPool/classes/questions/LogicalAnswerCompare/Expressions/ilAssLacSolutionExpressionInterface.php";
5 
14 {
26  public static $pattern = "/\\+[0-9]+\\+/";
27 
31  public static $identifier = "+n+";
32 
38  protected $numeric_value;
39 
47  protected function setMatches($matches)
48  {
49  $this->numeric_value = $matches[0][0];
50  }
51 
55  public function getNumericValue()
56  {
57  return $this->numeric_value;
58  }
59 
64  public function getValue()
65  {
66  return '+' . $this->numeric_value . "+";
67  }
68 
73  public function getDescription()
74  {
75  return "Anwort " . $this->numeric_value . " beantwortet ";
76  }
77 
85  public function checkResult($result, $comperator, $index = null)
86  {
87  $isTrue = false;
88  if ($index == null) {
89  $values = $result->getUserSolutionsByIdentifier("key");
90 
91  foreach ($values as $value) {
92  $isTrue = $isTrue || $this->compare($comperator, $value);
93  }
94  } else {
95  $solution = $result->getSolutionForKey($index);
96  $isTrue = $this->compare($comperator, $solution["value"]);
97  }
98 
99  return $isTrue;
100  }
101 
102  private function compare($comperator, $value)
103  {
104  switch ($comperator) {
105  case "=":
106  return $value == $this->getNumericValue();
107  break;
108  case "<>":
109  return $value != $this->getNumericValue();
110  break;
111  default:
112  return false;
113  }
114  }
115 }
$result
$index
Definition: metadata.php:60
getValue()
Get the value of this Expression.
$values
getDescription()
Get a human readable description of the Composite element.
Class NumberOfResultExpression fot the expression +n+.
checkResult($result, $comperator, $index=null)
setMatches($matches)
Sets the result of the parsed value by a specific expression pattern.