ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilAssLacStringResultExpression.php
Go to the documentation of this file.
1<?php
2
28{
40 public static $pattern = "/~.*?~/";
41
45 public static $identifier = "~TEXT~";
46
52 protected $text;
53
58 public function getPattern(): string
59 {
60 return '/~(.*)~/';
61 }
62
70 protected function setMatches($matches): void
71 {
72 $this->text = $matches[1][0];
73 }
74
78 public function getText(): string
79 {
80 return $this->text;
81 }
82
87 public function getValue(): string
88 {
89 return "~" . $this->text . '~';
90 }
91
96 public function getDescription(): string
97 {
98 return $this->text . " beantwortet ";
99 }
100
108 public function checkResult($result, $comperator, $index = null): bool
109 {
110 $isTrue = false;
111 if ($index == null) {
112 $values = $result->getUserSolutionsByIdentifier("value");
113
114 foreach ($values as $value) {
115 $isTrue = $isTrue || $this->compare($comperator, $value);
116 }
117 } else {
118 $solution = $result->getSolutionForKey($index);
119 $isTrue = $this->compare($comperator, $solution["value"] ?? "");
120 }
121
122 return $isTrue;
123 }
124
131 private function compare($comperator, $value): bool
132 {
133 switch ($comperator) {
134 case "=":
135 return $this->getText() == $value;
136 break;
137 case "<>":
138 return $this->getText() != $value;
139 break;
140 default:
141 return false;
142 }
143 }
144}
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...
checkResult($result, $comperator, $index=null)
setMatches($matches)
Sets the result of the parsed value by a specific expression pattern.
getValue()
Get the value of this Expression.
getDescription()
Get a human readable description of the Composite element.
getPattern()
Get the Pattern to match relevant informations for an Expression.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...