ILIAS  Release_3_10_x_branch Revision 61812
 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["test"]["total_max_points"])
139  {
140  $percentage = 0;
141  }
142  else
143  {
144  $percentage = ($result_array["test"]["total_reached_points"]/$result_array["test"]["total_max_points"])*100;
145  }
146  $total_max = $result_array["test"]["total_max_points"];
147  $total_reached = $result_array["test"]["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  $result_percentage = $percentage;
169  $result_total_reached = $total_reached;
170  $result_total_max = $total_max;
171  }
172  else
173  {
174  $template->setVariable("COLOR_CLASS", $color_class[$pass % 2]);
175  }
176  $template->setVariable("VALUE_PASS", $pass + 1);
177  $template->setVariable("VALUE_DATE",ilDatePresentation::formatDate(new ilDate($finishdate,IL_CAL_TIMESTAMP)));
178 
179  if (!$short)
180  {
181  $template->setVariable("VALUE_ANSWERED", $this->object->getAnsweredQuestionCount($active_id, $pass) . " " . strtolower($this->lng->txt("of")) . " " . (count($result_array)-1));
182  $template->setVariable("VALUE_REACHED", $total_reached . " " . strtolower($this->lng->txt("of")) . " " . $total_max);
183  $template->setVariable("VALUE_PERCENTAGE", sprintf("%.2f", $percentage) . "%");
184  }
185  $template->parseCurrentBlock();
186  }
187  }
188 
189  $template->setVariable("PASS_COUNTER", $this->lng->txt("pass"));
190  $template->setVariable("DATE", $this->lng->txt("date"));
191  if (!$short)
192  {
193  $template->setVariable("PASS_SCORED", $this->lng->txt("scored_pass"));
194  $template->setVariable("ANSWERED_QUESTIONS", $this->lng->txt("tst_answered_questions"));
195  $template->setVariable("REACHED_POINTS", $this->lng->txt("tst_reached_points"));
196  $template->setVariable("PERCENTAGE_CORRECT", $this->lng->txt("tst_percent_solved"));
197  }
198  $template->parseCurrentBlock();
199 
200  return $template->get();
201  }
202 
212  function getFinalStatement(&$test_data_array)
213  {
214  if (!$test_data_array["total_max_points"])
215  {
216  $percentage = 0;
217  }
218  else
219  {
220  $percentage = ($test_data_array["total_reached_points"]/$test_data_array["total_max_points"])*100;
221  }
222  $total_max = $test_data_array["total_max_points"];
223  $total_reached = $test_data_array["total_reached_points"];
224  $result_percentage = $percentage;
225  $result_total_reached = $total_reached;
226  $result_total_max = $total_max;
227 
228  $mark = "";
229  $markects = "";
230  $mark_obj = $this->object->mark_schema->getMatchingMark($result_percentage);
231  if ($mark_obj)
232  {
233  if ($mark_obj->getPassed())
234  {
235  $mark = $this->lng->txt("mark_tst_passed");
236  }
237  else
238  {
239  $mark = $this->lng->txt("mark_tst_failed");
240  }
241  $mark = str_replace("[mark]", $mark_obj->getOfficialName(), $mark);
242  $mark = str_replace("[markshort]", $mark_obj->getShortName(), $mark);
243  $mark = str_replace("[percentage]", sprintf("%.2f", $result_percentage), $mark);
244  $mark = str_replace("[reached]", $result_total_reached, $mark);
245  $mark = str_replace("[max]", $result_total_max, $mark);
246  }
247  if ($this->object->ects_output)
248  {
249  $passed_array =& $this->object->getTotalPointsPassedArray();
250  $ects_mark = $this->object->getECTSGrade($passed_array, $result_total_reached, $result_total_max);
251  $markects = $this->lng->txt("mark_tst_ects");
252  $markects = str_replace("[markects]", $this->lng->txt("ects_grade_". strtolower($ects_mark)), $markects);
253  }
254  return array("mark" => $mark, "markects" => $markects);
255  }
256 
269  function getPassListOfAnswers(&$result_array, $active_id, $pass, $show_solutions = FALSE, $only_answered_questions = FALSE, $show_question_only = FALSE, $show_reached_points = FALSE)
270  {
271  $maintemplate = new ilTemplate("tpl.il_as_tst_list_of_answers.html", TRUE, TRUE, "Modules/Test");
272 
273  $counter = 1;
274  // output of questions with solutions
275  foreach ($result_array as $question_data)
276  {
277  if (($question_data["workedthrough"] == 1) || ($only_answered_questions == FALSE))
278  {
279  $template = new ilTemplate("tpl.il_as_qpl_question_printview.html", TRUE, TRUE, "Modules/TestQuestionPool");
280  $question = $question_data["qid"];
281  if (is_numeric($question))
282  {
283  $maintemplate->setCurrentBlock("printview_question");
284  $question_gui = $this->object->createQuestionGUI("", $question);
285 
286  if ($show_reached_points)
287  {
288  $template->setCurrentBlock("result_points");
289  $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());
290  $template->parseCurrentBlock();
291  }
292  $template->setVariable("COUNTER_QUESTION", $counter.". ");
293  $template->setVariable("QUESTION_TITLE", $this->object->getQuestionTitle($question_gui->object->getTitle()));
294 
295  $show_question_only = ($this->object->getShowSolutionAnswersOnly()) ? TRUE : FALSE;
296  $result_output = $question_gui->getSolutionOutput($active_id, $pass, $show_solutions, FALSE, $show_question_only, $this->object->getShowSolutionFeedback());
297 
298  $template->setVariable("SOLUTION_OUTPUT", $result_output);
299  $maintemplate->setCurrentBlock("printview_question");
300  $maintemplate->setVariable("QUESTION_PRINTVIEW", $template->get());
301  $maintemplate->parseCurrentBlock();
302  $counter ++;
303  }
304  }
305  }
306  $maintemplate->setVariable("RESULTS_OVERVIEW", sprintf($this->lng->txt("tst_eval_results_by_pass"), $pass+1));
307  return $maintemplate->get();
308  }
309 
322  function getPassListOfAnswersWithScoring(&$result_array, $active_id, $pass, $show_solutions = FALSE)
323  {
324  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
325 
326  $maintemplate = new ilTemplate("tpl.il_as_tst_list_of_answers.html", TRUE, TRUE, "Modules/Test");
327 
328  include_once "./Modules/Test/classes/class.ilObjAssessmentFolder.php";
330 
331  $counter = 1;
332  // output of questions with solutions
333  foreach ($result_array as $question_data)
334  {
335  $question = $question_data["qid"];
336  if (is_numeric($question))
337  {
338  $question_gui = $this->object->createQuestionGUI("", $question);
339  if (in_array($question_gui->object->getQuestionTypeID(), $scoring))
340  {
341  $template = new ilTemplate("tpl.il_as_qpl_question_printview.html", TRUE, TRUE, "Modules/TestQuestionPool");
342  $scoretemplate = new ilTemplate("tpl.il_as_tst_manual_scoring_points.html", TRUE, TRUE, "Modules/Test");
343  $this->tpl->setCurrentBlock("printview_question");
344  $template->setVariable("COUNTER_QUESTION", $counter.". ");
345  $template->setVariable("QUESTION_TITLE", $this->object->getQuestionTitle($question_gui->object->getTitle()));
346  $points = $question_gui->object->getMaximumPoints();
347  if ($points == 1)
348  {
349  $template->setVariable("QUESTION_POINTS", $points . " " . $this->lng->txt("point"));
350  }
351  else
352  {
353  $template->setVariable("QUESTION_POINTS", $points . " " . $this->lng->txt("points"));
354  }
355 
356  $show_question_only = ($this->object->getShowSolutionAnswersOnly()) ? TRUE : FALSE;
357  $result_output = $question_gui->getSolutionOutput($active_id, $pass, $show_solutions, FALSE, $show_question_only, $this->object->getShowSolutionFeedback());
358 // if ($this->object->getShowSolutionFeedback())
359 // {
360  $scoretemplate->setCurrentBlock("feedback");
361  $scoretemplate->setVariable("FEEDBACK_NAME_INPUT", $question);
362  $feedback = $this->object->getManualFeedback($active_id, $question, $pass);
363  $scoretemplate->setVariable("VALUE_FEEDBACK", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($feedback, TRUE)));
364  $scoretemplate->setVariable("VALUE_SAVE", $this->lng->txt("save"));
365  $scoretemplate->setVariable("TEXT_MANUAL_FEEDBACK", $this->lng->txt("set_manual_feedback"));
366  $scoretemplate->parseCurrentBlock();
367 // }
368  $scoretemplate->setVariable("NAME_INPUT", $question);
369  $this->ctrl->setParameter($this, "active_id", $active_id);
370  $this->ctrl->setParameter($this, "pass", $pass);
371  $scoretemplate->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "manscoring"));
372  $scoretemplate->setVariable("LABEL_INPUT", $this->lng->txt("tst_change_points_for_question"));
373  $scoretemplate->setVariable("BUTTON_POINTS", $this->lng->txt("change"));
374  $scoretemplate->setVariable("VALUE_INPUT", " value=\"" . assQuestion::_getReachedPoints($active_id, $question_data["qid"], $pass) . "\"");
375 
376  $template->setVariable("SOLUTION_OUTPUT", $result_output);
377  $maintemplate->setCurrentBlock("printview_question");
378  $maintemplate->setVariable("QUESTION_PRINTVIEW", $template->get());
379  $maintemplate->setVariable("QUESTION_SCORING", $scoretemplate->get());
380  $maintemplate->parseCurrentBlock();
381  }
382  $counter ++;
383  }
384  }
385  if ($counter == 1)
386  {
387  // no scorable questions found
388  $maintemplate->setVariable("NO_QUESTIONS_FOUND", $this->lng->txt("manscoring_questions_not_found"));
389  }
390  $maintemplate->setVariable("RESULTS_OVERVIEW", sprintf($this->lng->txt("manscoring_results_pass"), $pass+1));
391 
392  return $maintemplate->get();
393  }
394 
395 
411  function getPassDetailsOverview($result_array, $active_id, $pass, $targetclass = "", $targetcommandsort = "", $targetcommanddetails = "", $standard_header = TRUE)
412  {
413  global $ilUser;
414 
415  $testresults = $result_array["test"];
416  unset($result_array["test"]);
417  $user_id = $this->object->_getUserIdFromActiveId($active_id);
418 
419  $sort = ($_GET["sort"]) ? ($_GET["sort"]) : "nr";
420  $sortorder = ($_GET["sortorder"]) ? ($_GET["sortorder"]) : "asc";
421 
422  if (!$standard_header)
423  {
424  // change sortorder of result array
425  usort($result_array, "sortResults");
426  }
427  $color_class = array("tblrow1", "tblrow2");
428  $counter = 0;
429  $template = new ilTemplate("tpl.il_as_tst_pass_details_overview.html", TRUE, TRUE, "Modules/Test");
430  $this->ctrl->setParameterByClass($targetclass, "pass", "$pass");
431 
432  if (!$testresults["total_max_points"])
433  {
434  $percentage = 0;
435  }
436  else
437  {
438  $percentage = ($testresults["total_reached_points"]/$testresults["total_max_points"])*100;
439  }
440  $total_max = $testresults["total_max_points"];
441  $total_reached = $testresults["total_reached_points"];
442 
443  $img_title_percent = "";
444  $img_title_nr = "";
445  $hasSuggestedSolutions = FALSE;
446 
447  foreach ($result_array as $key => $value)
448  {
449  if (strlen($value["solution"]))
450  {
451  $hasSuggestedSolutions = TRUE;
452  }
453  }
454  foreach ($result_array as $key => $value)
455  {
456  if (preg_match("/\d+/", $key))
457  {
458  if (strlen($targetclass) && strlen($targetcommanddetails))
459  {
460  $template->setCurrentBlock("linked_title");
461  $template->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
462  $template->setVariable("VALUE_QUESTION_TITLE", $value["title"]);
463  $this->ctrl->setParameterByClass($targetclass, "evaluation", $value["qid"]);
464  $this->ctrl->setParameterByClass($targetclass, "active_id", $active_id);
465  $template->setVariable("URL_QUESTION_TITLE", $this->ctrl->getLinkTargetByClass($targetclass, $targetcommanddetails));
466  $template->parseCurrentBlock();
467  }
468  else
469  {
470  $template->setCurrentBlock("plain_title");
471  $template->setVariable("VALUE_QUESTION_TITLE", $value["title"]);
472  $template->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
473  $template->parseCurrentBlock();
474  }
475  if ($hasSuggestedSolutions)
476  {
477  $template->setCurrentBlock("question_suggested_solution");
478  $template->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
479  if ((preg_match("/http/", $value["solution"])) || (preg_match("/goto/", $value["solution"])))
480  {
481  $template->setVariable("SOLUTION_HINT", "<a href=\"".$value["solution"]."\" target=\"content\">" . $this->lng->txt("solution_hint"). "</a>");
482  }
483  else
484  {
485  if ($value["solution"])
486  {
487  $template->setVariable("SOLUTION_HINT", $this->lng->txt($value["solution"]));
488  }
489  else
490  {
491  $template->setVariable("SOLUTION_HINT", "");
492  }
493  }
494  $template->parseCurrentBlock();
495  }
496  $template->setCurrentBlock("question");
497  $template->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
498  $template->setVariable("VALUE_QUESTION_COUNTER", $value["nr"]);
499  $template->setVariable("VALUE_MAX_POINTS", $value["max"]);
500  $template->setVariable("VALUE_REACHED_POINTS", $value["reached"]);
501  $template->setVariable("VALUE_PERCENT_SOLVED", $value["percent"]);
502  $template->parseCurrentBlock();
503  $counter++;
504  }
505  }
506 
507  if ($hasSuggestedSolutions)
508  {
509  $template->touchBlock("footer_suggested_solution");
510  }
511  $template->setCurrentBlock("footer");
512  $template->setVariable("VALUE_QUESTION_COUNTER", "<strong>" . $this->lng->txt("total") . "</strong>");
513  $template->setVariable("VALUE_QUESTION_TITLE", "");
514  $template->setVariable("VALUE_MAX_POINTS", "<strong>$total_max</strong>");
515  $template->setVariable("VALUE_REACHED_POINTS", "<strong>$total_reached</strong>");
516  $template->setVariable("VALUE_PERCENT_SOLVED", "<strong>" . sprintf("%2.2f", $percentage) . " %" . "</strong>");
517  $template->parseCurrentBlock();
518 
519  if ($standard_header)
520  {
521  if ($hasSuggestedSolutions)
522  {
523  $template->setCurrentBlock("standard_header_suggested_solution");
524  $template->setVariable("SOLUTION_HINT_HEADER", $this->lng->txt("solution_hint"));
525  $template->parseCurrentBlock();
526  }
527  $template->setCurrentBlock("standard_header");
528  $template->setVariable("QUESTION_COUNTER", $this->lng->txt("tst_question_no"));
529  $template->setVariable("PERCENT_SOLVED", $this->lng->txt("tst_percent_solved"));
530  $template->setVariable("QUESTION_TITLE", $this->lng->txt("tst_question_title"));
531  $template->setVariable("MAX_POINTS", $this->lng->txt("tst_maximum_points"));
532  $template->setVariable("REACHED_POINTS", $this->lng->txt("tst_reached_points"));
533  $template->parseCurrentBlock();
534  }
535  else
536  {
537  if ($hasSuggestedSolutions)
538  {
539  $template->setCurrentBlock("linked_header_suggested_solution");
540  if (strcmp($sort, "solution") == 0)
541  {
542  $this->ctrl->setParameterByClass($targetclass, "sortorder", !strcmp($sortorder, "asc") ? "desc" : "asc");
543  }
544  else
545  {
546  $this->ctrl->setParameterByClass($targetclass, "sortorder", "asc");
547  }
548  $this->ctrl->setParameterByClass($targetclass, "sort", "solution");
549  $template->setVariable("URL_SOLUTION_HINT_HEADER", $this->ctrl->getLinkTargetByClass($targetclass, $targetcommandsort));
550  $template->setVariable("SOLUTION_HINT_HEADER", $this->lng->txt("solution_hint"));
551  if (strcmp($sort, "solution") == 0)
552  {
553  $image = new ilTemplate("tpl.image.html", TRUE, TRUE);
554  $image->setVariable("IMAGE_SOURCE", ilUtil::getImagePath($sortorder . "_order.gif"));
555  $image->setVariable("IMAGE_ALT", $this->lng->txt("change_sort_direction"));
556  $image->setVariable("IMAGE_TITLE", $this->lng->txt("change_sort_direction"));
557  $template->setVariable("IMAGE_SOLUTION_HINT_HEADER", $image->get());
558  }
559  $template->parseCurrentBlock();
560  }
561  $template->setCurrentBlock("linked_header");
562  $this->ctrl->setParameterByClass($targetclass, "sort", "nr");
563  if (strcmp($sort, "nr") == 0)
564  {
565  $this->ctrl->setParameterByClass($targetclass, "sortorder", !strcmp($sortorder, "asc") ? "desc" : "asc");
566  }
567  else
568  {
569  $this->ctrl->setParameterByClass($targetclass, "sortorder", "asc");
570  }
571  $template->setVariable("URL_QUESTION_COUNTER", $this->ctrl->getLinkTargetByClass($targetclass, $targetcommandsort));
572  $template->setVariable("QUESTION_COUNTER", $this->lng->txt("tst_question_no"));
573  if (strcmp($sort, "nr") == 0)
574  {
575  $image = new ilTemplate("tpl.image.html", TRUE, TRUE);
576  $image->setVariable("IMAGE_SOURCE", ilUtil::getImagePath($sortorder . "_order.gif"));
577  $image->setVariable("IMAGE_ALT", $this->lng->txt("change_sort_direction"));
578  $image->setVariable("IMAGE_TITLE", $this->lng->txt("change_sort_direction"));
579  $template->setVariable("IMAGE_QUESTION_COUNTER", $image->get());
580  }
581  $this->ctrl->setParameterByClass($targetclass, "sort", "percent");
582  if (strcmp($sort, "percent") == 0)
583  {
584  $this->ctrl->setParameterByClass($targetclass, "sortorder", !strcmp($sortorder, "asc") ? "desc" : "asc");
585  }
586  else
587  {
588  $this->ctrl->setParameterByClass($targetclass, "sortorder", "asc");
589  }
590  $template->setVariable("URL_PERCENT_SOLVED", $this->ctrl->getLinkTargetByClass($targetclass, $targetcommandsort));
591  $template->setVariable("PERCENT_SOLVED", $this->lng->txt("tst_percent_solved"));
592  if (strcmp($sort, "percent") == 0)
593  {
594  $image = new ilTemplate("tpl.image.html", TRUE, TRUE);
595  $image->setVariable("IMAGE_SOURCE", ilUtil::getImagePath($sortorder . "_order.gif"));
596  $image->setVariable("IMAGE_ALT", $this->lng->txt("change_sort_direction"));
597  $image->setVariable("IMAGE_TITLE", $this->lng->txt("change_sort_direction"));
598  $template->setVariable("IMAGE_PERCENT_SOLVED", $image->get());
599  }
600  $this->ctrl->setParameterByClass($targetclass, "sort", "title");
601  if (strcmp($sort, "title") == 0)
602  {
603  $this->ctrl->setParameterByClass($targetclass, "sortorder", !strcmp($sortorder, "asc") ? "desc" : "asc");
604  }
605  else
606  {
607  $this->ctrl->setParameterByClass($targetclass, "sortorder", "asc");
608  }
609  $template->setVariable("URL_QUESTION_TITLE", $this->ctrl->getLinkTargetByClass($targetclass, $targetcommandsort));
610  $template->setVariable("QUESTION_TITLE", $this->lng->txt("tst_question_title"));
611  if (strcmp($sort, "title") == 0)
612  {
613  $image = new ilTemplate("tpl.image.html", TRUE, TRUE);
614  $image->setVariable("IMAGE_SOURCE", ilUtil::getImagePath($sortorder . "_order.gif"));
615  $image->setVariable("IMAGE_ALT", $this->lng->txt("change_sort_direction"));
616  $image->setVariable("IMAGE_TITLE", $this->lng->txt("change_sort_direction"));
617  $template->setVariable("IMAGE_QUESTION_TITLE", $image->get());
618  }
619  $this->ctrl->setParameterByClass($targetclass, "sort", "max");
620  if (strcmp($sort, "max") == 0)
621  {
622  $this->ctrl->setParameterByClass($targetclass, "sortorder", strcmp($sortorder, "asc") ? "desc" : "asc");
623  }
624  else
625  {
626  $this->ctrl->setParameterByClass($targetclass, "sortorder", "asc");
627  }
628  $template->setVariable("URL_MAX_POINTS", $this->ctrl->getLinkTargetByClass($targetclass, $targetcommandsort));
629  $template->setVariable("MAX_POINTS", $this->lng->txt("tst_maximum_points"));
630  if (strcmp($sort, "max") == 0)
631  {
632  $image = new ilTemplate("tpl.image.html", TRUE, TRUE);
633  $image->setVariable("IMAGE_SOURCE", ilUtil::getImagePath($sortorder . "_order.gif"));
634  $image->setVariable("IMAGE_ALT", $this->lng->txt("change_sort_direction"));
635  $image->setVariable("IMAGE_TITLE", $this->lng->txt("change_sort_direction"));
636  $template->setVariable("IMAGE_MAX_POINTS", $image->get());
637  }
638  $this->ctrl->setParameterByClass($targetclass, "sort", "reached");
639  if (strcmp($sort, "reached") == 0)
640  {
641  $this->ctrl->setParameterByClass($targetclass, "sortorder", !strcmp($sortorder, "asc") ? "desc" : "asc");
642  }
643  else
644  {
645  $this->ctrl->setParameterByClass($targetclass, "sortorder", "asc");
646  }
647  $template->setVariable("URL_REACHED_POINTS", $this->ctrl->getLinkTargetByClass($targetclass, $targetcommandsort));
648  $template->setVariable("REACHED_POINTS", $this->lng->txt("tst_reached_points"));
649  if (strcmp($sort, "reached") == 0)
650  {
651  $image = new ilTemplate("tpl.image.html", TRUE, TRUE);
652  $image->setVariable("IMAGE_SOURCE", ilUtil::getImagePath($sortorder . "_order.gif"));
653  $image->setVariable("IMAGE_ALT", $this->lng->txt("change_sort_direction"));
654  $image->setVariable("IMAGE_TITLE", $this->lng->txt("change_sort_direction"));
655  $template->setVariable("IMAGE_REACHED_POINTS", $image->get());
656  }
657  $template->parseCurrentBlock();
658  }
659 
660  return $template->get();
661  }
662 
672  {
673  if ($this->object->getShowSolutionSignature() && !$this->object->getAnonymity())
674  {
675  // output of time/date and signature
676  $template = new ilTemplate("tpl.il_as_tst_results_userdata_signature.html", TRUE, TRUE, "Modules/Test");
677  $template->setVariable("TXT_DATE", $this->lng->txt("date"));
678  $template->setVariable("VALUE_DATE", strftime("%Y-%m-%d %H:%M:%S", time()));
679  $template->setVariable("TXT_SIGNATURE", $this->lng->txt("tst_signature"));
680  $template->setVariable("IMG_SPACER", ilUtil::getImagePath("spacer.gif"));
681  return $template->get();
682  }
683  else
684  {
685  return "";
686  }
687  }
688 
699  function getResultsUserdata($active_id, $overwrite_anonymity = FALSE)
700  {
701  $template = new ilTemplate("tpl.il_as_tst_results_userdata.html", TRUE, TRUE, "Modules/Test");
702  include_once './Services/User/classes/class.ilObjUser.php';
703  $user_id = $this->object->_getUserIdFromActiveId($active_id);
704  if (strlen(ilObjUser::_lookupLogin($user_id)) > 0)
705  {
706  $user = new ilObjUser($user_id);
707  }
708  else
709  {
710  $user = new ilObjUser();
711  $user->setLastname($this->lng->txt("deleted_user"));
712  }
713  $t = $this->object->getTestSession($active_id)->getSubmittedTimestamp();
714  if (!$t)
715  {
716  $t = $this->object->_getLastAccess($this->object->getTestSession()->getActiveId());
717  }
718  $print_date = mktime(date("H"), date("i"), date("s"), date("m") , date("d"), date("Y"));
719 
720  $title_matric = "";
721  if (strlen($user->getMatriculation()) && (($this->object->getAnonymity() == FALSE) || ($overwrite_anonymity)))
722  {
723  $template->setCurrentBlock("user_matric");
724  $template->setVariable("TXT_USR_MATRIC", $this->lng->txt("matriculation"));
725  $template->parseCurrentBlock();
726  $template->setCurrentBlock("user_matric_value");
727  $template->setVariable("VALUE_USR_MATRIC", $user->getMatriculation());
728  $template->parseCurrentBlock();
729  $template->touchBlock("user_matric_separator");
730  $title_matric = " - " . $this->lng->txt("matriculation") . ": " . $user->getMatriculation();
731  }
732 
733  $invited_user = array_pop($this->object->getInvitedUsers($user_id));
734  if (strlen($invited_user->clientip))
735  {
736  $template->setCurrentBlock("user_clientip");
737  $template->setVariable("TXT_CLIENT_IP", $this->lng->txt("client_ip"));
738  $template->parseCurrentBlock();
739  $template->setCurrentBlock("user_clientip_value");
740  $template->setVariable("VALUE_CLIENT_IP", $invited_user->clientip);
741  $template->parseCurrentBlock();
742  $template->touchBlock("user_clientip_separator");
743  $title_client = " - " . $this->lng->txt("clientip") . ": " . $invited_user->clientip;
744  }
745 
746  $template->setVariable("TXT_TEST_TITLE", $this->lng->txt("title"));
747  $template->setVariable("VALUE_TEST_TITLE", $this->object->getTitle());
748  $template->setVariable("TXT_USR_NAME", $this->lng->txt("name"));
749  $uname = $this->object->userLookupFullName($user_id, $overwrite_anonymity);
750  $template->setVariable("VALUE_USR_NAME", $uname);
751  $template->setVariable("TXT_TEST_DATE", $this->lng->txt("tst_tst_date"));
752  $template->setVariable("VALUE_TEST_DATE", strftime("%Y-%m-%d %H:%M:%S",ilUtil::date_mysql2time($t)));
753  $template->setVariable("TXT_PRINT_DATE", $this->lng->txt("tst_print_date"));
754  $template->setVariable("VALUE_PRINT_DATE", strftime("%Y-%m-%d %H:%M:%S",$print_date));
755 
756  // change the pagetitle
757  $pagetitle = ": " . $this->object->getTitle() . $title_matric . $title_client;
758  $this->tpl->setHeaderPageTitle($pagetitle);
759 
760  return $template->get();
761  }
762 
774  function getCorrectSolutionOutput($question_id, $active_id, $pass)
775  {
776  global $ilUser;
777 
778  $test_id = $this->object->getTestId();
779  $question_gui = $this->object->createQuestionGUI("", $question_id);
780 
781  $template = new ilTemplate("tpl.il_as_tst_correct_solution_output.html", TRUE, TRUE, "Modules/Test");
782  $show_question_only = ($this->object->getShowSolutionAnswersOnly()) ? TRUE : FALSE;
783  $result_output = $question_gui->getSolutionOutput($active_id, $pass, TRUE, TRUE, $show_question_only, $this->object->getShowSolutionFeedback());
784  $best_output = $question_gui->getSolutionOutput($active_id, $pass, FALSE, FALSE, $show_question_only, FALSE, TRUE);
785  if (strlen($best_output))
786  {
787  $template->setCurrentBlock("best_solution");
788  $template->setVariable("TEXT_BEST_SOLUTION", $this->lng->txt("tst_best_solution_is"));
789  $template->setVariable("BEST_OUTPUT", $best_output);
790  $template->parseCurrentBlock();
791  }
792  $template->setVariable("TEXT_YOUR_SOLUTION", $this->lng->txt("tst_your_answer_was"));
793  $maxpoints = $question_gui->object->getMaximumPoints();
794  if ($maxpoints == 1)
795  {
796  $template->setVariable("QUESTION_TITLE", $this->object->getQuestionTitle($question_gui->object->getTitle()) . " (" . $maxpoints . " " . $this->lng->txt("point") . ")");
797  }
798  else
799  {
800  $template->setVariable("QUESTION_TITLE", $this->object->getQuestionTitle($question_gui->object->getTitle()) . " (" . $maxpoints . " " . $this->lng->txt("points") . ")");
801  }
802  $template->setVariable("SOLUTION_OUTPUT", $result_output);
803  $template->setVariable("RECEIVED_POINTS", sprintf($this->lng->txt("you_received_a_of_b_points"), $question_gui->object->getReachedPoints($active_id, $pass), $maxpoints));
804  $template->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
805  $template->setVariable("BACKLINK_TEXT", "&lt;&lt; " . $this->lng->txt("back"));
806  return $template->get();
807  }
808 
816  function getResultsOfUserOutput($active_id, $pass, $show_pass_details = TRUE, $show_answers = TRUE, $show_question_only = FALSE, $show_reached_points = FALSE)
817  {
818  global $ilias, $tpl;
819 
820  include_once("./classes/class.ilTemplate.php");
821  $template = new ilTemplate("tpl.il_as_tst_results_participant.html", TRUE, TRUE, "Modules/Test");
822 
823  $user_id = $this->object->_getUserIdFromActiveId($active_id);
824  $uname = $this->object->userLookupFullName($user_id, TRUE);
825 
826  if (((array_key_exists("pass", $_GET)) && (strlen($_GET["pass"]) > 0)) || (!is_null($pass)))
827  {
828  if (is_null($pass)) $pass = $_GET["pass"];
829  }
830 
831  $result_pass = $this->object->_getResultPass($active_id);
832  $result_array =& $this->object->getTestResult($active_id, $result_pass);
833  $statement = $this->getFinalStatement($result_array["test"]);
834  $user_data = $this->getResultsUserdata($active_id, TRUE);
835 
836  if (!is_null($pass))
837  {
838  $result_array =& $this->object->getTestResult($active_id, $pass);
839  $command_solution_details = "";
840  if ($show_pass_details)
841  {
842  $detailsoverview = $this->getPassDetailsOverview($result_array, $active_id, $pass, "iltestservicegui", "getResultsOfUserOutput", $command_solution_details);
843  }
844 
845  $user_id = $this->object->_getUserIdFromActiveId($active_id);
846  $showAllAnswers = TRUE;
847  if ($this->object->isExecutable($user_id))
848  {
849  $showAllAnswers = FALSE;
850  }
851  if ($show_answers)
852  {
853  $list_of_answers = $this->getPassListOfAnswers($result_array, $active_id, $pass, FALSE, $showAllAnswers, $show_question_only, $show_reached_points);
854  }
855 
856  $template->setVariable("LIST_OF_ANSWERS", $list_of_answers);
857  //$template->setVariable("PASS_RESULTS_OVERVIEW", sprintf($this->lng->txt("tst_results_overview_pass"), $pass + 1));
858  $template->setVariable("PASS_DETAILS", $detailsoverview);
859 
860  $signature = $this->getResultsSignature();
861  $template->setVariable("SIGNATURE", $signature);
862  }
863  $template->setVariable("TEXT_HEADING", sprintf($this->lng->txt("tst_result_user_name"), $uname));
864  $template->setVariable("USER_DATA", $user_data);
865  $template->setVariable("USER_MARK", $statement["mark"]);
866  if (strlen($statement["markects"]))
867  {
868  $template->setVariable("USER_MARK_ECTS", $statement["markects"]);
869  }
870  $template->parseCurrentBlock();
871 
872  return $template->get();
873  }
874 
882  function getResultsHeadUserAndPass($active_id, $pass)
883  {
884  $template = new ilTemplate("tpl.il_as_tst_results_head_user_pass.html", TRUE, TRUE, "Modules/Test");
885  include_once './Services/User/classes/class.ilObjUser.php';
886  $user_id = $this->object->_getUserIdFromActiveId($active_id);
887  if (strlen(ilObjUser::_lookupLogin($user_id)) > 0)
888  {
889  $user = new ilObjUser($user_id);
890  }
891  else
892  {
893  $user = new ilObjUser();
894  $user->setLastname($this->lng->txt("deleted_user"));
895  }
896  $title_matric = "";
897  if (strlen($user->getMatriculation()) && (($this->object->getAnonymity() == FALSE)))
898  {
899  $template->setCurrentBlock("user_matric");
900  $template->setVariable("TXT_USR_MATRIC", $this->lng->txt("matriculation"));
901  $template->parseCurrentBlock();
902  $template->setCurrentBlock("user_matric_value");
903  $template->setVariable("VALUE_USR_MATRIC", $user->getMatriculation());
904  $template->parseCurrentBlock();
905  $template->touchBlock("user_matric_separator");
906  $title_matric = " - " . $this->lng->txt("matriculation") . ": " . $user->getMatriculation();
907  }
908 
909  $invited_user = array_pop($this->object->getInvitedUsers($user_id));
910  if (strlen($invited_user->clientip))
911  {
912  $template->setCurrentBlock("user_clientip");
913  $template->setVariable("TXT_CLIENT_IP", $this->lng->txt("client_ip"));
914  $template->parseCurrentBlock();
915  $template->setCurrentBlock("user_clientip_value");
916  $template->setVariable("VALUE_CLIENT_IP", $invited_user->clientip);
917  $template->parseCurrentBlock();
918  $template->touchBlock("user_clientip_separator");
919  $title_client = " - " . $this->lng->txt("clientip") . ": " . $invited_user->clientip;
920  }
921 
922  $template->setVariable("TXT_USR_NAME", $this->lng->txt("name"));
923  $uname = $this->object->userLookupFullName($user_id, FALSE);
924  $template->setVariable("VALUE_USR_NAME", $uname);
925  $template->setVariable("TXT_PASS", $this->lng->txt("scored_pass"));
926  $template->setVariable("VALUE_PASS", $pass);
927  return $template->get();
928  }
929 
938  function getQuestionResultForTestUsers($question_id, $test_id)
939  {
940  $foundusers = $this->object->getParticipantsForTestAndQuestion($test_id, $question_id);
941  $output = "";
942  foreach ($foundusers as $active_id => $passes)
943  {
944  $resultpass = $this->object->_getResultPass($active_id);
945  for ($i = 0; $i < count($passes); $i++)
946  {
947  if (($resultpass != null) && ($resultpass == $passes[$i]["pass"]))
948  {
949  $question_gui =& $this->object->createQuestionGUI("", $passes[$i]["qid"]);
950  $output .= $this->getResultsHeadUserAndPass($active_id, $resultpass+1);
951  $output .= $question_gui->getSolutionOutput($active_id, $resultpass, $graphicalOutput = FALSE, $result_output = FALSE, $show_question_only = FALSE, $show_feedback = FALSE);
952  $output .= "<br /><br /><br />";
953  }
954  }
955  }
956  $printbody = new ilTemplate("tpl.il_as_tst_print_body.html", TRUE, TRUE, "Modules/Test");
957  $printbody->setVariable("TITLE", $this->lng->txt("tst_results"));
958  $printbody->setVariable("ADM_CONTENT", $output);
959  $printoutput = $printbody->get();
960  $printoutput = preg_replace("/href=\".*?\"/", "", $printoutput);
961  $fo = $this->object->processPrintoutput2FO($printoutput);
962  $this->object->deliverPDFfromFO($fo, $question_gui->object->getTitle());
963  }
964 }
965 
966 // internal sort function to sort the result array
967 function sortResults($a, $b)
968 {
969  $sort = ($_GET["sort"]) ? ($_GET["sort"]) : "nr";
970  $sortorder = ($_GET["sortorder"]) ? ($_GET["sortorder"]) : "asc";
971  if (strcmp($sortorder, "asc"))
972  {
973  $smaller = 1;
974  $greater = -1;
975  }
976  else
977  {
978  $smaller = -1;
979  $greater = 1;
980  }
981  if ($a[$sort] == $b[$sort]) return 0;
982  return ($a[$sort] < $b[$sort]) ? $smaller : $greater;
983 }
984 
985 ?>