ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.assAnswerCloze.php
Go to the documentation of this file.
1<?php
2
36{
37 protected ?string $lowerBound;
38
47 protected ?string $upperBound;
48
49 protected int $gap_size;
50
51
62 public function __construct(string $answertext = "", float $points = 0.0, int $order = 0, int $id = -1, int $state = 0)
63 {
65 $this->lowerBound = null;
66 $this->upperBound = null;
67 $this->gap_size = 0;
68 }
69
70 // fau: fixGapFormula - allow formula evaluation when checking bounds, save bound text instead of number
76 public function setLowerBound(string $bound): void
77 {
78 $boundvalue = $this->getNumericValueFromText($bound);
79 $value = $this->getNumericValueFromAnswerText();
80
81 if ($boundvalue === false || $boundvalue > $value) {
82 $this->lowerBound = $this->getAnswertext();
83 } else {
84 $this->lowerBound = $bound;
85 }
86 }
87
93 public function setUpperBound(string $bound): void
94 {
95 $boundvalue = $this->getNumericValueFromText($bound);
96 $value = $this->getNumericValueFromAnswerText();
97
98 if ($boundvalue === false || $boundvalue < $value) {
99 $this->upperBound = $this->getAnswertext();
100 } else {
101 $this->upperBound = $bound;
102 }
103 }
104
105 protected function getNumericValueFromAnswerText()
106 {
107 return $this->getNumericValueFromText($this->getAnswertext());
108 }
109
110 protected function getNumericValueFromText($text)
111 {
112 $eval = new EvalMath();
113 $eval->suppress_errors = true;
114 return $eval->e(str_replace(",", ".", ilUtil::stripSlashes($text, false)));
115 }
116 // fau.
117
123 public function getLowerBound(): ?string
124 {
125 return $this->lowerBound;
126 }
127
133 public function getUpperBound(): ?string
134 {
135 return $this->upperBound;
136 }
137
141 public function setGapSize(int $gap_size): void
142 {
143 $this->gap_size = $gap_size;
144 }
145
149 public function getGapSize(): int
150 {
151 return $this->gap_size;
152 }
153}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getAnswertext()
Gets the answer text.
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.
__construct(string $answertext="", float $points=0.0, int $order=0, int $id=-1, int $state=0)
assAnswerCloze constructor
setGapSize(int $gap_size)
setLowerBound(string $bound)
Sets the lower boind.
getLowerBound()
Returns the lower bound.
getUpperBound()
Returns the upper bound.
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc