ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTestServiceGUI.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 include_once 'Modules/Test/classes/class.ilTestService.php';
26 
42 {
46  public $object = null;
47 
51  public $service = null;
52 
53  var $lng;
54  var $tpl;
55 
59  var $ctrl;
60 
61  var $ilias;
62  var $tree;
63  var $ref_id;
64 
71  function ilTestServiceGUI(ilObjTest $a_object)
72  {
73  global $lng, $tpl, $ilCtrl, $ilias, $tree;
74 
75  $this->lng =& $lng;
76  $this->tpl =& $tpl;
77  $this->ctrl =& $ilCtrl;
78  $this->ilias =& $ilias;
79  $this->object =& $a_object;
80  $this->tree =& $tree;
81  $this->ref_id = $a_object->ref_id;
82 
83  $this->service = new ilTestService($a_object);
84  }
85 
89  function &executeCommand()
90  {
91  $cmd = $this->ctrl->getCmd();
92  $next_class = $this->ctrl->getNextClass($this);
93 
94  $cmd = $this->getCommand($cmd);
95  switch($next_class)
96  {
97  default:
98  $ret =& $this->$cmd();
99  break;
100  }
101  return $ret;
102  }
103 
109  function getCommand($cmd)
110  {
111  return $cmd;
112  }
113 
122  function getPassOverview($active_id, $targetclass = "", $targetcommand = "", $short = FALSE, $hide_details = FALSE)
123  {
124  global $ilUser;
125 
126  if ($short)
127  {
128  $template = new ilTemplate("tpl.il_as_tst_pass_overview_short.html", TRUE, TRUE, "Modules/Test");
129  }
130  else
131  {
132  $template = new ilTemplate("tpl.il_as_tst_pass_overview.html", TRUE, TRUE, "Modules/Test");
133  }
134  $color_class = array("tblrow1", "tblrow2");
135  $counter = 0;
136 
137  $user_id = $this->object->_getUserIdFromActiveId($active_id);
138  $counted_pass = $this->object->_getResultPass($active_id);
139  $reached_pass = $this->object->_getPass($active_id);
140 
141  $result_percentage = 0;
142  $result_total_reached = 0;
143  $result_total_max = 0;
144  for ($pass = 0; $pass <= $reached_pass; $pass++)
145  {
146  $finishdate = $this->object->getPassFinishDate($active_id, $pass);
147  if ($finishdate > 0)
148  {
149  if (!$short)
150  {
151  $result_array =& $this->object->getTestResult($active_id, $pass);
152  if (!$result_array["pass"]["total_max_points"])
153  {
154  $percentage = 0;
155  }
156  else
157  {
158  $percentage = ($result_array["pass"]["total_reached_points"]/$result_array["pass"]["total_max_points"])*100;
159  }
160  $total_max = $result_array["pass"]["total_max_points"];
161  $total_reached = $result_array["pass"]["total_reached_points"];
162  $total_requested_hints = $result_array["pass"]["total_requested_hints"];
163  }
164  if (!$hide_details)
165  {
166  if (strlen($targetclass) && strlen($targetcommand))
167  {
168  $this->ctrl->setParameterByClass($targetclass, "active_id", $active_id);
169  $this->ctrl->setParameterByClass($targetclass, "pass", $pass);
170  $template->setCurrentBlock("pass_details");
171 
172  require_once './Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php';
173  $aslgui = new ilAdvancedSelectionListGUI();
174  $aslgui->setListTitle($this->lng->txt("actions"));
175  $aslgui->setId($pass);
176  $aslgui->addItem(
177  $this->lng->txt("tst_pass_details"),
178  'tst_pass_details',
179  $this->ctrl->getLinkTargetByClass($targetclass, $targetcommand)
180  );
181  if($this->object->isPassDeletionAllowed() && $pass != $counted_pass)
182  {
183  $aslgui->addItem(
184  $this->lng->txt("delete"),
185  'tst_pass_delete',
186  $this->ctrl->getLinkTargetByClass($targetclass, 'confirmDeletePass')
187  );
188  }
189 
190  // Suppress output of advanced selection list for pdf-generation as solution for Mantis #9359
191  if (!($_GET['pdf'] == 1))
192  {
193  $template->setVariable("TEXT_PASS_DETAILS", $aslgui->getHTML());
194  }
195  $template->parseCurrentBlock();
196  }
197  }
198 
199  $template->setCurrentBlock("result_row");
200 
201  if (($pass == $counted_pass) && (!$short))
202  {
203  $template->setVariable("COLOR_CLASS", "tblrowmarked");
204  $template->setVariable("VALUE_SCORED", "&otimes;");
205  if (!$result_array["test"]["total_max_points"])
206  {
207  $result_percentage = 0;
208  }
209  else
210  {
211  $result_percentage = ($result_array["test"]["total_reached_points"]/$result_array["test"]["total_max_points"])*100;
212  }
213  $result_total_max = $result_array["test"]["total_max_points"];
214  $result_total_reached = $result_array["test"]["total_reached_points"];
215  }
216  else
217  {
218  $template->setVariable("COLOR_CLASS", $color_class[$pass % 2]);
219  }
220  $template->setVariable("VALUE_PASS", $pass + 1);
221  $template->setVariable("VALUE_DATE",ilDatePresentation::formatDate(new ilDate($finishdate,IL_CAL_UNIX)));
222 
223  if (!$short)
224  {
225  $answered = $result_array['pass']['num_workedthrough'] . ' ' . strtolower($this->lng->txt('of')) . ' ' . (count($result_array) - 2);
226  $template->setVariable("VALUE_ANSWERED", $answered);
227  if( $this->object->isOfferingQuestionHintsEnabled() )
228  {
229  $template->setVariable("VALUE_HINTS", $total_requested_hints);
230  }
231  $template->setVariable("VALUE_REACHED", $total_reached . " " . strtolower($this->lng->txt("of")) . " " . $total_max);
232  $template->setVariable("VALUE_PERCENTAGE", sprintf("%.2f", $percentage) . "%");
233  }
234  $template->parseCurrentBlock();
235  }
236  }
237 
238  $template->setVariable("PASS_COUNTER", $this->lng->txt("pass"));
239  $template->setVariable("DATE", $this->lng->txt("date"));
240  if (!$short)
241  {
242  $template->setVariable("PASS_SCORED", $this->lng->txt("scored_pass"));
243  $template->setVariable("ANSWERED_QUESTIONS", $this->lng->txt("tst_answered_questions"));
244  if( $this->object->isOfferingQuestionHintsEnabled() )
245  {
246  $template->setVariable("REQUESTED_HINTS", $this->lng->txt("tst_question_hints_requested_hint_count_header"));
247  }
248  $template->setVariable("REACHED_POINTS", $this->lng->txt("tst_reached_points"));
249  $template->setVariable("PERCENTAGE_CORRECT", $this->lng->txt("tst_percent_solved"));
250  }
251  $template->parseCurrentBlock();
252 
253  return $template->get();
254  }
255 
263  function getFinalStatement($active_id)
264  {
265  $test_data_array = $this->object->getResultsForActiveId($active_id);
266 
267  $obligationsAnswered = $test_data_array['obligations_answered'];
268 
269  if (!$test_data_array["max_points"])
270  {
271  $percentage = 0;
272  }
273  else
274  {
275  $percentage = ($test_data_array["reached_points"]/$test_data_array["max_points"])*100;
276  }
277  $total_max = $test_data_array["max_points"];
278  $total_reached = $test_data_array["reached_points"];
279  $result_percentage = $percentage;
280  $result_total_reached = $total_reached;
281  $result_total_max = $total_max;
282 
283  $mark = "";
284  $markects = "";
285  $mark_obj = $this->object->mark_schema->getMatchingMark($result_percentage);
286  if ($mark_obj)
287  {
288  require_once './Modules/Test/classes/class.ilTestFinalMarkLangVarBuilder.php';
289  $langVarBuilder = new ilTestFinalMarkLangVarBuilder(
290  $mark_obj->getPassed(), $obligationsAnswered, $this->object->areObligationsEnabled()
291  );
292 
293  $mark = $this->lng->txt( $langVarBuilder->build() );
294 
295  $mark = str_replace("[mark]", $mark_obj->getOfficialName(), $mark);
296  $mark = str_replace("[markshort]", $mark_obj->getShortName(), $mark);
297  $mark = str_replace("[percentage]", sprintf("%.2f", $result_percentage), $mark);
298  $mark = str_replace("[reached]", $result_total_reached, $mark);
299  $mark = str_replace("[max]", $result_total_max, $mark);
300  }
301  if ($this->object->ects_output)
302  {
303  $passed_array =& $this->object->getTotalPointsPassedArray();
304  $ects_mark = $this->object->getECTSGrade($passed_array, $result_total_reached, $result_total_max);
305  $markects = $this->lng->txt("mark_tst_ects");
306  $markects = str_replace("[markects]", $this->lng->txt("ects_grade_". strtolower($ects_mark)), $markects);
307  }
308  return array("mark" => $mark, "markects" => $markects);
309  }
310 
321  function getPassListOfAnswers(&$result_array, $active_id, $pass, $show_solutions = FALSE, $only_answered_questions = FALSE, $show_question_only = FALSE, $show_reached_points = FALSE)
322  {
323  $maintemplate = new ilTemplate("tpl.il_as_tst_list_of_answers.html", TRUE, TRUE, "Modules/Test");
324 
325  $counter = 1;
326  // output of questions with solutions
327  foreach ($result_array as $question_data)
328  {
329  if (($question_data["workedthrough"] == 1) || ($only_answered_questions == FALSE))
330  {
331  $template = new ilTemplate("tpl.il_as_qpl_question_printview.html", TRUE, TRUE, "Modules/TestQuestionPool");
332  $question = $question_data["qid"];
333  if (is_numeric($question))
334  {
335  $maintemplate->setCurrentBlock("printview_question");
336  $question_gui = $this->object->createQuestionGUI("", $question);
337  if (is_object($question_gui))
338  {
339  if ($show_reached_points)
340  {
341  $template->setCurrentBlock("result_points");
342  $template->setVariable("RESULT_POINTS", $this->lng->txt("tst_reached_points") . ": " . $question_gui->object->getReachedPoints($active_id, $pass) . " " . $this->lng->txt("of") . " " . $question_gui->object->getMaximumPoints());
343  $template->parseCurrentBlock();
344  }
345  $template->setVariable("COUNTER_QUESTION", $counter.". ");
346  $template->setVariable("QUESTION_TITLE", $this->object->getQuestionTitle($question_gui->object->getTitle()));
347 
348  $show_question_only = ($this->object->getShowSolutionAnswersOnly()) ? TRUE : FALSE;
349  $result_output = $question_gui->getSolutionOutput($active_id, $pass, $show_solutions, FALSE, $show_question_only, $this->object->getShowSolutionFeedback());
350 
351  $template->setVariable("SOLUTION_OUTPUT", $result_output);
352  $maintemplate->setCurrentBlock("printview_question");
353  $maintemplate->setVariable("QUESTION_PRINTVIEW", $template->get());
354  $maintemplate->parseCurrentBlock();
355  $counter ++;
356  }
357  }
358  }
359  }
360  $maintemplate->setVariable("RESULTS_OVERVIEW", sprintf($this->lng->txt("tst_eval_results_by_pass"), $pass+1));
361  return $maintemplate->get();
362  }
363 
376  function getPassListOfAnswersWithScoring(&$result_array, $active_id, $pass, $show_solutions = FALSE)
377  {
378  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
379 
380  $maintemplate = new ilTemplate("tpl.il_as_tst_list_of_answers.html", TRUE, TRUE, "Modules/Test");
381 
382  include_once "./Modules/Test/classes/class.ilObjAssessmentFolder.php";
384 
385  $counter = 1;
386  // output of questions with solutions
387  foreach ($result_array as $question_data)
388  {
389  $question = $question_data["qid"];
390  if (is_numeric($question))
391  {
392  $question_gui = $this->object->createQuestionGUI("", $question);
393  if (in_array($question_gui->object->getQuestionTypeID(), $scoring))
394  {
395  $template = new ilTemplate("tpl.il_as_qpl_question_printview.html", TRUE, TRUE, "Modules/TestQuestionPool");
396  $scoretemplate = new ilTemplate("tpl.il_as_tst_manual_scoring_points.html", TRUE, TRUE, "Modules/Test");
397  #mbecker: No such block. $this->tpl->setCurrentBlock("printview_question");
398  $template->setVariable("COUNTER_QUESTION", $counter.". ");
399  $template->setVariable("QUESTION_TITLE", $this->object->getQuestionTitle($question_gui->object->getTitle()));
400  $points = $question_gui->object->getMaximumPoints();
401  if ($points == 1)
402  {
403  $template->setVariable("QUESTION_POINTS", $points . " " . $this->lng->txt("point"));
404  }
405  else
406  {
407  $template->setVariable("QUESTION_POINTS", $points . " " . $this->lng->txt("points"));
408  }
409 
410  $show_question_only = ($this->object->getShowSolutionAnswersOnly()) ? TRUE : FALSE;
411  $result_output = $question_gui->getSolutionOutput($active_id, $pass, $show_solutions, FALSE, $show_question_only, $this->object->getShowSolutionFeedback(), FALSE, TRUE);
412 
413  $solout = $question_gui->object->getSuggestedSolutionOutput();
414  if (strlen($solout))
415  {
416  $scoretemplate->setCurrentBlock("suggested_solution");
417  $scoretemplate->setVariable("TEXT_SUGGESTED_SOLUTION", $this->lng->txt("solution_hint"));
418  $scoretemplate->setVariable("VALUE_SUGGESTED_SOLUTION", $solout);
419  $scoretemplate->parseCurrentBlock();
420  }
421 
422  $scoretemplate->setCurrentBlock("feedback");
423  $scoretemplate->setVariable("FEEDBACK_NAME_INPUT", $question);
424  $feedback = $this->object->getManualFeedback($active_id, $question, $pass);
425  $scoretemplate->setVariable("VALUE_FEEDBACK", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($feedback, TRUE)));
426  $scoretemplate->setVariable("TEXT_MANUAL_FEEDBACK", $this->lng->txt("set_manual_feedback"));
427  $scoretemplate->parseCurrentBlock();
428 
429  $scoretemplate->setVariable("NAME_INPUT", $question);
430  $this->ctrl->setParameter($this, "active_id", $active_id);
431  $this->ctrl->setParameter($this, "pass", $pass);
432  $scoretemplate->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "manscoring"));
433  $scoretemplate->setVariable("LABEL_INPUT", $this->lng->txt("tst_change_points_for_question"));
434  $scoretemplate->setVariable("VALUE_INPUT", " value=\"" . assQuestion::_getReachedPoints($active_id, $question_data["qid"], $pass) . "\"");
435  $scoretemplate->setVariable("VALUE_SAVE", $this->lng->txt("save"));
436 
437  $template->setVariable("SOLUTION_OUTPUT", $result_output);
438  $maintemplate->setCurrentBlock("printview_question");
439  $maintemplate->setVariable("QUESTION_PRINTVIEW", $template->get());
440  $maintemplate->setVariable("QUESTION_SCORING", $scoretemplate->get());
441  $maintemplate->parseCurrentBlock();
442  }
443  $counter ++;
444  }
445  }
446  if ($counter == 1)
447  {
448  // no scorable questions found
449  $maintemplate->setVariable("NO_QUESTIONS_FOUND", $this->lng->txt("manscoring_questions_not_found"));
450  }
451  $maintemplate->setVariable("RESULTS_OVERVIEW", sprintf($this->lng->txt("manscoring_results_pass"), $pass+1));
452 
453  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
455 
456  return $maintemplate->get();
457  }
458 
459 
473  function getPassDetailsOverview($result_array, $active_id, $pass, $targetclass = "", $targetcommandsort = "", $targetcommanddetails = "", $standard_header = TRUE)
474  {
475  global $ilUser;
476 
477  $testresults = $result_array["pass"];
478  unset($result_array["test"]);
479  $user_id = $this->object->_getUserIdFromActiveId($active_id);
480 
481  $sort = ($_GET["sort"]) ? ($_GET["sort"]) : "nr";
482  $sortorder = ($_GET["sortorder"]) ? ($_GET["sortorder"]) : "asc";
483 
484  if (!$standard_header)
485  {
486  // change sortorder of result array
487  usort($result_array, "sortResults");
488  }
489  $color_class = array("tblrow1top", "tblrow2top");
490  $counter = 0;
491  $template = new ilTemplate("tpl.il_as_tst_pass_details_overview.html", TRUE, TRUE, "Modules/Test");
492  $this->ctrl->setParameterByClass($targetclass, "pass", "$pass");
493 
494  if (!$testresults["total_max_points"])
495  {
496  $percentage = 0;
497  }
498  else
499  {
500  $percentage = ($testresults["total_reached_points"]/$testresults["total_max_points"])*100;
501  }
502  $total_max = $testresults["total_max_points"];
503  $total_reached = $testresults["total_reached_points"];
504  $totalRequestedHints = $testresults["total_requested_hints"];
505 
506  $img_title_percent = "";
507  $img_title_nr = "";
508  $hasSuggestedSolutions = FALSE;
509  if ($this->object->getShowSolutionSuggested())
510  {
511  foreach ($result_array as $key => $value)
512  {
513  if (strlen($value["solution"]))
514  {
515  $hasSuggestedSolutions = TRUE;
516  }
517  }
518  }
519  foreach ($result_array as $key => $value)
520  {
521  if (preg_match("/\d+/", $key))
522  {
523  if (strlen($targetclass) && strlen($targetcommanddetails))
524  {
525  $template->setCurrentBlock("linked_title");
526  $template->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
527  $template->setVariable("VALUE_QUESTION_TITLE", $value["title"]);
528  $this->ctrl->setParameterByClass($targetclass, "evaluation", $value["qid"]);
529  $this->ctrl->setParameterByClass($targetclass, "active_id", $active_id);
530  $template->setVariable("URL_QUESTION_TITLE", $this->ctrl->getLinkTargetByClass($targetclass, $targetcommanddetails));
531  $template->parseCurrentBlock();
532  }
533  else
534  {
535  $template->setCurrentBlock("plain_title");
536  $template->setVariable("VALUE_QUESTION_TITLE", $value["title"]);
537  $template->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
538  $template->parseCurrentBlock();
539  }
540  if ($hasSuggestedSolutions)
541  {
542  $template->setCurrentBlock("question_suggested_solution");
543  $template->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
544  $template->setVariable("SOLUTION_HINT", $this->object->prepareTextareaOutput($value["solution"], true));
545  $template->parseCurrentBlock();
546  }
547  $template->setCurrentBlock("question");
548  $template->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
549  $template->setVariable("VALUE_QUESTION_COUNTER", $value["nr"]);
550  $template->setVariable("VALUE_MAX_POINTS", $value["max"]);
551  $template->setVariable("VALUE_REACHED_POINTS", $value["reached"]);
552  if( $this->object->isOfferingQuestionHintsEnabled() )
553  {
554  $template->setVariable("VALUE_HINT_COUNT", $value["requested_hints"]);
555  }
556  $template->setVariable("VALUE_PERCENT_SOLVED", $value["percent"]);
557  $template->parseCurrentBlock();
558  $counter++;
559  }
560  }
561 
562  if ($hasSuggestedSolutions)
563  {
564  $template->touchBlock("footer_suggested_solution");
565  }
566  $template->setCurrentBlock("footer");
567  $template->setVariable("VALUE_QUESTION_COUNTER", "<strong>" . $this->lng->txt("total") . "</strong>");
568  $template->setVariable("VALUE_QUESTION_TITLE", "");
569  $template->setVariable("VALUE_MAX_POINTS", "<strong>$total_max</strong>");
570  $template->setVariable("VALUE_REACHED_POINTS", "<strong>$total_reached</strong>");
571  if( $this->object->isOfferingQuestionHintsEnabled() )
572  {
573  $template->setVariable("VALUE_TOTAL_HINT_COUNT", "<strong>$totalRequestedHints</strong>");
574  }
575  $template->setVariable("VALUE_PERCENT_SOLVED", "<strong>" . sprintf("%2.2f", $percentage) . " %" . "</strong>");
576  $template->parseCurrentBlock();
577 
578  if ($standard_header)
579  {
580  if ($hasSuggestedSolutions)
581  {
582  $template->setCurrentBlock("standard_header_suggested_solution");
583  $template->setVariable("SOLUTION_HINT_HEADER", $this->lng->txt("solution_hint"));
584  $template->parseCurrentBlock();
585  }
586  $template->setCurrentBlock("standard_header");
587  $template->setVariable("QUESTION_COUNTER", $this->lng->txt("tst_question_no"));
588  $template->setVariable("PERCENT_SOLVED", $this->lng->txt("tst_percent_solved"));
589  $template->setVariable("QUESTION_TITLE", $this->lng->txt("tst_question_title"));
590  $template->setVariable("MAX_POINTS", $this->lng->txt("tst_maximum_points"));
591  $template->setVariable("REACHED_POINTS", $this->lng->txt("tst_reached_points"));
592  if( $this->object->isOfferingQuestionHintsEnabled() )
593  {
594  $template->setVariable("HINT_COUNT", $this->lng->txt("tst_question_hints_requested_hint_count_header"));
595  }
596  $template->parseCurrentBlock();
597  }
598  else
599  {
600  if ($hasSuggestedSolutions)
601  {
602  $template->setCurrentBlock("linked_header_suggested_solution");
603  if (strcmp($sort, "solution") == 0)
604  {
605  $this->ctrl->setParameterByClass($targetclass, "sortorder", !strcmp($sortorder, "asc") ? "desc" : "asc");
606  }
607  else
608  {
609  $this->ctrl->setParameterByClass($targetclass, "sortorder", "asc");
610  }
611  $this->ctrl->setParameterByClass($targetclass, "sort", "solution");
612  $template->setVariable("URL_SOLUTION_HINT_HEADER", $this->ctrl->getLinkTargetByClass($targetclass, $targetcommandsort));
613  $template->setVariable("SOLUTION_HINT_HEADER", $this->lng->txt("solution_hint"));
614  if (strcmp($sort, "solution") == 0)
615  {
616  $image = new ilTemplate("tpl.image.html", TRUE, TRUE, "Modules/Test");
617  $image->setVariable("IMAGE_SOURCE", ilUtil::getImagePath($sortorder . "_order.png"));
618  $image->setVariable("IMAGE_ALT", $this->lng->txt("change_sort_direction"));
619  $image->setVariable("IMAGE_TITLE", $this->lng->txt("change_sort_direction"));
620  $template->setVariable("IMAGE_SOLUTION_HINT_HEADER", $image->get());
621  }
622  $template->parseCurrentBlock();
623  }
624  $template->setCurrentBlock("linked_header");
625  $this->ctrl->setParameterByClass($targetclass, "sort", "nr");
626  if (strcmp($sort, "nr") == 0)
627  {
628  $this->ctrl->setParameterByClass($targetclass, "sortorder", !strcmp($sortorder, "asc") ? "desc" : "asc");
629  }
630  else
631  {
632  $this->ctrl->setParameterByClass($targetclass, "sortorder", "asc");
633  }
634  $template->setVariable("URL_QUESTION_COUNTER", $this->ctrl->getLinkTargetByClass($targetclass, $targetcommandsort));
635  $template->setVariable("QUESTION_COUNTER", $this->lng->txt("tst_question_no"));
636  if (strcmp($sort, "nr") == 0)
637  {
638  $image = new ilTemplate("tpl.image.html", TRUE, TRUE, "Modules/Test");
639  $image->setVariable("IMAGE_SOURCE", ilUtil::getImagePath($sortorder . "_order.png"));
640  $image->setVariable("IMAGE_ALT", $this->lng->txt("change_sort_direction"));
641  $image->setVariable("IMAGE_TITLE", $this->lng->txt("change_sort_direction"));
642  $template->setVariable("IMAGE_QUESTION_COUNTER", $image->get());
643  }
644  $this->ctrl->setParameterByClass($targetclass, "sort", "percent");
645  if (strcmp($sort, "percent") == 0)
646  {
647  $this->ctrl->setParameterByClass($targetclass, "sortorder", !strcmp($sortorder, "asc") ? "desc" : "asc");
648  }
649  else
650  {
651  $this->ctrl->setParameterByClass($targetclass, "sortorder", "asc");
652  }
653  $template->setVariable("URL_PERCENT_SOLVED", $this->ctrl->getLinkTargetByClass($targetclass, $targetcommandsort));
654  $template->setVariable("PERCENT_SOLVED", $this->lng->txt("tst_percent_solved"));
655  if (strcmp($sort, "percent") == 0)
656  {
657  $image = new ilTemplate("tpl.image.html", TRUE, TRUE, "Modules/Test");
658  $image->setVariable("IMAGE_SOURCE", ilUtil::getImagePath($sortorder . "_order.png"));
659  $image->setVariable("IMAGE_ALT", $this->lng->txt("change_sort_direction"));
660  $image->setVariable("IMAGE_TITLE", $this->lng->txt("change_sort_direction"));
661  $template->setVariable("IMAGE_PERCENT_SOLVED", $image->get());
662  }
663  $this->ctrl->setParameterByClass($targetclass, "sort", "title");
664  if (strcmp($sort, "title") == 0)
665  {
666  $this->ctrl->setParameterByClass($targetclass, "sortorder", !strcmp($sortorder, "asc") ? "desc" : "asc");
667  }
668  else
669  {
670  $this->ctrl->setParameterByClass($targetclass, "sortorder", "asc");
671  }
672  $template->setVariable("URL_QUESTION_TITLE", $this->ctrl->getLinkTargetByClass($targetclass, $targetcommandsort));
673  $template->setVariable("QUESTION_TITLE", $this->lng->txt("tst_question_title"));
674  if (strcmp($sort, "title") == 0)
675  {
676  $image = new ilTemplate("tpl.image.html", TRUE, TRUE, "Modules/Test");
677  $image->setVariable("IMAGE_SOURCE", ilUtil::getImagePath($sortorder . "_order.png"));
678  $image->setVariable("IMAGE_ALT", $this->lng->txt("change_sort_direction"));
679  $image->setVariable("IMAGE_TITLE", $this->lng->txt("change_sort_direction"));
680  $template->setVariable("IMAGE_QUESTION_TITLE", $image->get());
681  }
682  $this->ctrl->setParameterByClass($targetclass, "sort", "max");
683  if (strcmp($sort, "max") == 0)
684  {
685  $this->ctrl->setParameterByClass($targetclass, "sortorder", strcmp($sortorder, "asc") ? "desc" : "asc");
686  }
687  else
688  {
689  $this->ctrl->setParameterByClass($targetclass, "sortorder", "asc");
690  }
691  $template->setVariable("URL_MAX_POINTS", $this->ctrl->getLinkTargetByClass($targetclass, $targetcommandsort));
692  $template->setVariable("MAX_POINTS", $this->lng->txt("tst_maximum_points"));
693  if (strcmp($sort, "max") == 0)
694  {
695  $image = new ilTemplate("tpl.image.html", TRUE, TRUE, "Modules/Test");
696  $image->setVariable("IMAGE_SOURCE", ilUtil::getImagePath($sortorder . "_order.png"));
697  $image->setVariable("IMAGE_ALT", $this->lng->txt("change_sort_direction"));
698  $image->setVariable("IMAGE_TITLE", $this->lng->txt("change_sort_direction"));
699  $template->setVariable("IMAGE_MAX_POINTS", $image->get());
700  }
701  $this->ctrl->setParameterByClass($targetclass, "sort", "reached");
702  if (strcmp($sort, "reached") == 0)
703  {
704  $this->ctrl->setParameterByClass($targetclass, "sortorder", !strcmp($sortorder, "asc") ? "desc" : "asc");
705  }
706  else
707  {
708  $this->ctrl->setParameterByClass($targetclass, "sortorder", "asc");
709  }
710  $template->setVariable("URL_REACHED_POINTS", $this->ctrl->getLinkTargetByClass($targetclass, $targetcommandsort));
711  $template->setVariable("REACHED_POINTS", $this->lng->txt("tst_reached_points"));
712  if (strcmp($sort, "reached") == 0)
713  {
714  $image = new ilTemplate("tpl.image.html", TRUE, TRUE, "Modules/Test");
715  $image->setVariable("IMAGE_SOURCE", ilUtil::getImagePath($sortorder . "_order.png"));
716  $image->setVariable("IMAGE_ALT", $this->lng->txt("change_sort_direction"));
717  $image->setVariable("IMAGE_TITLE", $this->lng->txt("change_sort_direction"));
718  $template->setVariable("IMAGE_REACHED_POINTS", $image->get());
719  }
720  $template->parseCurrentBlock();
721  }
722 
723  return $template->get();
724  }
725 
733  {
734  if ($this->object->getShowSolutionSignature() && !$this->object->getAnonymity())
735  {
736  // output of time/date and signature
737  $template = new ilTemplate("tpl.il_as_tst_results_userdata_signature.html", TRUE, TRUE, "Modules/Test");
738  $template->setVariable("TXT_DATE", $this->lng->txt("date"));
739  $template->setVariable("VALUE_DATE", strftime("%Y-%m-%d %H:%M:%S", time()));
740  $template->setVariable("TXT_SIGNATURE", $this->lng->txt("tst_signature"));
741  $template->setVariable("IMG_SPACER", ilUtil::getImagePath("spacer.png"));
742  return $template->get();
743  }
744  else
745  {
746  return "";
747  }
748  }
749 
758  function getResultsUserdata($active_id, $overwrite_anonymity = FALSE)
759  {
760  $template = new ilTemplate("tpl.il_as_tst_results_userdata.html", TRUE, TRUE, "Modules/Test");
761  include_once './Services/User/classes/class.ilObjUser.php';
762  $user_id = $this->object->_getUserIdFromActiveId($active_id);
763  if (strlen(ilObjUser::_lookupLogin($user_id)) > 0)
764  {
765  $user = new ilObjUser($user_id);
766  }
767  else
768  {
769  $user = new ilObjUser();
770  $user->setLastname($this->lng->txt("deleted_user"));
771  }
772  $t = $this->object->getTestSession($active_id)->getSubmittedTimestamp();
773  if (!$t)
774  {
775  $t = $this->object->_getLastAccess($this->object->getTestSession()->getActiveId());
776  }
777  $print_date = mktime(date("H"), date("i"), date("s"), date("m") , date("d"), date("Y"));
778 
779  $title_matric = "";
780  if (strlen($user->getMatriculation()) && (($this->object->getAnonymity() == FALSE) || ($overwrite_anonymity)))
781  {
782  $template->setCurrentBlock("user_matric");
783  $template->setVariable("TXT_USR_MATRIC", $this->lng->txt("matriculation"));
784  $template->parseCurrentBlock();
785  $template->setCurrentBlock("user_matric_value");
786  $template->setVariable("VALUE_USR_MATRIC", $user->getMatriculation());
787  $template->parseCurrentBlock();
788  $template->touchBlock("user_matric_separator");
789  $title_matric = " - " . $this->lng->txt("matriculation") . ": " . $user->getMatriculation();
790  }
791 
792  $invited_user = array_pop($this->object->getInvitedUsers($user_id));
793  if (strlen($invited_user["clientip"]))
794  {
795  $template->setCurrentBlock("user_clientip");
796  $template->setVariable("TXT_CLIENT_IP", $this->lng->txt("client_ip"));
797  $template->parseCurrentBlock();
798  $template->setCurrentBlock("user_clientip_value");
799  $template->setVariable("VALUE_CLIENT_IP", $invited_user["clientip"]);
800  $template->parseCurrentBlock();
801  $template->touchBlock("user_clientip_separator");
802  $title_client = " - " . $this->lng->txt("clientip") . ": " . $invited_user["clientip"];
803  }
804 
805  $template->setVariable("TXT_TEST_TITLE", $this->lng->txt("title"));
806  $template->setVariable("VALUE_TEST_TITLE", $this->object->getTitle());
807  $template->setVariable("TXT_USR_NAME", $this->lng->txt("name"));
808  $uname = $this->object->userLookupFullName($user_id, $overwrite_anonymity);
809  $template->setVariable("VALUE_USR_NAME", $uname);
810  $template->setVariable("TXT_TEST_DATE", $this->lng->txt("tst_tst_date"));
811  $template->setVariable("VALUE_TEST_DATE", strftime("%Y-%m-%d %H:%M:%S",ilUtil::date_mysql2time($t)));
812  $template->setVariable("TXT_PRINT_DATE", $this->lng->txt("tst_print_date"));
813  $template->setVariable("VALUE_PRINT_DATE", strftime("%Y-%m-%d %H:%M:%S",$print_date));
814 
815  // change the pagetitle
816  $pagetitle = ": " . $this->object->getTitle() . $title_matric . $title_client;
817  $this->tpl->setHeaderPageTitle($pagetitle);
818 
819  return $template->get();
820  }
821 
831  function getCorrectSolutionOutput($question_id, $active_id, $pass)
832  {
833  global $ilUser;
834 
835  $test_id = $this->object->getTestId();
836  $question_gui = $this->object->createQuestionGUI("", $question_id);
837 
838  $template = new ilTemplate("tpl.il_as_tst_correct_solution_output.html", TRUE, TRUE, "Modules/Test");
839  $show_question_only = ($this->object->getShowSolutionAnswersOnly()) ? TRUE : FALSE;
840  $result_output = $question_gui->getSolutionOutput($active_id, $pass, TRUE, FALSE, $show_question_only, $this->object->getShowSolutionFeedback(), FALSE, FALSE, TRUE);
841  $best_output = $question_gui->getSolutionOutput($active_id, $pass, FALSE, FALSE, $show_question_only, FALSE, TRUE, FALSE, FALSE);
842  if( $this->object->getShowSolutionFeedback() && $_GET['cmd'] != 'outCorrectSolution' )
843  {
844  $specificAnswerFeedback = $question_gui->getSpecificFeedbackOutput($active_id, $pass);
845  if( strlen($specificAnswerFeedback) )
846  {
847  $template->setCurrentBlock("outline_specific_feedback");
848  $template->setVariable("OUTLINE_SPECIFIC_FEEDBACK", $specificAnswerFeedback);
849  $template->parseCurrentBlock();
850  }
851  }
852  if ($this->object->isBestSolutionPrintedWithResult() && strlen($best_output))
853  {
854  $template->setCurrentBlock("best_solution");
855  $template->setVariable("TEXT_BEST_SOLUTION", $this->lng->txt("tst_best_solution_is"));
856  $template->setVariable("BEST_OUTPUT", $best_output);
857  $template->parseCurrentBlock();
858  }
859  $template->setVariable("TEXT_YOUR_SOLUTION", $this->lng->txt("tst_your_answer_was"));
860  $maxpoints = $question_gui->object->getMaximumPoints();
861  if ($maxpoints == 1)
862  {
863  $template->setVariable("QUESTION_TITLE", $this->object->getQuestionTitle($question_gui->object->getTitle()) . " (" . $maxpoints . " " . $this->lng->txt("point") . ")");
864  }
865  else
866  {
867  $template->setVariable("QUESTION_TITLE", $this->object->getQuestionTitle($question_gui->object->getTitle()) . " (" . $maxpoints . " " . $this->lng->txt("points") . ")");
868  }
869  $template->setVariable("SOLUTION_OUTPUT", $result_output);
870  $template->setVariable("RECEIVED_POINTS", sprintf($this->lng->txt("you_received_a_of_b_points"), $question_gui->object->getReachedPoints($active_id, $pass), $maxpoints));
871  $template->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
872  $template->setVariable("BACKLINK_TEXT", "&lt;&lt; " . $this->lng->txt("back"));
873  return $template->get();
874  }
875 
881  function getResultsOfUserOutput($active_id, $pass, $show_pass_details = TRUE, $show_answers = TRUE, $show_question_only = FALSE, $show_reached_points = FALSE)
882  {
883  global $ilias, $tpl;
884 
885  include_once("./Services/UICore/classes/class.ilTemplate.php");
886  $template = new ilTemplate("tpl.il_as_tst_results_participant.html", TRUE, TRUE, "Modules/Test");
887 
888  $user_id = $this->object->_getUserIdFromActiveId($active_id);
889  $uname = $this->object->userLookupFullName($user_id, TRUE);
890 
891  if (((array_key_exists("pass", $_GET)) && (strlen($_GET["pass"]) > 0)) || (!is_null($pass)))
892  {
893  if (is_null($pass)) $pass = $_GET["pass"];
894  }
895 
896  $statement = $this->getFinalStatement($active_id);
897  $user_data = $this->getResultsUserdata($active_id, TRUE);
898 
899  if (!is_null($pass))
900  {
901  $result_array =& $this->object->getTestResult($active_id, $pass);
902  $command_solution_details = "";
903  if ($show_pass_details)
904  {
905  $detailsoverview = $this->getPassDetailsOverview($result_array, $active_id, $pass, "iltestservicegui", "getResultsOfUserOutput", $command_solution_details);
906  }
907 
908  $user_id = $this->object->_getUserIdFromActiveId($active_id);
909  $showAllAnswers = TRUE;
910  if ($this->object->isExecutable($user_id))
911  {
912  $showAllAnswers = FALSE;
913  }
914  if ($show_answers)
915  {
916  $list_of_answers = $this->getPassListOfAnswers($result_array, $active_id, $pass, FALSE, $showAllAnswers, $show_question_only, $show_reached_points);
917  }
918 
919  $template->setVariable("LIST_OF_ANSWERS", $list_of_answers);
920  //$template->setVariable("PASS_RESULTS_OVERVIEW", sprintf($this->lng->txt("tst_results_overview_pass"), $pass + 1));
921  $template->setVariable("PASS_DETAILS", $detailsoverview);
922 
923  $signature = $this->getResultsSignature();
924  $template->setVariable("SIGNATURE", $signature);
925  }
926  $template->setVariable("TEXT_HEADING", sprintf($this->lng->txt("tst_result_user_name"), $uname));
927  $template->setVariable("USER_DATA", $user_data);
928  $template->setVariable("USER_MARK", $statement["mark"]);
929  if (strlen($statement["markects"]))
930  {
931  $template->setVariable("USER_MARK_ECTS", $statement["markects"]);
932  }
933  $template->parseCurrentBlock();
934 
935  return $template->get();
936  }
937 
945  function getResultsHeadUserAndPass($active_id, $pass)
946  {
947  $template = new ilTemplate("tpl.il_as_tst_results_head_user_pass.html", TRUE, TRUE, "Modules/Test");
948  include_once './Services/User/classes/class.ilObjUser.php';
949  $user_id = $this->object->_getUserIdFromActiveId($active_id);
950  if (strlen(ilObjUser::_lookupLogin($user_id)) > 0)
951  {
952  $user = new ilObjUser($user_id);
953  }
954  else
955  {
956  $user = new ilObjUser();
957  $user->setLastname($this->lng->txt("deleted_user"));
958  }
959  $title_matric = "";
960  if (strlen($user->getMatriculation()) && (($this->object->getAnonymity() == FALSE)))
961  {
962  $template->setCurrentBlock("user_matric");
963  $template->setVariable("TXT_USR_MATRIC", $this->lng->txt("matriculation"));
964  $template->parseCurrentBlock();
965  $template->setCurrentBlock("user_matric_value");
966  $template->setVariable("VALUE_USR_MATRIC", $user->getMatriculation());
967  $template->parseCurrentBlock();
968  $template->touchBlock("user_matric_separator");
969  $title_matric = " - " . $this->lng->txt("matriculation") . ": " . $user->getMatriculation();
970  }
971 
972  $invited_user = array_pop($this->object->getInvitedUsers($user_id));
973  if (strlen($invited_user["clientip"]))
974  {
975  $template->setCurrentBlock("user_clientip");
976  $template->setVariable("TXT_CLIENT_IP", $this->lng->txt("client_ip"));
977  $template->parseCurrentBlock();
978  $template->setCurrentBlock("user_clientip_value");
979  $template->setVariable("VALUE_CLIENT_IP", $invited_user["clientip"]);
980  $template->parseCurrentBlock();
981  $template->touchBlock("user_clientip_separator");
982  $title_client = " - " . $this->lng->txt("clientip") . ": " . $invited_user["clientip"];
983  }
984 
985  $template->setVariable("TXT_USR_NAME", $this->lng->txt("name"));
986  $uname = $this->object->userLookupFullName($user_id, FALSE);
987  $template->setVariable("VALUE_USR_NAME", $uname);
988  $template->setVariable("TXT_PASS", $this->lng->txt("scored_pass"));
989  $template->setVariable("VALUE_PASS", $pass);
990  return $template->get();
991  }
992 
1001  function getQuestionResultForTestUsers($question_id, $test_id)
1002  {
1003  // REQUIRED, since we call this object regardless of the loop
1004  $question_gui =& $this->object->createQuestionGUI("", $question_id);
1005 
1006  $foundusers = $this->object->getParticipantsForTestAndQuestion($test_id, $question_id);
1007  $output = "";
1008  foreach ($foundusers as $active_id => $passes)
1009  {
1010  $resultpass = $this->object->_getResultPass($active_id);
1011  for ($i = 0; $i < count($passes); $i++)
1012  {
1013  if (($resultpass !== null) && ($resultpass == $passes[$i]["pass"]))
1014  {
1015  // check if re-instantiation is really neccessary
1016  $question_gui =& $this->object->createQuestionGUI("", $passes[$i]["qid"]);
1017 
1018  $output .= $this->getResultsHeadUserAndPass($active_id, $resultpass+1);
1019  $output .= $question_gui->getSolutionOutput($active_id, $resultpass, $graphicalOutput = FALSE, $result_output = FALSE, $show_question_only = FALSE, $show_feedback = FALSE);
1020  $output .= "<br /><br /><br />";
1021  }
1022  }
1023  }
1024  $this->object->deliverPDFfromHTML($output, $question_gui->object->getTitle());
1025  }
1026 }
1027 
1028 // internal sort function to sort the result array
1029 function sortResults($a, $b)
1030 {
1031  $sort = ($_GET["sort"]) ? ($_GET["sort"]) : "nr";
1032  $sortorder = ($_GET["sortorder"]) ? ($_GET["sortorder"]) : "asc";
1033  if (strcmp($sortorder, "asc"))
1034  {
1035  $smaller = 1;
1036  $greater = -1;
1037  }
1038  else
1039  {
1040  $smaller = -1;
1041  $greater = 1;
1042  }
1043  if ($a[$sort] == $b[$sort]) return 0;
1044  return ($a[$sort] < $b[$sort]) ? $smaller : $greater;
1045 }
1046 
1047 ?>