ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
class.ilAssKprimChoiceAnswer.php
Go to the documentation of this file.
1<?php
2
7
31{
32 private $position;
33
34 private $answertext;
35
36 private $imageFile;
37
38 private $imageFsDir;
39
40 private $imageWebDir;
41
42 private $thumbPrefix;
43
44 private $correctness;
45
46 public function setPosition($position): void
47 {
48 $this->position = $position;
49 }
50
51 public function getPosition()
52 {
53 return $this->position;
54 }
55
56 public function setAnswertext($answertext): void
57 {
58 $this->answertext = $answertext;
59 }
60
61 public function getAnswertext()
62 {
63 return $this->answertext;
64 }
65
66 public function setImageFile(?string $imageFile): void
67 {
68 $this->imageFile = $imageFile;
69 }
70
71 public function getImageFile(): ?string
72 {
73 return $this->imageFile !== null
74 ? basename($this->imageFile)
75 : null;
76 }
77
78 // sk 2023-12-01: These are proxy functions to make things work like the other answertypes for Choice Questions
79 public function setImage(?string $image): void
80 {
81 $this->setImageFile($image);
82 }
83
84 public function getImage(): ?string
85 {
86 return $this->getImageFile();
87 }
88 // End proxy functions
89
90 public function setImageFsDir($imageFsDir): void
91 {
92 $this->imageFsDir = $imageFsDir;
93 }
94
95 public function getImageFsDir()
96 {
97 return $this->imageFsDir;
98 }
99
100 public function setImageWebDir($imageWebDir): void
101 {
102 $this->imageWebDir = $imageWebDir;
103 }
104
105 public function getImageWebDir()
106 {
107 return $this->imageWebDir;
108 }
109
113 public function setThumbPrefix($thumbPrefix): void
114 {
115 $this->thumbPrefix = $thumbPrefix;
116 }
117
121 public function getThumbPrefix()
122 {
123 return $this->thumbPrefix;
124 }
125
126 public function setCorrectness($correctness): void
127 {
128 $this->correctness = $correctness;
129 }
130
131 public function getCorrectness()
132 {
133 return $this->correctness;
134 }
135
136 public function getImageFsPath(): string
137 {
138 return $this->getImageFsDir() . $this->getImageFile();
139 }
140
141 public function getThumbFsPath(): string
142 {
143 return $this->getImageFsDir() . $this->getThumbPrefix() . $this->getImageFile();
144 }
145
146 public function getImageWebPath(): string
147 {
148 return $this->getImageWebDir() . $this->getImageFile();
149 }
150
151 public function getThumbWebPath(): string
152 {
153 return $this->getImageWebDir() . $this->getThumbPrefix() . $this->getImageFile();
154 }
155
156 public function toNormalized(
157 Transformations $transformations,
158 array $context = []
159 ): array|float|bool|int|string|null
160 {
161 return [
162 'position' => $this->position,
163 'answertext' => $this->answertext,
164 'image' => $this->imageFile
165 ? $transformations->normalize(new QuestionImage($this->imageFile, $context['question_id'] ?? null))
166 : null,
167 'correctness' => $this->correctness,
168 ];
169 }
170
171 public function fromNormalized(
172 array $normalized,
173 Transformations $transformations
174 ): static
175 {
176 $clone = clone $this;
177 $clone->position = $transformations->int($normalized['position']);
178 $clone->answertext = $transformations->nullableString($normalized['answertext']);
179 $clone->imageFile = $transformations->denormalize($normalized['image'], QuestionImage::class)?->getFilename();
180 $clone->correctness = $transformations->int($normalized['correctness']);
181 return $clone;
182 }
183}
Provides a set of transformations for normalizing and denormalizing values.
denormalize(array|float|bool|int|string|null $normalized, string|object $expected)
Wrapper object for an image file within a question (e.g.
fromNormalized(array $normalized, Transformations $transformations)
Restore the object from its normalized representation.
toNormalized(Transformations $transformations, array $context=[])
Convert the internal state of the implementing object into a language-neutral array structure.