ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilAssLacNumericResultExpression.php
Go to the documentation of this file.
1<?php
2
27{
39 public static $pattern = '/#-?[0-9\.]+#/';
40
44 public static $identifier = "#n#";
45
51 protected $numeric_value;
52
60 protected function setMatches($matches): void
61 {
62 $this->numeric_value = $matches[0][0];
63 }
64
68 public function getNumericValue(): float
69 {
71 }
72
77 public function getValue(): string
78 {
79 return "#" . $this->numeric_value . "#";
80 }
81
86 public function getDescription(): string
87 {
88 return $this->numeric_value . " beantwortet ";
89 }
90
98 public function checkResult($result, $comperator, $index = null): bool
99 {
100 $isTrue = false;
101 if ($index == null) {
102 $values = $result->getUserSolutionsByIdentifier("value");
103
104 foreach ($values as $value) {
105 $isTrue = $isTrue || $this->compare($comperator, $value);
106 }
107 } else {
108 $solution = $result->getSolutionForKey($index);
109 if($solution !== null) {
110 $isTrue = $this->compare($comperator, $solution["value"] ?? "");
111 }
112 }
113
114 return $isTrue;
115 }
116
117 private function compare($comperator, $value): bool
118 {
119 switch ($comperator) {
120 case "<":
121 return $value < $this->getNumericValue();
122 break;
123 case "<=":
124 return $value <= $this->getNumericValue();
125 break;
126 case "=":
127 return $value == $this->getNumericValue();
128 break;
129 case ">=":
130 return $value >= $this->getNumericValue();
131 break;
132 case ">":
133 return $value > $this->getNumericValue();
134 break;
135 case "<>":
136 return $value != $this->getNumericValue();
137 break;
138 default:
139 return false;
140 }
141 }
142}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...