ILIAS  release_4-3 Revision
 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 
40 {
49  function __construct($id = -1)
50  {
52  include_once "./Modules/TestQuestionPool/classes/class.assNumeric.php";
53  $this->object = new assNumeric();
54  if ($id >= 0)
55  {
56  $this->object->loadFromDb($id);
57  }
58  }
59 
60  function getCommand($cmd)
61  {
62  if (substr($cmd, 0, 6) == "delete")
63  {
64  $cmd = "delete";
65  }
66 
67  return $cmd;
68  }
69 
76  function writePostData($always = false)
77  {
78  $hasErrors = (!$always) ? $this->editQuestion(true) : false;
79  if (!$hasErrors)
80  {
81  $this->object->setTitle($_POST["title"]);
82  $this->object->setAuthor($_POST["author"]);
83  $this->object->setComment($_POST["comment"]);
84  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
85  $questiontext = $_POST["question"];
86  $this->object->setQuestion($questiontext);
87  $this->object->setMaxChars($_POST["maxchars"]);
88  $this->object->setEstimatedWorkingTime(
89  $_POST["Estimated"]["hh"],
90  $_POST["Estimated"]["mm"],
91  $_POST["Estimated"]["ss"]
92  );
93  $this->object->setLowerLimit($_POST['lowerlimit']);
94  $this->object->setUpperLimit($_POST['upperlimit']);
95  $this->object->setPoints($_POST['points']);
96  return 0;
97  }
98  else
99  {
100  return 1;
101  }
102  }
103 
109  public function editQuestion($checkonly = FALSE)
110  {
111  $save = $this->isSaveCommand();
112  $this->getQuestionTemplate();
113 
114  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
115  $form = new ilPropertyFormGUI();
116  $form->setFormAction($this->ctrl->getFormAction($this));
117  $form->setTitle($this->outQuestionType());
118  $form->setMultipart(TRUE);
119  $form->setTableWidth("100%");
120  $form->setId("assnumeric");
121 
122  $this->addBasicQuestionFormProperties($form);
123 
124  // maxchars
125  $maxchars = new ilNumberInputGUI($this->lng->txt("maxchars"), "maxchars");
126  $maxchars->setSize(10);
127  $maxchars->setDecimals(0);
128  $maxchars->setMinValue(1);
129  $maxchars->setRequired(true);
130  if ($this->object->getMaxChars() > 0) $maxchars->setValue($this->object->getMaxChars());
131  $form->addItem($maxchars);
132 
133  // points
134  $points = new ilNumberInputGUI($this->lng->txt("points"), "points");
135  $points->setValue($this->object->getPoints() > 0 ? $this->object->getPoints() : '');
136  $points->setRequired(TRUE);
137  $points->setSize(3);
138  $points->setMinValue(0.0);
139  $points->setMinvalueShouldBeGreater(true);
140  $form->addItem($points);
141 
142  $header = new ilFormSectionHeaderGUI();
143  $header->setTitle($this->lng->txt("range"));
144  $form->addItem($header);
145 
146  // lower bound
147  $lower_limit = new ilFormulaInputGUI($this->lng->txt("range_lower_limit"), "lowerlimit");
148  $lower_limit->setSize(25);
149  $lower_limit->setMaxLength(20);
150  $lower_limit->setRequired(true);
151  $lower_limit->setValue($this->object->getLowerLimit());
152  $form->addItem($lower_limit);
153 
154  // upper bound
155  $upper_limit = new ilFormulaInputGUI($this->lng->txt("range_upper_limit"), "upperlimit");
156  $upper_limit->setSize(25);
157  $upper_limit->setMaxLength(20);
158  $upper_limit->setRequired(true);
159  $upper_limit->setValue($this->object->getUpperLimit());
160  $form->addItem($upper_limit);
161 
162  if( $this->object->getMaxChars() > 0 )
163  {
164  $lower_limit->setSize($this->object->getMaxChars());
165  $lower_limit->setMaxLength($this->object->getMaxChars());
166  $upper_limit->setSize($this->object->getMaxChars());
167  $upper_limit->setMaxLength($this->object->getMaxChars());
168  }
169 
170  $this->addQuestionFormCommandButtons($form);
171 
172  $errors = false;
173 
174  if ($save)
175  {
176  $form->setValuesByPost();
177  $errors = !$form->checkInput();
178  $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
179  if ($errors) $checkonly = false;
180  }
181 
182  if (!$checkonly) $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
183  return $errors;
184  }
185 
195  function checkRange()
196  {
197  include_once "./Services/Math/classes/class.EvalMath.php";
198  $eval = new EvalMath();
199  $eval->suppress_errors = TRUE;
200  if (($eval->e($_POST["rang_lower_limit"]) !== FALSE) AND ($eval->e($_POST ["range_upper_limit"]) !== FALSE))
201  {
202  if ($eval->e($_POST["rang_lower_limit"]) < $eval->e($_POST["range_upper_limit"]))
203  {
204  return TRUE;
205  }
206  else
207  {
208  return FALSE;
209  }
210  }
211  else
212  {
213  return FALSE;
214  }
215  }
216 
217  function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE)
218  {
219  $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $use_post_solutions);
220  $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
221  $this->tpl->setVariable("FORMACTION", $formaction);
222  }
223 
238  $active_id,
239  $pass = NULL,
240  $graphicalOutput = FALSE,
241  $result_output = FALSE,
242  $show_question_only = TRUE,
243  $show_feedback = FALSE,
244  $show_correct_solution = FALSE,
245  $show_manual_scoring = FALSE,
246  $show_question_text = TRUE
247  )
248  {
249  // get the solution of the user for the active pass or from the last pass if allowed
250  $solutions = array();
251  if (($active_id > 0) && (!$show_correct_solution))
252  {
253  $solutions =& $this->object->getSolutionValues($active_id, $pass);
254  }
255  else
256  {
257  array_push($solutions, array("value1" => sprintf($this->lng->txt("value_between_x_and_y"), $this->object->getLowerLimit(), $this->object->getUpperLimit())));
258  }
259 
260  // generate the question output
261  include_once "./Services/UICore/classes/class.ilTemplate.php";
262  $template = new ilTemplate("tpl.il_as_qpl_numeric_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
263  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
264  if (is_array($solutions))
265  {
266  if (($active_id > 0) && (!$show_correct_solution))
267  {
268  if ($graphicalOutput)
269  {
270  // output of ok/not ok icons for user entered solutions
271  if ($this->object->getReachedPoints($active_id, $pass) == $this->object->getMaximumPoints())
272  {
273  $template->setCurrentBlock("icon_ok");
274  $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.png"));
275  $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
276  $template->parseCurrentBlock();
277  }
278  else
279  {
280  $template->setCurrentBlock("icon_ok");
281  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.png"));
282  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
283  $template->parseCurrentBlock();
284  }
285  }
286  }
287  foreach ($solutions as $solution)
288  {
289  $template->setVariable("NUMERIC_VALUE", $solution["value1"]);
290  }
291  if (count($solutions) == 0)
292  {
293  $template->setVariable("NUMERIC_VALUE", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
294  }
295  }
296  $template->setVariable("NUMERIC_SIZE", $this->object->getMaxChars());
297  $questiontext = $this->object->getQuestion();
298  if ($show_question_text==true)
299  {
300  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
301  }
302  $questionoutput = $template->get();
303  $feedback = ($show_feedback) ? $this->getAnswerFeedbackOutput($active_id, $pass) : "";
304  if (strlen($feedback)) $solutiontemplate->setVariable("FEEDBACK", $this->object->prepareTextareaOutput( $feedback, true ));
305  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
306 
307  $solutionoutput = $solutiontemplate->get();
308  if (!$show_question_only)
309  {
310  // get page object output
311  $solutionoutput = '<div class="ilc_question_Standard">'.$solutionoutput."</div>";
312  }
313  return $solutionoutput;
314  }
315 
316  function getPreview($show_question_only = FALSE)
317  {
318  // generate the question output
319  include_once "./Services/UICore/classes/class.ilTemplate.php";
320  $template = new ilTemplate("tpl.il_as_qpl_numeric_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
321  $template->setVariable("NUMERIC_SIZE", $this->object->getMaxChars());
322  $questiontext = $this->object->getQuestion();
323  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
324  $questionoutput = $template->get();
325  if (!$show_question_only)
326  {
327  // get page object output
328  $questionoutput = $this->getILIASPage($questionoutput);
329  }
330  return $questionoutput;
331  }
332 
333  function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE)
334  {
335  // get the solution of the user for the active pass or from the last pass if allowed
336  if ($active_id)
337  {
338  $solutions = NULL;
339  include_once "./Modules/Test/classes/class.ilObjTest.php";
340  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
341  {
342  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
343  }
344  $solutions =& $this->object->getSolutionValues($active_id, $pass);
345  }
346 
347  // generate the question output
348  include_once "./Services/UICore/classes/class.ilTemplate.php";
349  $template = new ilTemplate("tpl.il_as_qpl_numeric_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
350  if (is_array($solutions))
351  {
352  foreach ($solutions as $solution)
353  {
354  $template->setVariable("NUMERIC_VALUE", " value=\"".$solution["value1"]."\"");
355  }
356  }
357  $template->setVariable("NUMERIC_SIZE", $this->object->getMaxChars());
358  $questiontext = $this->object->getQuestion();
359  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
360  $questionoutput = $template->get();
361  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
362  return $pageoutput;
363  }
364 
372  function saveFeedback()
373  {
374  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
375  $errors = $this->feedback(true);
376  $this->object->saveFeedbackGeneric(0, $_POST["feedback_incomplete"]);
377  $this->object->saveFeedbackGeneric(1, $_POST["feedback_complete"]);
378  $this->object->cleanupMediaObjectUsage();
380  }
381 
389  function setQuestionTabs()
390  {
391  global $rbacsystem, $ilTabs;
392 
393  $this->ctrl->setParameterByClass("ilpageobjectgui", "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  {
399  $classname = $q_type . "GUI";
400  $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
401  $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
402  }
403 
404  if ($_GET["q_id"])
405  {
406  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
407  {
408  // edit page
409  $ilTabs->addTarget("edit_page",
410  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "edit"),
411  array("edit", "insert", "exec_pg"),
412  "", "", $force_active);
413  }
414 
415  // edit page
416  $ilTabs->addTarget("preview",
417  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "preview"),
418  array("preview"),
419  "ilPageObjectGUI", "", $force_active);
420  }
421 
422  $force_active = false;
423  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
424  {
425  $url = "";
426  if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
427  // edit question properties
428  $ilTabs->addTarget("edit_question",
429  $url,
430  array("editQuestion", "save", "cancel", "saveEdit", "originalSyncForm"),
431  $classname, "", $force_active);
432  }
433 
434  if ($_GET["q_id"])
435  {
436  $ilTabs->addTarget("feedback",
437  $this->ctrl->getLinkTargetByClass($classname, "feedback"),
438  array("feedback", "saveFeedback"),
439  $classname, "");
440  }
441 
442  // add tab for question hint within common class assQuestionGUI
443  $this->addTab_QuestionHints($ilTabs);
444 
445  if ($_GET["q_id"])
446  {
447  $ilTabs->addTarget("solution_hint",
448  $this->ctrl->getLinkTargetByClass($classname, "suggestedsolution"),
449  array("suggestedsolution", "saveSuggestedSolution", "outSolutionExplorer", "cancel",
450  "addSuggestedSolution","cancelExplorer", "linkChilds", "removeSuggestedSolution"
451  ),
452  $classname,
453  ""
454  );
455  }
456 
457  // Assessment of questions sub menu entry
458  if ($_GET["q_id"])
459  {
460  $ilTabs->addTarget("statistics",
461  $this->ctrl->getLinkTargetByClass($classname, "assessment"),
462  array("assessment"),
463  $classname, "");
464  }
465 
466  if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
467  {
468  $ref_id = $_GET["calling_test"];
469  if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
470 
471  global $___test_express_mode;
472 
473  if (!$_GET['test_express_mode'] && !$___test_express_mode) {
474  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
475  }
476  else {
478  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), $link);
479  }
480  }
481  else
482  {
483  $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
484  }
485  }
486 
487  function getSpecificFeedbackOutput($active_id, $pass)
488  {
489  $output = "";
490  return $this->object->prepareTextareaOutput($output, TRUE);
491  }
492 }