ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.assQuestionGUI.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/Test/classes/inc.AssessmentConstants.php";
25 
37 {
45  var $object;
46 
47  var $tpl;
48  var $lng;
49  var $error;
51 
60 
68  function assQuestionGUI()
69  {
70  global $lng, $tpl, $ilCtrl;
71 
72 
73  $this->lng =& $lng;
74  $this->tpl =& $tpl;
75  $this->ctrl =& $ilCtrl;
76  $this->ctrl->saveParameter($this, "q_id");
77 
78  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
79  $this->errormessage = $this->lng->txt("fill_out_all_required_fields");
80  $this->object = new assQuestion();
81  }
82 
86  function &executeCommand()
87  {
88  $cmd = $this->ctrl->getCmd("editQuestion");
89  $next_class = $this->ctrl->getNextClass($this);
90 
91  $cmd = $this->getCommand($cmd);
92 
93  switch($next_class)
94  {
95  default:
96  $ret =& $this->$cmd();
97  break;
98  }
99  return $ret;
100  }
101 
102  function getCommand($cmd)
103  {
104  return $cmd;
105  }
106 
110  function getType()
111  {
112  return $this->getQuestionType();
113  }
114 
123  {
124  $est_working_time = $this->object->getEstimatedWorkingTime();
125  $this->tpl->setVariable("TEXT_WORKING_TIME", $this->lng->txt("working_time"));
126  $this->tpl->setVariable("TIME_FORMAT", $this->lng->txt("time_format"));
127  $this->tpl->setVariable("VALUE_WORKING_TIME", ilUtil::makeTimeSelect("Estimated", false, $est_working_time[h], $est_working_time[m], $est_working_time[s]));
128  }
129 
138  function writePostData()
139  {
140  }
141 
145  function assessment()
146  {
147  $this->tpl->addBlockFile("CONTENT", "content", "tpl.il_as_qpl_content.html", "Modules/TestQuestionPool");
148  $this->tpl->addBlockFile("STATUSLINE", "statusline", "tpl.statusline.html");
149 
150  // catch feedback message
152 
153  $total_of_answers = $this->object->getTotalAnswers();
154  $counter = 0;
155  $color_class = array("tblrow1", "tblrow2");
156  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_qpl_assessment_of_questions.html", "Modules/TestQuestionPool");
157  if (!$total_of_answers)
158  {
159  $this->tpl->setCurrentBlock("emptyrow");
160  $this->tpl->setVariable("TXT_NO_ASSESSMENT", $this->lng->txt("qpl_assessment_no_assessment_of_questions"));
161  $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
162  $this->tpl->parseCurrentBlock();
163  }
164  else
165  {
166  $this->tpl->setCurrentBlock("row");
167  $this->tpl->setVariable("TXT_RESULT", $this->lng->txt("qpl_assessment_total_of_answers"));
168  $this->tpl->setVariable("TXT_VALUE", $total_of_answers);
169  $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
170  $counter++;
171  $this->tpl->parseCurrentBlock();
172  $this->tpl->setCurrentBlock("row");
173  $this->tpl->setVariable("TXT_RESULT", $this->lng->txt("qpl_assessment_total_of_right_answers"));
174  $this->tpl->setVariable("TXT_VALUE", sprintf("%2.2f", $this->object->_getTotalRightAnswers($_GET["q_id"]) * 100.0) . " %");
175  $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
176  $this->tpl->parseCurrentBlock();
177  }
178 
179  $instances =& $this->object->getInstances();
180  $counter = 0;
181  foreach ($instances as $instance)
182  {
183  if (is_array($instance["refs"]))
184  {
185  foreach ($instance["refs"] as $ref_id)
186  {
187  $this->tpl->setCurrentBlock("references");
188  $this->tpl->setVariable("GOTO", "./goto.php?target=tst_" . $ref_id);
189  $this->tpl->setVariable("TEXT_GOTO", $this->lng->txt("perma_link"));
190  $this->tpl->parseCurrentBlock();
191  }
192  }
193  $this->tpl->setCurrentBlock("instance_row");
194  $this->tpl->setVariable("TEST_TITLE", $instance["title"]);
195  $this->tpl->setVariable("TEST_AUTHOR", $instance["author"]);
196  $this->tpl->setVariable("QUESTION_ID", $instance["question_id"]);
197  $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
198  $counter++;
199  $this->tpl->parseCurrentBlock();
200  }
201  $this->tpl->setCurrentBlock("instances");
202  $this->tpl->setVariable("TEXT_TEST_TITLE", $this->lng->txt("title"));
203  $this->tpl->setVariable("TEXT_TEST_AUTHOR", $this->lng->txt("author"));
204  $this->tpl->setVariable("TEXT_TEST_LOCATION", $this->lng->txt("location"));
205  $this->tpl->setVariable("INSTANCES_TITLE", $this->lng->txt("question_instances_title"));
206  $this->tpl->parseCurrentBlock();
207 
208  $this->tpl->setCurrentBlock("adm_content");
209  $this->tpl->setVariable("TXT_QUESTION_TITLE", $this->lng->txt("question_cumulated_statistics"));
210  $this->tpl->setVariable("TXT_RESULT", $this->lng->txt("result"));
211  $this->tpl->setVariable("TXT_VALUE", $this->lng->txt("value"));
212  $this->tpl->parseCurrentBlock();
213  }
214 
215 
225  {
226  $this->object->setEstimatedWorkingTime(
227  ilUtil::stripSlashes($_POST["Estimated"][h]),
228  ilUtil::stripSlashes($_POST["Estimated"][m]),
229  ilUtil::stripSlashes($_POST["Estimated"][s])
230  );
231 
232  $saved = false;
233  return $saved;
234  }
235 
247  function &_getQuestionGUI($question_type, $question_id = -1)
248  {
249  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
250  if ((!$question_type) and ($question_id > 0))
251  {
252  $question_type = assQuestion::getQuestionTypeFromDb($question_id);
253  }
254  if (strlen($question_type) == 0) return NULL;
255  $question_type_gui = $question_type . "GUI";
256  assQuestion::_includeClass($question_type, 1);
257  $question =& new $question_type_gui();
258  if ($question_id > 0)
259  {
260  $question->object->loadFromDb($question_id);
261  }
262  return $question;
263  }
264 
265  function _getGUIClassNameForId($a_q_id)
266  {
267  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
268  include_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
269  $q_type = assQuestion::getQuestionTypeFromDb($a_q_id);
270  $class_name = assQuestionGUI::_getClassNameForQType($q_type);
271  return $class_name;
272  }
273 
274  function _getClassNameForQType($q_type)
275  {
276  return $q_type . "GUI";
277  }
278 
289  function &createQuestionGUI($question_type, $question_id = -1)
290  {
291  include_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
292  $this->question =& assQuestionGUI::_getQuestionGUI($question_type, $question_id);
293  }
294 
299  {
300  $this->tpl->addBlockFile("CONTENT", "content", "tpl.il_as_qpl_content.html", "Modules/TestQuestionPool");
301  $this->tpl->addBlockFile("STATUSLINE", "statusline", "tpl.statusline.html");
302  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_question.html", "Modules/TestQuestionPool");
303  }
304 
313  function getILIASPage($html = "")
314  {
315  include_once("./Services/COPage/classes/class.ilPageObject.php");
316  include_once("./Services/COPage/classes/class.ilPageObjectGUI.php");
317  //$page =& new ilPageObject("qpl", $this->object->getId());
318  $page_gui =& new ilPageObjectGUI("qpl", $this->object->getId());
319  $page_gui->setTemplateTargetVar($a_temp_var);
320  $page_gui->setEnabledInternalLinks(false);
321  $page_gui->setQuestionHTML($html);
322  $page_gui->setFileDownloadLink("ilias.php?baseClass=ilObjTestGUI&cmd=downloadFile".
323  "&amp;ref_id=".$_GET["ref_id"]);
324  $page_gui->setFullscreenLink("ilias.php?baseClass=ilObjTestGUI&cmd=fullscreen".
325  "&amp;ref_id=".$_GET["ref_id"]);
326  $page_gui->setSourcecodeDownloadScript("ilias.php?baseClass=ilObjTestGUI&ref_id=".$_GET["ref_id"]);
327  $page_gui->setEnabledPageFocus(false);
328  $page_gui->setOutputMode("presentation");
329  $page_gui->setPresentationTitle("");
330  $presentation = $page_gui->presentation();
331  // bugfix for non XHTML conform img tags in ILIAS Learning Module Editor
332  $presentation = preg_replace("/src=\".\\//ims", "src=\"" . ILIAS_HTTP_PATH . "/", $presentation);
333  return $presentation;
334  }
335 
339  function outQuestionPage($a_temp_var, $a_postponed = false, $active_id = "", $html = "")
340  {
341  $postponed = "";
342  if ($a_postponed)
343  {
344  $postponed = " (" . $this->lng->txt("postponed") . ")";
345  }
346 
347  include_once("./Services/COPage/classes/class.ilPageObject.php");
348  include_once("./Services/COPage/classes/class.ilPageObjectGUI.php");
349  $this->lng->loadLanguageModule("content");
350  //$page =& new ilPageObject("qpl", $this->object->getId());
351  $page_gui =& new ilPageObjectGUI("qpl", $this->object->getId());
352  $page_gui->setTemplateTargetVar($a_temp_var);
353  $page_gui->setFileDownloadLink("ilias.php?baseClass=ilObjTestGUI&cmd=downloadFile".
354  "&amp;ref_id=".$_GET["ref_id"]);
355  $page_gui->setFullscreenLink("ilias.php?baseClass=ilObjTestGUI&cmd=fullscreen".
356  "&amp;ref_id=".$_GET["ref_id"]);
357  $page_gui->setEnabledPageFocus(false);
358  if (strlen($html))
359  {
360  $page_gui->setQuestionHTML($html);
361  }
362  $page_gui->setSourcecodeDownloadScript("ilias.php?baseClass=ilObjTestGUI&ref_id=".$_GET["ref_id"]);
363  $page_gui->setOutputMode("presentation");
364 
365  include_once "./Modules/Test/classes/class.ilObjTest.php";
366  $title_output = ilObjTest::_getTitleOutput($active_id);
367  switch ($title_output)
368  {
369  case 1:
370  $page_gui->setPresentationTitle(sprintf($this->lng->txt("tst_position"), $this->getSequenceNumber(), $this->getQuestionCount())." - ".$this->object->getTitle().$postponed);
371  break;
372  case 2:
373  $page_gui->setPresentationTitle(sprintf($this->lng->txt("tst_position"), $this->getSequenceNumber(), $this->getQuestionCount()).$postponed);
374  break;
375  case 0:
376  default:
377  $maxpoints = $this->object->getMaximumPoints();
378  if ($maxpoints == 1)
379  {
380  $maxpoints = " (".$maxpoints." ".$this->lng->txt("point").")";
381  }
382  else
383  {
384  $maxpoints = " (".$maxpoints." ".$this->lng->txt("points").")";
385  }
386  $page_gui->setPresentationTitle(sprintf($this->lng->txt("tst_position"), $this->getSequenceNumber(), $this->getQuestionCount())." - ".$this->object->getTitle().$postponed.$maxpoints);
387  break;
388  }
389  $presentation = $page_gui->presentation();
390  if (strlen($maxpoints)) $presentation = str_replace($maxpoints, "<em>$maxpoints</em>", $presentation);
391  // bugfix for non XHTML conform img tags in ILIAS Learning Module Editor
392  $presentation = preg_replace("/src=\".\\//ims", "src=\"" . ILIAS_HTTP_PATH . "/", $presentation);
393  return $presentation;
394  }
395 
399  function cancel()
400  {
401  if ($_GET["calling_test"])
402  {
403  $_GET["ref_id"] = $_GET["calling_test"];
404  ilUtil::redirect("ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=".$_GET["calling_test"]);
405  }
406  elseif ($_GET["test_ref_id"])
407  {
408  $_GET["ref_id"] = $_GET["test_ref_id"];
409  ilUtil::redirect("ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=".$_GET["test_ref_id"]);
410  }
411  else
412  {
413  if ($_GET["q_id"] > 0)
414  {
415  $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]);
416  $this->ctrl->redirectByClass("ilpageobjectgui", "edit");
417  }
418  else
419  {
420  $this->ctrl->redirectByClass("ilobjquestionpoolgui", "questions");
421  }
422  }
423  }
424 
425  function originalSyncForm($return_to = "")
426  {
427  if (strlen($return_to))
428  {
429  $this->ctrl->setParameter($this, "return_to", $return_to);
430  }
431  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_qpl_sync_original.html", "Modules/TestQuestionPool");
432  $this->tpl->setCurrentBlock("adm_content");
433  $this->tpl->setVariable("BUTTON_YES", $this->lng->txt("yes"));
434  $this->tpl->setVariable("BUTTON_NO", $this->lng->txt("no"));
435  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
436  $this->tpl->setVariable("TEXT_SYNC", $this->lng->txt("confirm_sync_questions"));
437  $this->tpl->parseCurrentBlock();
438  }
439 
440  function sync()
441  {
442  $original_id = $this->object->original_id;
443  if ($original_id)
444  {
445  $this->object->syncWithOriginal();
446  }
447  if (strlen($_GET["return_to"]))
448  {
449  $this->ctrl->redirect($this, $_GET["return_to"]);
450  }
451  else
452  {
453  $_GET["ref_id"] = $_GET["calling_test"];
454  ilUtil::redirect("ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=".$_GET["calling_test"]);
455  }
456  }
457 
458  function cancelSync()
459  {
460  if (strlen($_GET["return_to"]))
461  {
462  $this->ctrl->redirect($this, $_GET["return_to"]);
463  }
464  else
465  {
466  $_GET["ref_id"] = $_GET["calling_test"];
467  ilUtil::redirect("ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=".$_GET["calling_test"]);
468  }
469  }
470 
478  function saveFeedback()
479  {
480  global $ilUser;
481 
482  $originalexists = $this->object->_questionExists($this->object->original_id);
483  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
484  if ($_GET["calling_test"] && $originalexists && assQuestion::_isWriteable($this->object->original_id, $ilUser->getId()))
485  {
486  $this->originalSyncForm("feedback");
487  }
488  else
489  {
490  $this->feedback();
491  }
492  }
493 
497  function saveEdit()
498  {
499  global $ilUser;
500 
501  $result = $this->writePostData();
502  if ($result == 0)
503  {
504  $ilUser->setPref("tst_lastquestiontype", $this->object->getQuestionType());
505  $ilUser->writePref("tst_lastquestiontype", $this->object->getQuestionType());
506  $this->object->saveToDb();
507  $originalexists = $this->object->_questionExists($this->object->original_id);
508  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
509  if ($_GET["calling_test"] && $originalexists && assQuestion::_isWriteable($this->object->original_id, $ilUser->getId()))
510  {
511  $this->originalSyncForm();
512  }
513  elseif ($_GET["calling_test"])
514  {
515  $_GET["ref_id"] = $_GET["calling_test"];
516  ilUtil::redirect("ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=".$_GET["calling_test"]);
517  return;
518  }
519  elseif ($_GET["test_ref_id"])
520  {
521  include_once ("./Modules/Test/classes/class.ilObjTest.php");
522  $_GET["ref_id"] = $_GET["test_ref_id"];
523  $test =& new ilObjTest($_GET["test_ref_id"], true);
524  $test->insertQuestion($this->object->getId());
525  ilUtil::redirect("ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=".$_GET["test_ref_id"]);
526  }
527  else
528  {
529  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
530  $this->editQuestion();
531  if (strcmp($_SESSION["info"], "") != 0)
532  {
533  ilUtil::sendInfo($_SESSION["info"] . "<br />" . $this->lng->txt("msg_obj_modified"), false);
534  }
535  else
536  {
537  ilUtil::sendInfo($this->lng->txt("msg_obj_modified"), false);
538  }
539  $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $this->object->getId());
540  $this->ctrl->redirectByClass("ilpageobjectgui", "edit");
541  }
542  }
543  else
544  {
545  ilUtil::sendInfo($this->lng->txt("fill_out_all_required_fields"));
546  $this->editQuestion();
547  }
548  }
549 
553  function save()
554  {
555  global $ilUser;
556  $old_id = $_GET["q_id"];
557  $result = $this->writePostData();
558  if ($result == 0)
559  {
560  $ilUser->setPref("tst_lastquestiontype", $this->object->getQuestionType());
561  $ilUser->writePref("tst_lastquestiontype", $this->object->getQuestionType());
562  $this->object->saveToDb();
563  $originalexists = $this->object->_questionExists($this->object->original_id);
564  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
565  if ($_GET["calling_test"] && $originalexists && assQuestion::_isWriteable($this->object->original_id, $ilUser->getId()))
566  {
567  $this->originalSyncForm();
568  }
569  elseif ($_GET["calling_test"])
570  {
571  $_GET["ref_id"] = $_GET["calling_test"];
572  ilUtil::redirect("ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=".$_GET["calling_test"]);
573  return;
574  }
575  elseif ($_GET["test_ref_id"])
576  {
577  include_once ("./Modules/Test/classes/class.ilObjTest.php");
578  $_GET["ref_id"] = $_GET["test_ref_id"];
579  $test =& new ilObjTest($_GET["test_ref_id"], true);
580  $test->insertQuestion($this->object->getId());
581  ilUtil::redirect("ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=".$_GET["test_ref_id"]);
582  }
583  else
584  {
585  if ($this->object->getId() != $old_id)
586  {
587  // first save
588  $this->ctrl->setParameterByClass($_GET["cmdClass"], "q_id", $this->object->getId());
589  $this->ctrl->setParameterByClass($_GET["cmdClass"], "sel_question_types", $_GET["sel_question_types"]);
590  ilUtil::sendInfo($this->lng->txt("msg_obj_modified"), true);
591  $this->ctrl->redirectByClass($_GET["cmdClass"], "editQuestion");
592  }
593  if (strcmp($_SESSION["info"], "") != 0)
594  {
595  ilUtil::sendInfo($_SESSION["info"] . "<br />" . $this->lng->txt("msg_obj_modified"), false);
596  }
597  else
598  {
599  ilUtil::sendInfo($this->lng->txt("msg_obj_modified"), false);
600  }
601  $this->editQuestion();
602  // $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $this->object->getId());
603  // $this->ctrl->redirectByClass("ilpageobjectgui", "view");
604  }
605  }
606  else
607  {
609  $this->editQuestion();
610  }
611  }
612 
616  function apply()
617  {
618  $this->writePostData();
619  $this->object->saveToDb();
620  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
621  $this->editQuestion();
622  }
623 
624  function cancelExplorer()
625  {
626 // unset($_SESSION["subquestion_index"]);
627 // unset($_SESSION["link_new_type"]);
628  $this->ctrl->redirect($this, "editQuestion");
629 // $this->editQuestion();
630  }
631 
640  {
641  global $tree;
642 
643  include_once("./Modules/TestQuestionPool/classes/class.ilSolutionExplorer.php");
644  if (strlen($_POST["internalLinkType"]))
645  {
646  switch ($_POST["internalLinkType"])
647  {
648  case "lm":
649  $type = "lm";
650  $search = "lm";
651  // $_SESSION["link_new_type"] = "lm";
652  // $_SESSION["search_link_type"] = "lm";
653  break;
654  case "glo":
655  $type = "glo";
656  $search = "glo";
657  // $_SESSION["link_new_type"] = "glo";
658  // $_SESSION["search_link_type"] = "glo";
659  break;
660  case "st":
661  $type = "lm";
662  $search = "st";
663  // $_SESSION["link_new_type"] = "lm";
664  // $_SESSION["search_link_type"] = "st";
665  break;
666  case "pg":
667  $type = "lm";
668  $search = "pg";
669  // $_SESSION["link_new_type"] = "lm";
670  // $_SESSION["search_link_type"] = "pg";
671  break;
672  // default:
673  // if (!$_SESSION["link_new_type"])
674  // {
675  // $_SESSION["link_new_type"] = "lm";
676  // }
677  // break;
678  }
679  }
680  else
681  {
682  $type = $_GET["link_new_type"];
683  $search = $_GET["search_link_type"];
684  }
685  $this->ctrl->setParameter($this, "link_new_type", $type);
686  $this->ctrl->setParameter($this, "search_link_type", $search);
687  $this->ctrl->saveParameter($this, array("subquestion_index", "link_new_type", "search_link_type"));
688 
689  ilUtil::sendInfo($this->lng->txt("select_object_to_link"));
690 
691  $exp = new ilSolutionExplorer($this->ctrl->getLinkTarget($this,'addSuggestedSolution'), get_class($this));
692 
693  $exp->setExpand($_GET["expand"] ? $_GET["expand"] : $tree->readRootId());
694  $exp->setExpandTarget($this->ctrl->getLinkTarget($this,'addSuggestedSolution'));
695  $exp->setTargetGet("ref_id");
696  $exp->setRefId($this->cur_ref_id);
697 // $exp->addFilter($_SESSION["link_new_type"]);
698 // $exp->setSelectableType($_SESSION["link_new_type"]);
699  $exp->addFilter($type);
700  $exp->setSelectableType($type);
701 
702  // build html-output
703  $exp->setOutput(0);
704 
705  $this->tpl->addBlockFile("EXPLORER", "explorer", "tpl.il_as_qpl_explorer.html", "Modules/TestQuestionPool");
706  $this->tpl->setVariable("EXPLORER_TREE",$exp->getOutput());
707  $this->tpl->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
708  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
709  }
710 
712  {
713  $this->object->suggested_solutions = array();
714  $this->object->saveToDb();
715  $this->editQuestion();
716  }
717 
718  function addPG()
719  {
720  $subquestion_index = 0;
721  if (strlen($_GET["subquestion_index"]) && $_GET["subquestion_index"] >= 0)
722  {
723  $subquestion_index = $_GET["subquestion_index"];
724  }
725  $this->object->saveSuggestedSolution("il__pg_" . $_GET["pg"], $subquestion_index);
726 // unset($_GET["subquestion_index"]);
727 // unset($_GET["link_new_type"]);
728 // unset($_GET["search_link_type"]);
729  ilUtil::sendInfo($this->lng->txt("suggested_solution_added_successfully"), TRUE);
730  $this->ctrl->redirect($this, "editQuestion");
731 // $this->editQuestion();
732  }
733 
734  function addST()
735  {
736  $subquestion_index = 0;
737  if (strlen($_GET["subquestion_index"]) && $_GET["subquestion_index"] >= 0)
738  {
739  $subquestion_index = $_GET["subquestion_index"];
740  }
741  $this->object->saveSuggestedSolution("il__st_" . $_GET["st"], $subquestion_index);
742 // unset($_GET["subquestion_index"]);
743 // unset($_GET["link_new_type"]);
744 // unset($_GET["search_link_type"]);
745  ilUtil::sendInfo($this->lng->txt("suggested_solution_added_successfully"), TRUE);
746  $this->ctrl->redirect($this, "editQuestion");
747 // $this->editQuestion();
748  }
749 
750  function addGIT()
751  {
752  $subquestion_index = 0;
753  if (strlen($_GET["subquestion_index"]) && $_GET["subquestion_index"] >= 0)
754  {
755  $subquestion_index = $_GET["subquestion_index"];
756  }
757  $this->object->saveSuggestedSolution("il__git_" . $_GET["git"], $subquestion_index);
758 // unset($_GET["subquestion_index"]);
759 // unset($_GET["link_new_type"]);
760 // unset($_GET["search_link_type"]);
761  ilUtil::sendInfo($this->lng->txt("suggested_solution_added_successfully"), TRUE);
762  $this->ctrl->redirect($this, "editQuestion");
763 // $this->editQuestion();
764  }
765 
772  function getContextPath($cont_obj, $a_endnode_id, $a_startnode_id = 1)
773  {
774  $path = "";
775 
776  $tmpPath = $cont_obj->getLMTree()->getPathFull($a_endnode_id, $a_startnode_id);
777 
778  // count -1, to exclude the learning module itself
779  for ($i = 1; $i < (count($tmpPath) - 1); $i++)
780  {
781  if ($path != "")
782  {
783  $path .= " > ";
784  }
785 
786  $path .= $tmpPath[$i]["title"];
787  }
788 
789  return $path;
790  }
791 
792  function linkChilds()
793  {
794  $this->ctrl->saveParameter($this, array("subquestion_index", "link_new_type", "search_link_type"));
795  switch ($_GET["search_link_type"])
796  {
797  case "pg":
798  include_once "./Modules/LearningModule/classes/class.ilLMPageObject.php";
799  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
800  $cont_obj_gui =& new ilObjContentObjectGUI("", $_GET["source_id"], true);
801  $cont_obj = $cont_obj_gui->object;
802  $pages = ilLMPageObject::getPageList($cont_obj->getId());
803  $shownpages = array();
804  $tree = $cont_obj->getLMTree();
805  $chapters = $tree->getSubtree($tree->getNodeData($tree->getRootId()));
806  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
807  $this->tpl->setVariable("HEADER", $this->object->getTitle());
808  $this->getQuestionTemplate();
809  $color_class = array("tblrow1", "tblrow2");
810  $counter = 0;
811  $this->tpl->addBlockFile("LINK_SELECTION", "link_selection", "tpl.il_as_qpl_internallink_selection.html", "Modules/TestQuestionPool");
812  foreach ($chapters as $chapter)
813  {
814  $chapterpages = $tree->getChildsByType($chapter["obj_id"], "pg");
815  foreach ($chapterpages as $page)
816  {
817  if($page["type"] == $_GET["search_link_type"])
818  {
819  array_push($shownpages, $page["obj_id"]);
820  $this->tpl->setCurrentBlock("linktable_row");
821  $this->tpl->setVariable("TEXT_LINK", $page["title"]);
822  $this->tpl->setVariable("TEXT_ADD", $this->lng->txt("add"));
823  $this->tpl->setVariable("LINK_HREF", $this->ctrl->getLinkTargetByClass(get_class($this), "add" . strtoupper($page["type"])) . "&" . $page["type"] . "=" . $page["obj_id"]);
824  $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
825  if ($tree->isInTree($page["obj_id"]))
826  {
827  $path_str = $this->getContextPath($cont_obj, $page["obj_id"]);
828  }
829  else
830  {
831  $path_str = "---";
832  }
833  $this->tpl->setVariable("TEXT_DESCRIPTION", ilUtil::prepareFormOutput($path_str));
834  $this->tpl->parseCurrentBlock();
835  $counter++;
836  }
837  }
838  }
839  foreach ($pages as $page)
840  {
841  if (!in_array($page["obj_id"], $shownpages))
842  {
843  $this->tpl->setCurrentBlock("linktable_row");
844  $this->tpl->setVariable("TEXT_LINK", $page["title"]);
845  $this->tpl->setVariable("TEXT_ADD", $this->lng->txt("add"));
846  $this->tpl->setVariable("LINK_HREF", $this->ctrl->getLinkTargetByClass(get_class($this), "add" . strtoupper($page["type"])) . "&" . $page["type"] . "=" . $page["obj_id"]);
847  $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
848  $path_str = "---";
849  $this->tpl->setVariable("TEXT_DESCRIPTION", ilUtil::prepareFormOutput($path_str));
850  $this->tpl->parseCurrentBlock();
851  $counter++;
852  }
853  }
854  $this->tpl->setCurrentBlock("link_selection");
855  $this->tpl->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
856  $this->tpl->setVariable("TEXT_LINK_TYPE", $this->lng->txt("obj_" . $_GET["search_link_type"]));
857  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
858  $this->tpl->parseCurrentBlock();
859  break;
860  case "st":
861  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
862  $this->tpl->setVariable("HEADER", $this->object->getTitle());
863  $this->getQuestionTemplate();
864  $color_class = array("tblrow1", "tblrow2");
865  $counter = 0;
866  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
867  $cont_obj_gui =& new ilObjContentObjectGUI("", $_GET["source_id"], true);
868  $cont_obj = $cont_obj_gui->object;
869  // get all chapters
870  $ctree =& $cont_obj->getLMTree();
871  $nodes = $ctree->getSubtree($ctree->getNodeData($ctree->getRootId()));
872  $this->tpl->addBlockFile("LINK_SELECTION", "link_selection", "tpl.il_as_qpl_internallink_selection.html", "Modules/TestQuestionPool");
873  foreach($nodes as $node)
874  {
875  if($node["type"] == $_GET["search_link_type"])
876  {
877  $this->tpl->setCurrentBlock("linktable_row");
878  $this->tpl->setVariable("TEXT_LINK", $node["title"]);
879  $this->tpl->setVariable("TEXT_ADD", $this->lng->txt("add"));
880  $this->tpl->setVariable("LINK_HREF", $this->ctrl->getLinkTargetByClass(get_class($this), "add" . strtoupper($node["type"])) . "&" . $node["type"] . "=" . $node["obj_id"]);
881  $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
882  $this->tpl->parseCurrentBlock();
883  $counter++;
884  }
885  }
886  $this->tpl->setCurrentBlock("link_selection");
887  $this->tpl->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
888  $this->tpl->setVariable("TEXT_LINK_TYPE", $this->lng->txt("obj_" . $_GET["search_link_type"]));
889  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
890  $this->tpl->parseCurrentBlock();
891  break;
892  case "glo":
893  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
894  $this->tpl->setVariable("HEADER", $this->object->getTitle());
895  $this->getQuestionTemplate();
896  $color_class = array("tblrow1", "tblrow2");
897  $counter = 0;
898  $this->tpl->addBlockFile("LINK_SELECTION", "link_selection", "tpl.il_as_qpl_internallink_selection.html", "Modules/TestQuestionPool");
899  include_once "./Modules/Glossary/classes/class.ilObjGlossary.php";
900  $glossary =& new ilObjGlossary($_GET["source_id"], true);
901  // get all glossary items
902  $terms = $glossary->getTermList();
903  foreach($terms as $term)
904  {
905  $this->tpl->setCurrentBlock("linktable_row");
906  $this->tpl->setVariable("TEXT_LINK", $term["term"]);
907  $this->tpl->setVariable("TEXT_ADD", $this->lng->txt("add"));
908  $this->tpl->setVariable("LINK_HREF", $this->ctrl->getLinkTargetByClass(get_class($this), "addGIT") . "&git=" . $term["id"]);
909  $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
910  $this->tpl->parseCurrentBlock();
911  $counter++;
912  }
913  $this->tpl->setCurrentBlock("link_selection");
914  $this->tpl->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
915  $this->tpl->setVariable("TEXT_LINK_TYPE", $this->lng->txt("glossary_term"));
916  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
917  $this->tpl->parseCurrentBlock();
918  break;
919  case "lm":
920  $subquestion_index = 0;
921  if (strlen($_GET["subquestion_index"]) && $_GET["subquestion_index"] >= 0)
922  {
923  $subquestion_index = $_GET["subquestion_index"];
924  }
925  $this->object->saveSuggestedSolution("il__lm_" . $_GET["source_id"], $subquestion_index);
926 // unset($_GET["subquestion_index"]);
927 // unset($_GET["link_new_type"]);
928 // unset($_GET["search_link_type"]);
929  ilUtil::sendInfo($this->lng->txt("suggested_solution_added_successfully"), TRUE);
930  $this->ctrl->redirect($this, "editQuestion");
931 // $this->editQuestion();
932  break;
933  }
934  }
935 
936  function setSequenceNumber($nr)
937  {
938  $this->sequence_no = $nr;
939  }
940 
941  function getSequenceNumber()
942  {
943  return $this->sequence_no;
944  }
945 
946  function setQuestionCount($a_question_count)
947  {
948  $this->question_count = $a_question_count;
949  }
950 
951  function getQuestionCount()
952  {
953  return $this->question_count;
954  }
955 
956  function getErrorMessage()
957  {
958  return $this->errormessage;
959  }
960 
962  {
963  $this->errormessage = $errormessage;
964  }
965 
967  {
968  $this->errormessage .= ((strlen($this->errormessage)) ? "<br />" : "") . $errormessage;
969  }
970 
972  {
973  }
974 
983  function getQuestionType()
984  {
985  return $this->object->getQuestionType();
986  }
987 
995  public function getAsValueAttribute($a_value)
996  {
997  $result = "";
998  if (strlen($a_value))
999  {
1000  $result = " value=\"$a_value\" ";
1001  }
1002  return $result;
1003  }
1004 
1015  function getAnswerFeedbackOutput($active_id, $pass)
1016  {
1017  $output = "";
1018  include_once "./Modules/Test/classes/class.ilObjTest.php";
1019  $manual_feedback = ilObjTest::getManualFeedback($active_id, $this->object->getId(), $pass);
1020  if (strlen($manual_feedback))
1021  {
1022  return $manual_feedback;
1023  }
1024  $correct_feedback = $this->object->getFeedbackGeneric(1);
1025  $incorrect_feedback = $this->object->getFeedbackGeneric(0);
1026  if (strlen($correct_feedback.$incorrect_feedback))
1027  {
1028  $reached_points = $this->object->calculateReachedPoints($active_id, $pass);
1029  $max_points = $this->object->getMaximumPoints();
1030  if ($reached_points == $max_points)
1031  {
1032  $output = $correct_feedback;
1033  }
1034  else
1035  {
1036  $output = $incorrect_feedback;
1037  }
1038  }
1039  return $this->object->prepareTextareaOutput($output, TRUE);
1040  }
1041 
1049  function feedback()
1050  {
1051  // overwrite in parent classes
1052  }
1053 
1054  public function outQuestionType()
1055  {
1056  include_once "./classes/class.ilTemplate.php";
1057  $template = new ilTemplate("tpl.il_as_qpl_questiontype.html", TRUE, TRUE, "Modules/TestQuestionPool");
1058  $count = $this->object->isInUse();
1059  if ($count)
1060  {
1061  global $rbacsystem;
1062  if ($rbacsystem->checkAccess("write", $_GET["ref_id"]))
1063  {
1064  $template->setCurrentBlock("infosign");
1065  $template->setVariable("INFO_IMG_SRC", ilUtil::getImagePath("messagebox_tip.png"));
1066  $template->setVariable("INFO_IMG_ALT", sprintf($this->lng->txt("qpl_question_is_in_use"), $count));
1067  $template->setVariable("INFO_IMG_TITLE", sprintf($this->lng->txt("qpl_question_is_in_use"), $count));
1068  $template->parseCurrentBlock();
1069  }
1070  }
1071  $template->setVariable("TEXT_QUESTION_TYPE", assQuestion::_getQuestionTypeName($this->object->getQuestionType()));
1072  return $template->get();
1073  }
1074 }
1075 ?>