ILIAS  Release_4_4_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 
22 class assFlashQuestionGUI extends assQuestionGUI //implements ilGuiQuestionScoringAdjustable
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  {
83 
84  $this->saveTaxonomyAssignments();
85  return 0;
86  }
87  return 1;
88  }
89 
90  public function writeQuestionSpecificPostData($always = true)
91  {
92  $this->setErrorMessage( "" );
93  if ($_POST['flash']['delete'] == 1)
94  {
95  $this->object->deleteApplet();
96  }
97  else
98  {
99  $this->object->setApplet( $_POST['flash']['filename'] );
100  }
101  if ($_FILES["flash"]["tmp_name"])
102  {
103  $this->object->deleteApplet();
104  $filename = $this->object->moveUploadedFile( $_FILES["flash"]["tmp_name"], $_FILES["flash"]["name"] );
105  $this->object->setApplet( $filename );
106  }
107  $this->object->clearParameters();
108  if (is_array( $_POST["flash"]["flash_param_name"] ))
109  {
110  foreach ($_POST['flash']['flash_param_name'] as $idx => $val)
111  {
112  $this->object->addParameter( $val, $_POST['flash']['flash_param_value'][$idx] );
113  }
114  }
115  if (is_array( $_POST['flash']['flash_param_delete'] ))
116  {
117  foreach ($_POST['flash']['flash_param_delete'] as $key => $value)
118  {
119  $this->object->removeParameter( $_POST['flash']['flash_param_name'][$key] );
120  }
121  }
122 
123  $this->object->setWidth( $_POST["flash"]["width"] );
124  $this->object->setHeight( $_POST["flash"]["height"] );
125  $this->object->setPoints( $_POST["points"] );
126  }
127 
133  public function editQuestion($checkonly = FALSE)
134  {
135  //$save = ((strcmp($this->ctrl->getCmd(), "save") == 0) || (strcmp($this->ctrl->getCmd(), "saveEdit") == 0)) ? TRUE : FALSE;
136  $save = $this->isSaveCommand();
137  $this->getQuestionTemplate();
138 
139  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
140  $form = new ilPropertyFormGUI();
141  $form->setFormAction($this->ctrl->getFormAction($this));
142  $form->setTitle($this->outQuestionType());
143  $form->setMultipart(TRUE);
144  $form->setTableWidth("100%");
145  $form->setId("flash");
146 
147  $this->addBasicQuestionFormProperties($form);
148  $this->populateQuestionSpecificFormPart( $form );
149 
150  $this->populateTaxonomyFormSection($form);
151 
152  $this->addQuestionFormCommandButtons($form);
153 
154  $errors = false;
155 
156  if ($save)
157  {
158  $form->setValuesByPost();
159  $errors = !$form->checkInput();
160  $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
161  if ($errors) $checkonly = false;
162  }
163 
164  if (!$checkonly) $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
165  return $errors;
166  }
167 
169  {
170  // flash file
171  $flash = new ilFlashFileInputGUI($this->lng->txt( "flashfile" ), "flash");
172  $flash->setRequired( TRUE );
173  if (strlen( $this->object->getApplet() ))
174  {
175  $flash->setApplet( $this->object->getApplet() );
176  $flash->setAppletPathWeb( $this->object->getFlashPathWeb() );
177  }
178  $flash->setWidth( $this->object->getWidth() );
179  $flash->setHeight( $this->object->getHeight() );
180  $flash->setParameters( $this->object->getParameters() );
181  $form->addItem( $flash );
182  if ($this->object->getId())
183  {
184  $hidden = new ilHiddenInputGUI("", "ID");
185  $hidden->setValue( $this->object->getId() );
186  $form->addItem( $hidden );
187  }
188  // points
189  $points = new ilNumberInputGUI($this->lng->txt( "points" ), "points");
190  $points->setValue( $this->object->getPoints() );
191  $points->setRequired( TRUE );
192  $points->setSize( 3 );
193  $points->setMinValue( 0.0 );
194  $form->addItem( $points );
195 
196  return $form;
197  }
198 
199  function flashAddParam()
200  {
201  $this->writePostData();
202  $this->object->addParameter("", "");
203  $this->editQuestion();
204  }
205 
206  function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
207  {
208  $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $use_post_solutions, $show_feedback);
209  $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
210  $this->tpl->setVariable("FORMACTION", $formaction);
211  }
212 
227  $active_id,
228  $pass = NULL,
229  $graphicalOutput = FALSE,
230  $result_output = FALSE,
231  $show_question_only = TRUE,
232  $show_feedback = FALSE,
233  $show_correct_solution = FALSE,
234  $show_manual_scoring = FALSE,
235  $show_question_text = TRUE
236  )
237  {
238  // get the solution of the user for the active pass or from the last pass if allowed
239  $template = new ilTemplate("tpl.il_as_qpl_flash_question_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
240 
241  $params = array();
242  if (is_array($this->object->getParameters()))
243  {
244  foreach ($this->object->getParameters() as $name => $value)
245  {
246  array_push($params, urlencode($name) . "=" . urlencode($value));
247  }
248  }
249 
250  array_push($params, "session_id=" . urlencode($_COOKIE["PHPSESSID"]));
251  array_push($params, "client=" . urlencode(CLIENT_ID));
252  array_push($params, "points_max=" . urlencode($this->object->getPoints()));
253  array_push($params, "server=" . urlencode(ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . "/webservice/soap/server.php?wsdl"));
254  if (!is_null($pass))
255  {
256  array_push($params, "pass=" . $pass);
257  }
258  else
259  {
260  include_once "./Modules/Test/classes/class.ilObjTest.php";
261  array_push($params, "pass=" . ilObjTest::_getPass($active_id));
262  }
263  if ($active_id)
264  {
265  array_push($params, "active_id=" . $active_id);
266  }
267  array_push($params, "question_id=" . $this->object->getId());
268 
269  if ($show_correct_solution)
270  {
271  array_push($params, "solution=correct");
272  }
273  else
274  {
275  array_push($params, "solution=user");
276  }
277 
278  if (($active_id > 0) && (!$show_correct_solution))
279  {
280  if ($graphicalOutput)
281  {
282  // output of ok/not ok icons for user entered solutions
283  $reached_points = $this->object->getReachedPoints($active_id, $pass);
284  if ($reached_points == $this->object->getMaximumPoints())
285  {
286  $template->setCurrentBlock("icon_ok");
287  $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.png"));
288  $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
289  $template->parseCurrentBlock();
290  }
291  else
292  {
293  $template->setCurrentBlock("icon_ok");
294  if ($reached_points > 0)
295  {
296  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_mostly_ok.png"));
297  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_not_correct_but_positive"));
298  }
299  else
300  {
301  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.png"));
302  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
303  }
304  $template->parseCurrentBlock();
305  }
306  }
307  }
308 
309  if (count($params))
310  {
311  $template->setCurrentBlock("flash_vars");
312  $template->setVariable("FLASH_VARS", join($params, "&"));
313  $template->parseCurrentBlock();
314  $template->setCurrentBlock("applet_parameters");
315  $template->setVariable("PARAM_VALUE", join($params, "&"));
316  $template->parseCurrentBlock();
317  }
318  if ($show_question_text==true)
319  {
320  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), TRUE));
321  }
322  $template->setVariable("APPLET_WIDTH", $this->object->getWidth());
323  $template->setVariable("APPLET_HEIGHT", $this->object->getHeight());
324  $template->setVariable("ID", $this->object->getId());
325  $template->setVariable("APPLET_PATH", $this->object->getFlashPathWeb() . $this->object->getApplet());
326  $template->setVariable("APPLET_FILE", $this->object->getApplet());
327 
328  $questionoutput = $template->get();
329  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
330  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
331  $solutionoutput = $solutiontemplate->get();
332  if (!$show_question_only)
333  {
334  // get page object output
335  $solutionoutput = '<div class="ilc_question_Standard">'.$solutionoutput."</div>";
336  }
337  return $solutionoutput;
338  }
339 
340  function getPreview($show_question_only = FALSE)
341  {
342  $template = new ilTemplate("tpl.il_as_qpl_flash_question_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
343  $params = array();
344  if (is_array($this->object->getParameters()))
345  {
346  foreach ($this->object->getParameters() as $name => $value)
347  {
348  array_push($params, urlencode($name) . "=" . urlencode($value));
349  }
350  }
351  if (count($params))
352  {
353  $template->setCurrentBlock("flash_vars");
354  $template->setVariable("FLASH_VARS", join($params, "&"));
355  $template->parseCurrentBlock();
356  $template->setCurrentBlock("applet_parameters");
357  $template->setVariable("PARAM_VALUE", join($params, "&"));
358  $template->parseCurrentBlock();
359  }
360  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), TRUE));
361  $template->setVariable("APPLET_WIDTH", $this->object->getWidth());
362  $template->setVariable("APPLET_HEIGHT", $this->object->getHeight());
363  $template->setVariable("ID", $this->object->getId());
364  $template->setVariable("APPLET_PATH", $this->object->getFlashPathWeb() . $this->object->getApplet());
365  $template->setVariable("APPLET_FILE", $this->object->getApplet());
366  $questionoutput = $template->get();
367  if (!$show_question_only)
368  {
369  // get page object output
370  $questionoutput = $this->getILIASPage($questionoutput);
371  }
372  return $questionoutput;
373  }
374 
375  function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
376  {
377  // generate the question output
378  $template = new ilTemplate("tpl.il_as_qpl_flash_question_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
379  $params = array();
380  if (is_array($this->object->getParameters()))
381  {
382  foreach ($this->object->getParameters() as $name => $value)
383  {
384  array_push($params, urlencode($name) . "=" . urlencode($value));
385  }
386  }
387 
388  array_push($params, "session_id=" . urlencode($_COOKIE["PHPSESSID"]));
389  array_push($params, "client=" . urlencode(CLIENT_ID));
390  array_push($params, "points_max=" . urlencode($this->object->getPoints()));
391  array_push($params, "server=" . urlencode(ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . "/webservice/soap/server.php?wsdl"));
392  if (strlen($pass))
393  {
394  array_push($params, "pass=" . $pass);
395  }
396  else
397  {
398  include_once "./Modules/Test/classes/class.ilObjTest.php";
399  array_push($params, "pass=" . ilObjTest::_getPass($active_id));
400  }
401  if ($active_id)
402  {
403  array_push($params, "active_id=" . $active_id);
404  }
405  array_push($params, "question_id=" . $this->object->getId());
406 
407  if (count($params))
408  {
409  $template->setCurrentBlock("flash_vars");
410  $template->setVariable("FLASH_VARS", join($params, "&"));
411  $template->parseCurrentBlock();
412  $template->setCurrentBlock("applet_parameters");
413  $template->setVariable("PARAM_VALUE", join($params, "&"));
414  $template->parseCurrentBlock();
415  }
416  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), TRUE));
417  $template->setVariable("APPLET_WIDTH", $this->object->getWidth());
418  $template->setVariable("APPLET_HEIGHT", $this->object->getHeight());
419  $template->setVariable("ID", $this->object->getId());
420  $template->setVariable("APPLET_PATH", $this->object->getFlashPathWeb() . $this->object->getApplet());
421  $template->setVariable("APPLET_FILE", $this->object->getFlashPathWeb() . $this->object->getApplet());
422  $questionoutput = $template->get();
423 
424  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
425  return $pageoutput;
426  }
427 
435  function setQuestionTabs()
436  {
437  global $rbacsystem, $ilTabs;
438 
439  $this->ctrl->setParameterByClass("ilAssQuestionPageGUI", "q_id", $_GET["q_id"]);
440  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
441  $q_type = $this->object->getQuestionType();
442 
443  if (strlen($q_type))
444  {
445  $classname = $q_type . "GUI";
446  $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
447  $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
448  }
449 
450  if ($_GET["q_id"])
451  {
452  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
453  {
454  // edit page
455  $ilTabs->addTarget("edit_page",
456  $this->ctrl->getLinkTargetByClass("ilAssQuestionPageGUI", "edit"),
457  array("edit", "insert", "exec_pg"),
458  "", "", $force_active);
459  }
460 
461  // edit page
462  $ilTabs->addTarget("preview",
463  $this->ctrl->getLinkTargetByClass("ilAssQuestionPageGUI", "preview"),
464  array("preview"),
465  "ilAssQuestionPageGUI", "", $force_active);
466  }
467 
468  $force_active = false;
469  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
470  {
471  $url = "";
472  if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
473  $commands = $_POST["cmd"];
474  if (is_array($commands))
475  {
476  foreach ($commands as $key => $value)
477  {
478  if (preg_match("/^suggestrange_.*/", $key, $matches))
479  {
480  $force_active = true;
481  }
482  }
483  }
484  // edit question properties
485  $ilTabs->addTarget("edit_question",
486  $url,
487  array("editQuestion", "save", "flashAddParam", "saveEdit", "originalSyncForm"),
488  $classname, "", $force_active);
489  }
490 
491  // add tab for question feedback within common class assQuestionGUI
492  $this->addTab_QuestionFeedback($ilTabs);
493 
494  // add tab for question hint within common class assQuestionGUI
495  $this->addTab_QuestionHints($ilTabs);
496 
497  if ($_GET["q_id"])
498  {
499  $ilTabs->addTarget("solution_hint",
500  $this->ctrl->getLinkTargetByClass($classname, "suggestedsolution"),
501  array("suggestedsolution", "saveSuggestedSolution", "outSolutionExplorer", "cancel",
502  "addSuggestedSolution","cancelExplorer", "linkChilds", "removeSuggestedSolution"
503  ),
504  $classname,
505  ""
506  );
507  }
508 
509  // Assessment of questions sub menu entry
510  if ($_GET["q_id"])
511  {
512  $ilTabs->addTarget("statistics",
513  $this->ctrl->getLinkTargetByClass($classname, "assessment"),
514  array("assessment"),
515  $classname, "");
516  }
517 
518  if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
519  {
520  $ref_id = $_GET["calling_test"];
521  if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
522 
523  global $___test_express_mode;
524 
525  if (!$_GET['test_express_mode'] && !$___test_express_mode) {
526  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
527  }
528  else {
530  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), $link);
531  }
532  }
533  else
534  {
535  $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
536  }
537  }
538 
539  function getSpecificFeedbackOutput($active_id, $pass)
540  {
541  $output = "";
542  return $this->object->prepareTextareaOutput($output, TRUE);
543  }
544 
555  {
556  return array();
557  }
558 
567  public function getAggregatedAnswersView($relevant_answers)
568  {
569  // Empty implementation here since a feasible way to aggregate answer is not known.
570  return ''; //print_r($relevant_answers,true);
571  }
572 }