ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.assTextSubsetGUI.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.assTextSubset.php";
51  $this->object = new assTextSubset();
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  if ($this->getSelfAssessmentEditingMode())
78  {
79  $this->object->setNrOfTries($_POST['nr_of_tries']);
80  }
81 
82  // mbecker: fix for 8407
83  $this->object->setEstimatedWorkingTime(
84  $_POST["Estimated"]["hh"],
85  $_POST["Estimated"]["mm"],
86  $_POST["Estimated"]["ss"]
87  );
88  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
89  $questiontext = $_POST["question"];
90  $this->object->setQuestion($questiontext);
91  $this->object->setCorrectAnswers($_POST["correctanswers"]);
92  $this->object->setTextRating($_POST["text_rating"]);
93  // Delete all existing answers and create new answers from the form data
94  $this->object->flushAnswers();
95  foreach ($_POST['answers']['answer'] as $index => $answer)
96  {
97  $answertext = $answer;
98  $this->object->addAnswer($answertext, $_POST['answers']['points'][$index], $index);
99  }
100  return 0;
101  }
102  else
103  {
104  return 1;
105  }
106  }
107 
113  public function editQuestion($checkonly = FALSE)
114  {
115  $save = $this->isSaveCommand();
116  $this->getQuestionTemplate();
117 
118  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
119  $form = new ilPropertyFormGUI();
120  $form->setFormAction($this->ctrl->getFormAction($this));
121  $form->setTitle($this->outQuestionType());
122  $form->setMultipart(FALSE);
123  $form->setTableWidth("100%");
124  $form->setId("asstextsubset");
125 
126  $this->addBasicQuestionFormProperties($form);
127 
128  // number of requested answers
129  $correctanswers = new ilNumberInputGUI($this->lng->txt("nr_of_correct_answers"), "correctanswers");
130  $correctanswers->setMinValue(1);
131  $correctanswers->setDecimals(0);
132  $correctanswers->setSize(3);
133  $correctanswers->setValue($this->object->getCorrectAnswers());
134  $correctanswers->setRequired(true);
135  $form->addItem($correctanswers);
136 
137  // maximum available points
138  $points = new ilNumberInputGUI($this->lng->txt("maximum_points"), "points");
139  $points->setMinValue(0.25);
140  $points->setSize(6);
141  $points->setDisabled(true);
142  $points->setValue($this->object->getMaximumPoints());
143  $points->setRequired(false);
144  $form->addItem($points);
145 
146  // text rating
147  $textrating = new ilSelectInputGUI($this->lng->txt("text_rating"), "text_rating");
148  $text_options = array(
149  "ci" => $this->lng->txt("cloze_textgap_case_insensitive"),
150  "cs" => $this->lng->txt("cloze_textgap_case_sensitive")
151  );
152  if (!$this->getSelfAssessmentEditingMode())
153  {
154  $text_options["l1"] = sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "1");
155  $text_options["l2"] = sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "2");
156  $text_options["l3"] = sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "3");
157  $text_options["l4"] = sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "4");
158  $text_options["l5"] = sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "5");
159  }
160  $textrating->setOptions($text_options);
161  $textrating->setValue($this->object->getTextRating());
162  $form->addItem($textrating);
163 
164  // Choices
165  include_once "./Modules/TestQuestionPool/classes/class.ilAnswerWizardInputGUI.php";
166  $choices = new ilAnswerWizardInputGUI($this->lng->txt("answers"), "answers");
167  $choices->setRequired(true);
168  $choices->setQuestionObject($this->object);
169  $choices->setSingleline(true);
170  $choices->setAllowMove(false);
171  if ($this->object->getAnswerCount() == 0) $this->object->addAnswer("", 0, 0);
172  $choices->setValues($this->object->getAnswers());
173  $form->addItem($choices);
174 
175  $this->addQuestionFormCommandButtons($form);
176 
177  $errors = false;
178 
179  if ($save)
180  {
181  $form->setValuesByPost();
182  $points->setValue($this->object->getMaximumPoints());
183  $errors = !$form->checkInput();
184  $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
185  if ($errors) $checkonly = false;
186  }
187 
188  if (!$checkonly) $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
189  return $errors;
190  }
191 
195  public function addanswers()
196  {
197  $this->writePostData(true);
198  $position = key($_POST['cmd']['addanswers']);
199  $this->object->addAnswer("", 0, $position+1);
200  $this->editQuestion();
201  }
202 
206  public function removeanswers()
207  {
208  $this->writePostData(true);
209  $position = key($_POST['cmd']['removeanswers']);
210  $this->object->deleteAnswer($position);
211  $this->editQuestion();
212  }
213 
214  function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE)
215  {
216  $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $use_post_solutions);
217  $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
218  $this->tpl->setVariable("FORMACTION", $formaction);
219  }
220 
235  $active_id,
236  $pass = NULL,
237  $graphicalOutput = FALSE,
238  $result_output = FALSE,
239  $show_question_only = TRUE,
240  $show_feedback = FALSE,
241  $show_correct_solution = FALSE,
242  $show_manual_scoring = FALSE
243  )
244  {
245  // get the solution of the user for the active pass or from the last pass if allowed
246  $solutions = array();
247  if (($active_id > 0) && (!$show_correct_solution))
248  {
249  $solutions =& $this->object->getSolutionValues($active_id, $pass);
250  }
251  else
252  {
253  $rank = array();
254  foreach ($this->object->answers as $answer)
255  {
256  if ($answer->getPoints() > 0)
257  {
258  if (!is_array($rank[$answer->getPoints()]))
259  {
260  $rank[$answer->getPoints()] = array();
261  }
262  array_push($rank[$answer->getPoints()], $answer->getAnswertext());
263  }
264  }
265  krsort($rank, SORT_NUMERIC);
266  foreach ($rank as $index => $bestsolutions)
267  {
268  array_push($solutions, array("value1" => join(",", $bestsolutions), "points" => $index));
269  }
270  }
271 
272  // generate the question output
273  include_once "./classes/class.ilTemplate.php";
274  $template = new ilTemplate("tpl.il_as_qpl_textsubset_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
275  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
276  $available_answers =& $this->object->getAvailableAnswers();
277  for ($i = 0; $i < $this->object->getCorrectAnswers(); $i++)
278  {
279  if ((!$test_id) && (strcmp($solutions[$i]["value1"], "") == 0))
280  {
281  }
282  else
283  {
284  if (($active_id > 0) && (!$show_correct_solution))
285  {
286  if ($graphicalOutput)
287  {
288  // output of ok/not ok icons for user entered solutions
289  $index = $this->object->isAnswerCorrect($available_answers, $solutions[$i]["value1"]);
290  $correct = FALSE;
291  if ($index !== FALSE)
292  {
293  unset($available_answers[$index]);
294  $correct = TRUE;
295  }
296  if ($correct)
297  {
298  $template->setCurrentBlock("icon_ok");
299  $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.gif"));
300  $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
301  $template->parseCurrentBlock();
302  }
303  else
304  {
305  $template->setCurrentBlock("icon_ok");
306  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.gif"));
307  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
308  $template->parseCurrentBlock();
309  }
310  }
311  }
312  $template->setCurrentBlock("textsubset_row");
313  $template->setVariable("SOLUTION", $solutions[$i]["value1"]);
314  $template->setVariable("COUNTER", $i+1);
315  if ($result_output)
316  {
317  $points = $solutions[$i]["points"];
318  $resulttext = ($points == 1) ? "(%s " . $this->lng->txt("point") . ")" : "(%s " . $this->lng->txt("points") . ")";
319  $template->setVariable("RESULT_OUTPUT", sprintf($resulttext, $points));
320  }
321  $template->parseCurrentBlock();
322  }
323  }
324  $questiontext = $this->object->getQuestion();
325  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
326  $questionoutput = $template->get();
327  $feedback = ($show_feedback) ? $this->getAnswerFeedbackOutput($active_id, $pass) : "";
328  if (strlen($feedback)) $solutiontemplate->setVariable("FEEDBACK", $feedback);
329  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
330 
331  $solutionoutput = $solutiontemplate->get();
332  if (!$show_question_only)
333  {
334  // get page object output
335  $solutionoutput = $this->getILIASPage($solutionoutput);
336  }
337  return $solutionoutput;
338  }
339 
340  function getPreview($show_question_only = FALSE)
341  {
342  // generate the question output
343  include_once "./classes/class.ilTemplate.php";
344  $template = new ilTemplate("tpl.il_as_qpl_textsubset_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
345  $width = $this->object->getMaxTextboxWidth();
346  for ($i = 0; $i < $this->object->getCorrectAnswers(); $i++)
347  {
348  $template->setCurrentBlock("textsubset_row");
349  $template->setVariable("COUNTER", $i+1);
350  $template->setVariable("TEXTFIELD_ID", sprintf("%02d", $i+1));
351  $template->setVariable("TEXTFIELD_SIZE", $width);
352  $template->parseCurrentBlock();
353  }
354  $questiontext = $this->object->getQuestion();
355  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
356  $questionoutput = $template->get();
357  if (!$show_question_only)
358  {
359  // get page object output
360  $questionoutput = $this->getILIASPage($questionoutput);
361  }
362  return $questionoutput;
363  }
364 
365  function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE)
366  {
367  // get the solution of the user for the active pass or from the last pass if allowed
368  $user_solution = "";
369  if ($active_id)
370  {
371  $solutions = NULL;
372  include_once "./Modules/Test/classes/class.ilObjTest.php";
373  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
374  {
375  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
376  }
377  $solutions =& $this->object->getSolutionValues($active_id, $pass);
378  }
379 
380  // generate the question output
381  include_once "./classes/class.ilTemplate.php";
382  $template = new ilTemplate("tpl.il_as_qpl_textsubset_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
383  $width = $this->object->getMaxTextboxWidth();
384  for ($i = 0; $i < $this->object->getCorrectAnswers(); $i++)
385  {
386  $template->setCurrentBlock("textsubset_row");
387  foreach ($solutions as $idx => $solution_value)
388  {
389  if ($idx == $i)
390  {
391  $template->setVariable("TEXTFIELD_VALUE", " value=\"" . $solution_value["value1"]."\"");
392  }
393  }
394  $template->setVariable("COUNTER", $i+1);
395  $template->setVariable("TEXTFIELD_ID", sprintf("%02d", $i+1));
396  $template->setVariable("TEXTFIELD_SIZE", $width);
397  $template->parseCurrentBlock();
398  }
399  $questiontext = $this->object->getQuestion();
400  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
401  $questionoutput = $template->get();
402  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
403  return $pageoutput;
404  }
405 
411  function saveFeedback()
412  {
413  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
414  $errors = $this->feedback(true);
415  $this->object->saveFeedbackGeneric(0, $_POST["feedback_incomplete"]);
416  $this->object->saveFeedbackGeneric(1, $_POST["feedback_complete"]);
417  $this->object->cleanupMediaObjectUsage();
419  }
420 
426  function setQuestionTabs()
427  {
428  global $rbacsystem, $ilTabs;
429 
430  $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]);
431  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
432  $q_type = $this->object->getQuestionType();
433 
434  if (strlen($q_type))
435  {
436  $classname = $q_type . "GUI";
437  $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
438  $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
439  }
440 
441  if ($_GET["q_id"])
442  {
443  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
444  {
445  // edit page
446  $ilTabs->addTarget("edit_content",
447  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "edit"),
448  array("edit", "insert", "exec_pg"),
449  "", "", $force_active);
450  }
451 
452  // edit page
453  $ilTabs->addTarget("preview",
454  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "preview"),
455  array("preview"),
456  "ilPageObjectGUI", "", $force_active);
457  }
458 
459  $force_active = false;
460  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
461  {
462  $url = "";
463  if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
464  // edit question properties
465  $ilTabs->addTarget("edit_properties",
466  $url,
467  array("editQuestion", "save", "saveEdit", "addanswers", "removeanswers", "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  if ($_GET["q_id"])
480  {
481  $ilTabs->addTarget("solution_hint",
482  $this->ctrl->getLinkTargetByClass($classname, "suggestedsolution"),
483  array("suggestedsolution", "saveSuggestedSolution", "outSolutionExplorer", "cancel",
484  "addSuggestedSolution","cancelExplorer", "linkChilds", "removeSuggestedSolution"
485  ),
486  $classname,
487  ""
488  );
489  }
490 
491  // Assessment of questions sub menu entry
492  if ($_GET["q_id"])
493  {
494  $ilTabs->addTarget("statistics",
495  $this->ctrl->getLinkTargetByClass($classname, "assessment"),
496  array("assessment"),
497  $classname, "");
498  }
499 
500  if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
501  {
502  $ref_id = $_GET["calling_test"];
503  if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
504 
505  global $___test_express_mode;
506 
507  if (!$_GET['test_express_mode'] && !$___test_express_mode) {
508  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
509  }
510  else {
512  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), $link);
513  }
514  }
515  else
516  {
517  $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
518  }
519  }
520 }
521 ?>