ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
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 private array $unit_categories = [];
98 private array $units = [];
99
100 public function setIdent(string $a_ident): void
101 {
102 $this->ident = $a_ident;
103 }
104
105 public function getIdent(): ?string
106 {
107 return $this->ident;
108 }
109
110 public function setTitle(string $a_title): void
111 {
112 $this->title = $a_title;
113 }
114
115 public function getTitle(): string
116 {
117 return $this->title;
118 }
119
120 public function setComment(string $a_comment): void
121 {
122 if (preg_match("/(.*?)\=(.*)/", $a_comment, $matches)) {
123 // special comments written by ILIAS
124 switch ($matches[1]) {
125 case "ILIAS Version":
126 $this->ilias_version = $matches[2];
127 return;
128 case "Questiontype":
129 $this->questiontype = $matches[2];
130 return;
131 case "Author":
132 $this->author = $matches[2] ?? '';
133 return;
134 }
135 }
136 $this->comment = $a_comment;
137 }
138
139 public function getComment(): string
140 {
141 return $this->comment;
142 }
143
144 public function setDuration(string $a_duration): void
145 {
146 if (preg_match("/P(\d+)Y(\d+)M(\d+)DT(\d+)H(\d+)M(\d+)S/", $a_duration, $matches)) {
147 $this->duration = [
148 "h" => $matches[4],
149 "m" => $matches[5],
150 "s" => $matches[6]
151 ];
152 }
153 }
154
158 public function getDuration(): ?array
159 {
160 return $this->duration;
161 }
162
163 public function setQuestiontext(ilQTIMaterial $a_questiontext): void
164 {
165 $this->questiontext = $a_questiontext;
166 }
167
168 public function getQuestiontext(): ?ilQTIMaterial
169 {
170 return $this->questiontext;
171 }
172
173 public function addResprocessing(ilQTIResprocessing $a_resprocessing): void
174 {
175 $this->resprocessing[] = $a_resprocessing;
176 }
177
178 public function addItemfeedback(ilQTIItemfeedback $a_itemfeedback): void
179 {
180 $this->itemfeedback[] = $a_itemfeedback;
181 }
182
183 public function setMaxattempts(string $a_maxattempts): void
184 {
185 $this->maxattempts = $a_maxattempts;
186 }
187
188 public function getMaxattempts(): string
189 {
190 return $this->maxattempts;
191 }
192
193 public function setLabel(string $a_label): void
194 {
195 $this->label = $a_label;
196 }
197
198 public function getLabel(): ?string
199 {
200 return $this->label;
201 }
202
203 public function setXmllang(string $a_xmllang): void
204 {
205 $this->xmllang = $a_xmllang;
206 }
207
208 public function getXmllang(): ?string
209 {
210 return $this->xmllang;
211 }
212
213 public function setPresentation(ilQTIPresentation $a_presentation): void
214 {
215 $this->presentation = $a_presentation;
216 }
217
219 {
220 return $this->presentation;
221 }
222
223 public function setQuestiontype(string $a_questiontype): void
224 {
225 $this->questiontype = $a_questiontype;
226 }
227
228 public function getQuestiontype(): ?string
229 {
230 return $this->questiontype;
231 }
232
236 public function addPresentationitem($a_presentationitem): void
237 {
238 $this->presentationitem[] = $a_presentationitem;
239 }
240
241 public function determineQuestionType(): ?string
242 {
243 if (in_array($this->questiontype, self::VALID_QUESTION_TYPES)) {
244 return $this->questiontype;
245 }
246
247 switch ($this->questiontype) {
248 case "ORDERING QUESTION":
249 return self::QT_ORDERING;
250 case "KPRIM CHOICE QUESTION":
252 case "LONG MENU QUESTION":
253 return self::QT_LONG_MENU;
254 case "SINGLE CHOICE QUESTION":
256 case "MULTIPLE CHOICE QUESTION":
257 break;
258 case "MATCHING QUESTION":
259 return self::QT_MATCHING;
260 case "CLOZE QUESTION":
261 return self::QT_CLOZE;
262 case "IMAGE MAP QUESTION":
263 return self::QT_IMAGEMAP;
264 case "TEXT QUESTION":
265 return self::QT_TEXT;
266 case "NUMERIC QUESTION":
267 return self::QT_NUMERIC;
268 case "TEXTSUBSET QUESTION":
269 return self::QT_TEXTSUBSET;
270 }
271 if (!$this->presentation) {
272 return self::QT_UNKNOWN;
273 }
274 foreach ($this->presentation->order as $entry) {
275 if ('response' !== $entry["type"]) {
276 continue;
277 }
278 $result = $this->typeFromResponse($this->presentation->response[$entry["index"]]);
279 if ($result !== null) {
280 return $result;
281 }
282 }
283 if ($this->questiontype === '') {
284 return self::QT_UNKNOWN;
285 }
286
287 return $this->questiontype;
288 }
289
290 public function addUnitCategory(string $label, array $unit_category): void
291 {
292 $this->unit_categories[$label] = $unit_category;
293 }
294
295 public function getUnitCategories(): array
296 {
298 }
299
303 public function getUnitCategoryObjets(): array
304 {
305 $unit_categories = [];
306 foreach ($this->getUnitCategories() as $key => $unit_category) {
307 $formula_question_unit_category = new assFormulaQuestionUnitCategory();
308 $formula_question_unit_category->setCategory($key);
309 $formula_question_unit_category->setId((int) $unit_category['id']);
310 $formula_question_unit_category->setQuestionFi((int) $unit_category['question_fi']);
311 $unit_categories[$key] = $formula_question_unit_category;
312 }
313
314 return $unit_categories;
315 }
316
317 public function addUnit(string $label, array $unit): void
318 {
319 $this->units[$label] = $unit;
320 }
321
322 public function getUnits(): array
323 {
324 return $this->units;
325 }
326
330 public function getUnitObjects(): array
331 {
332 $units = [];
333 foreach ($this->getUnits() as $key => $unit) {
334 $formula_question_unit = new assFormulaQuestionUnit();
335 $formula_question_unit->setUnit($key);
336 $formula_question_unit->setId((int) $unit['id']);
337 $formula_question_unit->setSequence((int) $unit['sequence']);
338 $formula_question_unit->setFactor((float) $unit['factor']);
339 $formula_question_unit->setBaseUnit((int) $unit['base_unit']);
340 $formula_question_unit->setBaseunitTitle($unit['base_unit_title']);
341 $formula_question_unit->setCategory((int) $unit['category']);
342 $units[$key] = $formula_question_unit;
343 }
344
345 return $units;
346 }
347
348 public function setAuthor(string $a_author): void
349 {
350 $this->author = $a_author;
351 }
352
353 public function getAuthor(): string
354 {
355 return $this->author;
356 }
357
358 public function getIliasSourceVersion(): ?string
359 {
361 }
362
363 public function setIliasSourceVersion(?string $iliasSourceVersion): void
364 {
365 $this->iliasSourceVersion = $iliasSourceVersion ?? '';
366 }
367
368 public function getIliasSourceNic(): ?string
369 {
371 }
372
373 public function setIliasSourceNic(?string $iliasSourceNic): void
374 {
375 $this->iliasSourceNic = $iliasSourceNic;
376 }
377
378 public function addSuggestedSolution(ilQTIMattext $a_solution, int $a_gap_index): void
379 {
380 $this->suggested_solutions[] = ["solution" => $a_solution, "gap_index" => $a_gap_index];
381 }
382
386 public function addMetadata(array $a_metadata): void
387 {
388 $this->itemmetadata[] = $a_metadata;
389 }
390
391 public function getMetadata(): array
392 {
393 return $this->itemmetadata;
394 }
395
396 public function getMetadataEntry(string $a_label): ?string
397 {
398 foreach ($this->itemmetadata as $metadata) {
399 if ($metadata["label"] === $a_label) {
400 return $metadata["entry"];
401 }
402 }
403 return null;
404 }
405
406 private function typeFromResponse(ilQTIResponse $response): ?string
407 {
408 switch ($response->getResponsetype()) {
410 switch ($response->getRCardinality()) {
414 }
415 // no break
418 switch ($response->getRCardinality()) {
421 }
422 // no break
424
425 default: return null;
426 }
427 }
428}
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
array $unit_categories
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
addUnitCategory(string $label, array $unit_category)
array $resprocessing
getMetadataEntry(string $a_label)
setXmllang(string $a_xmllang)
addUnit(string $label, array $unit)
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)