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