ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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["PHPSESSID"]));
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["PHPSESSID"]));
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 $rbacsystem, $ilTabs;
390
391 $ilTabs->clearTargets();
392
393 $this->ctrl->setParameterByClass("ilAssQuestionPageGUI", "q_id", $_GET["q_id"]);
394 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
395 $q_type = $this->object->getQuestionType();
396
397 if (strlen($q_type)) {
398 $classname = $q_type . "GUI";
399 $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
400 $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
401 }
402
403 if ($_GET["q_id"]) {
404 if ($rbacsystem->checkAccess('write', $_GET["ref_id"])) {
405 // edit page
406 $ilTabs->addTarget(
407 "edit_page",
408 $this->ctrl->getLinkTargetByClass("ilAssQuestionPageGUI", "edit"),
409 array("edit", "insert", "exec_pg"),
410 "",
411 "",
412 $force_active
413 );
414 }
415
416 $this->addTab_QuestionPreview($ilTabs);
417 }
418
419 $force_active = false;
420 if ($rbacsystem->checkAccess('write', $_GET["ref_id"])) {
421 $url = "";
422 if ($classname) {
423 $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
424 }
425 $commands = $_POST["cmd"];
426 if (is_array($commands)) {
427 foreach ($commands as $key => $value) {
428 if (preg_match("/^suggestrange_.*/", $key, $matches)) {
429 $force_active = true;
430 }
431 }
432 }
433 // edit question properties
434 $ilTabs->addTarget(
435 "edit_question",
436 $url,
437 array("editQuestion", "save", "flashAddParam", "saveEdit", "originalSyncForm"),
438 $classname,
439 "",
440 $force_active
441 );
442 }
443
444 // add tab for question feedback within common class assQuestionGUI
445 $this->addTab_QuestionFeedback($ilTabs);
446
447 // add tab for question hint within common class assQuestionGUI
448 $this->addTab_QuestionHints($ilTabs);
449
450 // add tab for question's suggested solution within common class assQuestionGUI
451 $this->addTab_SuggestedSolution($ilTabs, $classname);
452
453 // Assessment of questions sub menu entry
454 if ($_GET["q_id"]) {
455 $ilTabs->addTarget(
456 "statistics",
457 $this->ctrl->getLinkTargetByClass($classname, "assessment"),
458 array("assessment"),
459 $classname,
460 ""
461 );
462 }
463
464 $this->addBackTab($ilTabs);
465 }
466
467 public function getSpecificFeedbackOutput($active_id, $pass)
468 {
469 $output = "";
470 return $this->object->prepareTextareaOutput($output, true);
471 }
472
483 {
484 return array();
485 }
486
495 public function getAggregatedAnswersView($relevant_answers)
496 {
497 // Empty implementation here since a feasible way to aggregate answer is not known.
498 return ''; //print_r($relevant_answers,true);
499 }
500}
$_COOKIE['client_id']
Definition: server.php:9
$_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.
getSpecificFeedbackOutput($active_id, $pass)
Returns the answer specific feedback for the question.
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.
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="")
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
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\s+" &#(? foreach( $entity_files as $file) $output
Interface ilGuiQuestionScoringAdjustable.
if($format !==null) $name
Definition: metadata.php:146
$errors
Definition: index.php:6
$url
if(isset($_POST['submit'])) $form
$params
Definition: disable.php:11