ILIAS  trunk Revision v11.0_alpha-1744-gb0451eebef4
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilQTIItem.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
29 class ilQTIItem
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 = [
49  self::QT_KPRIM_CHOICE,
50  self::QT_LONG_MENU,
51  self::QT_MULTIPLE_CHOICE_SR,
52  self::QT_MULTIPLE_CHOICE_MR,
53  self::QT_CLOZE,
54  self::QT_ERRORTEXT,
55  self::QT_MATCHING,
56  self::QT_ORDERING,
57  self::QT_ORDERING_HORIZONTAL,
58  self::QT_IMAGEMAP,
59  self::QT_TEXT,
60  self::QT_FILEUPLOAD,
61  self::QT_NUMERIC,
62  self::QT_FORMULA,
63  self::QT_TEXTSUBSET
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 
215  public function getPresentation(): ?ilQTIPresentation
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":
248  return self::QT_KPRIM_CHOICE;
249  case "LONG MENU QUESTION":
250  return self::QT_LONG_MENU;
251  case "SINGLE CHOICE QUESTION":
252  return self::QT_MULTIPLE_CHOICE_SR;
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  {
309  return $this->iliasSourceNic;
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()) {
350  case ilQTIResponse::R_CARDINALITY_ORDERED: return self::QT_ORDERING;
351  case ilQTIResponse::R_CARDINALITY_SINGLE: return self::QT_MULTIPLE_CHOICE_SR;
352  case ilQTIResponse::R_CARDINALITY_MULTIPLE: return self::QT_MULTIPLE_CHOICE_MR;
353  }
354  // no break
355  case ilQTIResponse::RT_RESPONSE_XY: return self::QT_IMAGEMAP;
357  switch ($response->getRCardinality()) {
358  case ilQTIResponse::R_CARDINALITY_ORDERED: return self::QT_TEXT;
359  case ilQTIResponse::R_CARDINALITY_SINGLE: return self::QT_CLOZE;
360  }
361  // no break
362  case ilQTIResponse::RT_RESPONSE_GRP: return self::QT_MATCHING;
363 
364  default: return null;
365  }
366  }
367 }
string $xmllang
const QT_NUMERIC
const VALID_QUESTION_TYPES
setIdent(string $a_ident)
setIliasSourceNic(?string $iliasSourceNic)
const QT_UNKNOWN
getMetadataEntry(string $a_label)
const QT_ORDERING
array $presentationitem
string $questiontype
typeFromResponse(ilQTIResponse $response)
string $iliasSourceVersion
ilQTIMaterial $questiontext
setMaxattempts(string $a_maxattempts)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
string $ilias_version
const QT_FILEUPLOAD
const QT_KPRIM_CHOICE
setIliasSourceVersion(?string $iliasSourceVersion)
setPresentation(ilQTIPresentation $a_presentation)
array $suggested_solutions
ilQTIPresentation $presentation
const QT_FORMULA
setXmllang(string $a_xmllang)
array $itemmetadata
const QT_MULTIPLE_CHOICE_SR
const QT_ERRORTEXT
string $iliasSourceNic
setQuestiontext(ilQTIMaterial $a_questiontext)
setAuthor(string $a_author)
string $comment
const QT_LONG_MENU
setLabel(string $a_label)
setComment(string $a_comment)
const QT_MULTIPLE_CHOICE_MR
setDuration(string $a_duration)
const QT_MATCHING
setQuestiontype(string $a_questiontype)
const QT_TEXTSUBSET
array $resprocessing
array $itemfeedback
comment()
description: > Example for rendring a comment glyph.
Definition: comment.php:41
addResprocessing(ilQTIResprocessing $a_resprocessing)
const QT_IMAGEMAP
string $maxattempts
string $author
addItemfeedback(ilQTIItemfeedback $a_itemfeedback)
addMetadata(array $a_metadata)
setTitle(string $a_title)
addSuggestedSolution(ilQTIMattext $a_solution, int $a_gap_index)
addPresentationitem($a_presentationitem)
const QT_ORDERING_HORIZONTAL