ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
class.assAnswerCloze.php
Go to the documentation of this file.
1<?php
2
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
156 #[\Override]
157 public function toNormalized(
158 Transformations $transformations,
159 array $context = []
160 ): array|float|bool|int|string|null
161 {
162 return [
163 ...$transformations->normalize(parent::toNormalized($transformations, $context)),
164 'lower_bound' => $this->lowerBound,
165 'upper_bound' => $this->upperBound,
166 'gap_size' => $this->gap_size,
167 ];
168 }
169
170 #[\Override]
171 public function fromNormalized(
172 array $normalized,
173 Transformations $transformations
174 ): static
175 {
176 $clone = parent::fromNormalized($normalized, $transformations);
177 $clone->lowerBound = $transformations->nullableString($normalized['lower_bound']);
178 $clone->upperBound = $transformations->nullableString($normalized['upper_bound']);
179 $clone->gap_size = $transformations->int($normalized['gap_size']);
180 return $clone;
181 }
182}
Class for simple answers.
getAnswertext()
Gets the answer text.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Provides a set of transformations for normalizing and denormalizing values.
Class for cloze question numeric answers.
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.
toNormalized(Transformations $transformations, array $context=[])
Convert the internal state of the implementing object into a language-neutral array structure.
fromNormalized(array $normalized, Transformations $transformations)
Restore the object from its normalized representation.
getUpperBound()
Returns the upper bound.
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$text
Definition: xapiexit.php:21