ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.assFlashQuestionGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once './Modules/TestQuestionPool/classes/class.assQuestionGUI.php';
5 require_once './Modules/TestQuestionPool/interfaces/interface.ilGuiQuestionScoringAdjustable.php';
6 include_once './Modules/Test/classes/inc.AssessmentConstants.php';
7 
23 {
24  private $newUnitId;
25 
34  function __construct($id = -1)
35  {
37  include_once "./Modules/TestQuestionPool/classes/class.assFlashQuestion.php";
38  $this->object = new assFlashQuestion();
39  $this->newUnitId = null;
40  if ($id >= 0)
41  {
42  $this->object->loadFromDb($id);
43  }
44  }
45 
46  function getCommand($cmd)
47  {
48  if (preg_match("/suggestrange_(.*?)/", $cmd, $matches))
49  {
50  $cmd = "suggestRange";
51  }
52  return $cmd;
53  }
54 
60  function suggestRange()
61  {
62  if ($this->writePostData())
63  {
65  }
66  $this->editQuestion();
67  }
68 
76  public function writePostData($always = false)
77  {
78  $hasErrors = (!$always) ? $this->editQuestion(true) : false;
79  if (!$hasErrors)
80  {
81  require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
84 
85  $this->saveTaxonomyAssignments();
86  return 0;
87  }
88  return 1;
89  }
90 
92  {
93  $this->setErrorMessage( "" );
94  if ($_POST['flash']['delete'] == 1)
95  {
96  $this->object->deleteApplet();
97  }
98  else
99  {
100  $this->object->setApplet( $_POST['flash']['filename'] );
101  }
102  if ($_FILES["flash"]["tmp_name"])
103  {
104  $this->object->deleteApplet();
105  $filename = $this->object->moveUploadedFile( $_FILES["flash"]["tmp_name"], $_FILES["flash"]["name"] );
106  $this->object->setApplet( $filename );
107  }
108  $this->object->clearParameters();
109  if (is_array( $_POST["flash"]["flash_param_name"] ))
110  {
111  foreach ($_POST['flash']['flash_param_name'] as $idx => $val)
112  {
113  $this->object->addParameter( $val, $_POST['flash']['flash_param_value'][$idx] );
114  }
115  }
116  if (is_array( $_POST['flash']['flash_param_delete'] ))
117  {
118  foreach ($_POST['flash']['flash_param_delete'] as $key => $value)
119  {
120  $this->object->removeParameter( $_POST['flash']['flash_param_name'][$key] );
121  }
122  }
123 
124  $this->object->setWidth( $_POST["flash"]["width"] );
125  $this->object->setHeight( $_POST["flash"]["height"] );
126  $this->object->setPoints( $_POST["points"] );
127  }
128 
134  public function editQuestion($checkonly = FALSE)
135  {
136  //$save = ((strcmp($this->ctrl->getCmd(), "save") == 0) || (strcmp($this->ctrl->getCmd(), "saveEdit") == 0)) ? TRUE : FALSE;
137  $save = $this->isSaveCommand();
138  $this->getQuestionTemplate();
139 
140  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
141  $form = new ilPropertyFormGUI();
142  $form->setFormAction($this->ctrl->getFormAction($this));
143  $form->setTitle($this->outQuestionType());
144  $form->setMultipart(TRUE);
145  $form->setTableWidth("100%");
146  $form->setId("flash");
147 
148  $this->addBasicQuestionFormProperties($form);
149  $this->populateQuestionSpecificFormPart( $form );
150 
151  $this->populateTaxonomyFormSection($form);
152 
153  $this->addQuestionFormCommandButtons($form);
154 
155  $errors = false;
156 
157  if ($save)
158  {
159  $form->setValuesByPost();
160  $errors = !$form->checkInput();
161  $form->setValuesByPost(); // again, because checkInput now performs the whole stripSlashes handling and we need this if we don't want to have duplication of backslashes
162  if ($errors) $checkonly = false;
163  }
164 
165  if (!$checkonly) $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
166  return $errors;
167  }
168 
170  {
171  // flash file
172  $flash = new ilFlashFileInputGUI($this->lng->txt( "flashfile" ), "flash");
173  $flash->setRequired( TRUE );
174  if (strlen( $this->object->getApplet() ))
175  {
176  $flash->setApplet( $this->object->getApplet() );
177  $flash->setAppletPathWeb( $this->object->getFlashPathWeb() );
178  }
179  $flash->setWidth( $this->object->getWidth() );
180  $flash->setHeight( $this->object->getHeight() );
181  $flash->setParameters( $this->object->getParameters() );
182  $form->addItem( $flash );
183  if ($this->object->getId())
184  {
185  $hidden = new ilHiddenInputGUI("", "ID");
186  $hidden->setValue( $this->object->getId() );
187  $form->addItem( $hidden );
188  }
189  // points
190  $points = new ilNumberInputGUI($this->lng->txt( "points" ), "points");
191  $points->setValue( $this->object->getPoints() );
192  $points->setRequired( TRUE );
193  $points->setSize( 3 );
194  $points->setMinValue( 0.0 );
195  $form->addItem( $points );
196 
197  return $form;
198  }
199 
200  function flashAddParam()
201  {
202  $this->writePostData();
203  $this->object->addParameter("", "");
204  $this->editQuestion();
205  }
206 
221  $active_id,
222  $pass = NULL,
223  $graphicalOutput = FALSE,
224  $result_output = FALSE,
225  $show_question_only = TRUE,
226  $show_feedback = FALSE,
227  $show_correct_solution = FALSE,
228  $show_manual_scoring = FALSE,
229  $show_question_text = TRUE
230  )
231  {
232  // get the solution of the user for the active pass or from the last pass if allowed
233  $template = new ilTemplate("tpl.il_as_qpl_flash_question_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
234 
235  $params = array();
236  if (is_array($this->object->getParameters()))
237  {
238  foreach ($this->object->getParameters() as $name => $value)
239  {
240  array_push($params, urlencode($name) . "=" . urlencode($value));
241  }
242  }
243 
244  array_push($params, "session_id=" . urlencode($_COOKIE["PHPSESSID"]));
245  array_push($params, "client=" . urlencode(CLIENT_ID));
246  array_push($params, "points_max=" . urlencode($this->object->getPoints()));
247  array_push($params, "server=" . urlencode(ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . "/webservice/soap/server.php?wsdl"));
248  if (!is_null($pass))
249  {
250  array_push($params, "pass=" . $pass);
251  }
252  else
253  {
254  include_once "./Modules/Test/classes/class.ilObjTest.php";
255  array_push($params, "pass=" . ilObjTest::_getPass($active_id));
256  }
257  if ($active_id)
258  {
259  array_push($params, "active_id=" . $active_id);
260  }
261  array_push($params, "question_id=" . $this->object->getId());
262 
263  if ($show_correct_solution)
264  {
265  array_push($params, "solution=correct");
266  }
267  else
268  {
269  array_push($params, "solution=user");
270  }
271 
272  if (($active_id > 0) && (!$show_correct_solution))
273  {
274  if ($graphicalOutput)
275  {
276  // output of ok/not ok icons for user entered solutions
277  $reached_points = $this->object->getReachedPoints($active_id, $pass);
278  if ($reached_points == $this->object->getMaximumPoints())
279  {
280  $template->setCurrentBlock("icon_ok");
281  $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.svg"));
282  $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
283  $template->parseCurrentBlock();
284  }
285  else
286  {
287  $template->setCurrentBlock("icon_ok");
288  if ($reached_points > 0)
289  {
290  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_mostly_ok.svg"));
291  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_not_correct_but_positive"));
292  }
293  else
294  {
295  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.svg"));
296  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
297  }
298  $template->parseCurrentBlock();
299  }
300  }
301  }
302 
303  if (count($params))
304  {
305  $template->setCurrentBlock("flash_vars");
306  $template->setVariable("FLASH_VARS", join($params, "&"));
307  $template->parseCurrentBlock();
308  $template->setCurrentBlock("applet_parameters");
309  $template->setVariable("PARAM_VALUE", join($params, "&"));
310  $template->parseCurrentBlock();
311  }
312  if ($show_question_text==true)
313  {
314  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), TRUE));
315  }
316  $template->setVariable("APPLET_WIDTH", $this->object->getWidth());
317  $template->setVariable("APPLET_HEIGHT", $this->object->getHeight());
318  $template->setVariable("ID", $this->object->getId());
319  $template->setVariable("APPLET_PATH", $this->object->getFlashPathWeb() . $this->object->getApplet());
320  $template->setVariable("APPLET_FILE", $this->object->getApplet());
321 
322  $questionoutput = $template->get();
323  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
324  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
325  $solutionoutput = $solutiontemplate->get();
326  if (!$show_question_only)
327  {
328  // get page object output
329  $solutionoutput = $this->getILIASPage($solutionoutput);
330  }
331  return $solutionoutput;
332  }
333 
334  function getPreview($show_question_only = FALSE, $showInlineFeedback = false)
335  {
336  $template = new ilTemplate("tpl.il_as_qpl_flash_question_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
337  $params = array();
338  if (is_array($this->object->getParameters()))
339  {
340  foreach ($this->object->getParameters() as $name => $value)
341  {
342  array_push($params, urlencode($name) . "=" . urlencode($value));
343  }
344  }
345  if (count($params))
346  {
347  $template->setCurrentBlock("flash_vars");
348  $template->setVariable("FLASH_VARS", join($params, "&"));
349  $template->parseCurrentBlock();
350  $template->setCurrentBlock("applet_parameters");
351  $template->setVariable("PARAM_VALUE", join($params, "&"));
352  $template->parseCurrentBlock();
353  }
354  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), TRUE));
355  $template->setVariable("APPLET_WIDTH", $this->object->getWidth());
356  $template->setVariable("APPLET_HEIGHT", $this->object->getHeight());
357  $template->setVariable("ID", $this->object->getId());
358  $template->setVariable("APPLET_PATH", $this->object->getFlashPathWeb() . $this->object->getApplet());
359  $template->setVariable("APPLET_FILE", $this->object->getApplet());
360  $questionoutput = $template->get();
361  if (!$show_question_only)
362  {
363  // get page object output
364  $questionoutput = $this->getILIASPage($questionoutput);
365  }
366  return $questionoutput;
367  }
368 
369  function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
370  {
371  // generate the question output
372  $template = new ilTemplate("tpl.il_as_qpl_flash_question_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
373  $params = array();
374  if (is_array($this->object->getParameters()))
375  {
376  foreach ($this->object->getParameters() as $name => $value)
377  {
378  array_push($params, urlencode($name) . "=" . urlencode($value));
379  }
380  }
381 
382  array_push($params, "session_id=" . urlencode($_COOKIE["PHPSESSID"]));
383  array_push($params, "client=" . urlencode(CLIENT_ID));
384  array_push($params, "points_max=" . urlencode($this->object->getPoints()));
385  array_push($params, "server=" . urlencode(ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . "/webservice/soap/server.php?wsdl"));
386  if (strlen($pass))
387  {
388  array_push($params, "pass=" . $pass);
389  }
390  else
391  {
392  include_once "./Modules/Test/classes/class.ilObjTest.php";
393  array_push($params, "pass=" . ilObjTest::_getPass($active_id));
394  }
395  if ($active_id)
396  {
397  array_push($params, "active_id=" . $active_id);
398  }
399  array_push($params, "question_id=" . $this->object->getId());
400 
401  if (count($params))
402  {
403  $template->setCurrentBlock("flash_vars");
404  $template->setVariable("FLASH_VARS", join($params, "&"));
405  $template->parseCurrentBlock();
406  $template->setCurrentBlock("applet_parameters");
407  $template->setVariable("PARAM_VALUE", join($params, "&"));
408  $template->parseCurrentBlock();
409  }
410  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), TRUE));
411  $template->setVariable("APPLET_WIDTH", $this->object->getWidth());
412  $template->setVariable("APPLET_HEIGHT", $this->object->getHeight());
413  $template->setVariable("ID", $this->object->getId());
414  $template->setVariable("APPLET_PATH", $this->object->getFlashPathWeb() . $this->object->getApplet());
415  $template->setVariable("APPLET_FILE", $this->object->getFlashPathWeb() . $this->object->getApplet());
416  $questionoutput = $template->get();
417 
418  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
419  return $pageoutput;
420  }
421 
429  function setQuestionTabs()
430  {
431  global $rbacsystem, $ilTabs;
432 
433  $ilTabs->clearTargets();
434 
435  $this->ctrl->setParameterByClass("ilAssQuestionPageGUI", "q_id", $_GET["q_id"]);
436  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
437  $q_type = $this->object->getQuestionType();
438 
439  if (strlen($q_type))
440  {
441  $classname = $q_type . "GUI";
442  $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
443  $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
444  }
445 
446  if ($_GET["q_id"])
447  {
448  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
449  {
450  // edit page
451  $ilTabs->addTarget("edit_page",
452  $this->ctrl->getLinkTargetByClass("ilAssQuestionPageGUI", "edit"),
453  array("edit", "insert", "exec_pg"),
454  "", "", $force_active);
455  }
456 
457  $this->addTab_QuestionPreview($ilTabs);
458  }
459 
460  $force_active = false;
461  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
462  {
463  $url = "";
464  if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
465  $commands = $_POST["cmd"];
466  if (is_array($commands))
467  {
468  foreach ($commands as $key => $value)
469  {
470  if (preg_match("/^suggestrange_.*/", $key, $matches))
471  {
472  $force_active = true;
473  }
474  }
475  }
476  // edit question properties
477  $ilTabs->addTarget("edit_question",
478  $url,
479  array("editQuestion", "save", "flashAddParam", "saveEdit", "originalSyncForm"),
480  $classname, "", $force_active);
481  }
482 
483  // add tab for question feedback within common class assQuestionGUI
484  $this->addTab_QuestionFeedback($ilTabs);
485 
486  // add tab for question hint within common class assQuestionGUI
487  $this->addTab_QuestionHints($ilTabs);
488 
489  // add tab for question's suggested solution within common class assQuestionGUI
490  $this->addTab_SuggestedSolution($ilTabs, $classname);
491 
492  // Assessment of questions sub menu entry
493  if ($_GET["q_id"])
494  {
495  $ilTabs->addTarget("statistics",
496  $this->ctrl->getLinkTargetByClass($classname, "assessment"),
497  array("assessment"),
498  $classname, "");
499  }
500 
501  $this->addBackTab($ilTabs);
502  }
503 
504  function getSpecificFeedbackOutput($active_id, $pass)
505  {
506  $output = "";
507  return $this->object->prepareTextareaOutput($output, TRUE);
508  }
509 
520  {
521  return array();
522  }
523 
532  public function getAggregatedAnswersView($relevant_answers)
533  {
534  // Empty implementation here since a feasible way to aggregate answer is not known.
535  return ''; //print_r($relevant_answers,true);
536  }
537 }