ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilQuestionExporter.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 
5 require_once("./Modules/TestQuestionPool/classes/class.assQuestionGUI.php");
6 
17 {
18  static $exported = array(); //json data for all exported questions (class variable)
19  static $mobs = array(); //json data for all mobs (class variable)
20  static $media_files = array(); //json data for all files (class variable)
21 
22  var $db; // database object
23  var $ilias; // ilias object
24  var $ref_id; // reference ID
25  var $inst_id; // installation id
26  var $q_gui; // Question GUI object
27  var $tpl; //question template
28  var $json; //json object for current question
29  var $json_decoded; //json object (decoded) for current question
30  var $preview_mode; //preview mode activated yes/no
35  public function ilQuestionExporter($a_preview_mode = false)
36  {
37  global $ilDB, $ilias, $lng;
38 
39  $this->ref_id =& $a_ref_id;
40 
41  $this->db =& $ilDB;
42  $this->lng = $lng;
43 
44  $this->inst_id = IL_INST_ID;
45 
46  $this->preview_mode = $a_preview_mode;
47 
48  $this->tpl = new ilTemplate("tpl.question_export.html", true, true, "Modules/Scorm2004");
49 
50  // fix for bug 5386, alex 29.10.2009
51  if (!$a_preview_mode)
52  {
53  $this->tpl->setVariable("FORM_BEGIN", "<form onsubmit='return false;'>");
54  $this->tpl->setVariable("FORM_END", "</form>");
55  }
56 
57  }
58 
59 
60  public function exportQuestion($a_ref_id) {
61 
62  if ($a_ref_id != "")
63  {
65  if (!($inst_id > 0))
66  {
67  $q_id = ilInternalLink::_extractObjIdOfTarget($a_ref_id);
68  }
69  }
70 
71  $this->q_gui =& assQuestionGUI::_getQuestionGUI("", $q_id);
72 
73  $type = $this->q_gui->object->getQuestionType();
74  if (method_exists($this,$type))
75  {
76  $this->json = $this->q_gui->object->toJSON();
77  $this->json_decoded = json_decode($this->json);
78  self::$exported[$this->json_decoded->id] = $this->json;
79  self::$mobs[$this->json_decoded->id] = $this->json_decoded->mobs;
80  return $this->$type();
81  } else {
82  return "Error: Question Type not implemented/Question editing not finished";
83  }
84  }
85 
86  static public function indicateNewSco() {
87  self::$exported = array();
88  self::$mobs = array();
89  self::$media_files = array();
90  }
91 
92  static public function getMobs() {
93  $allmobs = array();
94  foreach (self::$mobs as $key => $value) {
95  for ($i=0;$i<count($mobs[$key]);$i++) {
96  array_push($allmobs,$mobs[$key][$i]);
97  }
98  }
99  return $allmobs;
100  }
101 
102  static public function getFiles() {
103  return self::$media_files;
104  }
105 
106  static public function questionsJS() {
107  $exportstring ='var questions = new Array();';
108  foreach (self::$exported as $key => $value) {
109  $exportstring .= "questions[$key]= $value;";
110  }
111  return $exportstring;
112  }
113 
114  private function setHeaderFooter()
115  {
116  $this->tpl->setCurrentBlock("common");
117  $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
118  $this->tpl->setVariable("VAL_TYPE", $this->json_decoded->type);
119  $this->tpl->parseCurrentBlock();
120  }
121 
122  private function assSingleChoice()
123  {
124  $this->tpl->setCurrentBlock("singlechoice");
125  $this->tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("cont_submit_answers"));
126  $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
127  if ($this->preview_mode) {
128  $this->tpl->setVariable("VAL_NO_DISPLAY", "style=\"display:none\"");
129  }
130  $this->tpl->parseCurrentBlock();
131  foreach ($this->json_decoded->answers as $answer) {
132  if ($answer->image!="") {
133  array_push(self::$media_files,$this->q_gui->object->getImagePath().$answer->image);
134  }
135  }
136 // $this->setHeaderFooter();
137  return $this->tpl->get();
138  }
139 
140  private function assMultipleChoice() {
141  $this->tpl->setCurrentBlock("multiplechoice");
142  $this->tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("cont_submit_answers"));
143  $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
144  if ($this->preview_mode) {
145  $this->tpl->setVariable("VAL_NO_DISPLAY", "style=\"display:none\"");
146  }
147  $this->tpl->parseCurrentBlock();
148  foreach ($this->json_decoded->answers as $answer) {
149  if ($answer->image!="") {
150  array_push(self::$media_files,$this->q_gui->object->getImagePath().$answer->image);
151  }
152  }
153 // $this->setHeaderFooter();
154  return $this->tpl->get();
155  }
156 
157 
158  private function assTextQuestion() {
159  $maxlength = $this->json_decoded->maxlength == 0 ? 4096 : $this->json_decoded->maxlength;
160  $this->tpl->setCurrentBlock("textquestion");
161  $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
162  $this->tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("cont_submit_answers"));
163  $this->tpl->setVariable("VAL_MAXLENGTH", $maxlength);
164  if ($this->preview_mode) {
165  $this->tpl->setVariable("VAL_NO_DISPLAY", "style=\"display:none\"");
166  }
167  $this->tpl->parseCurrentBlock();
168 // $this->setHeaderFooter();
169  return $this->tpl->get();
170  }
171 
172  private function assClozeTest() {
173  $this->tpl->setCurrentBlock("clozequestion");
174  $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
175  $this->tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("cont_submit_answers"));
176  if ($this->preview_mode) {
177  $this->tpl->setVariable("VAL_NO_DISPLAY", "style=\"display:none\"");
178  }
179  $this->tpl->parseCurrentBlock();
180 // $this->setHeaderFooter();
181  return $this->tpl->get();
182  }
183 
184  private function assOrderingQuestion() {
185  $this->tpl->setCurrentBlock("orderingquestion");
186  $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
187  $this->tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("cont_submit_answers"));
188  if ($this->preview_mode) {
189  $this->tpl->setVariable("VAL_NO_DISPLAY", "style=\"display:none\"");
190  }
191  $this->tpl->parseCurrentBlock();
192 // $this->setHeaderFooter();
193  return $this->tpl->get();
194  }
195 
196  private function assMatchingQuestion() {
197  $this->tpl->setCurrentBlock("matchingquestion");
198  $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
199  $this->tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("cont_submit_answers"));
200  if ($this->preview_mode) {
201  $this->tpl->setVariable("VAL_NO_DISPLAY", "style=\"display:none\"");
202  }
203  $this->tpl->parseCurrentBlock();
204 // $this->setHeaderFooter();
205  return $this->tpl->get();
206  }
207 
208  private function assImagemapQuestion() {
209  $this->tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("cont_submit_answers"));
210  array_push(self::$media_files,$this->q_gui->object->getImagePath().$this->q_gui->object->getImageFilename());
211  $this->tpl->setCurrentBlock("mapareas");
212  $areas = $this->json_decoded->answers;
213  //set areas in PHP cause of inteference between pure and highlighter
214  foreach ($areas as $area) {
215  $this->tpl->setVariable("VAL_COORDS", $area->coords);
216  $this->tpl->setVariable("VAL_ORDER", $area->order);
217  $this->tpl->setVariable("VAL_AREA", $area->area);
218  $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
219  $this->tpl->parseCurrentBlock();
220  }
221  $this->tpl->setCurrentBlock("imagemapquestion");
222  $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
223  if ($this->preview_mode) {
224  $this->tpl->setVariable("VAL_NO_DISPLAY", "style=\"display:none\"");
225  }
226  $this->tpl->parseCurrentBlock();
227 // $this->setHeaderFooter();
228  return $this->tpl->get();
229  }
230 
231 }
232 
233 ?>