ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
4require_once './Modules/TestQuestionPool/classes/class.assQuestionGUI.php';
5require_once './Modules/TestQuestionPool/interfaces/interface.ilGuiQuestionScoringAdjustable.php';
6include_once './Modules/Test/classes/inc.AssessmentConstants.php';
7
23{
24 private $newUnitId;
25
34 function __construct($id = -1)
35 {
36 parent::__construct();
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
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 // hey: prevPassSolutions - pass will be always available from now on
370 function getTestOutput($active_id, $pass, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
371 // hey.
372 {
373 // generate the question output
374 $template = new ilTemplate("tpl.il_as_qpl_flash_question_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
375 $params = array();
376 if (is_array($this->object->getParameters()))
377 {
378 foreach ($this->object->getParameters() as $name => $value)
379 {
380 array_push($params, urlencode($name) . "=" . urlencode($value));
381 }
382 }
383
384 array_push($params, "session_id=" . urlencode($_COOKIE["PHPSESSID"]));
385 array_push($params, "client=" . urlencode(CLIENT_ID));
386 array_push($params, "points_max=" . urlencode($this->object->getPoints()));
387 array_push($params, "server=" . urlencode(ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . "/webservice/soap/server.php?wsdl"));
388 if (strlen($pass))
389 {
390 array_push($params, "pass=" . $pass);
391 }
392 else
393 {
394 include_once "./Modules/Test/classes/class.ilObjTest.php";
395 array_push($params, "pass=" . ilObjTest::_getPass($active_id));
396 }
397 if ($active_id)
398 {
399 array_push($params, "active_id=" . $active_id);
400 }
401 array_push($params, "question_id=" . $this->object->getId());
402
403 if (count($params))
404 {
405 $template->setCurrentBlock("flash_vars");
406 $template->setVariable("FLASH_VARS", join($params, "&"));
407 $template->parseCurrentBlock();
408 $template->setCurrentBlock("applet_parameters");
409 $template->setVariable("PARAM_VALUE", join($params, "&"));
410 $template->parseCurrentBlock();
411 }
412 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), TRUE));
413 $template->setVariable("APPLET_WIDTH", $this->object->getWidth());
414 $template->setVariable("APPLET_HEIGHT", $this->object->getHeight());
415 $template->setVariable("ID", $this->object->getId());
416 $template->setVariable("APPLET_PATH", $this->object->getFlashPathWeb() . $this->object->getApplet());
417 $template->setVariable("APPLET_FILE", $this->object->getFlashPathWeb() . $this->object->getApplet());
418 $questionoutput = $template->get();
419
420 $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
421 return $pageoutput;
422 }
423
432 {
433 global $rbacsystem, $ilTabs;
434
435 $ilTabs->clearTargets();
436
437 $this->ctrl->setParameterByClass("ilAssQuestionPageGUI", "q_id", $_GET["q_id"]);
438 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
439 $q_type = $this->object->getQuestionType();
440
441 if (strlen($q_type))
442 {
443 $classname = $q_type . "GUI";
444 $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
445 $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
446 }
447
448 if ($_GET["q_id"])
449 {
450 if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
451 {
452 // edit page
453 $ilTabs->addTarget("edit_page",
454 $this->ctrl->getLinkTargetByClass("ilAssQuestionPageGUI", "edit"),
455 array("edit", "insert", "exec_pg"),
456 "", "", $force_active);
457 }
458
459 $this->addTab_QuestionPreview($ilTabs);
460 }
461
462 $force_active = false;
463 if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
464 {
465 $url = "";
466 if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
467 $commands = $_POST["cmd"];
468 if (is_array($commands))
469 {
470 foreach ($commands as $key => $value)
471 {
472 if (preg_match("/^suggestrange_.*/", $key, $matches))
473 {
474 $force_active = true;
475 }
476 }
477 }
478 // edit question properties
479 $ilTabs->addTarget("edit_question",
480 $url,
481 array("editQuestion", "save", "flashAddParam", "saveEdit", "originalSyncForm"),
482 $classname, "", $force_active);
483 }
484
485 // add tab for question feedback within common class assQuestionGUI
486 $this->addTab_QuestionFeedback($ilTabs);
487
488 // add tab for question hint within common class assQuestionGUI
489 $this->addTab_QuestionHints($ilTabs);
490
491 // add tab for question's suggested solution within common class assQuestionGUI
492 $this->addTab_SuggestedSolution($ilTabs, $classname);
493
494 // Assessment of questions sub menu entry
495 if ($_GET["q_id"])
496 {
497 $ilTabs->addTarget("statistics",
498 $this->ctrl->getLinkTargetByClass($classname, "assessment"),
499 array("assessment"),
500 $classname, "");
501 }
502
503 $this->addBackTab($ilTabs);
504 }
505
506 function getSpecificFeedbackOutput($active_id, $pass)
507 {
508 $output = "";
509 return $this->object->prepareTextareaOutput($output, TRUE);
510 }
511
522 {
523 return array();
524 }
525
534 public function getAggregatedAnswersView($relevant_answers)
535 {
536 // Empty implementation here since a feasible way to aggregate answer is not known.
537 return ''; //print_r($relevant_answers,true);
538 }
539}
$filename
Definition: buildRTE.php:89
$_GET["client_id"]
The assFlashQuestionGUI class encapsulates the GUI representation for flash questions.
setQuestionTabs()
Sets the ILIAS tabs for this question type.
getAfterParticipationSuppressionQuestionPostVars()
Returns a list of postvars which will be suppressed in the form output when used in scoring adjustmen...
getPreview($show_question_only=FALSE, $showInlineFeedback=false)
suggestRange()
Suggest a range for a result.
getSpecificFeedbackOutput($active_id, $pass)
Returns the answer specific feedback for the question.
editQuestion($checkonly=FALSE)
Creates an output of the edit form for the question.
writePostData($always=false)
Evaluates a posted edit form and writes the form data in the question object.
getTestOutput($active_id, $pass, $is_postponed=FALSE, $use_post_solutions=FALSE, $show_feedback=FALSE)
writeQuestionSpecificPostData(ilPropertyFormGUI $form)
Extracts the question specific values from $_POST and applies them to the data object.
getSolutionOutput( $active_id, $pass=NULL, $graphicalOutput=FALSE, $result_output=FALSE, $show_question_only=TRUE, $show_feedback=FALSE, $show_correct_solution=FALSE, $show_manual_scoring=FALSE, $show_question_text=TRUE)
Get the question solution output.
populateQuestionSpecificFormPart(ilPropertyFormGUI $form)
Adds the question specific forms parts to a question property form gui.
getAggregatedAnswersView($relevant_answers)
Returns an html string containing a question specific representation of the answers so far given in t...
__construct($id=-1)
assFlashQuestionGUI constructor
Class for Flash based questions.
Basic GUI class for assessment questions.
populateTaxonomyFormSection(ilPropertyFormGUI $form)
setErrorMessage($errormessage)
addTab_QuestionHints(ilTabsGUI $tabs)
adds the hints tab to ilTabsGUI
addQuestionFormCommandButtons($form)
Add the command buttons of a question properties form.
getILIASPage($html="")
Returns the ILIAS Page around a question.
getQuestionTemplate()
get question template
writePostData()
Evaluates a posted edit form and writes the form data in the question object.
addTab_SuggestedSolution(ilTabsGUI $tabs, $classname)
outQuestionPage($a_temp_var, $a_postponed=false, $active_id="", $html="")
output question page
addBackTab(ilTabsGUI $ilTabs)
addTab_QuestionFeedback(ilTabsGUI $tabs)
adds the feedback tab to ilTabsGUI
addBasicQuestionFormProperties($form)
Add basic question form properties: assessment: title, author, description, question,...
addTab_QuestionPreview(ilTabsGUI $tabsGUI)
This class represents an image file property in a property form.
This class represents a hidden form property in a property form.
This class represents a number property in a property form.
_getPass($active_id)
Retrieves the actual pass of a given user for a given test.
This class represents a property form user interface.
addItem($a_item)
Add Item (Property, SectionHeader).
special template class to simplify handling of ITX/PEAR
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static removeTrailingPathSeparators($path)
$_POST['username']
Definition: cron.php:12
$_COOKIE["ilClientId"]
Definition: cron.php:11
$params
Definition: example_049.php:96
Interface ilGuiQuestionScoringAdjustable.
$cmd
Definition: sahs_server.php:35
$url
Definition: shib_logout.php:72
$errors