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