ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
class.assAnswerTrueFalse.php
Go to the documentation of this file.
1<?php
2
20
36{
45
56 public function __construct($answertext = "", $points = 0.0, $order = 0, $correctness = false)
57 {
59
60 // force $this->correctness to be a string
61 // ilDB->quote makes 1 from true and saving it to ENUM('1','0') makes that '0'!!!
62 // (maybe that only happens for certain mysql versions)
63 $this->correctness = $correctness . "";
64 }
65
71 public function getCorrectness()
72 {
73 return $this->correctness;
74 }
75
81 public function isCorrect()
82 {
83 return $this->correctness;
84 }
85
91 public function isIncorrect(): bool
92 {
93 return !$this->correctness;
94 }
95
103 public function isTrue()
104 {
105 return $this->correctness;
106 }
107
115 public function isFalse(): bool
116 {
117 return !$this->correctness;
118 }
119
125 public function setCorrectness($correctness = false): void
126 {
127 // force $this->correctness to be a string
128 // ilDB->quote makes 1 from true and saving it to ENUM('1','0') makes that '0'!!!
129 // (maybe that only happens for certain mysql versions)
130 $this->correctness = $correctness . "";
131 }
132
138 public function setTrue(): void
139 {
140 $this->correctness = "1";
141 }
142
148 public function setFalse(): void
149 {
150 $this->correctness = "0";
151 }
152
153 #[\Override]
154 public function toNormalized(
155 Transformations $transformations,
156 array $context = []
157 ): array|float|bool|int|string|null
158 {
159 return [
160 ...$transformations->normalize(parent::toNormalized($transformations, $context)),
161 'correctness' => $this->correctness,
162 ];
163 }
164
165 #[\Override]
166 public function fromNormalized(
167 array $normalized,
168 Transformations $transformations
169 ): static
170 {
171 $clone = parent::fromNormalized($normalized, $transformations);
172 $clone->setCorrectness($transformations->string($normalized['correctness']));
173 return $clone;
174 }
175}
Class for simple answers.
Class for true/false or yes/no answers.
__construct($answertext="", $points=0.0, $order=0, $correctness=false)
ASS_AnswerTrueFalse constructor.
toNormalized(Transformations $transformations, array $context=[])
Convert the internal state of the implementing object into a language-neutral array structure.
isCorrect()
Gets the correctness.
setTrue()
Sets the answer as a correct answer.
fromNormalized(array $normalized, Transformations $transformations)
Restore the object from its normalized representation.
isTrue()
Gets the correctness.
isFalse()
Gets the correctness.
isIncorrect()
Gets the correctness.
setFalse()
Sets the answer as a incorrect answer.
setCorrectness($correctness=false)
Sets the correctness.
getCorrectness()
Gets the correctness.
Provides a set of transformations for normalizing and denormalizing values.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc