ILIAS  release_8 Revision v8.23
class.assAnswerCloze.php
Go to the documentation of this file.
1 <?php
2 
19 require_once './Modules/Test/classes/inc.AssessmentConstants.php';
20 
38 {
39  protected ?string $lowerBound;
40 
49  protected ?string $upperBound;
50 
51  protected int $gap_size;
52 
53 
64  public function __construct(string $answertext = "", float $points = 0.0, int $order = 0, int $id = -1, int $state = 0)
65  {
67  $this->lowerBound = null;
68  $this->upperBound = null;
69  $this->gap_size = 0;
70  }
71 
72  // fau: fixGapFormula - allow formula evaluation when checking bounds, save bound text instead of number
78  public function setLowerBound(string $bound): void
79  {
80  $boundvalue = $this->getNumericValueFromText($bound);
81  $value = $this->getNumericValueFromAnswerText();
82 
83  if ($boundvalue === false || $boundvalue > $value) {
84  $this->lowerBound = $this->getAnswertext();
85  } else {
86  $this->lowerBound = $bound;
87  }
88  }
89 
95  public function setUpperBound(string $bound): void
96  {
97  $boundvalue = $this->getNumericValueFromText($bound);
98  $value = $this->getNumericValueFromAnswerText();
99 
100  if ($boundvalue === false || $boundvalue < $value) {
101  $this->upperBound = $this->getAnswertext();
102  } else {
103  $this->upperBound = $bound;
104  }
105  }
106 
107  protected function getNumericValueFromAnswerText()
108  {
109  return $this->getNumericValueFromText($this->getAnswertext());
110  }
111 
112  protected function getNumericValueFromText($text)
113  {
114  include_once("./Services/Math/classes/class.EvalMath.php");
115  $eval = new EvalMath();
116  $eval->suppress_errors = true;
117  return $eval->e(str_replace(",", ".", ilUtil::stripSlashes($text, false)));
118  }
119  // fau.
120 
126  public function getLowerBound(): ?string
127  {
128  return $this->lowerBound;
129  }
130 
136  public function getUpperBound(): ?string
137  {
138  return $this->upperBound;
139  }
140 
144  public function setGapSize(int $gap_size): void
145  {
146  $this->gap_size = $gap_size;
147  }
148 
152  public function getGapSize(): int
153  {
154  return $this->gap_size;
155  }
156 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getLowerBound()
Returns the lower bound.
getUpperBound()
Returns the upper bound.
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setUpperBound(string $bound)
Sets the upper bound.
getAnswertext()
Gets the answer text.
__construct(Container $dic, ilPlugin $plugin)
setLowerBound(string $bound)
Sets the lower boind.
__construct(string $answertext="", float $points=0.0, int $order=0, int $id=-1, int $state=0)
assAnswerCloze constructor
setGapSize(int $gap_size)