ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.assTextQuestionGUI.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.assTextQuestion.php";
51  $this->object = new assTextQuestion();
52  if ($id >= 0)
53  {
54  $this->object->loadFromDb($id);
55  }
56  }
57 
64  function writePostData($always = false)
65  {
66  $hasErrors = (!$always) ? $this->editQuestion(true) : false;
67  if (!$hasErrors)
68  {
69  $this->object->setTitle($_POST["title"]);
70  $this->object->setAuthor($_POST["author"]);
71  $this->object->setComment($_POST["comment"]);
72  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
73  $questiontext = $_POST["question"];
74  $this->object->setQuestion($questiontext);
75  $this->object->setPoints($_POST["points"]);
76  $this->object->setMaxNumOfChars($_POST["maxchars"]);
77  $this->object->setKeywords($_POST["keywords"]);
78  $this->object->setTextRating($_POST["text_rating"]);
79  if ($this->getSelfAssessmentEditingMode())
80  {
81  $this->object->setNrOfTries($_POST['nr_of_tries']);
82  }
83  $this->object->setEstimatedWorkingTime(
84  $_POST["Estimated"]["hh"],
85  $_POST["Estimated"]["mm"],
86  $_POST["Estimated"]["ss"]
87  );
88  return 0;
89  }
90  else
91  {
92  return 1;
93  }
94  }
95 
101  public function editQuestion($checkonly = FALSE)
102  {
103  $save = ((strcmp($this->ctrl->getCmd(), "save") == 0) || (strcmp($this->ctrl->getCmd(), "saveEdit") == 0)) ? TRUE : FALSE;
104  $this->getQuestionTemplate();
105 
106  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
107  $form = new ilPropertyFormGUI();
108  $form->setFormAction($this->ctrl->getFormAction($this));
109  $form->setTitle($this->outQuestionType());
110  $form->setMultipart(TRUE);
111  $form->setTableWidth("100%");
112  $form->setId("asstextquestion");
113 
114  // title, author, description, question, working time (assessment mode)
115  $this->addBasicQuestionFormProperties($form);
116 
117  // maxchars
118  $maxchars = new ilNumberInputGUI($this->lng->txt("maxchars"), "maxchars");
119  $maxchars->setSize(5);
120  if ($this->object->getMaxNumOfChars() > 0) $maxchars->setValue($this->object->getMaxNumOfChars());
121  $maxchars->setInfo($this->lng->txt("description_maxchars"));
122  $form->addItem($maxchars);
123 
124  if (!$this->getSelfAssessmentEditingMode())
125  {
126  // points
127  $points = new ilNumberInputGUI($this->lng->txt("points"), "points");
128  $points->setValue($this->object->getPoints());
129  $points->setRequired(TRUE);
130  $points->setSize(3);
131  $points->setMinValue(0.0);
132  $form->addItem($points);
133 
134  $header = new ilFormSectionHeaderGUI();
135  $header->setTitle($this->lng->txt("optional_keywords"));
136  $form->addItem($header);
137 
138  // keywords
139  $keywords = new ilTextAreaInputGUI($this->lng->txt("keywords"), "keywords");
140  $keywords->setValue(ilUtil::prepareFormOutput($this->object->getKeywords()));
141  $keywords->setRequired(FALSE);
142  $keywords->setInfo($this->lng->txt("keywords_hint"));
143  $keywords->setRows(10);
144  $keywords->setCols(40);
145  $keywords->setUseRte(FALSE);
146  $form->addItem($keywords);
147  // text rating
148  $textrating = new ilSelectInputGUI($this->lng->txt("text_rating"), "text_rating");
149  $text_options = array(
150  "ci" => $this->lng->txt("cloze_textgap_case_insensitive"),
151  "cs" => $this->lng->txt("cloze_textgap_case_sensitive"),
152  "l1" => sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "1"),
153  "l2" => sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "2"),
154  "l3" => sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "3"),
155  "l4" => sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "4"),
156  "l5" => sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "5")
157  );
158  $textrating->setOptions($text_options);
159  $textrating->setValue($this->object->getTextRating());
160  $form->addItem($textrating);
161  }
162 
163  $this->addQuestionFormCommandButtons($form);
164  $errors = false;
165 
166  if ($save)
167  {
168  $form->setValuesByPost();
169  $errors = !$form->checkInput();
170  $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
171  if ($errors) $checkonly = false;
172  }
173 
174  if (!$checkonly) $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
175  return $errors;
176  }
177 
179  {
180  if ($this->object->getMaxNumOfChars() > 0)
181  {
182  $this->tpl->addBlockFile("CONTENT_BLOCK", "charcounter", "tpl.charcounter.html", "Modules/TestQuestionPool");
183  $this->tpl->setCurrentBlock("charcounter");
184  $this->tpl->setVariable("MAXCHARS", $this->object->getMaxNumOfChars());
185  $this->tpl->parseCurrentBlock();
186  }
187  }
188 
189  function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE)
190  {
191  $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $use_post_solutions);
192  $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
193  $this->tpl->setVariable("FORMACTION", $formaction);
194  include_once "./Services/RTE/classes/class.ilRTE.php";
195  $rtestring = ilRTE::_getRTEClassname();
196  include_once "./Services/RTE/classes/class.$rtestring.php";
197  $rte = new $rtestring();
198  include_once "./classes/class.ilObject.php";
199  $obj_id = ilObject::_lookupObjectId($_GET["ref_id"]);
200  $obj_type = ilObject::_lookupType($_GET["ref_id"], TRUE);
201  $rte->addUserTextEditor("textinput");
202  $this->outAdditionalOutput();
203  }
204 
219  $active_id,
220  $pass = NULL,
221  $graphicalOutput = FALSE,
222  $result_output = FALSE,
223  $show_question_only = TRUE,
224  $show_feedback = FALSE,
225  $show_correct_solution = FALSE,
226  $show_manual_scoring = FALSE
227  )
228  {
229  // get the solution of the user for the active pass or from the last pass if allowed
230  $user_solution = "";
231  if (($active_id > 0) && (!$show_correct_solution))
232  {
233  $solutions =& $this->object->getSolutionValues($active_id, $pass);
234  foreach ($solutions as $idx => $solution_value)
235  {
236  $user_solution = $solution_value["value1"];
237  }
238  }
239  else
240  {
241  $keywords = $this->object->getKeywordList();
242  if (count($keywords))
243  {
244  $user_solution = $this->lng->txt("solution_may_contain_keywords") . ": " . join(",", $keywords);
245  }
246  }
247 
248  // generate the question output
249  include_once "./classes/class.ilTemplate.php";
250  $template = new ilTemplate("tpl.il_as_qpl_text_question_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
251  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
252  $template->setVariable("ESSAY", $this->object->prepareTextareaOutput($user_solution));
253  $questiontext = $this->object->getQuestion();
254  if (($active_id > 0) && (!$show_correct_solution))
255  {
256  if ($graphicalOutput)
257  {
258  // output of ok/not ok icons for user entered solutions
259  $reached_points = $this->object->getReachedPoints($active_id, $pass);
260  if ($reached_points == $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  if ($reached_points > 0)
271  {
272  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_mostly_ok.gif"));
273  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_not_correct_but_positive"));
274  }
275  else
276  {
277  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.gif"));
278  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
279  }
280  $template->parseCurrentBlock();
281  }
282  }
283  }
284  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
285  $questionoutput = $template->get();
286  $feedback = ($show_feedback) ? $this->getAnswerFeedbackOutput($active_id, $pass) : "";
287  if (strlen($feedback)) $solutiontemplate->setVariable("FEEDBACK", $feedback);
288  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
289 
290  $solutionoutput = $solutiontemplate->get();
291  if (!$show_question_only)
292  {
293  // get page object output
294  $solutionoutput = $this->getILIASPage($solutionoutput);
295  }
296  return $solutionoutput;
297  }
298 
299  function getPreview($show_question_only = FALSE)
300  {
301  // generate the question output
302  include_once "./classes/class.ilTemplate.php";
303  $template = new ilTemplate("tpl.il_as_qpl_text_question_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
304  if ($this->object->getMaxNumOfChars())
305  {
306  $template->setCurrentBlock("maximum_char_hint");
307  $template->setVariable("MAXIMUM_CHAR_HINT", sprintf($this->lng->txt("text_maximum_chars_allowed"), $this->object->getMaxNumOfChars()));
308  $template->parseCurrentBlock();
309  $template->setCurrentBlock("has_maxchars");
310  $template->setVariable("MAXCHARS", $this->object->getMaxNumOfChars());
311  $template->parseCurrentBlock();
312  $template->setCurrentBlock("maxchars_counter");
313  $template->setVariable("MAXCHARS", $this->object->getMaxNumOfChars());
314  $template->setVariable("TEXTBOXSIZE", strlen($this->object->getMaxNumOfChars()));
315  $template->setVariable("CHARACTERS", $this->lng->txt("characters"));
316  $template->parseCurrentBlock();
317  }
318  $questiontext = $this->object->getQuestion();
319  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
320  $questionoutput = $template->get();
321  if (!$show_question_only)
322  {
323  // get page object output
324  $questionoutput = $this->getILIASPage($questionoutput);
325  }
326  return $questionoutput;
327  }
328 
329  function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE)
330  {
331  // get the solution of the user for the active pass or from the last pass if allowed
332  $user_solution = "";
333  if ($active_id)
334  {
335  $solutions = NULL;
336  include_once "./Modules/Test/classes/class.ilObjTest.php";
337  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
338  {
339  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
340  }
341  $solutions =& $this->object->getSolutionValues($active_id, $pass);
342  foreach ($solutions as $idx => $solution_value)
343  {
344  $user_solution = $solution_value["value1"];
345  }
346  }
347 
348  // generate the question output
349  include_once "./classes/class.ilTemplate.php";
350  $template = new ilTemplate("tpl.il_as_qpl_text_question_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
351  if ($this->object->getMaxNumOfChars())
352  {
353  $template->setCurrentBlock("maximum_char_hint");
354  $template->setVariable("MAXIMUM_CHAR_HINT", sprintf($this->lng->txt("text_maximum_chars_allowed"), $this->object->getMaxNumOfChars()));
355  $template->parseCurrentBlock();
356  $template->setCurrentBlock("has_maxchars");
357  $template->setVariable("MAXCHARS", $this->object->getMaxNumOfChars());
358  $template->parseCurrentBlock();
359  $template->setCurrentBlock("maxchars_counter");
360  $template->setVariable("MAXCHARS", $this->object->getMaxNumOfChars());
361  $template->setVariable("TEXTBOXSIZE", strlen($this->object->getMaxNumOfChars()));
362  $template->setVariable("CHARACTERS", $this->lng->txt("characters"));
363  $template->parseCurrentBlock();
364  }
365  $template->setVariable("ESSAY", ilUtil::prepareFormOutput($user_solution));
366  $questiontext = $this->object->getQuestion();
367  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
368  $questionoutput = $template->get();
369  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
370  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
372  return $pageoutput;
373  }
374 
376  {
377  $_SESSION["subquestion_index"] = 0;
378  if ($_POST["cmd"]["addSuggestedSolution"])
379  {
380  if ($this->writePostData())
381  {
383  $this->editQuestion();
384  return;
385  }
386  if (!$this->checkInput())
387  {
388  ilUtil::sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
389  $this->editQuestion();
390  return;
391  }
392  }
393  $this->object->saveToDb();
394  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
395  $this->tpl->setVariable("HEADER", $this->object->getTitle());
396  $this->getQuestionTemplate();
398  }
399 
405  function saveFeedback()
406  {
407  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
408  $errors = $this->feedback(true);
409  $this->object->saveFeedbackGeneric(0, $_POST["feedback_incomplete"]);
410  $this->object->saveFeedbackGeneric(1, $_POST["feedback_complete"]);
411  $this->object->cleanupMediaObjectUsage();
413  }
414 
420  function setQuestionTabs()
421  {
422  global $rbacsystem, $ilTabs;
423 
424  $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]);
425  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
426  $q_type = $this->object->getQuestionType();
427 
428  if (strlen($q_type))
429  {
430  $classname = $q_type . "GUI";
431  $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
432  $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
433  }
434 
435  if ($_GET["q_id"])
436  {
437  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
438  {
439  // edit page
440  $ilTabs->addTarget("edit_content",
441  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "edit"),
442  array("edit", "insert", "exec_pg"),
443  "", "", $force_active);
444  }
445 
446  // edit page
447  $ilTabs->addTarget("preview",
448  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "preview"),
449  array("preview"),
450  "ilPageObjectGUI", "", $force_active);
451  }
452 
453  $force_active = false;
454  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
455  {
456  $url = "";
457  if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
458  // edit question properties
459  $ilTabs->addTarget("edit_properties",
460  $url,
461  array("editQuestion", "save", "saveEdit", "originalSyncForm"),
462  $classname, "", $force_active);
463  }
464 
465  if ($_GET["q_id"])
466  {
467  $ilTabs->addTarget("feedback",
468  $this->ctrl->getLinkTargetByClass($classname, "feedback"),
469  array("feedback", "saveFeedback"),
470  $classname, "");
471  }
472 
473  if ($_GET["q_id"])
474  {
475  $ilTabs->addTarget("solution_hint",
476  $this->ctrl->getLinkTargetByClass($classname, "suggestedsolution"),
477  array("suggestedsolution", "saveSuggestedSolution", "outSolutionExplorer", "cancel",
478  "addSuggestedSolution","cancelExplorer", "linkChilds", "removeSuggestedSolution"
479  ),
480  $classname,
481  ""
482  );
483  }
484 
485  // Assessment of questions sub menu entry
486  if ($_GET["q_id"])
487  {
488  $ilTabs->addTarget("statistics",
489  $this->ctrl->getLinkTargetByClass($classname, "assessment"),
490  array("assessment"),
491  $classname, "");
492  }
493 
494  if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
495  {
496  $ref_id = $_GET["calling_test"];
497  if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
498  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
499  }
500  else
501  {
502  $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
503  }
504  }
505 }
506 ?>