ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.assErrorTextGUI.php
Go to the documentation of this file.
1 <?php
2  /*
3  +----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +----------------------------------------------------------------------------+
22 */
23 
24 include_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
25 include_once "./Modules/Test/classes/inc.AssessmentConstants.php";
26 
37 {
46  function __construct($id = -1)
47  {
49  include_once "./Modules/TestQuestionPool/classes/class.assErrorText.php";
50  $this->object = new assErrorText();
51  $this->setErrorMessage($this->lng->txt("msg_form_save_error"));
52  if ($id >= 0)
53  {
54  $this->object->loadFromDb($id);
55  }
56  }
57 
58  function getCommand($cmd)
59  {
60  return $cmd;
61  }
62 
69  function writePostData($always = false)
70  {
71  $hasErrors = (!$always) ? $this->editQuestion(true) : false;
72  if (!$hasErrors)
73  {
74  $this->object->setTitle($_POST["title"]);
75  $this->object->setAuthor($_POST["author"]);
76  $this->object->setComment($_POST["comment"]);
77  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
78  $questiontext = $_POST["question"];
79  $this->object->setQuestion($questiontext);
80  // adding estimated working time
81  $this->object->setEstimatedWorkingTime(
82  $_POST["Estimated"]["hh"],
83  $_POST["Estimated"]["mm"],
84  $_POST["Estimated"]["ss"]
85  );
86  $this->object->setTextSize($_POST["textsize"]);
87  $this->object->setErrorText($_POST["errortext"]);
88  $points_wrong = str_replace(",", ".", $_POST["points_wrong"]);
89  if (strlen($points_wrong) == 0) $points_wrong = -1.0;
90  $this->object->setPointsWrong($points_wrong);
91 
92  $this->object->flushErrorData();
93  if (is_array($_POST['errordata']['key']))
94  {
95  foreach ($_POST['errordata']['key'] as $idx => $val)
96  {
97  $this->object->addErrorData($val, $_POST['errordata']['value'][$idx], $_POST['errordata']['points'][$idx]);
98  }
99  }
100  return 0;
101  }
102  else
103  {
104  return 1;
105  }
106  }
107 
113  public function editQuestion($checkonly = FALSE)
114  {
115  $save = ((strcmp($this->ctrl->getCmd(), "save") == 0) || (strcmp($this->ctrl->getCmd(), "saveEdit") == 0)) ? TRUE : FALSE;
116  $this->getQuestionTemplate();
117 
118  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
119  $form = new ilPropertyFormGUI();
120  $form->setFormAction($this->ctrl->getFormAction($this));
121  $form->setTitle($this->outQuestionType());
122  $form->setMultipart(FALSE);
123  $form->setTableWidth("100%");
124  $form->setId("orderinghorizontal");
125 
126  $this->addBasicQuestionFormProperties($form);
127 
128  // errortext
129  $errortext = new ilTextAreaInputGUI($this->lng->txt("errortext"), "errortext");
130  $errortext->setValue(ilUtil::prepareFormOutput($this->object->getErrorText()));
131  $errortext->setRequired(TRUE);
132  $errortext->setInfo($this->lng->txt("errortext_info"));
133  $errortext->setRows(10);
134  $errortext->setCols(80);
135  $form->addItem($errortext);
136  //additional characters
137  include_once("./Services/Form/classes/class.ilAdditionalCharactersGUI.php");
138  $form->addItem(new ilAdditionalCharactersGUI());
139  // textsize
140  $textsize = new ilNumberInputGUI($this->lng->txt("textsize"), "textsize");
141  $textsize->setValue(strlen($this->object->getTextSize()) ? $this->object->getTextSize() : 100.0);
142  $textsize->setInfo($this->lng->txt("textsize_errortext_info"));
143  $textsize->setSize(6);
144  $textsize->setSuffix("%");
145  $textsize->setMinValue(10);
146  $textsize->setRequired(true);
147  $form->addItem($textsize);
148 
149  if (count($this->object->getErrorData()) || $checkonly)
150  {
151  $header = new ilFormSectionHeaderGUI();
152  $header->setTitle($this->lng->txt("errors_section"));
153  $form->addItem($header);
154 
155  include_once "./Modules/TestQuestionPool/classes/class.ilErrorTextWizardInputGUI.php";
156  $errordata = new ilErrorTextWizardInputGUI($this->lng->txt("errors"), "errordata");
157  $values = array();
158  $errordata->setKeyName($this->lng->txt('text_wrong'));
159  $errordata->setValueName($this->lng->txt('text_correct'));
160  $errordata->setValues($this->object->getErrorData());
161  $form->addItem($errordata);
162 
163  // points for wrong selection
164  $points_wrong = new ilNumberInputGUI($this->lng->txt("points_wrong"), "points_wrong");
165  $points_wrong->setValue($this->object->getPointsWrong());
166  $points_wrong->setInfo($this->lng->txt("points_wrong_info"));
167  $points_wrong->setSize(6);
168  $points_wrong->setRequired(true);
169  $form->addItem($points_wrong);
170  }
171 
172  $form->addCommandButton("analyze", $this->lng->txt('analyze_errortext'));
173  $this->addQuestionFormCommandButtons($form);
174 
175  $errors = false;
176 
177  if ($save)
178  {
179  $form->setValuesByPost();
180  $errors = !$form->checkInput();
181  $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
182  if ($errors) $checkonly = false;
183  }
184 
185  if (!$checkonly) $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
186  return $errors;
187  }
188 
192  public function analyze()
193  {
194  $this->writePostData(true);
195  $this->object->setErrorData($this->object->getErrorsFromText($_POST['errortext']));
196  $this->editQuestion();
197  }
198 
199  function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
200  {
201  $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $use_post_solutions, $show_feedback);
202  $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
203  $this->tpl->setVariable("FORMACTION", $formaction);
204  }
205 
220  $active_id,
221  $pass = NULL,
222  $graphicalOutput = FALSE,
223  $result_output = FALSE,
224  $show_question_only = TRUE,
225  $show_feedback = FALSE,
226  $show_correct_solution = FALSE,
227  $show_manual_scoring = FALSE
228  )
229  {
230  // get the solution of the user for the active pass or from the last pass if allowed
231  $template = new ilTemplate("tpl.il_as_qpl_errortext_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
232 
233  $selections = array();
234  if (($active_id > 0) && (!$show_correct_solution))
235  {
236  $solutions =& $this->object->getSolutionValues($active_id, $pass);
237  if (is_array($solutions))
238  {
239  foreach ($solutions as $solution)
240  {
241  array_push($selections, $solution['value1']);
242  }
243  $errortext_value = join(",", $selections);
244  }
245  }
246  else
247  {
248  $selections = $this->object->getBestSelection();
249  }
250 
251  if (($active_id > 0) && (!$show_correct_solution))
252  {
253  $reached_points = $this->object->getReachedPoints($active_id, $pass);
254  }
255  else
256  {
257  $reached_points = $this->object->getPoints();
258  }
259 
260  if ($result_output)
261  {
262  $resulttext = ($reached_points == 1) ? "(%s " . $this->lng->txt("point") . ")" : "(%s " . $this->lng->txt("points") . ")";
263  $template->setVariable("RESULT_OUTPUT", sprintf($resulttext, $reached_points));
264  }
265  if ($this->object->getTextSize() >= 10) echo $template->setVariable("STYLE", " style=\"font-size: " . $this->object->getTextSize() . "%;\"");
266  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), TRUE));
267  $errortext = $this->object->createErrorTextOutput($selections, $graphicalOutput, $show_correct_solution);
268  $errortext = preg_replace("/#HREF\d+/is", "javascript:void(0);", $errortext);
269  $template->setVariable("ERRORTEXT", $errortext);
270  $questionoutput = $template->get();
271 
272  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
273  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
274  $solutionoutput = $solutiontemplate->get();
275  if (!$show_question_only)
276  {
277  // get page object output
278  $solutionoutput = $this->getILIASPage($solutionoutput);
279  }
280  return $solutionoutput;
281  }
282 
283  function getPreview($show_question_only = FALSE)
284  {
285  $template = new ilTemplate("tpl.il_as_qpl_errortext_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
286  if ($this->object->getTextSize() >= 10) echo $template->setVariable("STYLE", " style=\"font-size: " . $this->object->getTextSize() . "%;\"");
287  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), TRUE));
288  $errortext = $this->object->createErrorTextOutput($selections);
289  $errortext = preg_replace("/#HREF\d+/is", "javascript:void(0);", $errortext);
290  $template->setVariable("ERRORTEXT", $errortext);
291  $template->setVariable("ERRORTEXT_ID", "qst_" . $this->object->getId());
292  $questionoutput = $template->get();
293  if (!$show_question_only)
294  {
295  // get page object output
296  $questionoutput = $this->getILIASPage($questionoutput);
297  }
298  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
300  $this->tpl->addJavascript("./Modules/TestQuestionPool/templates/default/errortext.js");
301  return $questionoutput;
302  }
303 
304  function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
305  {
306  // generate the question output
307  $template = new ilTemplate("tpl.il_as_qpl_errortext_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
308  if ($active_id)
309  {
310  $solutions = NULL;
311  include_once "./Modules/Test/classes/class.ilObjTest.php";
312  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
313  {
314  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
315  }
316  $solutions =& $this->object->getSolutionValues($active_id, $pass);
317  }
318  $errortext_value = "";
319  if (strlen($_SESSION['qst_selection']))
320  {
321  $this->object->toggleSelection($_SESSION['qst_selection'], $active_id, $pass);
322  unset($_SESSION['qst_selection']);
323  $solutions =& $this->object->getSolutionValues($active_id, $pass);
324  }
325  $selections = array();
326  if (is_array($solutions))
327  {
328  foreach ($solutions as $solution)
329  {
330  array_push($selections, $solution['value1']);
331  }
332  $errortext_value = join(",", $selections);
333  }
334  if ($this->object->getTextSize() >= 10) echo $template->setVariable("STYLE", " style=\"font-size: " . $this->object->getTextSize() . "%;\"");
335  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), TRUE));
336  $errortext = $this->object->createErrorTextOutput($selections);
337  $errortext = preg_replace_callback("/#HREF(\d+)/is", array(&$this, 'exchangeURL'), $errortext);
338  $this->ctrl->setParameterByClass('iltestoutputgui', 'errorvalue', '');
339  $template->setVariable("ERRORTEXT", $errortext);
340  $template->setVariable("ERRORTEXT_ID", "qst_" . $this->object->getId());
341  $template->setVariable("ERRORTEXT_VALUE", $errortext_value);
342  $questionoutput = $template->get();
343  if (!$show_question_only)
344  {
345  // get page object output
346  $questionoutput = $this->getILIASPage($questionoutput);
347  }
348  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
350  $this->tpl->addJavascript("./Modules/TestQuestionPool/templates/default/errortext.js");
351  $questionoutput = $template->get();
352  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
353  return $pageoutput;
354  }
355 
356  public function exchangeURL($matches)
357  {
358  $this->ctrl->setParameterByClass('iltestoutputgui', 'qst_selection', $matches[1]);
359  return $this->ctrl->getLinkTargetByClass('iltestoutputgui', 'gotoQuestion');
360  }
361 
367  function saveFeedback()
368  {
369  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
370  $errors = $this->feedback(true);
371  $this->object->saveFeedbackGeneric(0, $_POST["feedback_incomplete"]);
372  $this->object->saveFeedbackGeneric(1, $_POST["feedback_complete"]);
373  $this->object->cleanupMediaObjectUsage();
375  }
376 
382  function setQuestionTabs()
383  {
384  global $rbacsystem, $ilTabs;
385 
386  $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]);
387  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
388  $q_type = $this->object->getQuestionType();
389 
390  if (strlen($q_type))
391  {
392  $classname = $q_type . "GUI";
393  $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
394  $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
395  }
396 
397  if ($_GET["q_id"])
398  {
399  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
400  {
401  // edit page
402  $ilTabs->addTarget("edit_content",
403  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "edit"),
404  array("edit", "insert", "exec_pg"),
405  "", "", $force_active);
406  }
407 
408  // edit page
409  $ilTabs->addTarget("preview",
410  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "preview"),
411  array("preview"),
412  "ilPageObjectGUI", "", $force_active);
413  }
414 
415  $force_active = false;
416  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
417  {
418  $url = "";
419  if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
420  // edit question properties
421  $ilTabs->addTarget("edit_properties",
422  $url,
423  array("editQuestion", "save", "saveEdit", "analyze", "originalSyncForm"),
424  $classname, "", $force_active);
425  }
426 
427  if ($_GET["q_id"])
428  {
429  $ilTabs->addTarget("feedback",
430  $this->ctrl->getLinkTargetByClass($classname, "feedback"),
431  array("feedback", "saveFeedback"),
432  $classname, "");
433  }
434 
435  if ($_GET["q_id"])
436  {
437  $ilTabs->addTarget("solution_hint",
438  $this->ctrl->getLinkTargetByClass($classname, "suggestedsolution"),
439  array("suggestedsolution", "saveSuggestedSolution", "outSolutionExplorer", "cancel",
440  "addSuggestedSolution","cancelExplorer", "linkChilds", "removeSuggestedSolution"
441  ),
442  $classname,
443  ""
444  );
445  }
446 
447  // Assessment of questions sub menu entry
448  if ($_GET["q_id"])
449  {
450  $ilTabs->addTarget("statistics",
451  $this->ctrl->getLinkTargetByClass($classname, "assessment"),
452  array("assessment"),
453  $classname, "");
454  }
455 
456  if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
457  {
458  $ref_id = $_GET["calling_test"];
459  if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
460  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
461  }
462  else
463  {
464  $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
465  }
466  }
467 }
468 ?>