ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilAssLacStringResultExpression.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
15{
27 public static $pattern = "/~.*?~/";
28
32 public static $identifier = "~TEXT~";
33
39 protected $text;
40
45 public function getPattern()
46 {
47 return '/~(.*)~/';
48 }
49
57 protected function setMatches($matches)
58 {
59 $this->text = $matches[1][0];
60 }
61
65 public function getText()
66 {
67 return $this->text;
68 }
69
74 public function getValue()
75 {
76 return "~" . $this->text . '~';
77 }
78
83 public function getDescription()
84 {
85 return $this->text . " beantwortet ";
86 }
87
95 public function checkResult($result, $comperator, $index = null)
96 {
97 $isTrue = false;
98 if ($index == null) {
99 $values = $result->getUserSolutionsByIdentifier("value");
100
101 foreach ($values as $value) {
102 $isTrue = $isTrue || $this->compare($comperator, $value);
103 }
104 } else {
105 $solution = $result->getSolutionForKey($index);
106 $isTrue = $this->compare($comperator, $solution["value"]);
107 }
108
109 return $isTrue;
110 }
111
118 private function compare($comperator, $value)
119 {
120 switch ($comperator) {
121 case "=":
122 return $this->getText() == $value;
123 break;
124 case "<>":
125 return $this->getText() != $value;
126 break;
127 default:
128 return false;
129 }
130 }
131}
$result
An exception for terminatinating execution or to throw for unit testing.
Class StringResultExpression for the expression ~TEXT~.
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.
$index
Definition: metadata.php:60
$values