ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.assQuestionGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once './Modules/Test/classes/inc.AssessmentConstants.php';
5 require_once 'Modules/Test/classes/class.ilTestExpressPage.php';
6 
19 abstract class assQuestionGUI
20 {
21  const FORM_MODE_EDIT = 'edit';
22  const FORM_MODE_ADJUST = 'adjust';
23 
31  var $object;
32 
33  var $tpl;
34  var $lng;
35  var $error;
37 
46 
47  private $taxonomyIds = array();
48 
49  private $targetGuiClass = null;
50 
54  function __construct()
55  {
56  global $lng, $tpl, $ilCtrl;
57 
58 
59  $this->lng =& $lng;
60  $this->tpl =& $tpl;
61  $this->ctrl =& $ilCtrl;
62  $this->ctrl->saveParameter($this, "q_id");
63  $this->ctrl->saveParameter($this, "prev_qid");
64  $this->ctrl->saveParameter($this, "calling_test");
65  $this->ctrl->saveParameterByClass('ilAssQuestionPageGUI', 'test_express_mode');
66  $this->ctrl->saveParameterByClass('ilobjquestionpoolgui', 'test_express_mode');
67 
68  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
69  $this->errormessage = $this->lng->txt("fill_out_all_required_fields");
70 
71  $this->selfassessmenteditingmode = false;
72  $this->new_id_listeners = array();
73  $this->new_id_listener_cnt = 0;
74  }
75 
79  function &executeCommand()
80  {
81  $cmd = $this->ctrl->getCmd("editQuestion");
82  $next_class = $this->ctrl->getNextClass($this);
83 
84  $cmd = $this->getCommand($cmd);
85 
86  switch($next_class)
87  {
88  default:
89  $ret =& $this->$cmd();
90  break;
91  }
92  return $ret;
93  }
94 
95  function getCommand($cmd)
96  {
97  return $cmd;
98  }
99 
103  function getType()
104  {
105  return $this->getQuestionType();
106  }
107 
108  public function setTaxonomyIds($taxonomyIds)
109  {
110  $this->taxonomyIds = $taxonomyIds;
111  }
112 
113  public function getTaxonomyIds()
114  {
115  return $this->taxonomyIds;
116  }
117 
118  public function setTargetGui(ilTestPlayerAbstractGUI $linkTargetGui)
119  {
120  $this->setTargetGuiClass( get_class($linkTargetGui) );
121  }
122 
124  {
125  $this->targetGuiClass = $targetGuiClass;
126  }
127 
128  public function getTargetGuiClass()
129  {
130  return $this->targetGuiClass;
131  }
132 
139  function writePostData()
140  {
141  }
142 
146  function assessment()
147  {
148  $this->tpl->addBlockFile("CONTENT", "content", "tpl.il_as_qpl_content.html", "Modules/TestQuestionPool");
149  $this->tpl->addBlockFile("STATUSLINE", "statusline", "tpl.statusline.html");
150 
151  $total_of_answers = $this->object->getTotalAnswers();
152  $counter = 0;
153  $color_class = array("tblrow1", "tblrow2");
154  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_qpl_assessment_of_questions.html", "Modules/TestQuestionPool");
155  if (!$total_of_answers)
156  {
157  $this->tpl->setCurrentBlock("emptyrow");
158  $this->tpl->setVariable("TXT_NO_ASSESSMENT", $this->lng->txt("qpl_assessment_no_assessment_of_questions"));
159  $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
160  $this->tpl->parseCurrentBlock();
161  }
162  else
163  {
164  $this->tpl->setCurrentBlock("row");
165  $this->tpl->setVariable("TXT_RESULT", $this->lng->txt("qpl_assessment_total_of_answers"));
166  $this->tpl->setVariable("TXT_VALUE", $total_of_answers);
167  $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
168  $counter++;
169  $this->tpl->parseCurrentBlock();
170  $this->tpl->setCurrentBlock("row");
171  $this->tpl->setVariable("TXT_RESULT", $this->lng->txt("qpl_assessment_total_of_right_answers"));
172  $this->tpl->setVariable("TXT_VALUE", sprintf("%2.2f", $this->object->_getTotalRightAnswers($_GET["q_id"]) * 100.0) . " %");
173  $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
174  $this->tpl->parseCurrentBlock();
175  }
176 
177  $instances =& $this->object->getInstances();
178  $counter = 0;
179  foreach ($instances as $instance)
180  {
181  if (is_array($instance["refs"]))
182  {
183  foreach ($instance["refs"] as $ref_id)
184  {
185  $this->tpl->setCurrentBlock("references");
186  $this->tpl->setVariable("GOTO", "./goto.php?target=tst_" . $ref_id);
187  $this->tpl->setVariable("TEXT_GOTO", $this->lng->txt("perma_link"));
188  $this->tpl->parseCurrentBlock();
189  }
190  }
191  $this->tpl->setCurrentBlock("instance_row");
192  $this->tpl->setVariable("TEST_TITLE", $instance["title"]);
193  $this->tpl->setVariable("TEST_AUTHOR", $instance["author"]);
194  $this->tpl->setVariable("QUESTION_ID", $instance["question_id"]);
195  $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
196  $counter++;
197  $this->tpl->parseCurrentBlock();
198  }
199  $this->tpl->setCurrentBlock("instances");
200  $this->tpl->setVariable("TEXT_TEST_TITLE", $this->lng->txt("title"));
201  $this->tpl->setVariable("TEXT_TEST_AUTHOR", $this->lng->txt("author"));
202  $this->tpl->setVariable("TEXT_TEST_LOCATION", $this->lng->txt("location"));
203  $this->tpl->setVariable("INSTANCES_TITLE", $this->lng->txt("question_instances_title"));
204  $this->tpl->parseCurrentBlock();
205 
206  $this->tpl->setCurrentBlock("adm_content");
207  $this->tpl->setVariable("TXT_QUESTION_TITLE", $this->lng->txt("question_cumulated_statistics"));
208  $this->tpl->setVariable("TXT_RESULT", $this->lng->txt("result"));
209  $this->tpl->setVariable("TXT_VALUE", $this->lng->txt("value"));
210  $this->tpl->parseCurrentBlock();
211  }
212 
222  public function &_getQuestionGUI($question_type, $question_id = -1)
223  {
224  global $ilCtrl, $ilDB, $lng;
225 
226  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
227 
228  if ((!$question_type) and ($question_id > 0))
229  {
230  $question_type = assQuestion::getQuestionTypeFromDb($question_id);
231  }
232 
233  if (strlen($question_type) == 0) return NULL;
234 
235  assQuestion::_includeClass($question_type, 1);
236 
237  $question_type_gui = assQuestion::getGuiClassNameByQuestionType($question_type);
238  $question =& new $question_type_gui();
239 
240  $feedbackObjectClassname = assQuestion::getFeedbackClassNameByQuestionType($question_type);
241  $question->object->feedbackOBJ = new $feedbackObjectClassname($question->object, $ilCtrl, $ilDB, $lng);
242 
243  if ($question_id > 0)
244  {
245  $question->object->loadFromDb($question_id);
246  }
247 
248  return $question;
249  }
250 
254  function _getGUIClassNameForId($a_q_id)
255  {
256  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
257  include_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
258  $q_type = assQuestion::getQuestionTypeFromDb($a_q_id);
259  $class_name = assQuestionGUI::_getClassNameForQType($q_type);
260  return $class_name;
261  }
262 
266  function _getClassNameForQType($q_type)
267  {
268  return $q_type . "GUI";
269  }
270 
283  function &createQuestionGUI($question_type, $question_id = -1)
284  {
285  include_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
286  $this->question =& assQuestionGUI::_getQuestionGUI($question_type, $question_id);
287  }
288 
293  {
294  $this->tpl->addBlockFile("CONTENT", "content", "tpl.il_as_qpl_content.html", "Modules/TestQuestionPool");
295  $this->tpl->addBlockFile("STATUSLINE", "statusline", "tpl.statusline.html");
296  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_question.html", "Modules/TestQuestionPool");
297  }
298 
305  function getILIASPage($html = "")
306  {
307  include_once("./Modules/TestQuestionPool/classes/class.ilAssQuestionPageGUI.php");
308  $page_gui = new ilAssQuestionPageGUI($this->object->getId());
309  $page_gui->setQuestionHTML(array($this->object->getId() => $html));
310  $page_gui->setOutputMode("presentation");
311  $presentation = $page_gui->presentation();
312  $presentation = preg_replace("/src=\"\\.\\//ims", "src=\"" . ILIAS_HTTP_PATH . "/", $presentation);
313  return $presentation;
314  }
315 
319  function outQuestionPage($a_temp_var, $a_postponed = false, $active_id = "", $html = "")
320  {
321  $postponed = "";
322  if ($a_postponed)
323  {
324  $postponed = " (" . $this->lng->txt("postponed") . ")";
325  }
326 
327  include_once("./Modules/TestQuestionPool/classes/class.ilAssQuestionPageGUI.php");
328  $this->lng->loadLanguageModule("content");
329  $page_gui = new ilAssQuestionPageGUI($this->object->getId());
330  $page_gui->setTemplateTargetVar($a_temp_var);
331  if (strlen($html))
332  {
333  $page_gui->setQuestionHTML(array($this->object->getId() => $html));
334  }
335  $page_gui->setOutputMode("presentation");
336 
337  include_once "./Modules/Test/classes/class.ilObjTest.php";
338  $title_output = ilObjTest::_getTitleOutput($active_id);
339 
340  if( $this->object->areObligationsToBeConsidered() && ilObjTest::isQuestionObligatory($this->object->getId()) )
341  {
342  $obligatoryString = '([-_-])';
343  }
344  else
345  {
346  $obligatoryString = '';
347  }
348 
349  switch ($title_output)
350  {
351  case 1:
352  $page_gui->setPresentationTitle(sprintf($this->lng->txt("tst_position"), $this->getSequenceNumber(), $this->getQuestionCount())." - ".$this->object->getTitle().$postponed . $obligatoryString);
353  break;
354  case 2:
355  $page_gui->setPresentationTitle(sprintf($this->lng->txt("tst_position"), $this->getSequenceNumber(), $this->getQuestionCount()).$postponed . $obligatoryString);
356  break;
357  case 0:
358  default:
359  $maxpoints = $this->object->getMaximumPoints();
360  if ($maxpoints == 1)
361  {
362  $maxpoints = " (".$maxpoints." ".$this->lng->txt("point").")";
363  }
364  else
365  {
366  $maxpoints = " (".$maxpoints." ".$this->lng->txt("points").")";
367  }
368  $page_gui->setPresentationTitle(sprintf($this->lng->txt("tst_position"), $this->getSequenceNumber(), $this->getQuestionCount())." - ".$this->object->getTitle().$postponed.$maxpoints . $obligatoryString);
369  break;
370  }
371  $presentation = $page_gui->presentation();
372  if (strlen($maxpoints)) $presentation = str_replace($maxpoints, "<em>$maxpoints</em>", $presentation);
373  if (strlen($obligatoryString))
374  {
375  $replacement ='<br><span class="obligatory" style="font-size:small">'.
376  $this->lng->txt("tst_you_have_to_answer_this_question").'</span>';
377  $presentation = str_replace($obligatoryString, $replacement, $presentation);
378  }
379  $presentation = preg_replace("/src=\"\\.\\//ims", "src=\"" . ILIAS_HTTP_PATH . "/", $presentation);
380  return $presentation;
381  }
382 
386  function cancel()
387  {
388  if ($_GET["calling_test"])
389  {
390  $_GET["ref_id"] = $_GET["calling_test"];
391  ilUtil::redirect("ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=".$_GET["calling_test"]);
392  }
393  elseif ($_GET["test_ref_id"])
394  {
395  $_GET["ref_id"] = $_GET["test_ref_id"];
396  ilUtil::redirect("ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=".$_GET["test_ref_id"]);
397  }
398  else
399  {
400  if ($_GET["q_id"] > 0)
401  {
402  $this->ctrl->setParameterByClass("ilAssQuestionPageGUI", "q_id", $_GET["q_id"]);
403  $this->ctrl->redirectByClass("ilAssQuestionPageGUI", "edit");
404  }
405  else
406  {
407  $this->ctrl->redirectByClass("ilobjquestionpoolgui", "questions");
408  }
409  }
410  }
411 
416  function originalSyncForm($return_to = "", $return_to_feedback = '')
417  {
418  if (strlen($return_to))
419  {
420  $this->ctrl->setParameter($this, "return_to", $return_to);
421  }
422  else if ($_REQUEST['return_to']) {
423  $this->ctrl->setParameter($this, "return_to", $_REQUEST['return_to']);
424  }
425  if(strlen($return_to_feedback))
426  {
427  $this->ctrl->setParameter($this, 'return_to_fb', 'true');
428  }
429 
430  $template = new ilTemplate("tpl.il_as_qpl_sync_original.html",TRUE, TRUE, "Modules/TestQuestionPool");
431  $template->setVariable("BUTTON_YES", $this->lng->txt("yes"));
432  $template->setVariable("BUTTON_NO", $this->lng->txt("no"));
433  $template->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
434  $template->setVariable("TEXT_SYNC", $this->lng->txt("confirm_sync_questions"));
435  $this->tpl->setVariable("ADM_CONTENT", $template->get());
436  }
437 
438  function sync()
439  {
440  $original_id = $this->object->original_id;
441  if ($original_id)
442  {
443  $this->object->syncWithOriginal();
444  }
445  if (strlen($_GET["return_to"]))
446  {
447  $this->ctrl->redirect($this, $_GET["return_to"]);
448  }
449  if (strlen($_REQUEST["return_to_fb"]))
450  {
451  $this->ctrl->redirectByClass('ilAssQuestionFeedbackEditingGUI', 'show');
452  }
453  else
454  {
455  $_GET["ref_id"] = $_GET["calling_test"];
456  ilUtil::redirect("ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=".$_GET["calling_test"]);
457  }
458  }
459 
460  function cancelSync()
461  {
462  if (strlen($_GET["return_to"]))
463  {
464  $this->ctrl->redirect($this, $_GET["return_to"]);
465  }
466  if(strlen($_REQUEST['return_to_fb']))
467  {
468  $this->ctrl->redirectByClass('ilAssQuestionFeedbackEditingGUI', 'show');
469  }
470  else
471  {
472  $_GET["ref_id"] = $_GET["calling_test"];
473  ilUtil::redirect("ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=".$_GET["calling_test"]);
474  }
475  }
476 
480  function saveEdit()
481  {
482  global $ilUser;
483 
484  $result = $this->writePostData();
485  if ($result == 0)
486  {
487  $ilUser->setPref("tst_lastquestiontype", $this->object->getQuestionType());
488  $ilUser->writePref("tst_lastquestiontype", $this->object->getQuestionType());
489  $this->object->saveToDb();
490  $originalexists = $this->object->_questionExists($this->object->original_id);
491  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
492  if ($_GET["calling_test"] && $originalexists && assQuestion::_isWriteable($this->object->original_id, $ilUser->getId()))
493  {
494  $this->ctrl->redirect($this, "originalSyncForm");
495  }
496  elseif ($_GET["calling_test"])
497  {
498  $_GET["ref_id"] = $_GET["calling_test"];
499  ilUtil::redirect("ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=".$_GET["calling_test"]);
500  return;
501  }
502  elseif ($_GET["test_ref_id"])
503  {
504  global $tree, $ilDB, $ilPluginAdmin;
505 
506  include_once ("./Modules/Test/classes/class.ilObjTest.php");
507  $_GET["ref_id"] = $_GET["test_ref_id"];
508  $test =& new ilObjTest($_GET["test_ref_id"], true);
509 
510  require_once 'Modules/Test/classes/class.ilTestQuestionSetConfigFactory.php';
511  $testQuestionSetConfigFactory = new ilTestQuestionSetConfigFactory($tree, $ilDB, $ilPluginAdmin, $test);
512 
513  $test->insertQuestion( $testQuestionSetConfigFactory->getQuestionSetConfig(), $this->object->getId() );
514 
515  ilUtil::redirect("ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=".$_GET["test_ref_id"]);
516  }
517  else
518  {
519  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
520  $this->editQuestion();
521  if (strcmp($_SESSION["info"], "") != 0)
522  {
523  ilUtil::sendSuccess($_SESSION["info"] . "<br />" . $this->lng->txt("msg_obj_modified"), false);
524  }
525  else
526  {
527  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), false);
528  }
529  $this->ctrl->setParameterByClass("ilAssQuestionPageGUI", "q_id", $this->object->getId());
530  $this->ctrl->redirectByClass("ilAssQuestionPageGUI", "edit");
531  }
532  }
533  }
534 
538  function save()
539  {
540  global $ilUser;
541  $old_id = $_GET["q_id"];
542  $result = $this->writePostData();
543 
544  if($result == 0)
545  {
546  $ilUser->setPref("tst_lastquestiontype", $this->object->getQuestionType());
547  $ilUser->writePref("tst_lastquestiontype", $this->object->getQuestionType());
548  $this->object->saveToDb();
549  $originalexists = $this->object->_questionExistsInPool($this->object->original_id);
550 
551 
552  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
553  if($_GET["calling_test"] && $originalexists && assQuestion::_isWriteable($this->object->original_id, $ilUser->getId()))
554  {
555  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
556  $this->ctrl->setParameter($this, 'return_to', 'editQuestion');
557  $this->ctrl->redirect($this, "originalSyncForm");
558  return;
559  }
560  elseif($_GET["calling_test"])
561  {
562  require_once 'Modules/Test/classes/class.ilObjTest.php';
563  $test = new ilObjTest($_GET["calling_test"]);
564  if(!assQuestion::_questionExistsInTest($this->object->getId(), $test->getTestId()))
565  {
566  global $tree, $ilDB, $ilPluginAdmin;
567 
568  include_once("./Modules/Test/classes/class.ilObjTest.php");
569  $_GET["ref_id"] = $_GET["calling_test"];
570  $test = new ilObjTest($_GET["calling_test"], true);
571 
572  require_once 'Modules/Test/classes/class.ilTestQuestionSetConfigFactory.php';
573  $testQuestionSetConfigFactory = new ilTestQuestionSetConfigFactory($tree, $ilDB, $ilPluginAdmin, $test);
574 
575  $new_id = $test->insertQuestion(
576  $testQuestionSetConfigFactory->getQuestionSetConfig(), $this->object->getId()
577  );
578 
579  if(isset($_REQUEST['prev_qid']))
580  {
581  $test->moveQuestionAfter($this->object->getId() + 1, $_REQUEST['prev_qid']);
582  }
583 
584  $this->ctrl->setParameter($this, 'q_id', $new_id);
585  $this->ctrl->setParameter($this, 'calling_test', $_GET['calling_test']);
586  #$this->ctrl->setParameter($this, 'test_ref_id', false);
587  }
588  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
589  $this->ctrl->redirect($this, 'editQuestion');
590 
591  }
592  else
593  {
594  $this->callNewIdListeners($this->object->getId());
595 
596  if($this->object->getId() != $old_id)
597  {
598  // first save
599  $this->ctrl->setParameterByClass($_GET["cmdClass"], "q_id", $this->object->getId());
600  $this->ctrl->setParameterByClass($_GET["cmdClass"], "sel_question_types", $_GET["sel_question_types"]);
601  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
602 
603  //global $___test_express_mode;
607  if($_REQUEST['prev_qid'])
608  {
609  // @todo: bheyser/mbecker wtf? ..... thx@jposselt ....
610  // mbecker: Possible fix: Just instantiate the obj?
611  include_once("./Modules/Test/classes/class.ilObjTest.php");
612  $test =& new ilObjTest($_GET["ref_id"], true);
613  $test->moveQuestionAfter($_REQUEST['prev_qid'], $this->object->getId());
614  }
615  if( /*$___test_express_mode || */ $_REQUEST['express_mode'] )
616  {
617  global $tree, $ilDB, $ilPluginAdmin;
618 
619  include_once("./Modules/Test/classes/class.ilObjTest.php");
620  $test = new ilObjTest($_GET["ref_id"], true);
621 
622  require_once 'Modules/Test/classes/class.ilTestQuestionSetConfigFactory.php';
623  $testQuestionSetConfigFactory = new ilTestQuestionSetConfigFactory($tree, $ilDB, $ilPluginAdmin, $test);
624 
625  $test->insertQuestion(
626  $testQuestionSetConfigFactory->getQuestionSetConfig(), $this->object->getId()
627  );
628 
629  require_once 'Modules/Test/classes/class.ilTestExpressPage.php';
630  $_REQUEST['q_id'] = $this->object->getId();
632  }
633 
634  $this->ctrl->redirectByClass($_GET["cmdClass"], "editQuestion");
635  }
636  if(strcmp($_SESSION["info"], "") != 0)
637  {
638  ilUtil::sendSuccess($_SESSION["info"] . "<br />" . $this->lng->txt("msg_obj_modified"), true);
639  }
640  else
641  {
642  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
643  }
644  $this->ctrl->redirect($this, 'editQuestion');
645  }
646  }
647  }
648 
652  function saveReturn()
653  {
654  global $ilUser;
655  $old_id = $_GET["q_id"];
656  $result = $this->writePostData();
657  if($result == 0)
658  {
659  $ilUser->setPref("tst_lastquestiontype", $this->object->getQuestionType());
660  $ilUser->writePref("tst_lastquestiontype", $this->object->getQuestionType());
661  $this->object->saveToDb();
662  $originalexists = $this->object->_questionExistsInPool($this->object->original_id);
663  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
664  if($_GET["calling_test"] && $originalexists && assQuestion::_isWriteable($this->object->original_id, $ilUser->getId()))
665  {
666  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
667  $this->ctrl->redirect($this, "originalSyncForm");
668  return;
669  }
670  elseif($_GET["calling_test"])
671  {
672  require_once 'Modules/Test/classes/class.ilObjTest.php';
673  $test = new ilObjTest($_GET["calling_test"]);
674  #var_dump(assQuestion::_questionExistsInTest($this->object->getId(), $test->getTestId()));
675  $q_id = $this->object->getId();
676  if(!assQuestion::_questionExistsInTest($this->object->getId(), $test->getTestId()))
677  {
678  global $tree, $ilDB, $ilPluginAdmin;
679 
680  include_once("./Modules/Test/classes/class.ilObjTest.php");
681  $_GET["ref_id"] = $_GET["calling_test"];
682  $test = new ilObjTest($_GET["calling_test"], true);
683 
684  require_once 'Modules/Test/classes/class.ilTestQuestionSetConfigFactory.php';
685  $testQuestionSetConfigFactory = new ilTestQuestionSetConfigFactory($tree, $ilDB, $ilPluginAdmin, $test);
686 
687  $new_id = $test->insertQuestion(
688  $testQuestionSetConfigFactory->getQuestionSetConfig(), $this->object->getId()
689  );
690 
691  $q_id = $new_id;
692  if(isset($_REQUEST['prev_qid']))
693  {
694  $test->moveQuestionAfter($this->object->getId() + 1, $_REQUEST['prev_qid']);
695  }
696 
697  $this->ctrl->setParameter($this, 'q_id', $new_id);
698  $this->ctrl->setParameter($this, 'calling_test', $_GET['calling_test']);
699  #$this->ctrl->setParameter($this, 'test_ref_id', false);
700 
701  }
702  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
703  if( /*$___test_express_mode || */
704  $_REQUEST['test_express_mode']
705  )
706  {
708  }
709  else
710  {
711  ilUtil::redirect("ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=" . $_GET["calling_test"]);
712  }
713  }
714  else
715  {
716  if($this->object->getId() != $old_id)
717  {
718  $this->callNewIdListeners($this->object->getId());
719  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
720  $this->ctrl->redirectByClass("ilobjquestionpoolgui", "questions");
721  }
722  if(strcmp($_SESSION["info"], "") != 0)
723  {
724  ilUtil::sendSuccess($_SESSION["info"] . "<br />" . $this->lng->txt("msg_obj_modified"), true);
725  }
726  else
727  {
728  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
729  }
730  $this->ctrl->redirectByClass("ilobjquestionpoolgui", "questions");
731  }
732  }
733  }
734 
738  function apply()
739  {
740  $this->writePostData();
741  $this->object->saveToDb();
742  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
743  $this->editQuestion();
744  }
745 
752  function getContextPath($cont_obj, $a_endnode_id, $a_startnode_id = 1)
753  {
754  $path = "";
755 
756  $tmpPath = $cont_obj->getLMTree()->getPathFull($a_endnode_id, $a_startnode_id);
757 
758  // count -1, to exclude the learning module itself
759  for ($i = 1; $i < (count($tmpPath) - 1); $i++)
760  {
761  if ($path != "")
762  {
763  $path .= " > ";
764  }
765 
766  $path .= $tmpPath[$i]["title"];
767  }
768 
769  return $path;
770  }
771 
772  function setSequenceNumber($nr)
773  {
774  $this->sequence_no = $nr;
775  }
776 
777  function getSequenceNumber()
778  {
779  return $this->sequence_no;
780  }
781 
782  function setQuestionCount($a_question_count)
783  {
784  $this->question_count = $a_question_count;
785  }
786 
787  function getQuestionCount()
788  {
789  return $this->question_count;
790  }
791 
792  function getErrorMessage()
793  {
794  return $this->errormessage;
795  }
796 
798  {
799  $this->errormessage = $errormessage;
800  }
801 
803  {
804  $this->errormessage .= ((strlen($this->errormessage)) ? "<br />" : "") . $errormessage;
805  }
806 
808  {
809  }
810 
819  function getQuestionType()
820  {
821  return $this->object->getQuestionType();
822  }
823 
831  public function getAsValueAttribute($a_value)
832  {
833  $result = "";
834  if (strlen($a_value))
835  {
836  $result = " value=\"$a_value\" ";
837  }
838  return $result;
839  }
840 
841  // scorm2004-start
846  function addNewIdListener(&$a_object, $a_method, $a_parameters = "")
847  {
848  $cnt = $this->new_id_listener_cnt;
849  $this->new_id_listeners[$cnt]["object"] =& $a_object;
850  $this->new_id_listeners[$cnt]["method"] = $a_method;
851  $this->new_id_listeners[$cnt]["parameters"] = $a_parameters;
852  $this->new_id_listener_cnt++;
853  }
854 
858  function callNewIdListeners($a_new_id)
859  {
860 
861  for ($i=0; $i<$this->new_id_listener_cnt; $i++)
862  {
863  $this->new_id_listeners[$i]["parameters"]["new_id"] = $a_new_id;
864  $object =& $this->new_id_listeners[$i]["object"];
865  $method = $this->new_id_listeners[$i]["method"];
866  $parameters = $this->new_id_listeners[$i]["parameters"];
867 //var_dump($object);
868 //var_dump($method);
869 //var_dump($parameters);
870 
871  $object->$method($parameters);
872  }
873  }
874 
879  {
880  //if (!$this->object->getSelfAssessmentEditingMode() && !$_GET["calling_test"]) $form->addCommandButton("saveEdit", $this->lng->txt("save_edit"));
881  if(!$this->object->getSelfAssessmentEditingMode())
882  {
883  $form->addCommandButton("saveReturn", $this->lng->txt("save_return"));
884  }
885  $form->addCommandButton("save", $this->lng->txt("save"));
886  }
887 
895  {
896  // title
897  $title = new ilTextInputGUI($this->lng->txt("title"), "title");
898  $title->setValue($this->object->getTitle());
899  $title->setRequired(TRUE);
900  $form->addItem($title);
901 
902  if (!$this->object->getSelfAssessmentEditingMode())
903  {
904  // author
905  $author = new ilTextInputGUI($this->lng->txt("author"), "author");
906  $author->setValue($this->object->getAuthor());
907  $author->setRequired(TRUE);
908  $form->addItem($author);
909 
910  // description
911  $description = new ilTextInputGUI($this->lng->txt("description"), "comment");
912  $description->setValue($this->object->getComment());
913  $description->setRequired(FALSE);
914  $form->addItem($description);
915  }
916  else
917  {
918  // author as hidden field
919  $hi = new ilHiddenInputGUI("author");
920  $author = ilUtil::prepareFormOutput($this->object->getAuthor());
921  if (trim($author) == "")
922  {
923  $author = "-";
924  }
925  $hi->setValue($author);
926  $form->addItem($hi);
927 
928  }
929 
930  // questiontext
931  $question = new ilTextAreaInputGUI($this->lng->txt("question"), "question");
932  $question->setValue($this->object->prepareTextareaOutput($this->object->getQuestion()));
933  $question->setRequired(TRUE);
934  $question->setRows(10);
935  $question->setCols(80);
936  if (!$this->object->getSelfAssessmentEditingMode())
937  {
938  if( $this->object->getAdditionalContentEditingMode() != assQuestion::ADDITIONAL_CONTENT_EDITING_MODE_PAGE_OBJECT )
939  {
940  $question->setUseRte(TRUE);
941  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
942  $question->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("assessment"));
943  $question->addPlugin("latex");
944  $question->addButton("latex");
945  $question->addButton("pastelatex");
946  $question->setRTESupport($this->object->getId(), "qpl", "assessment");
947  }
948  }
949  else
950  {
951  $question->setRteTags(self::getSelfAssessmentTags());
952  $question->setUseTagsForRteOnly(false);
953  }
954  $form->addItem($question);
955 
956  if (!$this->object->getSelfAssessmentEditingMode())
957  {
958  // duration
959  $duration = new ilDurationInputGUI($this->lng->txt("working_time"), "Estimated");
960  $duration->setShowHours(TRUE);
961  $duration->setShowMinutes(TRUE);
962  $duration->setShowSeconds(TRUE);
963  $ewt = $this->object->getEstimatedWorkingTime();
964  $duration->setHours($ewt["h"]);
965  $duration->setMinutes($ewt["m"]);
966  $duration->setSeconds($ewt["s"]);
967  $duration->setRequired(FALSE);
968  $form->addItem($duration);
969  }
970  else
971  {
972  // number of tries
973  if (strlen($this->object->getNrOfTries()))
974  {
975  $nr_tries = $this->object->getNrOfTries();
976  }
977  else
978  {
979  $nr_tries = $this->object->getDefaultNrOfTries();
980  }
981  /*if ($nr_tries <= 0)
982  {
983  $nr_tries = 1;
984  }*/
985 
986  if ($nr_tries < 0)
987  {
988  $nr_tries = 0;
989  }
990 
991  $ni = new ilNumberInputGUI($this->lng->txt("qst_nr_of_tries"), "nr_of_tries");
992  $ni->setValue($nr_tries);
993  //$ni->setMinValue(1);
994  $ni->setMinValue(0);
995  $ni->setSize(5);
996  $ni->setMaxLength(5);
997  $ni->setRequired(true);
998  $form->addItem($ni);
999  }
1000  }
1001 
1002  protected function saveTaxonomyAssignments()
1003  {
1004  if( count($this->getTaxonomyIds()) )
1005  {
1006  require_once 'Services/Taxonomy/classes/class.ilTaxAssignInputGUI.php';
1007 
1008  foreach($this->getTaxonomyIds() as $taxonomyId)
1009  {
1010  $postvar = "tax_node_assign_$taxonomyId";
1011 
1012  $tax_node_assign = new ilTaxAssignInputGUI($taxonomyId, true, '', $postvar);
1013  // TODO: determine tst/qpl when tax assigns become maintainable within tests
1014  $tax_node_assign->saveInput("qpl", $this->object->getObjId(), "quest", $this->object->getId());
1015  }
1016  }
1017  }
1018 
1020  {
1021  if( count($this->getTaxonomyIds()) )
1022  {
1023  $sectHeader = new ilFormSectionHeaderGUI();
1024  $sectHeader->setTitle($this->lng->txt('qpl_qst_edit_form_taxonomy_section'));
1025  $form->addItem($sectHeader);
1026 
1027  require_once 'Services/Taxonomy/classes/class.ilTaxAssignInputGUI.php';
1028 
1029  foreach($this->getTaxonomyIds() as $taxonomyId)
1030  {
1031  $taxonomy = new ilObjTaxonomy($taxonomyId);
1032  $label = sprintf($this->lng->txt('qpl_qst_edit_form_taxonomy'), $taxonomy->getTitle());
1033  $postvar = "tax_node_assign_$taxonomyId";
1034 
1035  $taxNodeAssign = new ilTaxAssignInputGUI($taxonomy->getId(), true, $label, $postvar);
1036  // TODO: determine tst/qpl when tax assigns become maintainable within tests
1037  $taxNodeAssign->setCurrentValues('qpl', $this->object->getObjId(), 'quest', $this->object->getId());
1038  $form->addItem($taxNodeAssign);
1039  }
1040  }
1041  }
1042 
1048  {
1049  // set tags we allow in self assessment mode
1050  $st = ilUtil::getSecureTags();
1051 
1052  // we allow these tags, since they are typically used in the Tiny Assessment editor
1053  // and should not be deleted, if questions are copied from pools to learning modules
1054  $not_supported = array("img", "p");
1055  $tags = array();
1056  foreach ($st as $s)
1057  {
1058  if (!in_array($s, $not_supported))
1059  {
1060  $tags[] = $s;
1061  }
1062  }
1063 
1064  return $tags;
1065  }
1066 
1067 
1077  function getAnswerFeedbackOutput($active_id, $pass)
1078  {
1079  return $this->getGenericFeedbackOutput($active_id, $pass);
1080  }
1081 
1091  function getGenericFeedbackOutput($active_id, $pass)
1092  {
1093  $output = "";
1094  include_once "./Modules/Test/classes/class.ilObjTest.php";
1095  $manual_feedback = ilObjTest::getManualFeedback($active_id, $this->object->getId(), $pass);
1096  if (strlen($manual_feedback))
1097  {
1098  return $manual_feedback;
1099  }
1100  $correct_feedback = $this->object->feedbackOBJ->getGenericFeedbackTestPresentation($this->object->getId(), true);
1101  $incorrect_feedback = $this->object->feedbackOBJ->getGenericFeedbackTestPresentation($this->object->getId(), false);
1102  if (strlen($correct_feedback.$incorrect_feedback))
1103  {
1104  $reached_points = $this->object->calculateReachedPoints($active_id, $pass);
1105  $max_points = $this->object->getMaximumPoints();
1106  if ($reached_points == $max_points)
1107  {
1108  $output = $correct_feedback;
1109  }
1110  else
1111  {
1112  $output = $incorrect_feedback;
1113  }
1114  }
1115  return $this->object->prepareTextareaOutput($output, TRUE);
1116  }
1117 
1129  abstract function getSpecificFeedbackOutput($active_id, $pass);
1130 
1131  public function outQuestionType()
1132  {
1133  include_once "./Services/UICore/classes/class.ilTemplate.php";
1134  $template = new ilTemplate("tpl.il_as_qpl_questiontype.html", TRUE, TRUE, "Modules/TestQuestionPool");
1135  $count = $this->object->isInUse();
1136  if (assQuestion::_questionExistsInPool($this->object->getId()) && $count)
1137  {
1138  global $rbacsystem;
1139  if ($rbacsystem->checkAccess("write", $_GET["ref_id"]))
1140  {
1141  $template->setCurrentBlock("infosign");
1142  $template->setVariable("INFO_IMG_SRC", ilUtil::getImagePath("messagebox_tip.png"));
1143  $template->setVariable("INFO_IMG_ALT", sprintf($this->lng->txt("qpl_question_is_in_use"), $count));
1144  $template->setVariable("INFO_IMG_TITLE", sprintf($this->lng->txt("qpl_question_is_in_use"), $count));
1145  $template->parseCurrentBlock();
1146  }
1147  }
1148  $template->setVariable("TEXT_QUESTION_TYPE", assQuestion::_getQuestionTypeName($this->object->getQuestionType()));
1149  return $template->get();
1150  }
1151 
1152  public function showSuggestedSolution()
1153  {
1154  $this->suggestedsolution();
1155  }
1156 
1162  public function suggestedsolution()
1163  {
1164  global $ilUser;
1165  global $ilAccess;
1166 
1167  $save = (is_array($_POST["cmd"]) && array_key_exists("suggestedsolution", $_POST["cmd"])) ? TRUE : FALSE;
1168 
1169  if ($save && $_POST["deleteSuggestedSolution"] == 1)
1170  {
1171  $this->object->deleteSuggestedSolutions();
1172  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
1173  $this->ctrl->redirect($this, "suggestedsolution");
1174  }
1175 
1176  $output = "";
1177  $solution_array = $this->object->getSuggestedSolution(0);
1178  $options = array(
1179  "lm" => $this->lng->txt("obj_lm"),
1180  "st" => $this->lng->txt("obj_st"),
1181  "pg" => $this->lng->txt("obj_pg"),
1182  "git" => $this->lng->txt("glossary_term"),
1183  "file" => $this->lng->txt("fileDownload"),
1184  "text" => $this->lng->txt("solutionText")
1185  );
1186 
1187  if ((strcmp($_POST["solutiontype"], "file") == 0) && (strcmp($solution_array["type"], "file") != 0))
1188  {
1189  $solution_array = array(
1190  "type" => "file"
1191  );
1192  }
1193  elseif ((strcmp($_POST["solutiontype"], "text") == 0) && (strcmp($solution_array["type"], "text") != 0))
1194  {
1195  $solution_array = array(
1196  "type" => "text",
1197  "value" => $this->getSolutionOutput(0, NULL, FALSE, FALSE, TRUE, FALSE, TRUE)
1198  );
1199  }
1200  if ($save && strlen($_POST["filename"]))
1201  {
1202  $solution_array["value"]["filename"] = $_POST["filename"];
1203  }
1204  if ($save && strlen($_POST["solutiontext"]))
1205  {
1206  $solution_array["value"] = $_POST["solutiontext"];
1207  }
1208  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
1209  if (count($solution_array))
1210  {
1211  $form = new ilPropertyFormGUI();
1212  $form->setFormAction($this->ctrl->getFormAction($this));
1213  $form->setTitle($this->lng->txt("solution_hint"));
1214  $form->setMultipart(TRUE);
1215  $form->setTableWidth("100%");
1216  $form->setId("suggestedsolutiondisplay");
1217 
1218  // suggested solution output
1219  include_once "./Modules/TestQuestionPool/classes/class.ilSolutionTitleInputGUI.php";
1220  $title = new ilSolutionTitleInputGUI($this->lng->txt("showSuggestedSolution"), "solutiontype");
1221  $template = new ilTemplate("tpl.il_as_qpl_suggested_solution_input_presentation.html", TRUE, TRUE, "Modules/TestQuestionPool");
1222  if (strlen($solution_array["internal_link"]))
1223  {
1224  $href = assQuestion::_getInternalLinkHref($solution_array["internal_link"]);
1225  $template->setCurrentBlock("preview");
1226  $template->setVariable("TEXT_SOLUTION", $this->lng->txt("solution_hint"));
1227  $template->setVariable("VALUE_SOLUTION", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("view"). "</a> ");
1228  $template->parseCurrentBlock();
1229  }
1230  elseif ((strcmp($solution_array["type"], "file") == 0) && (is_array($solution_array["value"])))
1231  {
1232  $href = $this->object->getSuggestedSolutionPathWeb() . $solution_array["value"]["name"];
1233  $template->setCurrentBlock("preview");
1234  $template->setVariable("TEXT_SOLUTION", $this->lng->txt("solution_hint"));
1235  $template->setVariable("VALUE_SOLUTION", " <a href=\"$href\" target=\"content\">" . ilUtil::prepareFormOutput((strlen($solution_array["value"]["filename"])) ? $solution_array["value"]["filename"] : $solution_array["value"]["name"]). "</a> ");
1236  $template->parseCurrentBlock();
1237  }
1238  $template->setVariable("TEXT_TYPE", $this->lng->txt("type"));
1239  $template->setVariable("VALUE_TYPE", $options[$solution_array["type"]]);
1240  $title->setHtml($template->get());
1241  $deletesolution = new ilCheckboxInputGUI("", "deleteSuggestedSolution");
1242  $deletesolution->setOptionTitle($this->lng->txt("deleteSuggestedSolution"));
1243  $title->addSubItem($deletesolution);
1244  $form->addItem($title);
1245 
1246  if (strcmp($solution_array["type"], "file") == 0)
1247  {
1248  // file
1249  $file = new ilFileInputGUI($this->lng->txt("fileDownload"), "file");
1250  $file->setRequired(TRUE);
1251  $file->enableFileNameSelection("filename");
1252  //$file->setSuffixes(array("doc","xls","png","jpg","gif","pdf"));
1253  if( $_FILES["file"]["tmp_name"] && $file->checkInput() )
1254  {
1255  if (!file_exists($this->object->getSuggestedSolutionPath())) ilUtil::makeDirParents($this->object->getSuggestedSolutionPath());
1256 
1257  $res = ilUtil::moveUploadedFile($_FILES["file"]["tmp_name"], $_FILES["file"]["name"], $this->object->getSuggestedSolutionPath() . $_FILES["file"]["name"]);
1258  if ($res)
1259  {
1260  ilUtil::renameExecutables($this->object->getSuggestedSolutionPath());
1261 
1262  // remove an old file download
1263  if (is_array($solution_array["value"])) @unlink($this->object->getSuggestedSolutionPath() . $solution_array["value"]["name"]);
1264  $file->setValue($_FILES["file"]["name"]);
1265  $this->object->saveSuggestedSolution("file", "", 0, array("name" => $_FILES["file"]["name"], "type" => $_FILES["file"]["type"], "size" => $_FILES["file"]["size"], "filename" => $_POST["filename"]));
1266  $originalexists = $this->object->_questionExistsInPool($this->object->original_id);
1267  if ($_GET["calling_test"] && $originalexists && assQuestion::_isWriteable($this->object->original_id, $ilUser->getId()))
1268  {
1269  return $this->originalSyncForm("suggestedsolution");
1270  }
1271  else
1272  {
1273  ilUtil::sendSuccess($this->lng->txt("suggested_solution_added_successfully"), TRUE);
1274  $this->ctrl->redirect($this, "suggestedsolution");
1275  }
1276  }
1277  else
1278  {
1279  // BH: $res as info string? wtf? it holds a bool or something else!!?
1280  ilUtil::sendInfo($res);
1281  }
1282  }
1283  else
1284  {
1285  if (is_array($solution_array["value"]))
1286  {
1287  $file->setValue($solution_array["value"]["name"]);
1288  $file->setFilename((strlen($solution_array["value"]["filename"])) ? $solution_array["value"]["filename"] : $solution_array["value"]["name"]);
1289  }
1290  }
1291  $form->addItem($file);
1292  $hidden = new ilHiddenInputGUI("solutiontype");
1293  $hidden->setValue("file");
1294  $form->addItem($hidden);
1295  }
1296  else if (strcmp($solution_array["type"], "text") == 0)
1297  {
1298  $question = new ilTextAreaInputGUI($this->lng->txt("solutionText"), "solutiontext");
1299  $question->setValue($this->object->prepareTextareaOutput($solution_array["value"]));
1300  $question->setRequired(TRUE);
1301  $question->setRows(10);
1302  $question->setCols(80);
1303  $question->setUseRte(TRUE);
1304  $question->addPlugin("latex");
1305  $question->addButton("latex");
1306  $question->setRTESupport($this->object->getId(), "qpl", "assessment");
1307  $hidden = new ilHiddenInputGUI("solutiontype");
1308  $hidden->setValue("text");
1309  $form->addItem($hidden);
1310  $form->addItem($question);
1311  }
1312  if ($ilAccess->checkAccess("write", "", $_GET['ref_id']))
1313  {
1314  $form->addCommandButton('showSuggestedSolution', $this->lng->txt('cancel'));
1315  $form->addCommandButton('suggestedsolution', $this->lng->txt('save'));
1316  }
1317 
1318  if ($save)
1319  {
1320  if ($form->checkInput())
1321  {
1322  switch ($solution_array["type"])
1323  {
1324  case "file":
1325  $this->object->saveSuggestedSolution("file", "", 0, array("name" => $solution_array["value"]["name"], "type" => $solution_array["value"]["type"], "size" => $solution_array["value"]["size"], "filename" => $_POST["filename"]));
1326  break;
1327  case "text":
1328  $this->object->saveSuggestedSolution("text", "", 0, $solution_array["value"]);
1329  break;
1330  }
1331  $originalexists = $this->object->_questionExistsInPool($this->object->original_id);
1332  if ($_GET["calling_test"] && $originalexists && assQuestion::_isWriteable($this->object->original_id, $ilUser->getId()))
1333  {
1334  return $this->originalSyncForm("suggestedsolution");
1335  }
1336  else
1337  {
1338  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
1339  $this->ctrl->redirect($this, "suggestedsolution");
1340  }
1341  }
1342  }
1343 
1344  $output = $form->getHTML();
1345  }
1346 
1347  $savechange = (strcmp($this->ctrl->getCmd(), "saveSuggestedSolution") == 0) ? TRUE : FALSE;
1348 
1349  $changeoutput = "";
1350  if ($ilAccess->checkAccess("write", "", $_GET['ref_id']))
1351  {
1352  $formchange = new ilPropertyFormGUI();
1353  $formchange->setFormAction($this->ctrl->getFormAction($this));
1354  $formchange->setTitle((count($solution_array)) ? $this->lng->txt("changeSuggestedSolution") : $this->lng->txt("addSuggestedSolution"));
1355  $formchange->setMultipart(FALSE);
1356  $formchange->setTableWidth("100%");
1357  $formchange->setId("suggestedsolution");
1358 
1359  $solutiontype = new ilRadioGroupInputGUI($this->lng->txt("suggestedSolutionType"), "solutiontype");
1360  foreach($options as $opt_value => $opt_caption)
1361  {
1362  $solutiontype->addOption(new ilRadioOption($opt_caption, $opt_value));
1363  }
1364  if (count($solution_array))
1365  {
1366  $solutiontype->setValue($solution_array["type"]);
1367  }
1368  $solutiontype->setRequired(TRUE);
1369  $formchange->addItem($solutiontype);
1370 
1371  $formchange->addCommandButton("saveSuggestedSolution", $this->lng->txt("select"));
1372 
1373  if ($savechange)
1374  {
1375  $formchange->checkInput();
1376  }
1377  $changeoutput = $formchange->getHTML();
1378  }
1379 
1380  $this->tpl->setVariable("ADM_CONTENT", $changeoutput . $output);
1381  }
1382 
1383  public function outSolutionExplorer()
1384  {
1385  global $tree;
1386 
1387  include_once("./Modules/TestQuestionPool/classes/class.ilSolutionExplorer.php");
1388  $type = $_GET["link_new_type"];
1389  $search = $_GET["search_link_type"];
1390  $this->ctrl->setParameter($this, "link_new_type", $type);
1391  $this->ctrl->setParameter($this, "search_link_type", $search);
1392  $this->ctrl->saveParameter($this, array("subquestion_index", "link_new_type", "search_link_type"));
1393 
1394  ilUtil::sendInfo($this->lng->txt("select_object_to_link"));
1395 
1396  $parent_ref_id = $tree->getParentId($_GET["ref_id"]);
1397  $exp = new ilSolutionExplorer($this->ctrl->getLinkTarget($this, 'suggestedsolution'), get_class($this));
1398  $exp->setExpand($_GET['expand_sol'] ? $_GET['expand_sol'] : $parent_ref_id);
1399  $exp->setExpandTarget($this->ctrl->getLinkTarget($this, 'outSolutionExplorer'));
1400  $exp->setTargetGet("ref_id");
1401  $exp->setRefId($_GET["ref_id"]);
1402  $exp->addFilter($type);
1403  $exp->setSelectableType($type);
1404  if(isset($_GET['expandCurrentPath']) && $_GET['expandCurrentPath'])
1405  {
1406  $exp->expandPathByRefId($parent_ref_id);
1407  }
1408 
1409  // build html-output
1410  $exp->setOutput(0);
1411 
1412  $template = new ilTemplate("tpl.il_as_qpl_explorer.html", TRUE, TRUE, "Modules/TestQuestionPool");
1413  $template->setVariable("EXPLORER_TREE",$exp->getOutput());
1414  $template->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
1415  $template->setVariable("FORMACTION",$this->ctrl->getFormAction($this, "suggestedsolution"));
1416  $this->tpl->setVariable("ADM_CONTENT", $template->get());
1417  }
1418 
1419  public function saveSuggestedSolution()
1420  {
1421  global $tree;
1422 
1423  include_once("./Modules/TestQuestionPool/classes/class.ilSolutionExplorer.php");
1424  switch ($_POST["solutiontype"])
1425  {
1426  case "lm":
1427  $type = "lm";
1428  $search = "lm";
1429  break;
1430  case "git":
1431  $type = "glo";
1432  $search = "glo";
1433  break;
1434  case "st":
1435  $type = "lm";
1436  $search = "st";
1437  break;
1438  case "pg":
1439  $type = "lm";
1440  $search = "pg";
1441  break;
1442  case "file":
1443  case "text":
1444  return $this->suggestedsolution();
1445  break;
1446  default:
1447  return $this->suggestedsolution();
1448  break;
1449  }
1450  if(isset($_POST['solutiontype']))
1451  {
1452  $this->ctrl->setParameter($this, 'expandCurrentPath', 1);
1453  }
1454  $this->ctrl->setParameter($this, "link_new_type", $type);
1455  $this->ctrl->setParameter($this, "search_link_type", $search);
1456  $this->ctrl->redirect($this, "outSolutionExplorer");
1457  }
1458 
1459  function cancelExplorer()
1460  {
1461  $this->ctrl->redirect($this, "suggestedsolution");
1462  }
1463 
1464  function outPageSelector()
1465  {
1466  include_once "./Modules/LearningModule/classes/class.ilLMPageObject.php";
1467  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1468  $cont_obj_gui =& new ilObjContentObjectGUI("", $_GET["source_id"], true);
1469  $cont_obj = $cont_obj_gui->object;
1470  $pages = ilLMPageObject::getPageList($cont_obj->getId());
1471  $shownpages = array();
1472  $tree = $cont_obj->getLMTree();
1473  $chapters = $tree->getSubtree($tree->getNodeData($tree->getRootId()));
1474  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
1475  $color_class = array("tblrow1", "tblrow2");
1476  $counter = 0;
1477  $template = new ilTemplate("tpl.il_as_qpl_internallink_selection.html", TRUE, TRUE, "Modules/TestQuestionPool");
1478  foreach ($chapters as $chapter)
1479  {
1480  $chapterpages = $tree->getChildsByType($chapter["obj_id"], "pg");
1481  foreach ($chapterpages as $page)
1482  {
1483  if($page["type"] == $_GET["search_link_type"])
1484  {
1485  array_push($shownpages, $page["obj_id"]);
1486  $template->setCurrentBlock("linktable_row");
1487  $template->setVariable("TEXT_LINK", $page["title"]);
1488  $template->setVariable("TEXT_ADD", $this->lng->txt("add"));
1489  $template->setVariable("LINK_HREF", $this->ctrl->getLinkTargetByClass(get_class($this), "add" . strtoupper($page["type"])) . "&" . $page["type"] . "=" . $page["obj_id"]);
1490  $template->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
1491  if ($tree->isInTree($page["obj_id"]))
1492  {
1493  $path_str = $this->getContextPath($cont_obj, $page["obj_id"]);
1494  }
1495  else
1496  {
1497  $path_str = "---";
1498  }
1499  $template->setVariable("TEXT_DESCRIPTION", ilUtil::prepareFormOutput($path_str));
1500  $template->parseCurrentBlock();
1501  $counter++;
1502  }
1503  }
1504  }
1505  foreach ($pages as $page)
1506  {
1507  if (!in_array($page["obj_id"], $shownpages))
1508  {
1509  $template->setCurrentBlock("linktable_row");
1510  $template->setVariable("TEXT_LINK", $page["title"]);
1511  $template->setVariable("TEXT_ADD", $this->lng->txt("add"));
1512  $template->setVariable("LINK_HREF", $this->ctrl->getLinkTargetByClass(get_class($this), "add" . strtoupper($page["type"])) . "&" . $page["type"] . "=" . $page["obj_id"]);
1513  $template->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
1514  $path_str = "---";
1515  $template->setVariable("TEXT_DESCRIPTION", ilUtil::prepareFormOutput($path_str));
1516  $template->parseCurrentBlock();
1517  $counter++;
1518  }
1519  }
1520  $template->setCurrentBlock("link_selection");
1521  $template->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
1522  $template->setVariable("TEXT_LINK_TYPE", $this->lng->txt("obj_" . $_GET["search_link_type"]));
1523  $template->setVariable("FORMACTION",$this->ctrl->getFormAction($this, "cancelExplorer"));
1524  $template->parseCurrentBlock();
1525  $this->tpl->setVariable("ADM_CONTENT", $template->get());
1526  }
1527 
1528  public function outChapterSelector()
1529  {
1530  $template = new ilTemplate("tpl.il_as_qpl_internallink_selection.html", TRUE, TRUE, "Modules/TestQuestionPool");
1531  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
1532  $color_class = array("tblrow1", "tblrow2");
1533  $counter = 0;
1534  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
1535  $cont_obj_gui =& new ilObjContentObjectGUI("", $_GET["source_id"], true);
1536  $cont_obj = $cont_obj_gui->object;
1537  // get all chapters
1538  $ctree =& $cont_obj->getLMTree();
1539  $nodes = $ctree->getSubtree($ctree->getNodeData($ctree->getRootId()));
1540  foreach($nodes as $node)
1541  {
1542  if($node["type"] == $_GET["search_link_type"])
1543  {
1544  $template->setCurrentBlock("linktable_row");
1545  $template->setVariable("TEXT_LINK", $node["title"]);
1546  $template->setVariable("TEXT_ADD", $this->lng->txt("add"));
1547  $template->setVariable("LINK_HREF", $this->ctrl->getLinkTargetByClass(get_class($this), "add" . strtoupper($node["type"])) . "&" . $node["type"] . "=" . $node["obj_id"]);
1548  $template->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
1549  $template->parseCurrentBlock();
1550  $counter++;
1551  }
1552  }
1553  $template->setCurrentBlock("link_selection");
1554  $template->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
1555  $template->setVariable("TEXT_LINK_TYPE", $this->lng->txt("obj_" . $_GET["search_link_type"]));
1556  $template->setVariable("FORMACTION",$this->ctrl->getFormAction($this, "cancelExplorer"));
1557  $template->parseCurrentBlock();
1558  $this->tpl->setVariable("ADM_CONTENT", $template->get());
1559  }
1560 
1561  public function outGlossarySelector()
1562  {
1563  $template = new ilTemplate("tpl.il_as_qpl_internallink_selection.html", TRUE, TRUE, "Modules/TestQuestionPool");
1564  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
1565  $color_class = array("tblrow1", "tblrow2");
1566  $counter = 0;
1567  include_once "./Modules/Glossary/classes/class.ilObjGlossary.php";
1568  $glossary =& new ilObjGlossary($_GET["source_id"], true);
1569  // get all glossary items
1570  $terms = $glossary->getTermList();
1571  foreach($terms as $term)
1572  {
1573  $template->setCurrentBlock("linktable_row");
1574  $template->setVariable("TEXT_LINK", $term["term"]);
1575  $template->setVariable("TEXT_ADD", $this->lng->txt("add"));
1576  $template->setVariable("LINK_HREF", $this->ctrl->getLinkTargetByClass(get_class($this), "addGIT") . "&git=" . $term["id"]);
1577  $template->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
1578  $template->parseCurrentBlock();
1579  $counter++;
1580  }
1581  $template->setCurrentBlock("link_selection");
1582  $template->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
1583  $template->setVariable("TEXT_LINK_TYPE", $this->lng->txt("glossary_term"));
1584  $template->setVariable("FORMACTION",$this->ctrl->getFormAction($this, "cancelExplorer"));
1585  $template->parseCurrentBlock();
1586  $this->tpl->setVariable("ADM_CONTENT", $template->get());
1587  }
1588 
1589  function linkChilds()
1590  {
1591  $this->ctrl->saveParameter($this, array("subquestion_index", "link_new_type", "search_link_type"));
1592  switch ($_GET["search_link_type"])
1593  {
1594  case "pg":
1595  return $this->outPageSelector();
1596  break;
1597  case "st":
1598  return $this->outChapterSelector();
1599  break;
1600  case "glo":
1601  return $this->outGlossarySelector();
1602  break;
1603  case "lm":
1604  $subquestion_index = ($_GET["subquestion_index"] > 0) ? $_GET["subquestion_index"] : 0;
1605  $this->object->saveSuggestedSolution("lm", "il__lm_" . $_GET["source_id"], $subquestion_index);
1606  ilUtil::sendSuccess($this->lng->txt("suggested_solution_added_successfully"), TRUE);
1607  $this->ctrl->redirect($this, "suggestedsolution");
1608  break;
1609  }
1610  }
1611 
1612  function addPG()
1613  {
1614  $subquestion_index = 0;
1615  if (strlen($_GET["subquestion_index"]) && $_GET["subquestion_index"] >= 0)
1616  {
1617  $subquestion_index = $_GET["subquestion_index"];
1618  }
1619  $this->object->saveSuggestedSolution("pg", "il__pg_" . $_GET["pg"], $subquestion_index);
1620  ilUtil::sendSuccess($this->lng->txt("suggested_solution_added_successfully"), TRUE);
1621  $this->ctrl->redirect($this, "suggestedsolution");
1622  }
1623 
1624  function addST()
1625  {
1626  $subquestion_index = 0;
1627  if (strlen($_GET["subquestion_index"]) && $_GET["subquestion_index"] >= 0)
1628  {
1629  $subquestion_index = $_GET["subquestion_index"];
1630  }
1631  $this->object->saveSuggestedSolution("st", "il__st_" . $_GET["st"], $subquestion_index);
1632  ilUtil::sendSuccess($this->lng->txt("suggested_solution_added_successfully"), TRUE);
1633  $this->ctrl->redirect($this, "suggestedsolution");
1634  }
1635 
1636  function addGIT()
1637  {
1638  $subquestion_index = 0;
1639  if (strlen($_GET["subquestion_index"]) && $_GET["subquestion_index"] >= 0)
1640  {
1641  $subquestion_index = $_GET["subquestion_index"];
1642  }
1643  $this->object->saveSuggestedSolution("git", "il__git_" . $_GET["git"], $subquestion_index);
1644  ilUtil::sendSuccess($this->lng->txt("suggested_solution_added_successfully"), TRUE);
1645  $this->ctrl->redirect($this, "suggestedsolution");
1646  }
1647 
1648  function isSaveCommand()
1649  {
1650  return in_array($this->ctrl->getCmd(), array('save', 'saveEdit', 'saveReturn'));
1651  }
1652 
1661  public static function getCommandsFromClassConstants($guiClassName, $cmdConstantNameBegin = 'CMD_')
1662  {
1663  $reflectionClass = new ReflectionClass($guiClassName);
1664 
1665  $commands = null;
1666 
1667  if( $reflectionClass instanceof ReflectionClass )
1668  {
1669  $commands = array();
1670 
1671  foreach($reflectionClass->getConstants() as $constName => $constValue)
1672  {
1673  if( substr($constName, 0, strlen($cmdConstantNameBegin)) == $cmdConstantNameBegin )
1674  {
1675  $commands[] = $constValue;
1676  }
1677  }
1678  }
1679 
1680  return $commands;
1681  }
1682 
1683  public function setQuestionTabs()
1684  {
1685  }
1686 
1693  protected function addTab_QuestionFeedback(ilTabsGUI $tabs)
1694  {
1695  global $ilCtrl;
1696 
1697  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionFeedbackEditingGUI.php';
1698  $tabCommands = self::getCommandsFromClassConstants('ilAssQuestionFeedbackEditingGUI');
1699 
1700  $tabLink = $ilCtrl->getLinkTargetByClass('ilAssQuestionFeedbackEditingGUI', ilAssQuestionFeedbackEditingGUI::CMD_SHOW);
1701 
1702  $tabs->addTarget('feedback', $tabLink, $tabCommands, $ilCtrl->getCmdClass(), '');
1703  }
1704 
1708  protected function addTab_Units(ilTabsGUI $tabs)
1709  {
1713  global $ilCtrl;
1714 
1715  $tabs->addTarget('units', $ilCtrl->getLinkTargetByClass('ilLocalUnitConfigurationGUI', ''), '', 'illocalunitconfigurationgui');
1716  }
1717 
1724  protected function addTab_QuestionHints(ilTabsGUI $tabs)
1725  {
1726  global $ilCtrl;
1727 
1728  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintsGUI.php';
1729 
1730  switch( $ilCtrl->getCmdClass() )
1731  {
1732  case 'ilassquestionhintsgui':
1733 
1734  $tabCommands = self::getCommandsFromClassConstants('ilAssQuestionHintsGUI');
1735  break;
1736 
1737  case 'ilassquestionhintgui':
1738 
1739  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintGUI.php';
1740  $tabCommands = self::getCommandsFromClassConstants('ilAssQuestionHintGUI');
1741  break;
1742 
1743  default:
1744 
1745  $tabCommands = array();
1746  }
1747 
1748  $tabLink = $ilCtrl->getLinkTargetByClass('ilAssQuestionHintsGUI', ilAssQuestionHintsGUI::CMD_SHOW_LIST);
1749 
1750  $tabs->addTarget('tst_question_hints_tab', $tabLink, $tabCommands, $ilCtrl->getCmdClass(), '');
1751  }
1752 
1753  abstract public function getSolutionOutput(
1754  $active_id,
1755  $pass = NULL,
1756  $graphicalOutput = FALSE,
1757  $result_output = FALSE,
1758  $show_question_only = TRUE,
1759  $show_feedback = FALSE,
1760  $show_correct_solution = FALSE,
1761  $show_manual_scoring = FALSE,
1762  $show_question_text = TRUE
1763  );
1764 
1765  public function isAutosaveable()
1766  {
1767  return $this->object->isAutosaveable();
1768  }
1769 
1770  protected function writeQuestionGenericPostData()
1771  {
1772  $this->object->setTitle( $_POST["title"] );
1773  $this->object->setAuthor( $_POST["author"] );
1774  $this->object->setComment( $_POST["comment"] );
1775  if ($this->object->getSelfAssessmentEditingMode())
1776  {
1777  $this->object->setNrOfTries( $_POST['nr_of_tries'] );
1778  }
1779  $this->object->setQuestion( ilUtil::stripOnlySlashes($_POST['question']) ); // ?
1780  $this->object->setEstimatedWorkingTime(
1781  $_POST["Estimated"]["hh"],
1782  $_POST["Estimated"]["mm"],
1783  $_POST["Estimated"]["ss"]
1784  );
1785  }
1786 
1787  public function showHints()
1788  {
1789  global $ilCtrl;
1790 
1791  $ilCtrl->redirectByClass('ilAssQuestionHintsGUI', ilAssQuestionHintsGUI::CMD_SHOW_LIST);
1792  }
1793 }