ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.assNumericGUI.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 
39 {
48  function __construct($id = -1)
49  {
51  include_once "./Modules/TestQuestionPool/classes/class.assNumeric.php";
52  $this->object = new assNumeric();
53  if ($id >= 0)
54  {
55  $this->object->loadFromDb($id);
56  }
57  }
58 
59  function getCommand($cmd)
60  {
61  if (substr($cmd, 0, 6) == "delete")
62  {
63  $cmd = "delete";
64  }
65 
66  return $cmd;
67  }
68 
75  function writePostData($always = false)
76  {
77  $hasErrors = (!$always) ? $this->editQuestion(true) : false;
78  if (!$hasErrors)
79  {
80  $this->object->setTitle($_POST["title"]);
81  $this->object->setAuthor($_POST["author"]);
82  $this->object->setComment($_POST["comment"]);
83  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
84  $questiontext = $_POST["question"];
85  $this->object->setQuestion($questiontext);
86  $this->object->setMaxChars($_POST["maxchars"]);
87  $this->object->setEstimatedWorkingTime(
88  $_POST["Estimated"]["hh"],
89  $_POST["Estimated"]["mm"],
90  $_POST["Estimated"]["ss"]
91  );
92  $this->object->setLowerLimit($_POST['lowerlimit']);
93  $this->object->setUpperLimit($_POST['upperlimit']);
94  $this->object->setPoints($_POST['points']);
95  return 0;
96  }
97  else
98  {
99  return 1;
100  }
101  }
102 
108  public function editQuestion($checkonly = FALSE)
109  {
110  $save = ((strcmp($this->ctrl->getCmd(), "save") == 0) || (strcmp($this->ctrl->getCmd(), "saveEdit") == 0)) ? TRUE : FALSE;
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(TRUE);
118  $form->setTableWidth("100%");
119  $form->setId("assnumeric");
120 
121  $this->addBasicQuestionFormProperties($form);
122 
123  // maxchars
124  $maxchars = new ilNumberInputGUI($this->lng->txt("maxchars"), "maxchars");
125  $maxchars->setSize(10);
126  $maxchars->setDecimals(0);
127  $maxchars->setMinValue(1);
128  $maxchars->setRequired(true);
129  if ($this->object->getMaxChars() > 0) $maxchars->setValue($this->object->getMaxChars());
130  $form->addItem($maxchars);
131 
132  // points
133  $points = new ilNumberInputGUI($this->lng->txt("points"), "points");
134  $points->setValue($this->object->getPoints() > 0 ? $this->object->getPoints() : '');
135  $points->setRequired(TRUE);
136  $points->setSize(3);
137  $points->setMinValue(0.0);
138  $points->setMinvalueShouldBeGreater(true);
139  $form->addItem($points);
140 
141  $header = new ilFormSectionHeaderGUI();
142  $header->setTitle($this->lng->txt("range"));
143  $form->addItem($header);
144 
145  // lower bound
146  $lower_limit = new ilFormulaInputGUI($this->lng->txt("range_lower_limit"), "lowerlimit");
147  $lower_limit->setSize(25);
148  $lower_limit->setMaxLength(20);
149  $lower_limit->setRequired(true);
150  $lower_limit->setValue($this->object->getLowerLimit());
151  $form->addItem($lower_limit);
152 
153  // upper bound
154  $upper_limit = new ilFormulaInputGUI($this->lng->txt("range_upper_limit"), "upperlimit");
155  $upper_limit->setSize(25);
156  $upper_limit->setMaxLength(20);
157  $upper_limit->setRequired(true);
158  $upper_limit->setValue($this->object->getUpperLimit());
159  $form->addItem($upper_limit);
160 
161  $this->addQuestionFormCommandButtons($form);
162 
163  $errors = false;
164 
165  if ($save)
166  {
167  $form->setValuesByPost();
168  $errors = !$form->checkInput();
169  $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
170  if ($errors) $checkonly = false;
171  }
172 
173  if (!$checkonly) $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
174  return $errors;
175  }
176 
186  function checkRange()
187  {
188  include_once "./Services/Math/classes/class.EvalMath.php";
189  $eval = new EvalMath();
190  $eval->suppress_errors = TRUE;
191  if (($eval->e($_POST["rang_lower_limit"]) !== FALSE) AND ($eval->e($_POST ["range_upper_limit"]) !== FALSE))
192  {
193  if ($eval->e($_POST["rang_lower_limit"]) < $eval->e($_POST["range_upper_limit"]))
194  {
195  return TRUE;
196  }
197  else
198  {
199  return FALSE;
200  }
201  }
202  else
203  {
204  return FALSE;
205  }
206  }
207 
208  function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE)
209  {
210  $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $use_post_solutions);
211  $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
212  $this->tpl->setVariable("FORMACTION", $formaction);
213  }
214 
229  $active_id,
230  $pass = NULL,
231  $graphicalOutput = FALSE,
232  $result_output = FALSE,
233  $show_question_only = TRUE,
234  $show_feedback = FALSE,
235  $show_correct_solution = FALSE,
236  $show_manual_scoring = FALSE
237  )
238  {
239  // get the solution of the user for the active pass or from the last pass if allowed
240  $solutions = array();
241  if (($active_id > 0) && (!$show_correct_solution))
242  {
243  $solutions =& $this->object->getSolutionValues($active_id, $pass);
244  }
245  else
246  {
247  array_push($solutions, array("value1" => sprintf($this->lng->txt("value_between_x_and_y"), $this->object->getLowerLimit(), $this->object->getUpperLimit())));
248  }
249 
250  // generate the question output
251  include_once "./classes/class.ilTemplate.php";
252  $template = new ilTemplate("tpl.il_as_qpl_numeric_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
253  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
254  if (is_array($solutions))
255  {
256  if (($active_id > 0) && (!$show_correct_solution))
257  {
258  if ($graphicalOutput)
259  {
260  // output of ok/not ok icons for user entered solutions
261  if ($this->object->getReachedPoints($active_id, $pass) == $this->object->getMaximumPoints())
262  {
263  $template->setCurrentBlock("icon_ok");
264  $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.gif"));
265  $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
266  $template->parseCurrentBlock();
267  }
268  else
269  {
270  $template->setCurrentBlock("icon_ok");
271  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.gif"));
272  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
273  $template->parseCurrentBlock();
274  }
275  }
276  }
277  foreach ($solutions as $solution)
278  {
279  $template->setVariable("NUMERIC_VALUE", $solution["value1"]);
280  }
281  if (count($solutions) == 0)
282  {
283  $template->setVariable("NUMERIC_VALUE", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
284  }
285  }
286  $template->setVariable("NUMERIC_SIZE", $this->object->getMaxChars());
287  $questiontext = $this->object->getQuestion();
288  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
289  $questionoutput = $template->get();
290  $feedback = ($show_feedback) ? $this->getAnswerFeedbackOutput($active_id, $pass) : "";
291  if (strlen($feedback)) $solutiontemplate->setVariable("FEEDBACK", $feedback);
292  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
293 
294  $solutionoutput = $solutiontemplate->get();
295  if (!$show_question_only)
296  {
297  // get page object output
298  $solutionoutput = $this->getILIASPage($solutionoutput);
299  }
300  return $solutionoutput;
301  }
302 
303  function getPreview($show_question_only = FALSE)
304  {
305  // generate the question output
306  include_once "./classes/class.ilTemplate.php";
307  $template = new ilTemplate("tpl.il_as_qpl_numeric_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
308  $template->setVariable("NUMERIC_SIZE", $this->object->getMaxChars());
309  $questiontext = $this->object->getQuestion();
310  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
311  $questionoutput = $template->get();
312  if (!$show_question_only)
313  {
314  // get page object output
315  $questionoutput = $this->getILIASPage($questionoutput);
316  }
317  return $questionoutput;
318  }
319 
320  function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE)
321  {
322  // get the solution of the user for the active pass or from the last pass if allowed
323  if ($active_id)
324  {
325  $solutions = NULL;
326  include_once "./Modules/Test/classes/class.ilObjTest.php";
327  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
328  {
329  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
330  }
331  $solutions =& $this->object->getSolutionValues($active_id, $pass);
332  }
333 
334  // generate the question output
335  include_once "./classes/class.ilTemplate.php";
336  $template = new ilTemplate("tpl.il_as_qpl_numeric_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
337  if (is_array($solutions))
338  {
339  foreach ($solutions as $solution)
340  {
341  $template->setVariable("NUMERIC_VALUE", " value=\"".$solution["value1"]."\"");
342  }
343  }
344  $template->setVariable("NUMERIC_SIZE", $this->object->getMaxChars());
345  $questiontext = $this->object->getQuestion();
346  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
347  $questionoutput = $template->get();
348  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
349  return $pageoutput;
350  }
351 
359  function saveFeedback()
360  {
361  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
362  $errors = $this->feedback(true);
363  $this->object->saveFeedbackGeneric(0, $_POST["feedback_incomplete"]);
364  $this->object->saveFeedbackGeneric(1, $_POST["feedback_complete"]);
365  $this->object->cleanupMediaObjectUsage();
367  }
368 
374  function setQuestionTabs()
375  {
376  global $rbacsystem, $ilTabs;
377 
378  $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]);
379  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
380  $q_type = $this->object->getQuestionType();
381 
382  if (strlen($q_type))
383  {
384  $classname = $q_type . "GUI";
385  $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
386  $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
387  }
388 
389  if ($_GET["q_id"])
390  {
391  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
392  {
393  // edit page
394  $ilTabs->addTarget("edit_content",
395  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "edit"),
396  array("edit", "insert", "exec_pg"),
397  "", "", $force_active);
398  }
399 
400  // edit page
401  $ilTabs->addTarget("preview",
402  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "preview"),
403  array("preview"),
404  "ilPageObjectGUI", "", $force_active);
405  }
406 
407  $force_active = false;
408  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
409  {
410  $url = "";
411  if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
412  // edit question properties
413  $ilTabs->addTarget("edit_properties",
414  $url,
415  array("editQuestion", "save", "cancel", "saveEdit", "originalSyncForm"),
416  $classname, "", $force_active);
417  }
418 
419  if ($_GET["q_id"])
420  {
421  $ilTabs->addTarget("feedback",
422  $this->ctrl->getLinkTargetByClass($classname, "feedback"),
423  array("feedback", "saveFeedback"),
424  $classname, "");
425  }
426 
427  if ($_GET["q_id"])
428  {
429  $ilTabs->addTarget("solution_hint",
430  $this->ctrl->getLinkTargetByClass($classname, "suggestedsolution"),
431  array("suggestedsolution", "saveSuggestedSolution", "outSolutionExplorer", "cancel",
432  "addSuggestedSolution","cancelExplorer", "linkChilds", "removeSuggestedSolution"
433  ),
434  $classname,
435  ""
436  );
437  }
438 
439  // Assessment of questions sub menu entry
440  if ($_GET["q_id"])
441  {
442  $ilTabs->addTarget("statistics",
443  $this->ctrl->getLinkTargetByClass($classname, "assessment"),
444  array("assessment"),
445  $classname, "");
446  }
447 
448  if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
449  {
450  $ref_id = $_GET["calling_test"];
451  if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
452  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
453  }
454  else
455  {
456  $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
457  }
458  }
459 }
460 ?>