ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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  $eval = new EvalMath();
115  $eval->suppress_errors = true;
116  return $eval->e(str_replace(",", ".", ilUtil::stripSlashes($text, false)));
117  }
118  // fau.
119 
125  public function getLowerBound(): ?string
126  {
127  return $this->lowerBound;
128  }
129 
135  public function getUpperBound(): ?string
136  {
137  return $this->upperBound;
138  }
139 
143  public function setGapSize(int $gap_size): void
144  {
145  $this->gap_size = $gap_size;
146  }
147 
151  public function getGapSize(): int
152  {
153  return $this->gap_size;
154  }
155 }
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="")
__construct(VocabulariesInterface $vocabularies)
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.
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)