ILIAS  release_7 Revision v7.30-3-g800a261c036
ilAssLacNumericResultExpression.php
Go to the documentation of this file.
1<?php
2
3include_once "Modules/TestQuestionPool/classes/questions/LogicalAnswerCompare/Expressions/ilAssLacAbstractExpression.php";
4include_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 {
58 }
59
64 public function getValue()
65 {
66 return "#" . $this->numeric_value . "#";
67 }
68
73 public function getDescription()
74 {
75 return $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("value");
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 case "=":
112 return $value == $this->getNumericValue();
113 break;
114 case ">=":
115 return $value >= $this->getNumericValue();
116 break;
117 case ">":
118 return $value > $this->getNumericValue();
119 break;
120 case "<>":
121 return $value != $this->getNumericValue();
122 break;
123 default:
124 return false;
125 }
126 }
127}
$result
An exception for terminatinating execution or to throw for unit testing.
Class NumericResultExpression for the expression #n#.
getDescription()
Get a human readable description of the Composite element.
getValue()
Get the value of this Expression.
checkResult($result, $comperator, $index=null)
setMatches($matches)
Sets the result of the parsed value by a specific expression pattern.
$index
Definition: metadata.php:128