ILIAS  Release_3_10_x_branch Revision 61812
 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 {
48  $id = -1
49  )
50  {
51  $this->assQuestionGUI();
52  include_once "./Modules/TestQuestionPool/classes/class.assTextQuestion.php";
53  $this->object = new assTextQuestion();
54  if ($id >= 0)
55  {
56  $this->object->loadFromDb($id);
57  }
58  }
59 
65  function editQuestion()
66  {
67  $save = ((strcmp($this->ctrl->getCmd(), "save") == 0) || (strcmp($this->ctrl->getCmd(), "saveEdit") == 0) || (strcmp($this->ctrl->getCmd(), "addSuggestedSolution") == 0)) ? TRUE : FALSE;
68 
69  $this->tpl->addJavascript("./Services/JavaScript/js/Basic.js");
70  $this->getQuestionTemplate();
71 
72  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
73  $form = new ilPropertyFormGUI();
74  $form->setFormAction($this->ctrl->getFormAction($this));
75  $form->setTitle($this->lng->txt("assTextQuestion"));
76  $form->setMultipart(TRUE);
77  $form->setTableWidth("100%");
78  $form->setId("flash");
79 
80  // title
81  $title = new ilTextInputGUI($this->lng->txt("title"), "title");
82  $title->setValue($this->object->getTitle());
83  $title->setRequired(TRUE);
84  $form->addItem($title);
85  // author
86  $author = new ilTextInputGUI($this->lng->txt("author"), "author");
87  $author->setValue($this->object->getAuthor());
88  $author->setRequired(TRUE);
89  $form->addItem($author);
90  // description
91  $description = new ilTextInputGUI($this->lng->txt("description"), "comment");
92  $description->setValue($this->object->getComment());
93  $description->setRequired(FALSE);
94  $form->addItem($description);
95  // questiontext
96  $question = new ilTextAreaInputGUI($this->lng->txt("question"), "question");
97  $question->setValue($this->object->prepareTextareaOutput($this->object->getQuestion()));
98  $question->setRequired(TRUE);
99  $question->setRows(10);
100  $question->setCols(80);
101  $question->setUseRte(TRUE);
102  $question->addPlugin("latex");
103  $question->addButton("latex");
104  $question->setRTESupport($this->object->getId(), "qpl", "assessment");
105  $form->addItem($question);
106  // maxchars
107  $maxchars = new ilTextInputGUI($this->lng->txt("maxchars"), "maxchars");
108  $maxchars->setSize(5);
109  if ($this->object->getMaxNumOfChars() > 0) $maxchars->setValue($this->object->getMaxNumOfChars());
110  $maxchars->setInfo($this->lng->txt("description_maxchars"));
111  $form->addItem($maxchars);
112  // duration
113  $duration = new ilDurationInputGUI($this->lng->txt("working_time"), "Estimated");
114  $duration->setShowHours(TRUE);
115  $duration->setShowMinutes(TRUE);
116  $duration->setShowSeconds(TRUE);
117  $ewt = $this->object->getEstimatedWorkingTime();
118  $duration->setHours($ewt["h"]);
119  $duration->setMinutes($ewt["m"]);
120  $duration->setSeconds($ewt["s"]);
121  $duration->setRequired(FALSE);
122  $form->addItem($duration);
123  // suggested solution
124  include_once "./Modules/TestQuestionPool/classes/class.ilSuggestedSolutionSelectorGUI.php";
125  $solution = new ilSuggestedSolutionSelectorGUI($this->lng->txt("solution_hint"), "internalLinkType");
126  $internallinks = array(
127  "lm" => $this->lng->txt("obj_lm"),
128  "st" => $this->lng->txt("obj_st"),
129  "pg" => $this->lng->txt("obj_pg"),
130  "glo" => $this->lng->txt("glossary_term")
131  );
132  $solution->setOptions($internallinks);
133  $solution->setAddCommand("addSuggestedSolution");
134  $solution_array = $this->object->getSuggestedSolution(0);
135  if ($solution_array["internal_link"])
136  {
137  $solution->setInternalLink(assQuestion::_getInternalLinkHref($solution_array["internal_link"]));
138  $solution->setInternalLinkText($this->lng->txt("solution_hint"));
139  }
140  $form->addItem($solution);
141  // points
142  $points = new ilNumberInputGUI($this->lng->txt("points"), "points");
143  $points->setValue($this->object->getPoints());
144  $points->setRequired(TRUE);
145  $points->setSize(3);
146  $points->setMinValue(0.0);
147  $form->addItem($points);
148 
149  $header = new ilFormSectionHeaderGUI();
150  $header->setTitle($this->lng->txt("optional_keywords"));
151  $form->addItem($header);
152 
153  // keywords
154  $keywords = new ilTextAreaInputGUI($this->lng->txt("keywords"), "keywords");
155  $keywords->setValue(ilUtil::prepareFormOutput($this->object->getKeywords()));
156  $keywords->setRequired(FALSE);
157  $keywords->setInfo($this->lng->txt("keywords_hint"));
158  $keywords->setRows(10);
159  $keywords->setCols(40);
160  $keywords->setUseRte(FALSE);
161  $form->addItem($keywords);
162  // text rating
163  $textrating = new ilSelectInputGUI($this->lng->txt("text_rating"), "text_rating");
164  $text_options = array(
165  "ci" => $this->lng->txt("cloze_textgap_case_insensitive"),
166  "cs" => $this->lng->txt("cloze_textgap_case_sensitive"),
167  "l1" => sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "1"),
168  "l2" => sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "2"),
169  "l3" => sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "3"),
170  "l4" => sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "4"),
171  "l5" => sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "5")
172  );
173  $textrating->setOptions($text_options);
174  $textrating->setValue($this->object->getTextRating());
175  $form->addItem($textrating);
176  $form->addCommandButton("save", $this->lng->txt("save"));
177  $form->addCommandButton("saveEdit", $this->lng->txt("save_edit"));
178  $form->addCommandButton("cancel", $this->lng->txt("cancel"));
179  if ($save)
180  {
181  $form->checkInput();
182  }
183  $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
184  }
185 
189  function checkInput()
190  {
191  $cmd = $this->ctrl->getCmd();
192 
193  if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]) or (strlen($_POST["points"]) == 0))
194  {
195  return false;
196  }
197  return true;
198  }
199 
208  function writePostData()
209  {
210  $result = 0;
211  if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]) or (strlen($_POST["points"]) == 0))
212  {
213  $result = 1;
214  }
215 
216  $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
217  $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
218  $this->object->setComment(ilUtil::stripSlashes($_POST["comment"]));
219  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
220  $questiontext = ilUtil::stripSlashes($_POST["question"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment"));
221  $this->object->setQuestion($questiontext);
222  $this->object->setPoints($_POST["points"]);
223  if ($_POST["points"] < 0)
224  {
225  $result = 1;
226  $this->setErrorMessage($this->lng->txt("negative_points_not_allowed"));
227  }
228  $this->object->setSuggestedSolution($_POST["solution_hint"], 0);
229  $this->object->setMaxNumOfChars($_POST["maxchars"]);
230  $this->object->setKeywords(ilUtil::stripSlashes($_POST["keywords"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment")));
231  $this->object->setTextRating($_POST["text_rating"]);
232  $this->object->setEstimatedWorkingTime(
233  ilUtil::stripSlashes($_POST["Estimated"]["hh"]),
234  ilUtil::stripSlashes($_POST["Estimated"]["mm"]),
235  ilUtil::stripSlashes($_POST["Estimated"]["ss"])
236  );
237 
238  // Set the question id from a hidden form parameter
239  if ($_POST["text_question_id"] > 0)
240  {
241  $this->object->setId($_POST["text_question_id"]);
242  }
243 
244  return $result;
245  }
246 
248  {
249  if ($this->object->getMaxNumOfChars() > 0)
250  {
251  $this->tpl->addBlockFile("CONTENT_BLOCK", "charcounter", "tpl.charcounter.html", "Modules/TestQuestionPool");
252  $this->tpl->setCurrentBlock("charcounter");
253  $this->tpl->setVariable("MAXCHARS", $this->object->getMaxNumOfChars());
254  $this->tpl->parseCurrentBlock();
255  }
256  }
257 
258  function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE)
259  {
260  $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $use_post_solutions);
261  $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
262  $this->tpl->setVariable("FORMACTION", $formaction);
263  include_once "./Services/RTE/classes/class.ilRTE.php";
264  $rtestring = ilRTE::_getRTEClassname();
265  include_once "./Services/RTE/classes/class.$rtestring.php";
266  $rte = new $rtestring();
267  include_once "./classes/class.ilObject.php";
268  $obj_id = ilObject::_lookupObjectId($_GET["ref_id"]);
269  $obj_type = ilObject::_lookupType($_GET["ref_id"], TRUE);
270  $rte->addUserTextEditor("textinput");
271  $this->outAdditionalOutput();
272  }
273 
274  function getSolutionOutput($active_id, $pass = NULL, $graphicalOutput = FALSE, $result_output = FALSE, $show_question_only = TRUE, $show_feedback = FALSE, $show_correct_solution = FALSE)
275  {
276  // get the solution of the user for the active pass or from the last pass if allowed
277  $user_solution = "";
278  if (($active_id > 0) && (!$show_correct_solution))
279  {
280  $solutions =& $this->object->getSolutionValues($active_id, $pass);
281  foreach ($solutions as $idx => $solution_value)
282  {
283  $user_solution = $solution_value["value1"];
284  }
285  }
286  else
287  {
288  $keywords = $this->object->getKeywordList();
289  if (count($keywords))
290  {
291  $user_solution = $this->lng->txt("solution_may_contain_keywords") . ": " . join(",", $keywords);
292  }
293  }
294 
295  // generate the question output
296  include_once "./classes/class.ilTemplate.php";
297  $template = new ilTemplate("tpl.il_as_qpl_text_question_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
298  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
299  $template->setVariable("ESSAY", $this->object->prepareTextareaOutput($user_solution));
300  $questiontext = $this->object->getQuestion();
301  if (($active_id > 0) && (!$show_correct_solution))
302  {
303  if ($graphicalOutput)
304  {
305  // output of ok/not ok icons for user entered solutions
306  $reached_points = $this->object->getReachedPoints($active_id, $pass);
307  if ($reached_points == $this->object->getMaximumPoints())
308  {
309  $template->setCurrentBlock("icon_ok");
310  $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.gif"));
311  $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
312  $template->parseCurrentBlock();
313  }
314  else
315  {
316  $template->setCurrentBlock("icon_ok");
317  if ($reached_points > 0)
318  {
319  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_mostly_ok.gif"));
320  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_not_correct_but_positive"));
321  }
322  else
323  {
324  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.gif"));
325  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
326  }
327  $template->parseCurrentBlock();
328  }
329  }
330  }
331  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
332  $questionoutput = $template->get();
333  $feedback = ($show_feedback) ? $this->getAnswerFeedbackOutput($active_id, $pass) : "";
334  if (strlen($feedback)) $solutiontemplate->setVariable("FEEDBACK", $feedback);
335  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
336 
337  $solutionoutput = $solutiontemplate->get();
338  if (!$show_question_only)
339  {
340  // get page object output
341  $solutionoutput = $this->getILIASPage($solutionoutput);
342  }
343  return $solutionoutput;
344  }
345 
346  function getPreview($show_question_only = FALSE)
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  $questiontext = $this->object->getQuestion();
366  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
367  $questionoutput = $template->get();
368  if (!$show_question_only)
369  {
370  // get page object output
371  $questionoutput = $this->getILIASPage($questionoutput);
372  }
373  return $questionoutput;
374  }
375 
376  function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE)
377  {
378  // get the solution of the user for the active pass or from the last pass if allowed
379  $user_solution = "";
380  if ($active_id)
381  {
382  $solutions = NULL;
383  include_once "./Modules/Test/classes/class.ilObjTest.php";
384  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
385  {
386  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
387  }
388  $solutions =& $this->object->getSolutionValues($active_id, $pass);
389  foreach ($solutions as $idx => $solution_value)
390  {
391  $user_solution = $solution_value["value1"];
392  }
393  }
394 
395  // generate the question output
396  include_once "./classes/class.ilTemplate.php";
397  $template = new ilTemplate("tpl.il_as_qpl_text_question_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
398  if ($this->object->getMaxNumOfChars())
399  {
400  $template->setCurrentBlock("maximum_char_hint");
401  $template->setVariable("MAXIMUM_CHAR_HINT", sprintf($this->lng->txt("text_maximum_chars_allowed"), $this->object->getMaxNumOfChars()));
402  $template->parseCurrentBlock();
403  $template->setCurrentBlock("has_maxchars");
404  $template->setVariable("MAXCHARS", $this->object->getMaxNumOfChars());
405  $template->parseCurrentBlock();
406  $template->setCurrentBlock("maxchars_counter");
407  $template->setVariable("MAXCHARS", $this->object->getMaxNumOfChars());
408  $template->setVariable("TEXTBOXSIZE", strlen($this->object->getMaxNumOfChars()));
409  $template->setVariable("CHARACTERS", $this->lng->txt("characters"));
410  $template->parseCurrentBlock();
411  }
412  $template->setVariable("ESSAY", ilUtil::prepareFormOutput($user_solution));
413  $questiontext = $this->object->getQuestion();
414  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
415  $questionoutput = $template->get();
416  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
417  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
419  return $pageoutput;
420  }
421 
423  {
424  $_SESSION["subquestion_index"] = 0;
425  if ($_POST["cmd"]["addSuggestedSolution"])
426  {
427  if ($this->writePostData())
428  {
430  $this->editQuestion();
431  return;
432  }
433  if (!$this->checkInput())
434  {
435  ilUtil::sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
436  $this->editQuestion();
437  return;
438  }
439  }
440  $this->object->saveToDb();
441  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
442  $this->tpl->setVariable("HEADER", $this->object->getTitle());
443  $this->getQuestionTemplate();
445  }
446 
454  function saveFeedback()
455  {
456  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
457  $this->object->saveFeedbackGeneric(0, ilUtil::stripSlashes($_POST["feedback_incomplete"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment")));
458  $this->object->saveFeedbackGeneric(1, ilUtil::stripSlashes($_POST["feedback_complete"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment")));
459  $this->object->cleanupMediaObjectUsage();
461  }
462 
470  function feedback()
471  {
472  $this->tpl->addBlockFile("ADM_CONTENT", "feedback", "tpl.il_as_qpl_text_question_feedback.html", "Modules/TestQuestionPool");
473  $this->tpl->setVariable("FEEDBACK_TEXT", $this->lng->txt("feedback"));
474  $this->tpl->setVariable("FEEDBACK_COMPLETE", $this->lng->txt("feedback_complete_solution"));
475  $this->tpl->setVariable("VALUE_FEEDBACK_COMPLETE", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(1)), FALSE));
476  $this->tpl->setVariable("FEEDBACK_INCOMPLETE", $this->lng->txt("feedback_incomplete_solution"));
477  $this->tpl->setVariable("VALUE_FEEDBACK_INCOMPLETE", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(0)), FALSE));
478  global $rbacsystem;
479  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
480  {
481  $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
482  }
483  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
484 
485  include_once "./Services/RTE/classes/class.ilRTE.php";
486  $rtestring = ilRTE::_getRTEClassname();
487  include_once "./Services/RTE/classes/class.$rtestring.php";
488  $rte = new $rtestring();
489  $rte->addPlugin("latex");
490  $rte->addButton("latex"); $rte->addButton("pastelatex");
491  include_once "./classes/class.ilObject.php";
492  $obj_id = $_GET["q_id"];
493  $obj_type = ilObject::_lookupType($_GET["ref_id"], TRUE);
494  $rte->addRTESupport($obj_id, $obj_type, "assessment");
495  }
496 
504  function setQuestionTabs()
505  {
506  global $rbacsystem, $ilTabs;
507 
508  $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]);
509  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
510  $q_type = $this->object->getQuestionType();
511 
512  if (strlen($q_type))
513  {
514  $classname = $q_type . "GUI";
515  $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
516  $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
517  }
518 
519  if ($_GET["q_id"])
520  {
521  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
522  {
523  // edit page
524  $ilTabs->addTarget("edit_content",
525  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "edit"),
526  array("edit", "insert", "exec_pg"),
527  "", "", $force_active);
528  }
529 
530  // edit page
531  $ilTabs->addTarget("preview",
532  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "preview"),
533  array("preview"),
534  "ilPageObjectGUI", "", $force_active);
535  }
536 
537  $force_active = false;
538  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
539  {
540  $url = "";
541  if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
542  // edit question properties
543  $ilTabs->addTarget("edit_properties",
544  $url,
545  array("editQuestion", "save", "cancel", "addSuggestedSolution",
546  "cancelExplorer", "linkChilds", "removeSuggestedSolution",
547  "saveEdit"),
548  $classname, "", $force_active);
549  }
550 
551  if ($_GET["q_id"])
552  {
553  $ilTabs->addTarget("feedback",
554  $this->ctrl->getLinkTargetByClass($classname, "feedback"),
555  array("feedback", "saveFeedback"),
556  $classname, "");
557  }
558 
559  // Assessment of questions sub menu entry
560  if ($_GET["q_id"])
561  {
562  $ilTabs->addTarget("statistics",
563  $this->ctrl->getLinkTargetByClass($classname, "assessment"),
564  array("assessment"),
565  $classname, "");
566  }
567 
568  if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
569  {
570  $ref_id = $_GET["calling_test"];
571  if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
572  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
573  }
574  else
575  {
576  $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
577  }
578  }
579 }
580 ?>