ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.assOrderingHorizontalGUI.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.assOrderingHorizontal.php";
50  $this->object = new assOrderingHorizontal();
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  $this->object->setPoints($_POST["points"]);
81  // adding estimated working time
82  $this->object->setEstimatedWorkingTime(
83  $_POST["Estimated"]["hh"],
84  $_POST["Estimated"]["mm"],
85  $_POST["Estimated"]["ss"]
86  );
87  $this->object->setTextSize($_POST["textsize"]);
88  $this->object->setOrderText($_POST["ordertext"]);
89  return 0;
90  }
91  else
92  {
93  return 1;
94  }
95  }
96 
102  public function editQuestion($checkonly = FALSE)
103  {
104  $save = ((strcmp($this->ctrl->getCmd(), "save") == 0) || (strcmp($this->ctrl->getCmd(), "saveEdit") == 0)) ? TRUE : FALSE;
105  $this->getQuestionTemplate();
106 
107  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
108  $form = new ilPropertyFormGUI();
109  $form->setFormAction($this->ctrl->getFormAction($this));
110  $form->setTitle($this->outQuestionType());
111  $form->setMultipart(FALSE);
112  $form->setTableWidth("100%");
113  $form->setId("orderinghorizontal");
114 
115  $this->addBasicQuestionFormProperties($form);
116 
117  // ordertext
118  $ordertext = new ilTextAreaInputGUI($this->lng->txt("ordertext"), "ordertext");
119  $ordertext->setValue($this->object->prepareTextareaOutput($this->object->getOrderText()));
120  $ordertext->setRequired(TRUE);
121  $ordertext->setInfo(sprintf($this->lng->txt("ordertext_info"), $this->object->separator));
122  $ordertext->setRows(10);
123  $ordertext->setCols(80);
124  $form->addItem($ordertext);
125  //additional characters
126  include_once("./Services/Form/classes/class.ilAdditionalCharactersGUI.php");
127  $form->addItem(new ilAdditionalCharactersGUI());
128  // textsize
129  $textsize = new ilNumberInputGUI($this->lng->txt("textsize"), "textsize");
130  $textsize->setValue($this->object->getTextSize());
131  $textsize->setInfo($this->lng->txt("textsize_info"));
132  $textsize->setSize(6);
133  $textsize->setMinValue(10);
134  $textsize->setRequired(FALSE);
135  $form->addItem($textsize);
136  // points
137  $points = new ilNumberInputGUI($this->lng->txt("points"), "points");
138  $points->setValue($this->object->getPoints());
139  $points->setRequired(TRUE);
140  $points->setSize(3);
141  $points->setMinValue(0.0);
142  $points->setMinvalueShouldBeGreater(true);
143  $form->addItem($points);
144 
145  $this->addQuestionFormCommandButtons($form);
146 
147  $errors = false;
148 
149  if ($save)
150  {
151  $form->setValuesByPost();
152  $errors = !$form->checkInput();
153  $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
154  if ($errors) $checkonly = false;
155  }
156 
157  if (!$checkonly) $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
158  return $errors;
159  }
160 
161  function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
162  {
163  $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $use_post_solutions, $show_feedback);
164  $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
165  $this->tpl->setVariable("FORMACTION", $formaction);
166  }
167 
182  $active_id,
183  $pass = NULL,
184  $graphicalOutput = FALSE,
185  $result_output = FALSE,
186  $show_question_only = TRUE,
187  $show_feedback = FALSE,
188  $show_correct_solution = FALSE,
189  $show_manual_scoring = FALSE
190  )
191  {
192  // get the solution of the user for the active pass or from the last pass if allowed
193  $template = new ilTemplate("tpl.il_as_qpl_orderinghorizontal_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
194 
195  $solutionvalue = "";
196  if (($active_id > 0) && (!$show_correct_solution))
197  {
198  $solutions =& $this->object->getSolutionValues($active_id, $pass);
199  if (strlen($solutions[0]["value1"]))
200  {
201  $elements = split("{::}", $solutions[0]["value1"]);
202  foreach ($elements as $id => $element)
203  {
204  $template->setCurrentBlock("element");
205  $template->setVariable("ELEMENT_ID", "e$id");
206  $template->setVariable("ELEMENT_VALUE", ilUtil::prepareFormOutput($element));
207  $template->parseCurrentBlock();
208  }
209  }
210  $solutionvalue = str_replace("{::}", " ", $solutions[0]["value1"]);
211  }
212  else
213  {
214  $elements = $this->object->getOrderingElements();
215  foreach ($elements as $id => $element)
216  {
217  $template->setCurrentBlock("element");
218  $template->setVariable("ELEMENT_ID", "e$id");
219  $template->setVariable("ELEMENT_VALUE", ilUtil::prepareFormOutput($element));
220  $template->parseCurrentBlock();
221  }
222  $solutionvalue = join($this->object->getOrderingElements(), " ");
223  }
224 
225  if (($active_id > 0) && (!$show_correct_solution))
226  {
227  $reached_points = $this->object->getReachedPoints($active_id, $pass);
228  if ($graphicalOutput)
229  {
230  // output of ok/not ok icons for user entered solutions
231  if ($reached_points == $this->object->getMaximumPoints())
232  {
233  $template->setCurrentBlock("icon_ok");
234  $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.gif"));
235  $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
236  $template->parseCurrentBlock();
237  }
238  else
239  {
240  $template->setCurrentBlock("icon_ok");
241  if ($reached_points > 0)
242  {
243  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_mostly_ok.gif"));
244  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_not_correct_but_positive"));
245  }
246  else
247  {
248  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.gif"));
249  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
250  }
251  $template->parseCurrentBlock();
252  }
253  }
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  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), TRUE));
266 // $template->setVariable("SOLUTION_TEXT", ilUtil::prepareFormOutput($solutionvalue));
267  if ($this->object->textsize >= 10) echo $template->setVariable("STYLE", " style=\"font-size: " . $this->object->textsize . "%;\"");
268 
269  $questionoutput = $template->get();
270  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
271  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
272  $solutionoutput = $solutiontemplate->get();
273  if (!$show_question_only)
274  {
275  // get page object output
276  $solutionoutput = $this->getILIASPage($solutionoutput);
277  }
278  return $solutionoutput;
279  }
280 
281  function getPreview($show_question_only = FALSE)
282  {
283  $template = new ilTemplate("tpl.il_as_qpl_orderinghorizontal_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
284  $elements = $this->object->getRandomOrderingElements();
285  foreach ($elements as $id => $element)
286  {
287  $template->setCurrentBlock("element");
288  $template->setVariable("ELEMENT_ID", "e$id");
289  $template->setVariable("ELEMENT_VALUE", ilUtil::prepareFormOutput($element));
290  $template->parseCurrentBlock();
291  }
292  if ($this->object->textsize >= 10) echo $template->setVariable("STYLE", " style=\"font-size: " . $this->object->textsize . "%;\"");
293  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), TRUE));
294  $questionoutput = $template->get();
295  if (!$show_question_only)
296  {
297  // get page object output
298  $questionoutput = $this->getILIASPage($questionoutput);
299  }
300  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
302  $this->tpl->addJavascript("./Modules/TestQuestionPool/templates/default/orderinghorizontal.js");
303  return $questionoutput;
304  }
305 
306  function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
307  {
308  // generate the question output
309  $template = new ilTemplate("tpl.il_as_qpl_orderinghorizontal_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
310  $elements = $this->object->getRandomOrderingElements();
311 
312  if ($active_id)
313  {
314  $solutions = NULL;
315  include_once "./Modules/Test/classes/class.ilObjTest.php";
316  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
317  {
318  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
319  }
320  $solutions =& $this->object->getSolutionValues($active_id, $pass);
321  if (count($solutions) == 1)
322  {
323  $elements = split("{::}", $solutions[0]["value1"]);
324  }
325  }
326  if (strlen($_SESSION['qst_selection']))
327  {
328  $this->object->moveRight($_SESSION['qst_selection'], $active_id, $pass);
329  unset($_SESSION['qst_selection']);
330  $solutions =& $this->object->getSolutionValues($active_id, $pass);
331  if (count($solutions) == 1)
332  {
333  $elements = split("{::}", $solutions[0]["value1"]);
334  }
335  }
336  if (count($solutions) == 0)
337  {
338  $_SESSION['qst_ordering_horizontal_elements'] = $elements;
339  }
340  else
341  {
342  unset($_SESSION['qst_ordering_horizontal_elements']);
343  }
344  $idx = 0;
345  foreach ($elements as $id => $element)
346  {
347  $template->setCurrentBlock("element");
348  $template->setVariable("ELEMENT_ID", "e_" . $this->object->getId() . "_$id");
349  $template->setVariable("ELEMENT_VALUE", ilUtil::prepareFormOutput($element));
350  $this->ctrl->setParameterByClass('iltestoutputgui', 'qst_selection', $idx);
351  $idx++;
352  $url = $this->ctrl->getLinkTargetByClass('iltestoutputgui', 'gotoQuestion');
353  $template->setVariable("MOVE_RIGHT", $url);
354  $template->setVariable("TEXT_MOVE_RIGHT", $this->lng->txt('move_right'));
355  $template->setVariable("RIGHT_IMAGE", ilUtil::getImagePath('nav_arr_R.gif'));
356  $template->parseCurrentBlock();
357  }
358  if ($this->object->textsize >= 10) echo $template->setVariable("STYLE", " style=\"font-size: " . $this->object->textsize . "%;\"");
359  $template->setVariable("VALUE_ORDERRESULT", ' value="' . join($elements, '{::}') . '"');
360  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), TRUE));
361  $questionoutput = $template->get();
362  if (!$show_question_only)
363  {
364  // get page object output
365  $questionoutput = $this->getILIASPage($questionoutput);
366  }
367  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
369  $this->tpl->addJavascript("./Modules/TestQuestionPool/templates/default/orderinghorizontal.js");
370  $questionoutput = $template->get();
371  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
372  return $pageoutput;
373  }
374 
380  function saveFeedback()
381  {
382  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
383  $errors = $this->feedback(true);
384  $this->object->saveFeedbackGeneric(0, $_POST["feedback_incomplete"]);
385  $this->object->saveFeedbackGeneric(1, $_POST["feedback_complete"]);
386  $this->object->cleanupMediaObjectUsage();
388  }
389 
395  function setQuestionTabs()
396  {
397  global $rbacsystem, $ilTabs;
398 
399  $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]);
400  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
401  $q_type = $this->object->getQuestionType();
402 
403  if (strlen($q_type))
404  {
405  $classname = $q_type . "GUI";
406  $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
407  $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
408  }
409 
410  if ($_GET["q_id"])
411  {
412  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
413  {
414  // edit page
415  $ilTabs->addTarget("edit_content",
416  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "edit"),
417  array("edit", "insert", "exec_pg"),
418  "", "", $force_active);
419  }
420 
421  // edit page
422  $ilTabs->addTarget("preview",
423  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "preview"),
424  array("preview"),
425  "ilPageObjectGUI", "", $force_active);
426  }
427 
428  $force_active = false;
429  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
430  {
431  $url = "";
432  if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
433  $commands = $_POST["cmd"];
434  if (is_array($commands))
435  {
436  foreach ($commands as $key => $value)
437  {
438  if (preg_match("/^suggestrange_.*/", $key, $matches))
439  {
440  $force_active = true;
441  }
442  }
443  }
444  // edit question properties
445  $ilTabs->addTarget("edit_properties",
446  $url,
447  array("editQuestion", "save", "saveEdit", "originalSyncForm"),
448  $classname, "", $force_active);
449  }
450 
451  if ($_GET["q_id"])
452  {
453  $ilTabs->addTarget("feedback",
454  $this->ctrl->getLinkTargetByClass($classname, "feedback"),
455  array("feedback", "saveFeedback"),
456  $classname, "");
457  }
458 
459  if ($_GET["q_id"])
460  {
461  $ilTabs->addTarget("solution_hint",
462  $this->ctrl->getLinkTargetByClass($classname, "suggestedsolution"),
463  array("suggestedsolution", "saveSuggestedSolution", "outSolutionExplorer", "cancel",
464  "addSuggestedSolution","cancelExplorer", "linkChilds", "removeSuggestedSolution"
465  ),
466  $classname,
467  ""
468  );
469  }
470 
471  // Assessment of questions sub menu entry
472  if ($_GET["q_id"])
473  {
474  $ilTabs->addTarget("statistics",
475  $this->ctrl->getLinkTargetByClass($classname, "assessment"),
476  array("assessment"),
477  $classname, "");
478  }
479 
480  if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
481  {
482  $ref_id = $_GET["calling_test"];
483  if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
484  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
485  }
486  else
487  {
488  $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
489  }
490  }
491 }
492 ?>