ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilQTIItem.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
30 class ilQTIItem
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;
60  public ?ilQTIMaterial $questiontext = 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 
198  public function getPresentation(): ?ilQTIPresentation
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":
227  return self::QT_KPRIM_CHOICE;
228  case "LONG MENU QUESTION":
229  return self::QT_LONG_MENU;
230  case "SINGLE CHOICE QUESTION":
231  return self::QT_MULTIPLE_CHOICE_SR;
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  {
287  return $this->iliasSourceNic;
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()) {
328  case ilQTIResponse::R_CARDINALITY_ORDERED: return self::QT_ORDERING;
329  case ilQTIResponse::R_CARDINALITY_SINGLE: return self::QT_MULTIPLE_CHOICE_SR;
330  case ilQTIResponse::R_CARDINALITY_MULTIPLE: return self::QT_MULTIPLE_CHOICE_MR;
331  }
332  // no break
333  case ilQTIResponse::RT_RESPONSE_XY: return self::QT_IMAGEMAP;
335  switch ($response->getRCardinality()) {
336  case ilQTIResponse::R_CARDINALITY_ORDERED: return self::QT_TEXT;
337  case ilQTIResponse::R_CARDINALITY_SINGLE: return self::QT_CLOZE;
338  }
339  // no break
340  case ilQTIResponse::RT_RESPONSE_GRP: return self::QT_MATCHING;
341 
342  default: return null;
343  }
344  }
345 }
string $xmllang
const QT_NUMERIC
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)
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
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