ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
class.assAnswerSimple.php
Go to the documentation of this file.
1<?php
2
23
35{
36 protected string $answertext;
37
45 protected $points;
46
54 protected $order;
55
63 protected $id;
64
75 public function __construct($answertext = "", $points = 0.0, $order = 0, $id = -1)
76 {
77 $this->answertext = $answertext;
78 $this->setPoints($points);
79 $this->order = $order;
80 $this->id = $id;
81 }
82
92 public function getId(): int
93 {
94 return $this->id;
95 }
96
106 public function getAnswertext(): string
107 {
108 return $this->answertext;
109 }
110
120 public function getPoints(): float
121 {
122 return $this->points;
123 }
124
136 public function checkPoints($a_points): bool
137 {
138 return is_numeric($a_points);
139 }
140
150 public function getOrder(): int
151 {
152 return $this->order;
153 }
154
166 public function setOrder($order = 0): void
167 {
168 if ($order >= 0) {
169 $this->order = $order;
170 }
171 }
172
180 public function setId($id = -1): void
181 {
182 $this->id = $id;
183 }
184
194 public function setAnswertext($answertext = ""): void
195 {
196 $this->answertext = $answertext;
197 }
198
210 public function setPoints($points = 0.0): void
211 {
212 $new_points = str_replace(",", ".", $points);
213 if ($this->checkPoints($new_points)) {
214 $this->points = $new_points;
215 } else {
216 $this->points = 0.0;
217 }
218 }
219
220 #[\Override]
221 public function toNormalized(
222 Transformations $transformations,
223 array $context = []
224 ): array|float|bool|int|string|null
225 {
226 return [
227 'id' => $transformations->normalize(new Id($this->id, 'answer')),
228 'answertext' => $this->answertext,
229 'points' => $this->points,
230 'order' => $this->order,
231 ];
232 }
233
234 #[\Override]
235 public function fromNormalized(
236 array $normalized,
237 Transformations $transformations
238 ): static
239 {
240 return new static(
241 $transformations->string($normalized['answertext']),
242 $transformations->float($normalized['points']),
243 $transformations->int($normalized['order']),
244 $transformations->denormalize($normalized['id'], Id::class)->getId()
245 );
246 }
247}
Class for simple answers.
setOrder($order=0)
Sets the order.
__construct($answertext="", $points=0.0, $order=0, $id=-1)
ASS_AnswerSimple constructor.
getOrder()
Gets the sort/display order.
getPoints()
Gets the points.
checkPoints($a_points)
Checks, if the point value is numeric.
setId($id=-1)
Sets the answer id.
getId()
Gets the answer id.
fromNormalized(array $normalized, Transformations $transformations)
Restore the object from its normalized representation.
setAnswertext($answertext="")
Sets the answer text.
setPoints($points=0.0)
Sets the points.
toNormalized(Transformations $transformations, array $context=[])
Convert the internal state of the implementing object into a language-neutral array structure.
getAnswertext()
Gets the answer text.
Wrapper object for an object identifier and an optional object type the identifier belongs to.
Definition: Id.php:33
Provides a set of transformations for normalizing and denormalizing values.
denormalize(array|float|bool|int|string|null $normalized, string|object $expected)