ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilQTIItem.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 define ("QT_UNKNOWN", "unknown");
25 define ("QT_MULTIPLE_CHOICE_SR", "assSingleChoice");
26 define ("QT_MULTIPLE_CHOICE_MR", "assMultipleChoice");
27 define ("QT_CLOZE", "assClozeTest");
28 define ("QT_MATCHING", "assMatchingQuestion");
29 define ("QT_ORDERING", "assOrderingQuestion");
30 define ("QT_IMAGEMAP", "assImagemapQuestion");
31 define ("QT_JAVAAPPLET", "assJavaApplet");
32 define ("QT_TEXT", "assTextQuestion");
33 define ("QT_NUMERIC", "assNumeric");
34 define ("QT_TEXTSUBSET", "assTextSubset");
35 
44 class ilQTIItem
45 {
46  var $ident;
47  var $title;
49  var $label;
50  var $xmllang;
51 
52  var $comment;
54  var $author;
56  var $duration;
64 
65  function ilQTIItem()
66  {
67  $this->response = array();
68  $this->resprocessing = array();
69  $this->itemfeedback = array();
70  $this->presentation = NULL;
71  $this->presentationitem = array();
72  $this->suggested_solutions = array();
73  $this->itemmetadata = array();
74  }
75 
76  function setIdent($a_ident)
77  {
78  $this->ident = $a_ident;
79  }
80 
81  function getIdent()
82  {
83  return $this->ident;
84  }
85 
86  function setTitle($a_title)
87  {
88  $this->title = $a_title;
89  }
90 
91  function getTitle()
92  {
93  return $this->title;
94  }
95 
96  function setComment($a_comment)
97  {
98  if (preg_match("/(.*?)\=(.*)/", $a_comment, $matches))
99  {
100  // special comments written by ILIAS
101  switch ($matches[1])
102  {
103  case "ILIAS Version":
104  $this->ilias_version = $matches[2];
105  return;
106  break;
107  case "Questiontype":
108  $this->questiontype = $matches[2];
109  return;
110  break;
111  case "Author":
112  $this->author = $matches[2];
113  return;
114  break;
115  }
116  }
117  $this->comment = $a_comment;
118  }
119 
120  function getComment()
121  {
122  return $this->comment;
123  }
124 
125  function setDuration($a_duration)
126  {
127  if (preg_match("/P(\d+)Y(\d+)M(\d+)DT(\d+)H(\d+)M(\d+)S/", $a_duration, $matches))
128  {
129  $this->duration = array(
130  "h" => $matches[4],
131  "m" => $matches[5],
132  "s" => $matches[6]
133  );
134  }
135  }
136 
137  function getDuration()
138  {
139  return $this->duration;
140  }
141 
142  function setQuestiontext($a_questiontext)
143  {
144  $this->questiontext = $a_questiontext;
145  }
146 
147  function getQuestiontext()
148  {
149  return $this->questiontext;
150  }
151 
152  function addResprocessing($a_resprocessing)
153  {
154  array_push($this->resprocessing, $a_resprocessing);
155  }
156 
157  function addItemfeedback($a_itemfeedback)
158  {
159  array_push($this->itemfeedback, $a_itemfeedback);
160  }
161 
162  function setMaxattempts($a_maxattempts)
163  {
164  $this->maxattempts = $a_maxattempts;
165  }
166 
167  function getMaxattempts()
168  {
169  return $this->maxattempts;
170  }
171 
172  function setLabel($a_label)
173  {
174  $this->label = $a_label;
175  }
176 
177  function getLabel()
178  {
179  return $this->label;
180  }
181 
182  function setXmllang($a_xmllang)
183  {
184  $this->xmllang = $a_xmllang;
185  }
186 
187  function getXmllang()
188  {
189  return $this->xmllang;
190  }
191 
192  function setPresentation($a_presentation)
193  {
194  $this->presentation = $a_presentation;
195  }
196 
197  function getPresentation()
198  {
199  return $this->presentation;
200  }
201 
202  function collectResponses()
203  {
204  $result = array();
205  if ($this->presentation != NULL)
206  {
207  }
208  }
209 
210  function setQuestiontype($a_questiontype)
211  {
212  $this->questiontype = $a_questiontype;
213  }
214 
215  function getQuestiontype()
216  {
217  return $this->questiontype;
218  }
219 
220  function addPresentationitem($a_presentationitem)
221  {
222  array_push($this->presentationitem, $a_presentationitem);
223  }
224 
226  {
227  switch ($this->questiontype)
228  {
229  case "ORDERING QUESTION":
230  return QT_ORDERING;
231  case "SINGLE CHOICE QUESTION":
232  return QT_MULTIPLE_CHOICE_SR;
233  case "MULTIPLE CHOICE QUESTION":
234  break;
235  case "MATCHING QUESTION":
236  return QT_MATCHING;
237  case "CLOZE QUESTION":
238  return QT_CLOZE;
239  case "IMAGE MAP QUESTION":
240  return QT_IMAGEMAP;
241  case "JAVA APPLET QUESTION":
242  return QT_JAVAAPPLET;
243  case "TEXT QUESTION":
244  return QT_TEXT;
245  case "NUMERIC QUESTION":
246  return QT_NUMERIC;
247  case "TEXTSUBSET QUESTION":
248  return QT_TEXTSUBSET;
249  }
250  if (!$this->presentation) return QT_UNKNOWN;
251  foreach ($this->presentation->order as $entry)
252  {
253  switch ($entry["type"])
254  {
255  case "response":
256  $response = $this->presentation->response[$entry["index"]];
257  switch ($response->getResponsetype())
258  {
259  case RT_RESPONSE_LID:
260  switch ($response->getRCardinality())
261  {
263  return QT_ORDERING;
264  break;
266  return QT_MULTIPLE_CHOICE_SR;
267  break;
269  return QT_MULTIPLE_CHOICE_MR;
270  break;
271  }
272  break;
273  case RT_RESPONSE_XY:
274  return QT_IMAGEMAP;
275  break;
276  case RT_RESPONSE_STR:
277  switch ($response->getRCardinality())
278  {
280  return QT_TEXT;
281  break;
283  return QT_CLOZE;
284  break;
285  }
286  break;
287  case RT_RESPONSE_GRP:
288  return QT_MATCHING;
289  break;
290  default:
291  break;
292  }
293  break;
294  case "material":
295  $material = $this->presentation->material[$entry["index"]];
296  if (count($material->matapplet) > 0) return QT_JAVAAPPLET;
297  break;
298  }
299  }
300  if (strlen($this->questiontype) == 0)
301  {
302  return QT_UNKNOWN;
303  }
304  else
305  {
306  return $this->questiontype;
307  }
308  }
309 
310  function setAuthor($a_author)
311  {
312  $this->author = $a_author;
313  }
314 
315  function getAuthor()
316  {
317  return $this->author;
318  }
319 
320  function addSuggestedSolution($a_solution, $a_gap_index)
321  {
322  array_push($this->suggested_solutions, array("solution" => $a_solution, "gap_index" => $a_gap_index));
323  }
324 
325  function addMetadata($a_metadata)
326  {
327  array_push($this->itemmetadata, $a_metadata);
328  }
329 
330  function getMetadata()
331  {
332  return $this->itemmetadata;
333  }
334 
335  function getMetadataEntry($a_label)
336  {
337  foreach ($this->itemmetadata as $metadata)
338  {
339  if (strcmp($metadata["label"], $a_label) == 0)
340  {
341  return $metadata["entry"];
342  }
343  }
344  return null;
345  }
346 }
347 ?>