ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilQTIItem.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
30{
31 public const QT_UNKNOWN = "unknown";
32 public const QT_KPRIM_CHOICE = "assKprimChoice";
33 public const QT_LONG_MENU = "assLongMenu";
34 public const QT_MULTIPLE_CHOICE_SR = "assSingleChoice";
35 public const QT_MULTIPLE_CHOICE_MR = "assMultipleChoice";
36 public const QT_CLOZE = "assClozeTest";
37 public const QT_ERRORTEXT = "assErrorText";
38 public const QT_MATCHING = "assMatchingQuestion";
39 public const QT_ORDERING = "assOrderingQuestion";
40 public const QT_ORDERING_HORIZONTAL = "assOrderingHorizontal";
41 public const QT_IMAGEMAP = "assImagemapQuestion";
42 public const QT_TEXT = "assTextQuestion";
43 public const QT_FILEUPLOAD = "assFileUpload";
44 public const QT_NUMERIC = "assNumeric";
45 public const QT_FORMULA = "assFormulaQuestion";
46 public const QT_TEXTSUBSET = "assTextSubset";
47
48 private const VALID_QUESTION_TYPES = [
64 ];
65
66 public ?string $ident = null;
67 public string $title = '';
68 public string $maxattempts = '';
69 public ?string $label = null;
70 public ?string $xmllang = null;
71 public string $comment = '';
72 public ?string $ilias_version = null;
73 public string $author = '';
74 public ?string $questiontype = null;
76 public ?array $duration = null;
79 public array $resprocessing = [];
81 public array $itemfeedback = [];
84 public array $presentationitem = [];
88 public array $suggested_solutions = [];
92 public array $itemmetadata = [];
93 protected ?string $iliasSourceVersion = null;
94 protected ?string $iliasSourceNic = null;
95 protected array $response = [];
96
97 public function setIdent(string $a_ident): void
98 {
99 $this->ident = $a_ident;
100 }
101
102 public function getIdent(): ?string
103 {
104 return $this->ident;
105 }
106
107 public function setTitle(string $a_title): void
108 {
109 $this->title = $a_title;
110 }
111
112 public function getTitle(): string
113 {
114 return $this->title;
115 }
116
117 public function setComment(string $a_comment): void
118 {
119 if (preg_match("/(.*?)\=(.*)/", $a_comment, $matches)) {
120 // special comments written by ILIAS
121 switch ($matches[1]) {
122 case "ILIAS Version":
123 $this->ilias_version = $matches[2];
124 return;
125 case "Questiontype":
126 $this->questiontype = $matches[2];
127 return;
128 case "Author":
129 $this->author = $matches[2] ?? '';
130 return;
131 }
132 }
133 $this->comment = $a_comment;
134 }
135
136 public function getComment(): string
137 {
138 return $this->comment;
139 }
140
141 public function setDuration(string $a_duration): void
142 {
143 if (preg_match("/P(\d+)Y(\d+)M(\d+)DT(\d+)H(\d+)M(\d+)S/", $a_duration, $matches)) {
144 $this->duration = [
145 "h" => $matches[4],
146 "m" => $matches[5],
147 "s" => $matches[6]
148 ];
149 }
150 }
151
155 public function getDuration(): ?array
156 {
157 return $this->duration;
158 }
159
160 public function setQuestiontext(ilQTIMaterial $a_questiontext): void
161 {
162 $this->questiontext = $a_questiontext;
163 }
164
165 public function getQuestiontext(): ?ilQTIMaterial
166 {
167 return $this->questiontext;
168 }
169
170 public function addResprocessing(ilQTIResprocessing $a_resprocessing): void
171 {
172 $this->resprocessing[] = $a_resprocessing;
173 }
174
175 public function addItemfeedback(ilQTIItemfeedback $a_itemfeedback): void
176 {
177 $this->itemfeedback[] = $a_itemfeedback;
178 }
179
180 public function setMaxattempts(string $a_maxattempts): void
181 {
182 $this->maxattempts = $a_maxattempts;
183 }
184
185 public function getMaxattempts(): string
186 {
187 return $this->maxattempts;
188 }
189
190 public function setLabel(string $a_label): void
191 {
192 $this->label = $a_label;
193 }
194
195 public function getLabel(): ?string
196 {
197 return $this->label;
198 }
199
200 public function setXmllang(string $a_xmllang): void
201 {
202 $this->xmllang = $a_xmllang;
203 }
204
205 public function getXmllang(): ?string
206 {
207 return $this->xmllang;
208 }
209
210 public function setPresentation(ilQTIPresentation $a_presentation): void
211 {
212 $this->presentation = $a_presentation;
213 }
214
216 {
217 return $this->presentation;
218 }
219
220 public function setQuestiontype(string $a_questiontype): void
221 {
222 $this->questiontype = $a_questiontype;
223 }
224
225 public function getQuestiontype(): ?string
226 {
227 return $this->questiontype;
228 }
229
233 public function addPresentationitem($a_presentationitem): void
234 {
235 $this->presentationitem[] = $a_presentationitem;
236 }
237
238 public function determineQuestionType(): ?string
239 {
240 if (in_array($this->questiontype, self::VALID_QUESTION_TYPES)) {
241 return $this->questiontype;
242 }
243
244 switch ($this->questiontype) {
245 case "ORDERING QUESTION":
246 return self::QT_ORDERING;
247 case "KPRIM CHOICE QUESTION":
249 case "LONG MENU QUESTION":
250 return self::QT_LONG_MENU;
251 case "SINGLE CHOICE QUESTION":
253 case "MULTIPLE CHOICE QUESTION":
254 break;
255 case "MATCHING QUESTION":
256 return self::QT_MATCHING;
257 case "CLOZE QUESTION":
258 return self::QT_CLOZE;
259 case "IMAGE MAP QUESTION":
260 return self::QT_IMAGEMAP;
261 case "TEXT QUESTION":
262 return self::QT_TEXT;
263 case "NUMERIC QUESTION":
264 return self::QT_NUMERIC;
265 case "TEXTSUBSET QUESTION":
266 return self::QT_TEXTSUBSET;
267 }
268 if (!$this->presentation) {
269 return self::QT_UNKNOWN;
270 }
271 foreach ($this->presentation->order as $entry) {
272 if ('response' !== $entry["type"]) {
273 continue;
274 }
275 $result = $this->typeFromResponse($this->presentation->response[$entry["index"]]);
276 if ($result !== null) {
277 return $result;
278 }
279 }
280 if ($this->questiontype === '') {
281 return self::QT_UNKNOWN;
282 }
283
284 return $this->questiontype;
285 }
286
287 public function setAuthor(string $a_author): void
288 {
289 $this->author = $a_author;
290 }
291
292 public function getAuthor(): string
293 {
294 return $this->author;
295 }
296
297 public function getIliasSourceVersion(): ?string
298 {
300 }
301
302 public function setIliasSourceVersion(?string $iliasSourceVersion): void
303 {
304 $this->iliasSourceVersion = $iliasSourceVersion ?? '';
305 }
306
307 public function getIliasSourceNic(): ?string
308 {
310 }
311
312 public function setIliasSourceNic(?string $iliasSourceNic): void
313 {
314 $this->iliasSourceNic = $iliasSourceNic;
315 }
316
317 public function addSuggestedSolution(ilQTIMattext $a_solution, int $a_gap_index): void
318 {
319 $this->suggested_solutions[] = ["solution" => $a_solution, "gap_index" => $a_gap_index];
320 }
321
325 public function addMetadata(array $a_metadata): void
326 {
327 $this->itemmetadata[] = $a_metadata;
328 }
329
330 public function getMetadata(): array
331 {
332 return $this->itemmetadata;
333 }
334
335 public function getMetadataEntry(string $a_label): ?string
336 {
337 foreach ($this->itemmetadata as $metadata) {
338 if ($metadata["label"] === $a_label) {
339 return $metadata["entry"];
340 }
341 }
342 return null;
343 }
344
345 private function typeFromResponse(ilQTIResponse $response): ?string
346 {
347 switch ($response->getResponsetype()) {
349 switch ($response->getRCardinality()) {
353 }
354 // no break
357 switch ($response->getRCardinality()) {
360 }
361 // no break
363
364 default: return null;
365 }
366 }
367}
const QT_MULTIPLE_CHOICE_MR
addMetadata(array $a_metadata)
setPresentation(ilQTIPresentation $a_presentation)
const QT_MULTIPLE_CHOICE_SR
const QT_LONG_MENU
const QT_FORMULA
setAuthor(string $a_author)
const QT_KPRIM_CHOICE
array $itemmetadata
const QT_NUMERIC
const VALID_QUESTION_TYPES
setQuestiontext(ilQTIMaterial $a_questiontext)
string $questiontype
setIdent(string $a_ident)
setQuestiontype(string $a_questiontype)
string $iliasSourceNic
setComment(string $a_comment)
setLabel(string $a_label)
const QT_MATCHING
const QT_ORDERING
string $xmllang
ilQTIMaterial $questiontext
const QT_IMAGEMAP
const QT_FILEUPLOAD
array $itemfeedback
string $ilias_version
array $suggested_solutions
addItemfeedback(ilQTIItemfeedback $a_itemfeedback)
const QT_ORDERING_HORIZONTAL
setTitle(string $a_title)
string $iliasSourceVersion
addResprocessing(ilQTIResprocessing $a_resprocessing)
const QT_ERRORTEXT
array $resprocessing
getMetadataEntry(string $a_label)
setXmllang(string $a_xmllang)
setDuration(string $a_duration)
setIliasSourceVersion(?string $iliasSourceVersion)
addPresentationitem($a_presentationitem)
string $maxattempts
const QT_UNKNOWN
string $comment
addSuggestedSolution(ilQTIMattext $a_solution, int $a_gap_index)
ilQTIPresentation $presentation
array $presentationitem
const QT_TEXTSUBSET
string $author
setMaxattempts(string $a_maxattempts)
typeFromResponse(ilQTIResponse $response)
setIliasSourceNic(?string $iliasSourceNic)