ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
24{
25 private $newUnitId;
26
35 public function __construct($id = -1)
36 {
37 parent::__construct();
38 include_once "./Modules/TestQuestionPool/classes/class.assFlashQuestion.php";
39 $this->object = new assFlashQuestion();
40 $this->newUnitId = null;
41 if ($id >= 0) {
42 $this->object->loadFromDb($id);
43 }
44 }
45
46 public function getCommand($cmd)
47 {
48 if (preg_match("/suggestrange_(.*?)/", $cmd, $matches)) {
49 $cmd = "suggestRange";
50 }
51 return $cmd;
52 }
53
59 public function suggestRange()
60 {
61 if ($this->writePostData()) {
63 }
64 $this->editQuestion();
65 }
66
70 protected function writePostData($always = false)
71 {
72 $hasErrors = (!$always) ? $this->editQuestion(true) : false;
73 if (!$hasErrors) {
74 require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
77
79 return 0;
80 }
81 return 1;
82 }
83
85 {
86 $this->setErrorMessage("");
87 if ($_POST['flash']['delete'] == 1) {
88 $this->object->deleteApplet();
89 } else {
90 $this->object->setApplet($_POST['flash']['filename']);
91 }
92 if ($_FILES["flash"]["tmp_name"]) {
93 $this->object->deleteApplet();
94 $filename = $this->object->moveUploadedFile($_FILES["flash"]["tmp_name"], $_FILES["flash"]["name"]);
95 $this->object->setApplet($filename);
96 }
97 $this->object->clearParameters();
98 if (is_array($_POST["flash"]["flash_param_name"])) {
99 foreach ($_POST['flash']['flash_param_name'] as $idx => $val) {
100 $this->object->addParameter($val, $_POST['flash']['flash_param_value'][$idx]);
101 }
102 }
103 if (is_array($_POST['flash']['flash_param_delete'])) {
104 foreach ($_POST['flash']['flash_param_delete'] as $key => $value) {
105 $this->object->removeParameter($_POST['flash']['flash_param_name'][$key]);
106 }
107 }
108
109 $this->object->setWidth($_POST["flash"]["width"]);
110 $this->object->setHeight($_POST["flash"]["height"]);
111 $this->object->setPoints($_POST["points"]);
112 }
113
119 public function editQuestion($checkonly = false)
120 {
121 //$save = ((strcmp($this->ctrl->getCmd(), "save") == 0) || (strcmp($this->ctrl->getCmd(), "saveEdit") == 0)) ? TRUE : FALSE;
122 $save = $this->isSaveCommand();
123 $this->getQuestionTemplate();
124
125 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
126 $form = new ilPropertyFormGUI();
127 $this->editForm = $form;
128
129 $form->setFormAction($this->ctrl->getFormAction($this));
130 $form->setTitle($this->outQuestionType());
131 $form->setMultipart(true);
132 $form->setTableWidth("100%");
133 $form->setId("flash");
134
137
139
141
142 $errors = false;
143
144 if ($save) {
145 $form->setValuesByPost();
146 $errors = !$form->checkInput();
147 $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
148 if ($errors) {
149 $checkonly = false;
150 }
151 }
152
153 if (!$checkonly) {
154 $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
155 }
156 return $errors;
157 }
158
160 {
161 // flash file
162 $flash = new ilFlashFileInputGUI($this->lng->txt("flashfile"), "flash");
163 $flash->setRequired(true);
164 if (strlen($this->object->getApplet())) {
165 $flash->setApplet($this->object->getApplet());
166 $flash->setAppletPathWeb($this->object->getFlashPathWeb());
167 }
168 $flash->setWidth($this->object->getWidth());
169 $flash->setHeight($this->object->getHeight());
170 $flash->setParameters($this->object->getParameters());
171 $form->addItem($flash);
172 if ($this->object->getId()) {
173 $hidden = new ilHiddenInputGUI("", "ID");
174 $hidden->setValue($this->object->getId());
175 $form->addItem($hidden);
176 }
177 // points
178 $points = new ilNumberInputGUI($this->lng->txt("points"), "points");
179 $points->setValue($this->object->getPoints());
180 $points->setRequired(true);
181 $points->setSize(3);
182 $points->setMinValue(0.0);
183 $form->addItem($points);
184
185 return $form;
186 }
187
188 public function flashAddParam()
189 {
190 $this->writePostData();
191 $this->object->addParameter("", "");
192 $this->editQuestion();
193 }
194
208 public function getSolutionOutput(
209 $active_id,
210 $pass = null,
211 $graphicalOutput = false,
212 $result_output = false,
213 $show_question_only = true,
214 $show_feedback = false,
215 $show_correct_solution = false,
216 $show_manual_scoring = false,
217 $show_question_text = true
218 ) {
219 // get the solution of the user for the active pass or from the last pass if allowed
220 $template = new ilTemplate("tpl.il_as_qpl_flash_question_output_solution.html", true, true, "Modules/TestQuestionPool");
221
222 $params = array();
223 if (is_array($this->object->getParameters())) {
224 foreach ($this->object->getParameters() as $name => $value) {
225 array_push($params, urlencode($name) . "=" . urlencode($value));
226 }
227 }
228
229 array_push($params, "session_id=" . urlencode($_COOKIE[session_name()]));
230 array_push($params, "client=" . urlencode(CLIENT_ID));
231 array_push($params, "points_max=" . urlencode($this->object->getPoints()));
232 array_push($params, "server=" . urlencode(ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . "/webservice/soap/server.php?wsdl"));
233 if (!is_null($pass)) {
234 array_push($params, "pass=" . $pass);
235 } else {
236 include_once "./Modules/Test/classes/class.ilObjTest.php";
237 array_push($params, "pass=" . ilObjTest::_getPass($active_id));
238 }
239 if ($active_id) {
240 array_push($params, "active_id=" . $active_id);
241 }
242 array_push($params, "question_id=" . $this->object->getId());
243
244 if ($show_correct_solution) {
245 array_push($params, "solution=correct");
246 } else {
247 array_push($params, "solution=user");
248 }
249
250 if (($active_id > 0) && (!$show_correct_solution)) {
251 if ($graphicalOutput) {
252 // output of ok/not ok icons for user entered solutions
253 $reached_points = $this->object->getReachedPoints($active_id, $pass);
254 if ($reached_points == $this->object->getMaximumPoints()) {
255 $template->setCurrentBlock("icon_ok");
256 $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.svg"));
257 $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
258 $template->parseCurrentBlock();
259 } else {
260 $template->setCurrentBlock("icon_ok");
261 if ($reached_points > 0) {
262 $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_mostly_ok.svg"));
263 $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_not_correct_but_positive"));
264 } else {
265 $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.svg"));
266 $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
267 }
268 $template->parseCurrentBlock();
269 }
270 }
271 }
272
273 if (count($params)) {
274 $template->setCurrentBlock("flash_vars");
275 $template->setVariable("FLASH_VARS", join("&", $params));
276 $template->parseCurrentBlock();
277 $template->setCurrentBlock("applet_parameters");
278 $template->setVariable("PARAM_VALUE", join("&", $params));
279 $template->parseCurrentBlock();
280 }
281 if ($show_question_text == true) {
282 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), true));
283 }
284 $template->setVariable("APPLET_WIDTH", $this->object->getWidth());
285 $template->setVariable("APPLET_HEIGHT", $this->object->getHeight());
286 $template->setVariable("ID", $this->object->getId());
287 $template->setVariable("APPLET_PATH", $this->object->getFlashPathWeb() . $this->object->getApplet());
288 $template->setVariable("APPLET_FILE", $this->object->getApplet());
289
290 $questionoutput = $template->get();
291 $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html", true, true, "Modules/TestQuestionPool");
292 $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
293 $solutionoutput = $solutiontemplate->get();
294 if (!$show_question_only) {
295 // get page object output
296 $solutionoutput = $this->getILIASPage($solutionoutput);
297 }
298 return $solutionoutput;
299 }
300
301 public function getPreview($show_question_only = false, $showInlineFeedback = false)
302 {
303 $template = new ilTemplate("tpl.il_as_qpl_flash_question_output.html", true, true, "Modules/TestQuestionPool");
304 $params = array();
305 if (is_array($this->object->getParameters())) {
306 foreach ($this->object->getParameters() as $name => $value) {
307 array_push($params, urlencode($name) . "=" . urlencode($value));
308 }
309 }
310 if (count($params)) {
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 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), true));
319 $template->setVariable("APPLET_WIDTH", $this->object->getWidth());
320 $template->setVariable("APPLET_HEIGHT", $this->object->getHeight());
321 $template->setVariable("ID", $this->object->getId());
322 $template->setVariable("APPLET_PATH", $this->object->getFlashPathWeb() . $this->object->getApplet());
323 $template->setVariable("APPLET_FILE", $this->object->getApplet());
324 $questionoutput = $template->get();
325 if (!$show_question_only) {
326 // get page object output
327 $questionoutput = $this->getILIASPage($questionoutput);
328 }
329 return $questionoutput;
330 }
331
332 // hey: prevPassSolutions - pass will be always available from now on
333 public function getTestOutput($active_id, $pass, $is_postponed = false, $use_post_solutions = false, $show_feedback = false)
334 // hey.
335 {
336 // generate the question output
337 $template = new ilTemplate("tpl.il_as_qpl_flash_question_output.html", true, true, "Modules/TestQuestionPool");
338 $params = array();
339 if (is_array($this->object->getParameters())) {
340 foreach ($this->object->getParameters() as $name => $value) {
341 array_push($params, urlencode($name) . "=" . urlencode($value));
342 }
343 }
344
345 array_push($params, "session_id=" . urlencode($_COOKIE[session_name()]));
346 array_push($params, "client=" . urlencode(CLIENT_ID));
347 array_push($params, "points_max=" . urlencode($this->object->getPoints()));
348 array_push($params, "server=" . urlencode(ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . "/webservice/soap/server.php?wsdl"));
349 if (strlen($pass)) {
350 array_push($params, "pass=" . $pass);
351 } else {
352 include_once "./Modules/Test/classes/class.ilObjTest.php";
353 array_push($params, "pass=" . ilObjTest::_getPass($active_id));
354 }
355 if ($active_id) {
356 array_push($params, "active_id=" . $active_id);
357 }
358 array_push($params, "question_id=" . $this->object->getId());
359
360 if (count($params)) {
361 $template->setCurrentBlock("flash_vars");
362 $template->setVariable("FLASH_VARS", join("&", $params));
363 $template->parseCurrentBlock();
364 $template->setCurrentBlock("applet_parameters");
365 $template->setVariable("PARAM_VALUE", join("&", $params));
366 $template->parseCurrentBlock();
367 }
368 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), true));
369 $template->setVariable("APPLET_WIDTH", $this->object->getWidth());
370 $template->setVariable("APPLET_HEIGHT", $this->object->getHeight());
371 $template->setVariable("ID", $this->object->getId());
372 $template->setVariable("APPLET_PATH", $this->object->getFlashPathWeb() . $this->object->getApplet());
373 $template->setVariable("APPLET_FILE", $this->object->getFlashPathWeb() . $this->object->getApplet());
374 $questionoutput = $template->get();
375
376 $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
377 return $pageoutput;
378 }
379
387 public function setQuestionTabs()
388 {
389 global $DIC;
390 $rbacsystem = $DIC['rbacsystem'];
391 $ilTabs = $DIC['ilTabs'];
392
393 $ilTabs->clearTargets();
394
395 $this->ctrl->setParameterByClass("ilAssQuestionPageGUI", "q_id", $_GET["q_id"]);
396 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
397 $q_type = $this->object->getQuestionType();
398
399 if (strlen($q_type)) {
400 $classname = $q_type . "GUI";
401 $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
402 $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
403 }
404
405 if ($_GET["q_id"]) {
406 if ($rbacsystem->checkAccess('write', $_GET["ref_id"])) {
407 // edit page
408 $ilTabs->addTarget(
409 "edit_page",
410 $this->ctrl->getLinkTargetByClass("ilAssQuestionPageGUI", "edit"),
411 array("edit", "insert", "exec_pg"),
412 "",
413 "",
414 $force_active
415 );
416 }
417
418 $this->addTab_QuestionPreview($ilTabs);
419 }
420
421 $force_active = false;
422 if ($rbacsystem->checkAccess('write', $_GET["ref_id"])) {
423 $url = "";
424 if ($classname) {
425 $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
426 }
427 $commands = $_POST["cmd"];
428 if (is_array($commands)) {
429 foreach ($commands as $key => $value) {
430 if (preg_match("/^suggestrange_.*/", $key, $matches)) {
431 $force_active = true;
432 }
433 }
434 }
435 // edit question properties
436 $ilTabs->addTarget(
437 "edit_question",
438 $url,
439 array("editQuestion", "save", "flashAddParam", "saveEdit", "originalSyncForm"),
440 $classname,
441 "",
442 $force_active
443 );
444 }
445
446 // add tab for question feedback within common class assQuestionGUI
447 $this->addTab_QuestionFeedback($ilTabs);
448
449 // add tab for question hint within common class assQuestionGUI
450 $this->addTab_QuestionHints($ilTabs);
451
452 // add tab for question's suggested solution within common class assQuestionGUI
453 $this->addTab_SuggestedSolution($ilTabs, $classname);
454
455 // Assessment of questions sub menu entry
456 if ($_GET["q_id"]) {
457 $ilTabs->addTarget(
458 "statistics",
459 $this->ctrl->getLinkTargetByClass($classname, "assessment"),
460 array("assessment"),
461 $classname,
462 ""
463 );
464 }
465
466 $this->addBackTab($ilTabs);
467 }
468
469 public function getSpecificFeedbackOutput($userSolution)
470 {
471 $output = "";
472 return $this->object->prepareTextareaOutput($output, true);
473 }
474
485 {
486 return array();
487 }
488
497 public function getAggregatedAnswersView($relevant_answers)
498 {
499 // Empty implementation here since a feasible way to aggregate answer is not known.
500 return ''; //print_r($relevant_answers,true);
501 }
502}
$_COOKIE['client_id']
Definition: server.php:9
$filename
Definition: buildRTE.php:89
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
The assFlashQuestionGUI class encapsulates the GUI representation for flash questions.
editQuestion($checkonly=false)
Creates an output of the edit form for the question.
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...
suggestRange()
Suggest a range for a result.
writePostData($always=false)
{Evaluates a posted edit form and writes the form data in the question object.integer A positive valu...
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.
getSpecificFeedbackOutput($userSolution)
Returns the answer specific feedback for the question.
writeQuestionSpecificPostData(ilPropertyFormGUI $form)
Extracts the question specific values from $_POST and applies them to the data object.
getPreview($show_question_only=false, $showInlineFeedback=false)
populateQuestionSpecificFormPart(ilPropertyFormGUI $form)
Adds the question specific forms parts to a question property form gui.
getTestOutput($active_id, $pass, $is_postponed=false, $use_post_solutions=false, $show_feedback=false)
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
addTab_SuggestedSolution(ilTabsGUI $tabs, $classname)
outQuestionPage($a_temp_var, $a_postponed=false, $active_id="", $html="", $inlineFeedbackEnabled=false)
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.
static _getPass($active_id)
Retrieves the actual pass of a given user for a given test.
This class represents a property form user interface.
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)
$template
$key
Definition: croninfo.php:18
if(!array_key_exists('StateId', $_REQUEST)) $id
Interface ilGuiQuestionScoringAdjustable.
$errors
Definition: index.php:6
$url
if(isset($_POST['submit'])) $form
global $DIC
Definition: saml.php:7