ILIAS  eassessment Revision 61809
 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 
40 {
41  var $object;
42  var $lng;
43  var $tpl;
44  var $ctrl;
45  var $ilias;
46  var $tree;
47  var $ref_id;
48 
57  function ilTestServiceGUI($a_object)
58  {
59  global $lng, $tpl, $ilCtrl, $ilias, $tree;
60 
61  $this->lng =& $lng;
62  $this->tpl =& $tpl;
63  $this->ctrl =& $ilCtrl;
64  $this->ilias =& $ilias;
65  $this->object =& $a_object;
66  $this->tree =& $tree;
67  $this->ref_id = $a_object->ref_id;
68  }
69 
73  function &executeCommand()
74  {
75  $cmd = $this->ctrl->getCmd();
76  $next_class = $this->ctrl->getNextClass($this);
77 
78  $cmd = $this->getCommand($cmd);
79  switch($next_class)
80  {
81  default:
82  $ret =& $this->$cmd();
83  break;
84  }
85  return $ret;
86  }
87 
95  function getCommand($cmd)
96  {
97  return $cmd;
98  }
99 
108  function getPassOverview($active_id, $targetclass = "", $targetcommand = "", $short = FALSE, $hide_details = FALSE)
109  {
110  global $ilUser;
111 
112  if ($short)
113  {
114  $template = new ilTemplate("tpl.il_as_tst_pass_overview_short.html", TRUE, TRUE, "Modules/Test");
115  }
116  else
117  {
118  $template = new ilTemplate("tpl.il_as_tst_pass_overview.html", TRUE, TRUE, "Modules/Test");
119  }
120  $color_class = array("tblrow1", "tblrow2");
121  $counter = 0;
122 
123  $user_id = $this->object->_getUserIdFromActiveId($active_id);
124  $counted_pass = $this->object->_getResultPass($active_id);
125  $reached_pass = $this->object->_getPass($active_id);
126 
127  $result_percentage = 0;
128  $result_total_reached = 0;
129  $result_total_max = 0;
130  for ($pass = 0; $pass <= $reached_pass; $pass++)
131  {
132  $finishdate = $this->object->getPassFinishDate($active_id, $pass);
133  if ($finishdate > 0)
134  {
135  if (!$short)
136  {
137  $result_array =& $this->object->getTestResult($active_id, $pass);
138  if (!$result_array["pass"]["total_max_points"])
139  {
140  $percentage = 0;
141  }
142  else
143  {
144  $percentage = ($result_array["pass"]["total_reached_points"]/$result_array["pass"]["total_max_points"])*100;
145  }
146  $total_max = $result_array["pass"]["total_max_points"];
147  $total_reached = $result_array["pass"]["total_reached_points"];
148  }
149  if (!$hide_details)
150  {
151  if (strlen($targetclass) && strlen($targetcommand))
152  {
153  $this->ctrl->setParameterByClass($targetclass, "active_id", $active_id);
154  $this->ctrl->setParameterByClass($targetclass, "pass", $pass);
155  $template->setCurrentBlock("pass_details");
156  $template->setVariable("HREF_PASS_DETAILS", $this->ctrl->getLinkTargetByClass($targetclass, $targetcommand));
157  $template->setVariable("TEXT_PASS_DETAILS", $this->lng->txt("tst_pass_details"));
158  $template->parseCurrentBlock();
159  }
160  }
161 
162  $template->setCurrentBlock("result_row");
163 
164  if (($pass == $counted_pass) && (!$short))
165  {
166  $template->setVariable("COLOR_CLASS", "tblrowmarked");
167  $template->setVariable("VALUE_SCORED", "&otimes;");
168  if (!$result_array["test"]["total_max_points"])
169  {
170  $result_percentage = 0;
171  }
172  else
173  {
174  $result_percentage = ($result_array["test"]["total_reached_points"]/$result_array["test"]["total_max_points"])*100;
175  }
176  $result_total_max = $result_array["test"]["total_max_points"];
177  $result_total_reached = $result_array["test"]["total_reached_points"];
178  }
179  else
180  {
181  $template->setVariable("COLOR_CLASS", $color_class[$pass % 2]);
182  }
183  $template->setVariable("VALUE_PASS", $pass + 1);
184  $template->setVariable("VALUE_DATE",ilDatePresentation::formatDate(new ilDate($finishdate,IL_CAL_UNIX)));
185 
186  if (!$short)
187  {
188  $template->setVariable("VALUE_ANSWERED", $this->object->getAnsweredQuestionCount($active_id, $pass) . " " . strtolower($this->lng->txt("of")) . " " . (count($result_array)-2));
189  $template->setVariable("VALUE_REACHED", $total_reached . " " . strtolower($this->lng->txt("of")) . " " . $total_max);
190  $template->setVariable("VALUE_PERCENTAGE", sprintf("%.2f", $percentage) . "%");
191  }
192  $template->parseCurrentBlock();
193  }
194  }
195 
196  $template->setVariable("PASS_COUNTER", $this->lng->txt("pass"));
197  $template->setVariable("DATE", $this->lng->txt("date"));
198  if (!$short)
199  {
200  $template->setVariable("PASS_SCORED", $this->lng->txt("scored_pass"));
201  $template->setVariable("ANSWERED_QUESTIONS", $this->lng->txt("tst_answered_questions"));
202  $template->setVariable("REACHED_POINTS", $this->lng->txt("tst_reached_points"));
203  $template->setVariable("PERCENTAGE_CORRECT", $this->lng->txt("tst_percent_solved"));
204  }
205  $template->parseCurrentBlock();
206 
207  return $template->get();
208  }
209 
219  function getFinalStatement($active_id)
220  {
221  $test_data_array = $this->object->getResultsForActiveId($active_id);
222  if (!$test_data_array["max_points"])
223  {
224  $percentage = 0;
225  }
226  else
227  {
228  $percentage = ($test_data_array["reached_points"]/$test_data_array["max_points"])*100;
229  }
230  $total_max = $test_data_array["max_points"];
231  $total_reached = $test_data_array["reached_points"];
232  $result_percentage = $percentage;
233  $result_total_reached = $total_reached;
234  $result_total_max = $total_max;
235 
236  $mark = "";
237  $markects = "";
238  $mark_obj = $this->object->mark_schema->getMatchingMark($result_percentage);
239  if ($mark_obj)
240  {
241  if ($mark_obj->getPassed())
242  {
243  $mark = $this->lng->txt("mark_tst_passed");
244  }
245  else
246  {
247  $mark = $this->lng->txt("mark_tst_failed");
248  }
249  $mark = str_replace("[mark]", $mark_obj->getOfficialName(), $mark);
250  $mark = str_replace("[markshort]", $mark_obj->getShortName(), $mark);
251  $mark = str_replace("[percentage]", sprintf("%.2f", $result_percentage), $mark);
252  $mark = str_replace("[reached]", $result_total_reached, $mark);
253  $mark = str_replace("[max]", $result_total_max, $mark);
254  }
255  if ($this->object->ects_output)
256  {
257  $passed_array =& $this->object->getTotalPointsPassedArray();
258  $ects_mark = $this->object->getECTSGrade($passed_array, $result_total_reached, $result_total_max);
259  $markects = $this->lng->txt("mark_tst_ects");
260  $markects = str_replace("[markects]", $this->lng->txt("ects_grade_". strtolower($ects_mark)), $markects);
261  }
262  return array("mark" => $mark, "markects" => $markects);
263  }
264 
275  function getPassListOfAnswers(&$result_array, $active_id, $pass, $show_solutions = FALSE, $only_answered_questions = FALSE, $show_question_only = FALSE, $show_reached_points = FALSE, $compare_solutions = FALSE)
276  {
277  $maintemplate = new ilTemplate("tpl.il_as_tst_list_of_answers.html", TRUE, TRUE, "Modules/Test");
278  $counter = 1;
279  // output of questions with solutions
280  foreach ($result_array as $question_data)
281  {
282  if (($question_data["workedthrough"] == 1) || ($only_answered_questions == FALSE))
283  {
284  $template = new ilTemplate("tpl.il_as_qpl_question_printview.html", TRUE, TRUE, "Modules/TestQuestionPool");
285  $question = $question_data["qid"];
286  if (is_numeric($question))
287  {
288  $maintemplate->setCurrentBlock("printview_question");
289  $question_gui = $this->object->createQuestionGUI("", $question);
290  if (is_object($question_gui))
291  {
292  if ($show_reached_points)
293  {
294  $template->setCurrentBlock("result_points");
295  $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());
296  $template->parseCurrentBlock();
297  }
298  $template->setVariable("COUNTER_QUESTION", $counter.". ");
299  $template->setVariable("QUESTION_ID", $question_gui->object->getId());
300  $template->setVariable("QUESTION_TITLE", $this->object->getQuestionTitle($question_gui->object->getTitle()));
301 
302  $show_question_only = ($this->object->getShowSolutionAnswersOnly()) ? TRUE : FALSE;
303  if ($compare_solutions)
304  {
305  $result_output = $question_gui->getSolutionOutput($active_id, $pass, $show_solutions = TRUE, FALSE, $show_question_only, $this->object->getShowSolutionFeedback());
306  $best_output = $question_gui->getSolutionOutput($active_id, $pass, $show_solutions, FALSE, $show_question_only, $this->object->getShowSolutionFeedback(), true);
307  $compare_template = new ilTemplate("tpl.il_as_tst_answers_compare.html", TRUE, TRUE, "Modules/Test");
308  if (strlen(trim($this->lng->txt('tst_header_participant'))))
309  {
310  $compare_template->setCurrentBlock('header_participant');
311  $compare_template->setVariable("HEADER_PARTICIPANT", $this->lng->txt('tst_header_participant'));
312  $compare_template->parseCurrentBlock();
313  }
314  if (strlen(trim($this->lng->txt('tst_header_solution'))))
315  {
316  $compare_template->setCurrentBlock('header_solution');
317  $compare_template->setVariable("HEADER_SOLUTION", $this->lng->txt('tst_header_solution'));
318  $compare_template->parseCurrentBlock();
319  }
320  $compare_template->setVariable("PARTICIPANT", $result_output);
321  $compare_template->setVariable("SOLUTION", $best_output);
322  $template->setVariable("SOLUTION_OUTPUT", $compare_template->get());
323  }
324  else
325  {
326  $result_output = $question_gui->getSolutionOutput($active_id, $pass, $show_solutions, FALSE, $show_question_only, $this->object->getShowSolutionFeedback());
327  $template->setVariable("SOLUTION_OUTPUT", $result_output);
328  }
329  $maintemplate->setCurrentBlock("printview_question");
330  $maintemplate->setVariable("QUESTION_PRINTVIEW", $template->get());
331  $maintemplate->parseCurrentBlock();
332  $counter ++;
333  }
334  }
335  }
336  }
337  $maintemplate->setVariable("RESULTS_OVERVIEW", sprintf($this->lng->txt("tst_eval_results_by_pass"), $pass+1));
338  return $maintemplate->get();
339  }
340 
351  function getPassListOfAnswersWithScoring(&$result_array, $active_id, $pass, $show_solutions = FALSE)
352  {
353  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
354 
355  $maintemplate = new ilTemplate("tpl.il_as_tst_list_of_answers.html", TRUE, TRUE, "Modules/Test");
356 
357  include_once "./Modules/Test/classes/class.ilObjAssessmentFolder.php";
359 
360  $counter = 1;
361  // output of questions with solutions
362  foreach ($result_array as $question_data)
363  {
364  $question = $question_data["qid"];
365  if (is_numeric($question))
366  {
367  $question_gui = $this->object->createQuestionGUI("", $question);
368  if (in_array($question_gui->object->getQuestionTypeID(), $scoring))
369  {
370  $template = new ilTemplate("tpl.il_as_qpl_question_printview.html", TRUE, TRUE, "Modules/TestQuestionPool");
371  $scoretemplate = new ilTemplate("tpl.il_as_tst_manual_scoring_points.html", TRUE, TRUE, "Modules/Test");
372  $this->tpl->setCurrentBlock("printview_question");
373  $template->setVariable("COUNTER_QUESTION", $counter.". ");
374  $template->setVariable("QUESTION_TITLE", $this->object->getQuestionTitle($question_gui->object->getTitle()));
375  $points = $question_gui->object->getMaximumPoints();
376  if ($points == 1)
377  {
378  $template->setVariable("QUESTION_POINTS", $points . " " . $this->lng->txt("point"));
379  }
380  else
381  {
382  $template->setVariable("QUESTION_POINTS", $points . " " . $this->lng->txt("points"));
383  }
384 
385  $show_question_only = ($this->object->getShowSolutionAnswersOnly()) ? TRUE : FALSE;
386  $result_output = $question_gui->getSolutionOutput($active_id, $pass, $show_solutions, FALSE, $show_question_only, $this->object->getShowSolutionFeedback(), FALSE, TRUE);
387 
388  $solout = $question_gui->object->getSuggestedSolutionOutput();
389  if (strlen($solout))
390  {
391  $scoretemplate->setCurrentBlock("suggested_solution");
392  $scoretemplate->setVariable("TEXT_SUGGESTED_SOLUTION", $this->lng->txt("solution_hint"));
393  $scoretemplate->setVariable("VALUE_SUGGESTED_SOLUTION", $solout);
394  $scoretemplate->parseCurrentBlock();
395  }
396 
397  $scoretemplate->setCurrentBlock("feedback");
398  $scoretemplate->setVariable("FEEDBACK_NAME_INPUT", $question);
399  $feedback = $this->object->getManualFeedback($active_id, $question, $pass);
400  $scoretemplate->setVariable("VALUE_FEEDBACK", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($feedback, TRUE)));
401  $scoretemplate->setVariable("TEXT_MANUAL_FEEDBACK", $this->lng->txt("set_manual_feedback"));
402  $scoretemplate->parseCurrentBlock();
403 
404  $scoretemplate->setVariable("NAME_INPUT", $question);
405  $this->ctrl->setParameter($this, "active_id", $active_id);
406  $this->ctrl->setParameter($this, "pass", $pass);
407  $scoretemplate->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "manscoring"));
408  $scoretemplate->setVariable("LABEL_INPUT", $this->lng->txt("tst_change_points_for_question"));
409  $scoretemplate->setVariable("VALUE_INPUT", " value=\"" . assQuestion::_getReachedPoints($active_id, $question_data["qid"], $pass) . "\"");
410  $scoretemplate->setVariable("VALUE_SAVE", $this->lng->txt("save"));
411 
412  $template->setVariable("SOLUTION_OUTPUT", $result_output);
413  $maintemplate->setCurrentBlock("printview_question");
414  $maintemplate->setVariable("QUESTION_PRINTVIEW", $template->get());
415  $maintemplate->setVariable("QUESTION_SCORING", $scoretemplate->get());
416  $maintemplate->parseCurrentBlock();
417  }
418  $counter ++;
419  }
420  }
421  if ($counter == 1)
422  {
423  // no scorable questions found
424  $maintemplate->setVariable("NO_QUESTIONS_FOUND", $this->lng->txt("manscoring_questions_not_found"));
425  }
426  $maintemplate->setVariable("RESULTS_OVERVIEW", sprintf($this->lng->txt("manscoring_results_pass"), $pass+1));
427 
428  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
430 
431  return $maintemplate->get();
432  }
433 
434 
450  function getPassDetailsOverview($result_array, $active_id, $pass, $targetclass = "", $targetcommandsort = "", $targetcommanddetails = "", $standard_header = TRUE)
451  {
452  global $ilUser;
453 
454  $testresults = $result_array["pass"];
455  unset($result_array["test"]);
456  $user_id = $this->object->_getUserIdFromActiveId($active_id);
457 
458  $sort = ($_GET["sort"]) ? ($_GET["sort"]) : "nr";
459  $sortorder = ($_GET["sortorder"]) ? ($_GET["sortorder"]) : "asc";
460 
461  if (!$standard_header)
462  {
463  // change sortorder of result array
464  usort($result_array, "sortResults");
465  }
466  $color_class = array("tblrow1top", "tblrow2top");
467  $counter = 0;
468  $template = new ilTemplate("tpl.il_as_tst_pass_details_overview.html", TRUE, TRUE, "Modules/Test");
469  $this->ctrl->setParameterByClass($targetclass, "pass", "$pass");
470 
471  if (!$testresults["total_max_points"])
472  {
473  $percentage = 0;
474  }
475  else
476  {
477  $percentage = ($testresults["total_reached_points"]/$testresults["total_max_points"])*100;
478  }
479  $total_max = $testresults["total_max_points"];
480  $total_reached = $testresults["total_reached_points"];
481 
482  $img_title_percent = "";
483  $img_title_nr = "";
484  $hasSuggestedSolutions = FALSE;
485  if ($this->object->getShowSolutionSuggested())
486  {
487  foreach ($result_array as $key => $value)
488  {
489  if (strlen($value["solution"]))
490  {
491  $hasSuggestedSolutions = TRUE;
492  }
493  }
494  }
495  foreach ($result_array as $key => $value)
496  {
497  if (preg_match("/\d+/", $key))
498  {
499  if (strlen($targetclass) && strlen($targetcommanddetails))
500  {
501  $template->setCurrentBlock("linked_title");
502  $template->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
503  $template->setVariable("VALUE_QUESTION_TITLE", $value["title"]);
504  $template->setVariable("VALUE_QUESTION_ID", $value["qid"]);
505  $this->ctrl->setParameterByClass($targetclass, "evaluation", $value["qid"]);
506  $this->ctrl->setParameterByClass($targetclass, "active_id", $active_id);
507  $template->setVariable("URL_QUESTION_TITLE", $this->ctrl->getLinkTargetByClass($targetclass, $targetcommanddetails));
508  $template->parseCurrentBlock();
509  }
510  else
511  {
512  $template->setCurrentBlock("plain_title");
513  $template->setVariable("VALUE_QUESTION_TITLE", $value["title"]);
514  $template->setVariable("VALUE_QUESTION_ID", $value["qid"]);
515  $template->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
516  $template->parseCurrentBlock();
517  }
518  if ($hasSuggestedSolutions)
519  {
520  $template->setCurrentBlock("question_suggested_solution");
521  $template->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
522  $template->setVariable("SOLUTION_HINT", $value["solution"]);
523  $template->parseCurrentBlock();
524  }
525  $template->setCurrentBlock("question");
526  $template->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
527  $template->setVariable("VALUE_QUESTION_COUNTER", $value["nr"]);
528  $template->setVariable("VALUE_MAX_POINTS", $value["max"]);
529  $template->setVariable("VALUE_REACHED_POINTS", $value["reached"]);
530  $template->setVariable("VALUE_PERCENT_SOLVED", $value["percent"]);
531  $template->parseCurrentBlock();
532  $counter++;
533  }
534  }
535 
536  if ($hasSuggestedSolutions)
537  {
538  $template->touchBlock("footer_suggested_solution");
539  }
540  $template->setCurrentBlock("footer");
541  $template->setVariable("VALUE_QUESTION_COUNTER", "<strong>" . $this->lng->txt("total") . "</strong>");
542  $template->setVariable("VALUE_QUESTION_TITLE", "");
543  $template->setVariable("VALUE_QUESTION_ID", "");
544  $template->setVariable("VALUE_MAX_POINTS", "<strong>$total_max</strong>");
545  $template->setVariable("VALUE_REACHED_POINTS", "<strong>$total_reached</strong>");
546  $template->setVariable("VALUE_PERCENT_SOLVED", "<strong>" . sprintf("%2.2f", $percentage) . " %" . "</strong>");
547  $template->parseCurrentBlock();
548 
549  if ($standard_header)
550  {
551  if ($hasSuggestedSolutions)
552  {
553  $template->setCurrentBlock("standard_header_suggested_solution");
554  $template->setVariable("SOLUTION_HINT_HEADER", $this->lng->txt("solution_hint"));
555  $template->parseCurrentBlock();
556  }
557  $template->setCurrentBlock("standard_header");
558  $template->setVariable("QUESTION_COUNTER", $this->lng->txt("tst_question_no"));
559  $template->setVariable("PERCENT_SOLVED", $this->lng->txt("tst_percent_solved"));
560  $template->setVariable("QUESTION_TITLE", $this->lng->txt("tst_question_title"));
561  $template->setVariable("QUESTION_ID", $this->lng->txt("question_id"));
562  $template->setVariable("MAX_POINTS", $this->lng->txt("tst_maximum_points"));
563  $template->setVariable("REACHED_POINTS", $this->lng->txt("tst_reached_points"));
564  $template->parseCurrentBlock();
565  }
566  else
567  {
568  if ($hasSuggestedSolutions)
569  {
570  $template->setCurrentBlock("linked_header_suggested_solution");
571  if (strcmp($sort, "solution") == 0)
572  {
573  $this->ctrl->setParameterByClass($targetclass, "sortorder", !strcmp($sortorder, "asc") ? "desc" : "asc");
574  }
575  else
576  {
577  $this->ctrl->setParameterByClass($targetclass, "sortorder", "asc");
578  }
579  $this->ctrl->setParameterByClass($targetclass, "sort", "solution");
580  $template->setVariable("URL_SOLUTION_HINT_HEADER", $this->ctrl->getLinkTargetByClass($targetclass, $targetcommandsort));
581  $template->setVariable("SOLUTION_HINT_HEADER", $this->lng->txt("solution_hint"));
582  if (strcmp($sort, "solution") == 0)
583  {
584  $image = new ilTemplate("tpl.image.html", TRUE, TRUE);
585  $image->setVariable("IMAGE_SOURCE", ilUtil::getImagePath($sortorder . "_order.gif"));
586  $image->setVariable("IMAGE_ALT", $this->lng->txt("change_sort_direction"));
587  $image->setVariable("IMAGE_TITLE", $this->lng->txt("change_sort_direction"));
588  $template->setVariable("IMAGE_SOLUTION_HINT_HEADER", $image->get());
589  }
590  $template->parseCurrentBlock();
591  }
592  $template->setCurrentBlock("linked_header");
593  $this->ctrl->setParameterByClass($targetclass, "sort", "nr");
594  if (strcmp($sort, "nr") == 0)
595  {
596  $this->ctrl->setParameterByClass($targetclass, "sortorder", !strcmp($sortorder, "asc") ? "desc" : "asc");
597  }
598  else
599  {
600  $this->ctrl->setParameterByClass($targetclass, "sortorder", "asc");
601  }
602  $template->setVariable("URL_QUESTION_COUNTER", $this->ctrl->getLinkTargetByClass($targetclass, $targetcommandsort));
603  $template->setVariable("QUESTION_COUNTER", $this->lng->txt("tst_question_no"));
604  if (strcmp($sort, "nr") == 0)
605  {
606  $image = new ilTemplate("tpl.image.html", TRUE, TRUE);
607  $image->setVariable("IMAGE_SOURCE", ilUtil::getImagePath($sortorder . "_order.gif"));
608  $image->setVariable("IMAGE_ALT", $this->lng->txt("change_sort_direction"));
609  $image->setVariable("IMAGE_TITLE", $this->lng->txt("change_sort_direction"));
610  $template->setVariable("IMAGE_QUESTION_COUNTER", $image->get());
611  }
612  $this->ctrl->setParameterByClass($targetclass, "sort", "percent");
613  if (strcmp($sort, "percent") == 0)
614  {
615  $this->ctrl->setParameterByClass($targetclass, "sortorder", !strcmp($sortorder, "asc") ? "desc" : "asc");
616  }
617  else
618  {
619  $this->ctrl->setParameterByClass($targetclass, "sortorder", "asc");
620  }
621  $template->setVariable("URL_PERCENT_SOLVED", $this->ctrl->getLinkTargetByClass($targetclass, $targetcommandsort));
622  $template->setVariable("PERCENT_SOLVED", $this->lng->txt("tst_percent_solved"));
623  if (strcmp($sort, "percent") == 0)
624  {
625  $image = new ilTemplate("tpl.image.html", TRUE, TRUE);
626  $image->setVariable("IMAGE_SOURCE", ilUtil::getImagePath($sortorder . "_order.gif"));
627  $image->setVariable("IMAGE_ALT", $this->lng->txt("change_sort_direction"));
628  $image->setVariable("IMAGE_TITLE", $this->lng->txt("change_sort_direction"));
629  $template->setVariable("IMAGE_PERCENT_SOLVED", $image->get());
630  }
631  $this->ctrl->setParameterByClass($targetclass, "sort", "title");
632  if (strcmp($sort, "title") == 0)
633  {
634  $this->ctrl->setParameterByClass($targetclass, "sortorder", !strcmp($sortorder, "asc") ? "desc" : "asc");
635  }
636  else
637  {
638  $this->ctrl->setParameterByClass($targetclass, "sortorder", "asc");
639  }
640  $template->setVariable("URL_QUESTION_TITLE", $this->ctrl->getLinkTargetByClass($targetclass, $targetcommandsort));
641  $template->setVariable("QUESTION_TITLE", $this->lng->txt("tst_question_title"));
642  if (strcmp($sort, "title") == 0)
643  {
644  $image = new ilTemplate("tpl.image.html", TRUE, TRUE);
645  $image->setVariable("IMAGE_SOURCE", ilUtil::getImagePath($sortorder . "_order.gif"));
646  $image->setVariable("IMAGE_ALT", $this->lng->txt("change_sort_direction"));
647  $image->setVariable("IMAGE_TITLE", $this->lng->txt("change_sort_direction"));
648  $template->setVariable("IMAGE_QUESTION_TITLE", $image->get());
649  }
650  $this->ctrl->setParameterByClass($targetclass, "sort", "max");
651  if (strcmp($sort, "max") == 0)
652  {
653  $this->ctrl->setParameterByClass($targetclass, "sortorder", strcmp($sortorder, "asc") ? "desc" : "asc");
654  }
655  else
656  {
657  $this->ctrl->setParameterByClass($targetclass, "sortorder", "asc");
658  }
659  $template->setVariable("URL_MAX_POINTS", $this->ctrl->getLinkTargetByClass($targetclass, $targetcommandsort));
660  $template->setVariable("MAX_POINTS", $this->lng->txt("tst_maximum_points"));
661  if (strcmp($sort, "max") == 0)
662  {
663  $image = new ilTemplate("tpl.image.html", TRUE, TRUE);
664  $image->setVariable("IMAGE_SOURCE", ilUtil::getImagePath($sortorder . "_order.gif"));
665  $image->setVariable("IMAGE_ALT", $this->lng->txt("change_sort_direction"));
666  $image->setVariable("IMAGE_TITLE", $this->lng->txt("change_sort_direction"));
667  $template->setVariable("IMAGE_MAX_POINTS", $image->get());
668  }
669  $this->ctrl->setParameterByClass($targetclass, "sort", "reached");
670  if (strcmp($sort, "reached") == 0)
671  {
672  $this->ctrl->setParameterByClass($targetclass, "sortorder", !strcmp($sortorder, "asc") ? "desc" : "asc");
673  }
674  else
675  {
676  $this->ctrl->setParameterByClass($targetclass, "sortorder", "asc");
677  }
678  $template->setVariable("URL_REACHED_POINTS", $this->ctrl->getLinkTargetByClass($targetclass, $targetcommandsort));
679  $template->setVariable("REACHED_POINTS", $this->lng->txt("tst_reached_points"));
680  if (strcmp($sort, "reached") == 0)
681  {
682  $image = new ilTemplate("tpl.image.html", TRUE, TRUE);
683  $image->setVariable("IMAGE_SOURCE", ilUtil::getImagePath($sortorder . "_order.gif"));
684  $image->setVariable("IMAGE_ALT", $this->lng->txt("change_sort_direction"));
685  $image->setVariable("IMAGE_TITLE", $this->lng->txt("change_sort_direction"));
686  $template->setVariable("IMAGE_REACHED_POINTS", $image->get());
687  }
688  $template->parseCurrentBlock();
689  }
690 
691  return $template->get();
692  }
693 
703  {
704  if ($this->object->getShowSolutionSignature() && !$this->object->getAnonymity())
705  {
706  // output of time/date and signature
707  $template = new ilTemplate("tpl.il_as_tst_results_userdata_signature.html", TRUE, TRUE, "Modules/Test");
708  if ($this->object->getShowSerial())
709  {
710  $template->setCurrentBlock("tst_serial");
711  $template->setVariable("VALUE_SERIAL", $this->object->getSerial());
712  $template->setVariable("TXT_SERIAL", $this->lng->txt('tst_serial'));
713  $template->parseCurrentBlock();
714  }
715  $template->setVariable("TXT_DATE", $this->lng->txt("date"));
716  $template->setVariable("VALUE_DATE", strftime("%Y-%m-%d %H:%M:%S", time()));
717  $template->setVariable("TXT_SIGNATURE", $this->lng->txt("tst_signature"));
718  $template->setVariable("IMG_SPACER", ilUtil::getImagePath("spacer.gif"));
719  return $template->get();
720  }
721  else
722  {
723  return "";
724  }
725  }
726 
737  function getResultsUserdata($active_id, $overwrite_anonymity = FALSE)
738  {
739  $template = new ilTemplate("tpl.il_as_tst_results_userdata.html", TRUE, TRUE, "Modules/Test");
740  include_once './Services/User/classes/class.ilObjUser.php';
741  $user_id = $this->object->_getUserIdFromActiveId($active_id);
742  if (strlen(ilObjUser::_lookupLogin($user_id)) > 0)
743  {
744  $user = new ilObjUser($user_id);
745  }
746  else
747  {
748  $user = new ilObjUser();
749  $user->setLastname($this->lng->txt("deleted_user"));
750  }
751  $t = $this->object->getTestSession($active_id)->getSubmittedTimestamp();
752  if (!$t)
753  {
754  $t = $this->object->_getLastAccess($this->object->getTestSession()->getActiveId());
755  }
756  $print_date = mktime(date("H"), date("i"), date("s"), date("m") , date("d"), date("Y"));
757 
758  $title_matric = "";
759  if (strlen($user->getMatriculation()) && (($this->object->getAnonymity() == FALSE) || ($overwrite_anonymity)))
760  {
761  $template->setCurrentBlock("user_matric");
762  $template->setVariable("TXT_USR_MATRIC", $this->lng->txt("matriculation"));
763  $template->parseCurrentBlock();
764  $template->setCurrentBlock("user_matric_value");
765  $template->setVariable("VALUE_USR_MATRIC", $user->getMatriculation());
766  $template->parseCurrentBlock();
767  $template->touchBlock("user_matric_separator");
768  $title_matric = " - " . $this->lng->txt("matriculation") . ": " . $user->getMatriculation();
769  }
770 
771  $invited_user = array_pop($this->object->getInvitedUsers($user_id));
772  if (strlen($invited_user["clientip"]))
773  {
774  $template->setCurrentBlock("user_clientip");
775  $template->setVariable("TXT_CLIENT_IP", $this->lng->txt("client_ip"));
776  $template->parseCurrentBlock();
777  $template->setCurrentBlock("user_clientip_value");
778  $template->setVariable("VALUE_CLIENT_IP", $invited_user["clientip"]);
779  $template->parseCurrentBlock();
780  $template->touchBlock("user_clientip_separator");
781  $title_client = " - " . $this->lng->txt("clientip") . ": " . $invited_user["clientip"];
782  }
783 
784  $template->setVariable("TXT_TEST_TITLE", $this->lng->txt("title"));
785  $template->setVariable("VALUE_TEST_TITLE", $this->object->getTitle());
786  $template->setVariable("TXT_USR_NAME", $this->lng->txt("name"));
787  $uname = $this->object->userLookupFullName($user_id, $overwrite_anonymity);
788  $template->setVariable("VALUE_USR_NAME", $uname);
789  $template->setVariable("TXT_USR_LOGIN", $this->lng->txt("login"));
790  $template->setVariable("VALUE_USR_LOGIN", ilObjUser::_lookupLogin($user_id));
791  $template->setVariable("TXT_TEST_DATE", $this->lng->txt("tst_tst_date"));
792  $template->setVariable("VALUE_TEST_DATE", strftime("%Y-%m-%d %H:%M:%S",ilUtil::date_mysql2time($t)));
793  $template->setVariable("TXT_PRINT_DATE", $this->lng->txt("tst_print_date"));
794  $template->setVariable("VALUE_PRINT_DATE", strftime("%Y-%m-%d %H:%M:%S",$print_date));
795 
796  // change the pagetitle
797  $pagetitle = ": " . $this->object->getTitle() . $title_matric . $title_client;
798  $this->tpl->setHeaderPageTitle($pagetitle);
799 
800  return $template->get();
801  }
802 
814  function getCorrectSolutionOutput($question_id, $active_id, $pass)
815  {
816  global $ilUser;
817 
818  $test_id = $this->object->getTestId();
819  $question_gui = $this->object->createQuestionGUI("", $question_id);
820 
821  $template = new ilTemplate("tpl.il_as_tst_correct_solution_output.html", TRUE, TRUE, "Modules/Test");
822  $show_question_only = ($this->object->getShowSolutionAnswersOnly()) ? TRUE : FALSE;
823  $result_output = $question_gui->getSolutionOutput($active_id, $pass, TRUE, FALSE, $show_question_only, $this->object->getShowSolutionFeedback());
824  $best_output = $question_gui->getSolutionOutput($active_id, $pass, FALSE, FALSE, $show_question_only, FALSE, TRUE);
825  if (strlen($best_output))
826  {
827  $template->setCurrentBlock("best_solution");
828  $template->setVariable("TEXT_BEST_SOLUTION", $this->lng->txt("tst_best_solution_is"));
829  $template->setVariable("BEST_OUTPUT", $best_output);
830  $template->parseCurrentBlock();
831  }
832  $template->setVariable("TEXT_YOUR_SOLUTION", $this->lng->txt("tst_your_answer_was"));
833  $maxpoints = $question_gui->object->getMaximumPoints();
834  if ($maxpoints == 1)
835  {
836  $template->setVariable("QUESTION_TITLE", $this->object->getQuestionTitle($question_gui->object->getTitle()) . " (" . $maxpoints . " " . $this->lng->txt("point") . ")");
837  }
838  else
839  {
840  $template->setVariable("QUESTION_TITLE", $this->object->getQuestionTitle($question_gui->object->getTitle()) . " (" . $maxpoints . " " . $this->lng->txt("points") . ")");
841  }
842  $template->setVariable("SOLUTION_OUTPUT", $result_output);
843  $template->setVariable("RECEIVED_POINTS", sprintf($this->lng->txt("you_received_a_of_b_points"), $question_gui->object->getReachedPoints($active_id, $pass), $maxpoints));
844  $template->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
845  $template->setVariable("BACKLINK_TEXT", "&lt;&lt; " . $this->lng->txt("back"));
846  return $template->get();
847  }
848 
856  function getResultsOfUserOutput($active_id, $pass, $show_pass_details = TRUE, $show_answers = TRUE, $show_question_only = FALSE, $show_reached_points = FALSE)
857  {
858  global $ilias, $tpl;
859 
860  include_once("./classes/class.ilTemplate.php");
861  $template = new ilTemplate("tpl.il_as_tst_results_participant.html", TRUE, TRUE, "Modules/Test");
862 
863  $user_id = $this->object->_getUserIdFromActiveId($active_id);
864  $uname = $this->object->userLookupFullName($user_id, TRUE);
865 
866  if (((array_key_exists("pass", $_GET)) && (strlen($_GET["pass"]) > 0)) || (!is_null($pass)))
867  {
868  if (is_null($pass)) $pass = $_GET["pass"];
869  }
870 
871  $statement = $this->getFinalStatement($active_id);
872  $user_data = $this->getResultsUserdata($active_id, TRUE);
873 
874  if (!is_null($pass))
875  {
876  $result_array =& $this->object->getTestResult($active_id, $pass);
877  $command_solution_details = "";
878  if ($show_pass_details)
879  {
880  $detailsoverview = $this->getPassDetailsOverview($result_array, $active_id, $pass, "iltestservicegui", "getResultsOfUserOutput", $command_solution_details);
881  }
882 
883  $user_id = $this->object->_getUserIdFromActiveId($active_id);
884  $showAllAnswers = TRUE;
885  if ($this->object->isExecutable($user_id))
886  {
887  $showAllAnswers = FALSE;
888  }
889  if ($show_answers)
890  {
891  $list_of_answers = $this->getPassListOfAnswers($result_array, $active_id, $pass, FALSE, $showAllAnswers, $show_question_only, $show_reached_points, $compare_solutions = $this->object->getShowSolutionListComparison());
892  }
893 
894  $template->setVariable("LIST_OF_ANSWERS", $list_of_answers);
895  //$template->setVariable("PASS_RESULTS_OVERVIEW", sprintf($this->lng->txt("tst_results_overview_pass"), $pass + 1));
896  $template->setVariable("PASS_DETAILS", $detailsoverview);
897 
898  $signature = $this->getResultsSignature();
899  $template->setVariable("SIGNATURE", $signature);
900  }
901  $template->setVariable("TEXT_HEADING", sprintf($this->lng->txt("tst_result_user_name"), $uname));
902  $template->setVariable("USER_DATA", $user_data);
903  $template->setVariable("USER_MARK", $statement["mark"]);
904  if (strlen($statement["markects"]))
905  {
906  $template->setVariable("USER_MARK_ECTS", $statement["markects"]);
907  }
908  $template->parseCurrentBlock();
909 
910  return $template->get();
911  }
912 
920  function getResultsHeadUserAndPass($active_id, $pass)
921  {
922  $template = new ilTemplate("tpl.il_as_tst_results_head_user_pass.html", TRUE, TRUE, "Modules/Test");
923  include_once './Services/User/classes/class.ilObjUser.php';
924  $user_id = $this->object->_getUserIdFromActiveId($active_id);
925  if (strlen(ilObjUser::_lookupLogin($user_id)) > 0)
926  {
927  $user = new ilObjUser($user_id);
928  }
929  else
930  {
931  $user = new ilObjUser();
932  $user->setLastname($this->lng->txt("deleted_user"));
933  }
934  $title_matric = "";
935  if (strlen($user->getMatriculation()) && (($this->object->getAnonymity() == FALSE)))
936  {
937  $template->setCurrentBlock("user_matric");
938  $template->setVariable("TXT_USR_MATRIC", $this->lng->txt("matriculation"));
939  $template->parseCurrentBlock();
940  $template->setCurrentBlock("user_matric_value");
941  $template->setVariable("VALUE_USR_MATRIC", $user->getMatriculation());
942  $template->parseCurrentBlock();
943  $template->touchBlock("user_matric_separator");
944  $title_matric = " - " . $this->lng->txt("matriculation") . ": " . $user->getMatriculation();
945  }
946 
947  $invited_user = array_pop($this->object->getInvitedUsers($user_id));
948  if (strlen($invited_user["clientip"]))
949  {
950  $template->setCurrentBlock("user_clientip");
951  $template->setVariable("TXT_CLIENT_IP", $this->lng->txt("client_ip"));
952  $template->parseCurrentBlock();
953  $template->setCurrentBlock("user_clientip_value");
954  $template->setVariable("VALUE_CLIENT_IP", $invited_user["clientip"]);
955  $template->parseCurrentBlock();
956  $template->touchBlock("user_clientip_separator");
957  $title_client = " - " . $this->lng->txt("clientip") . ": " . $invited_user["clientip"];
958  }
959 
960  $template->setVariable("TXT_USR_NAME", $this->lng->txt("name"));
961  $uname = $this->object->userLookupFullName($user_id, FALSE);
962  $template->setVariable("VALUE_USR_NAME", $uname);
963  $template->setVariable("TXT_PASS", $this->lng->txt("scored_pass"));
964  $template->setVariable("VALUE_PASS", $pass);
965  return $template->get();
966  }
967 
976  function getQuestionResultForTestUsers($question_id, $test_id)
977  {
978  $foundusers = $this->object->getParticipantsForTestAndQuestion($test_id, $question_id);
979  $output = "";
980  $file_name = "out_question";
981  foreach ($foundusers as $active_id => $passes)
982  {
983  $resultpass = $this->object->_getResultPass($active_id);
984  for ($i = 0; $i < count($passes); $i++)
985  {
986  if (($resultpass != null) && ($resultpass == $passes[$i]["pass"]))
987  {
988  $question_gui =& $this->object->createQuestionGUI("", $passes[$i]["qid"]);
989  $output .= $this->getResultsHeadUserAndPass($active_id, $resultpass+1);
990  $output .= $question_gui->getSolutionOutput($active_id, $resultpass, $graphicalOutput = FALSE, $result_output = FALSE, $show_question_only = FALSE, $show_feedback = FALSE);
991  $output .= "<br /><br /><br />";
992  $file_name = $question_gui->object->getTitle();
993  }
994  }
995  }
996  $this->object->deliverPDFFromHTML($output, $file_name);
997  }
998 }
999 
1000 // internal sort function to sort the result array
1001 function sortResults($a, $b)
1002 {
1003  $sort = ($_GET["sort"]) ? ($_GET["sort"]) : "nr";
1004  $sortorder = ($_GET["sortorder"]) ? ($_GET["sortorder"]) : "asc";
1005  if (strcmp($sortorder, "asc"))
1006  {
1007  $smaller = 1;
1008  $greater = -1;
1009  }
1010  else
1011  {
1012  $smaller = -1;
1013  $greater = 1;
1014  }
1015  if ($a[$sort] == $b[$sort]) return 0;
1016  return ($a[$sort] < $b[$sort]) ? $smaller : $greater;
1017 }
1018 
1019 ?>