ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilAssLacStringResultExpression.php
Go to the documentation of this file.
1 <?php
2 
3 include_once "Modules/TestQuestionPool/classes/questions/LogicalAnswerCompare/Expressions/ilAssLacAbstractExpression.php";
4 include_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  {
100  $values = $result->getUserSolutionsByIdentifier("value");
101 
102  foreach($values as $value)
103  {
104  $isTrue = $isTrue || $this->compare($comperator, $value);
105  }
106  }
107  else
108  {
109  $solution = $result->getSolutionForKey($index);
110  $isTrue = $this->compare($comperator, $solution["value"]);
111  }
112 
113  return $isTrue;
114  }
115 
122  private function compare($comperator, $value)
123  {
124  switch($comperator)
125  {
126  case "=":
127  return $this->getText() == $value;
128  break;
129  case "<>":
130  return $this->getText() != $value;
131  break;
132  default:
133  return false;
134  }
135  }
136 }
$result
getValue()
Get the value of this Expression.
Class StringResultExpression for the expression ~TEXT~.
getDescription()
Get a human readable description of the Composite element.
checkResult($result, $comperator, $index=null)
getPattern()
Get the Pattern to match relevant informations for an Expression.
setMatches($matches)
Sets the result of the parsed value by a specific expression pattern.