ILIAS  release_4-3 Revision
 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 
38 {
47  function __construct($id = -1)
48  {
50  include_once "./Modules/TestQuestionPool/classes/class.assOrderingHorizontal.php";
51  $this->object = new assOrderingHorizontal();
52  $this->setErrorMessage($this->lng->txt("msg_form_save_error"));
53  if ($id >= 0)
54  {
55  $this->object->loadFromDb($id);
56  }
57  }
58 
59  function getCommand($cmd)
60  {
61  return $cmd;
62  }
63 
70  function writePostData($always = false)
71  {
72  $hasErrors = (!$always) ? $this->editQuestion(true) : false;
73  if (!$hasErrors)
74  {
75  $this->object->setTitle($_POST["title"]);
76  $this->object->setAuthor($_POST["author"]);
77  $this->object->setComment($_POST["comment"]);
78  if ($this->getSelfAssessmentEditingMode())
79  {
80  $this->object->setNrOfTries($_POST['nr_of_tries']);
81  }
82 
83  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
84  $questiontext = $_POST["question"];
85  $this->object->setQuestion($questiontext);
86  $this->object->setPoints($_POST["points"]);
87  // adding estimated working time
88  $this->object->setEstimatedWorkingTime(
89  $_POST["Estimated"]["hh"],
90  $_POST["Estimated"]["mm"],
91  $_POST["Estimated"]["ss"]
92  );
93  $this->object->setTextSize($_POST["textsize"]);
94  $this->object->setOrderText($_POST["ordertext"]);
95  return 0;
96  }
97  else
98  {
99  return 1;
100  }
101  }
102 
108  public function editQuestion($checkonly = FALSE)
109  {
110  $save = $this->isSaveCommand();
111  $this->getQuestionTemplate();
112 
113  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
114  $form = new ilPropertyFormGUI();
115  $form->setFormAction($this->ctrl->getFormAction($this));
116  $form->setTitle($this->outQuestionType());
117  $form->setMultipart(FALSE);
118  $form->setTableWidth("100%");
119  $form->setId("orderinghorizontal");
120 
121  $this->addBasicQuestionFormProperties($form);
122 
123  // ordertext
124  $ordertext = new ilTextAreaInputGUI($this->lng->txt("ordertext"), "ordertext");
125  $ordertext->setValue($this->object->prepareTextareaOutput($this->object->getOrderText()));
126  $ordertext->setRequired(TRUE);
127  $ordertext->setInfo(sprintf($this->lng->txt("ordertext_info"), $this->object->separator));
128  $ordertext->setRows(10);
129  $ordertext->setCols(80);
130  $form->addItem($ordertext);
131  // textsize
132  $textsize = new ilNumberInputGUI($this->lng->txt("textsize"), "textsize");
133  $textsize->setValue($this->object->getTextSize());
134  $textsize->setInfo($this->lng->txt("textsize_info"));
135  $textsize->setSize(6);
136  $textsize->setMinValue(10);
137  $textsize->setRequired(FALSE);
138  $form->addItem($textsize);
139  // points
140  $points = new ilNumberInputGUI($this->lng->txt("points"), "points");
141 
142  $points->allowDecimals(true);
143  // mbecker: Fix for mantis bug 7866: Predefined values schould make sense.
144  // This implements a default value of "1" for this question type.
145  if($this->object->getPoints() == null)
146  {
147  $points->setValue("1");
148  }
149  else
150  {
151  $points->setValue($this->object->getPoints());
152  }
153  $points->setRequired(TRUE);
154  $points->setSize(3);
155  $points->setMinValue(0.0);
156  $points->setMinvalueShouldBeGreater(true);
157  $form->addItem($points);
158 
159  $this->addQuestionFormCommandButtons($form);
160 
161  $errors = false;
162 
163  if ($save)
164  {
165  $form->setValuesByPost();
166  $errors = !$form->checkInput();
167  $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
168  if ($errors) $checkonly = false;
169  }
170 
171  if (!$checkonly) $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
172  return $errors;
173  }
174 
175  function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
176  {
177  $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $use_post_solutions, $show_feedback);
178  $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
179  $this->tpl->setVariable("FORMACTION", $formaction);
180  }
181 
196  $active_id,
197  $pass = NULL,
198  $graphicalOutput = FALSE,
199  $result_output = FALSE,
200  $show_question_only = TRUE,
201  $show_feedback = FALSE,
202  $show_correct_solution = FALSE,
203  $show_manual_scoring = FALSE,
204  $show_question_text = TRUE
205  )
206  {
207  // get the solution of the user for the active pass or from the last pass if allowed
208  $template = new ilTemplate("tpl.il_as_qpl_orderinghorizontal_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
209 
210  $solutionvalue = "";
211  if (($active_id > 0) && (!$show_correct_solution))
212  {
213  $solutions =& $this->object->getSolutionValues($active_id, $pass);
214  if (strlen($solutions[0]["value1"]))
215  {
216  $elements = split("{::}", $solutions[0]["value1"]);
217  foreach ($elements as $id => $element)
218  {
219  $template->setCurrentBlock("element");
220  $template->setVariable("ELEMENT_ID", "e$id");
221  $template->setVariable("ELEMENT_VALUE", ilUtil::prepareFormOutput($element));
222  $template->parseCurrentBlock();
223  }
224  }
225  $solutionvalue = str_replace("{::}", " ", $solutions[0]["value1"]);
226  }
227  else
228  {
229  $elements = $this->object->getOrderingElements();
230  foreach ($elements as $id => $element)
231  {
232  $template->setCurrentBlock("element");
233  $template->setVariable("ELEMENT_ID", "e$id");
234  $template->setVariable("ELEMENT_VALUE", ilUtil::prepareFormOutput($element));
235  $template->parseCurrentBlock();
236  }
237  $solutionvalue = join($this->object->getOrderingElements(), " ");
238  }
239 
240  if (($active_id > 0) && (!$show_correct_solution))
241  {
242  $reached_points = $this->object->getReachedPoints($active_id, $pass);
243  if ($graphicalOutput)
244  {
245  // output of ok/not ok icons for user entered solutions
246  if ($reached_points == $this->object->getMaximumPoints())
247  {
248  $template->setCurrentBlock("icon_ok");
249  $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.png"));
250  $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
251  $template->parseCurrentBlock();
252  }
253  else
254  {
255  $template->setCurrentBlock("icon_ok");
256  if ($reached_points > 0)
257  {
258  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_mostly_ok.png"));
259  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_not_correct_but_positive"));
260  }
261  else
262  {
263  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.png"));
264  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
265  }
266  $template->parseCurrentBlock();
267  }
268  }
269  }
270  else
271  {
272  $reached_points = $this->object->getPoints();
273  }
274 
275  if ($result_output)
276  {
277  $resulttext = ($reached_points == 1) ? "(%s " . $this->lng->txt("point") . ")" : "(%s " . $this->lng->txt("points") . ")";
278  $template->setVariable("RESULT_OUTPUT", sprintf($resulttext, $reached_points));
279  }
280  if($show_question_text==true)
281  {
282  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), TRUE));
283  }
284 // $template->setVariable("SOLUTION_TEXT", ilUtil::prepareFormOutput($solutionvalue));
285  if ($this->object->textsize >= 10) echo $template->setVariable("STYLE", " style=\"font-size: " . $this->object->textsize . "%;\"");
286 
287  $questionoutput = $template->get();
288  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
289  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
290  $solutionoutput = $solutiontemplate->get();
291  if (!$show_question_only)
292  {
293  // get page object output
294  $solutionoutput = '<div class="ilc_question_Standard">'.$solutionoutput."</div>";
295  }
296  return $solutionoutput;
297  }
298 
299  function getPreview($show_question_only = FALSE)
300  {
301  $template = new ilTemplate("tpl.il_as_qpl_orderinghorizontal_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
302  $elements = $this->object->getRandomOrderingElements();
303  foreach ($elements as $id => $element)
304  {
305  $template->setCurrentBlock("element");
306  $template->setVariable("ELEMENT_ID", "e$id");
307  $template->setVariable("ELEMENT_VALUE", ilUtil::prepareFormOutput($element));
308  $template->parseCurrentBlock();
309  }
310  if ($this->object->textsize >= 10) echo $template->setVariable("STYLE", " style=\"font-size: " . $this->object->textsize . "%;\"");
311  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), TRUE));
312  $questionoutput = $template->get();
313  if (!$show_question_only)
314  {
315  // get page object output
316  $questionoutput = $this->getILIASPage($questionoutput);
317  }
318  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
320  $this->tpl->addJavascript("./Modules/TestQuestionPool/templates/default/orderinghorizontal.js");
321  return $questionoutput;
322  }
323 
324  function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
325  {
326  // generate the question output
327  $template = new ilTemplate("tpl.il_as_qpl_orderinghorizontal_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
328  $elements = $this->object->getRandomOrderingElements();
329 
330  if ($active_id)
331  {
332  $solutions = NULL;
333  include_once "./Modules/Test/classes/class.ilObjTest.php";
334  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
335  {
336  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
337  }
338  $solutions =& $this->object->getSolutionValues($active_id, $pass);
339  if (count($solutions) == 1)
340  {
341  $elements = split("{::}", $solutions[0]["value1"]);
342  }
343  }
344  if (strlen($_SESSION['qst_selection']))
345  {
346  $this->object->moveRight($_SESSION['qst_selection'], $active_id, $pass);
347  unset($_SESSION['qst_selection']);
348  $solutions =& $this->object->getSolutionValues($active_id, $pass);
349  if (count($solutions) == 1)
350  {
351  $elements = split("{::}", $solutions[0]["value1"]);
352  }
353  }
354  if (count($solutions) == 0)
355  {
356  $_SESSION['qst_ordering_horizontal_elements'] = $elements;
357  }
358  else
359  {
360  unset($_SESSION['qst_ordering_horizontal_elements']);
361  }
362  $idx = 0;
363  foreach ($elements as $id => $element)
364  {
365  $template->setCurrentBlock("element");
366  $template->setVariable("ELEMENT_ID", "e_" . $this->object->getId() . "_$id");
367  $template->setVariable("ELEMENT_VALUE", ilUtil::prepareFormOutput($element));
368  $this->ctrl->setParameterByClass('iltestoutputgui', 'qst_selection', $idx);
369  $idx++;
370  $url = $this->ctrl->getLinkTargetByClass('iltestoutputgui', 'gotoQuestion');
371  $template->setVariable("MOVE_RIGHT", $url);
372  $template->setVariable("TEXT_MOVE_RIGHT", $this->lng->txt('move_right'));
373  $template->setVariable("RIGHT_IMAGE", ilUtil::getImagePath('nav_arr_R.png'));
374  $template->parseCurrentBlock();
375  }
376  if ($this->object->textsize >= 10) echo $template->setVariable("STYLE", " style=\"font-size: " . $this->object->textsize . "%;\"");
377  $template->setVariable("VALUE_ORDERRESULT", ' value="' . join($elements, '{::}') . '"');
378  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), TRUE));
379  $questionoutput = $template->get();
380  if (!$show_question_only)
381  {
382  // get page object output
383  $questionoutput = $this->getILIASPage($questionoutput);
384  }
385  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
387  $this->tpl->addJavascript("./Modules/TestQuestionPool/templates/default/orderinghorizontal.js");
388  $questionoutput = $template->get();
389  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
390  return $pageoutput;
391  }
392 
398  function saveFeedback()
399  {
400  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
401  $errors = $this->feedback(true);
402  $this->object->saveFeedbackGeneric(0, $_POST["feedback_incomplete"]);
403  $this->object->saveFeedbackGeneric(1, $_POST["feedback_complete"]);
404  $this->object->cleanupMediaObjectUsage();
406  }
407 
415  function setQuestionTabs()
416  {
417  global $rbacsystem, $ilTabs;
418 
419  $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]);
420  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
421  $q_type = $this->object->getQuestionType();
422 
423  if (strlen($q_type))
424  {
425  $classname = $q_type . "GUI";
426  $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
427  $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
428  }
429 
430  if ($_GET["q_id"])
431  {
432  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
433  {
434  // edit page
435  $ilTabs->addTarget("edit_page",
436  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "edit"),
437  array("edit", "insert", "exec_pg"),
438  "", "", $force_active);
439  }
440 
441  // edit page
442  $ilTabs->addTarget("preview",
443  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "preview"),
444  array("preview"),
445  "ilPageObjectGUI", "", $force_active);
446  }
447 
448  $force_active = false;
449  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
450  {
451  $url = "";
452  if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
453  $commands = $_POST["cmd"];
454  if (is_array($commands))
455  {
456  foreach ($commands as $key => $value)
457  {
458  if (preg_match("/^suggestrange_.*/", $key, $matches))
459  {
460  $force_active = true;
461  }
462  }
463  }
464  // edit question properties
465  $ilTabs->addTarget("edit_question",
466  $url,
467  array("editQuestion", "save", "saveEdit", "originalSyncForm"),
468  $classname, "", $force_active);
469  }
470 
471  if ($_GET["q_id"])
472  {
473  $ilTabs->addTarget("feedback",
474  $this->ctrl->getLinkTargetByClass($classname, "feedback"),
475  array("feedback", "saveFeedback"),
476  $classname, "");
477  }
478 
479  // add tab for question hint within common class assQuestionGUI
480  $this->addTab_QuestionHints($ilTabs);
481 
482  if ($_GET["q_id"])
483  {
484  $ilTabs->addTarget("solution_hint",
485  $this->ctrl->getLinkTargetByClass($classname, "suggestedsolution"),
486  array("suggestedsolution", "saveSuggestedSolution", "outSolutionExplorer", "cancel",
487  "addSuggestedSolution","cancelExplorer", "linkChilds", "removeSuggestedSolution"
488  ),
489  $classname,
490  ""
491  );
492  }
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  if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
504  {
505  $ref_id = $_GET["calling_test"];
506  if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
507 
508  global $___test_express_mode;
509 
510  if (!$_GET['test_express_mode'] && !$___test_express_mode) {
511  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
512  }
513  else {
515  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), $link);
516  }
517  }
518  else
519  {
520  $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
521  }
522  }
523 
524  function getSpecificFeedbackOutput($active_id, $pass)
525  {
526  $output = "";
527  return $this->object->prepareTextareaOutput($output, TRUE);
528  }
529 }