ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
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  {
70  return $this->numeric_value;
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  $isTrue = $this->compare($comperator, $solution["value"]);
110  }
111 
112  return $isTrue;
113  }
114 
115  private function compare($comperator, $value): bool
116  {
117  switch ($comperator) {
118  case "<":
119  return $value < $this->getNumericValue();
120  break;
121  case "<=":
122  return $value <= $this->getNumericValue();
123  break;
124  case "=":
125  return $value == $this->getNumericValue();
126  break;
127  case ">=":
128  return $value >= $this->getNumericValue();
129  break;
130  case ">":
131  return $value > $this->getNumericValue();
132  break;
133  case "<>":
134  return $value != $this->getNumericValue();
135  break;
136  default:
137  return false;
138  }
139  }
140 }
getDescription()
Get a human readable description of the Composite element.
$index
Definition: metadata.php:145
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getValue()
Get the value of this Expression.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
checkResult($result, $comperator, $index=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setMatches($matches)
Sets the result of the parsed value by a specific expression pattern.