ILIAS  Release_4_0_x_branch Revision 61816
 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)
276  {
277  $maintemplate = new ilTemplate("tpl.il_as_tst_list_of_answers.html", TRUE, TRUE, "Modules/Test");
278 
279  $counter = 1;
280  // output of questions with solutions
281  foreach ($result_array as $question_data)
282  {
283  if (($question_data["workedthrough"] == 1) || ($only_answered_questions == FALSE))
284  {
285  $template = new ilTemplate("tpl.il_as_qpl_question_printview.html", TRUE, TRUE, "Modules/TestQuestionPool");
286  $question = $question_data["qid"];
287  if (is_numeric($question))
288  {
289  $maintemplate->setCurrentBlock("printview_question");
290  $question_gui = $this->object->createQuestionGUI("", $question);
291  if (is_object($question_gui))
292  {
293  if ($show_reached_points)
294  {
295  $template->setCurrentBlock("result_points");
296  $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());
297  $template->parseCurrentBlock();
298  }
299  $template->setVariable("COUNTER_QUESTION", $counter.". ");
300  $template->setVariable("QUESTION_TITLE", $this->object->getQuestionTitle($question_gui->object->getTitle()));
301 
302  $show_question_only = ($this->object->getShowSolutionAnswersOnly()) ? TRUE : FALSE;
303  $result_output = $question_gui->getSolutionOutput($active_id, $pass, $show_solutions, FALSE, $show_question_only, $this->object->getShowSolutionFeedback());
304 
305  $template->setVariable("SOLUTION_OUTPUT", $result_output);
306  $maintemplate->setCurrentBlock("printview_question");
307  $maintemplate->setVariable("QUESTION_PRINTVIEW", $template->get());
308  $maintemplate->parseCurrentBlock();
309  $counter ++;
310  }
311  }
312  }
313  }
314  $maintemplate->setVariable("RESULTS_OVERVIEW", sprintf($this->lng->txt("tst_eval_results_by_pass"), $pass+1));
315  return $maintemplate->get();
316  }
317 
328  function getPassListOfAnswersWithScoring(&$result_array, $active_id, $pass, $show_solutions = FALSE)
329  {
330  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
331 
332  $maintemplate = new ilTemplate("tpl.il_as_tst_list_of_answers.html", TRUE, TRUE, "Modules/Test");
333 
334  include_once "./Modules/Test/classes/class.ilObjAssessmentFolder.php";
336 
337  $counter = 1;
338  // output of questions with solutions
339  foreach ($result_array as $question_data)
340  {
341  $question = $question_data["qid"];
342  if (is_numeric($question))
343  {
344  $question_gui = $this->object->createQuestionGUI("", $question);
345  if (in_array($question_gui->object->getQuestionTypeID(), $scoring))
346  {
347  $template = new ilTemplate("tpl.il_as_qpl_question_printview.html", TRUE, TRUE, "Modules/TestQuestionPool");
348  $scoretemplate = new ilTemplate("tpl.il_as_tst_manual_scoring_points.html", TRUE, TRUE, "Modules/Test");
349  $this->tpl->setCurrentBlock("printview_question");
350  $template->setVariable("COUNTER_QUESTION", $counter.". ");
351  $template->setVariable("QUESTION_TITLE", $this->object->getQuestionTitle($question_gui->object->getTitle()));
352  $points = $question_gui->object->getMaximumPoints();
353  if ($points == 1)
354  {
355  $template->setVariable("QUESTION_POINTS", $points . " " . $this->lng->txt("point"));
356  }
357  else
358  {
359  $template->setVariable("QUESTION_POINTS", $points . " " . $this->lng->txt("points"));
360  }
361 
362  $show_question_only = ($this->object->getShowSolutionAnswersOnly()) ? TRUE : FALSE;
363  $result_output = $question_gui->getSolutionOutput($active_id, $pass, $show_solutions, FALSE, $show_question_only, $this->object->getShowSolutionFeedback(), FALSE, TRUE);
364 
365  $solout = $question_gui->object->getSuggestedSolutionOutput();
366  if (strlen($solout))
367  {
368  $scoretemplate->setCurrentBlock("suggested_solution");
369  $scoretemplate->setVariable("TEXT_SUGGESTED_SOLUTION", $this->lng->txt("solution_hint"));
370  $scoretemplate->setVariable("VALUE_SUGGESTED_SOLUTION", $solout);
371  $scoretemplate->parseCurrentBlock();
372  }
373 
374  $scoretemplate->setCurrentBlock("feedback");
375  $scoretemplate->setVariable("FEEDBACK_NAME_INPUT", $question);
376  $feedback = $this->object->getManualFeedback($active_id, $question, $pass);
377  $scoretemplate->setVariable("VALUE_FEEDBACK", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($feedback, TRUE)));
378  $scoretemplate->setVariable("TEXT_MANUAL_FEEDBACK", $this->lng->txt("set_manual_feedback"));
379  $scoretemplate->parseCurrentBlock();
380 
381  $scoretemplate->setVariable("NAME_INPUT", $question);
382  $this->ctrl->setParameter($this, "active_id", $active_id);
383  $this->ctrl->setParameter($this, "pass", $pass);
384  $scoretemplate->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "manscoring"));
385  $scoretemplate->setVariable("LABEL_INPUT", $this->lng->txt("tst_change_points_for_question"));
386  $scoretemplate->setVariable("VALUE_INPUT", " value=\"" . assQuestion::_getReachedPoints($active_id, $question_data["qid"], $pass) . "\"");
387  $scoretemplate->setVariable("VALUE_SAVE", $this->lng->txt("save"));
388 
389  $template->setVariable("SOLUTION_OUTPUT", $result_output);
390  $maintemplate->setCurrentBlock("printview_question");
391  $maintemplate->setVariable("QUESTION_PRINTVIEW", $template->get());
392  $maintemplate->setVariable("QUESTION_SCORING", $scoretemplate->get());
393  $maintemplate->parseCurrentBlock();
394  }
395  $counter ++;
396  }
397  }
398  if ($counter == 1)
399  {
400  // no scorable questions found
401  $maintemplate->setVariable("NO_QUESTIONS_FOUND", $this->lng->txt("manscoring_questions_not_found"));
402  }
403  $maintemplate->setVariable("RESULTS_OVERVIEW", sprintf($this->lng->txt("manscoring_results_pass"), $pass+1));
404 
405  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
407 
408  return $maintemplate->get();
409  }
410 
411 
427  function getPassDetailsOverview($result_array, $active_id, $pass, $targetclass = "", $targetcommandsort = "", $targetcommanddetails = "", $standard_header = TRUE)
428  {
429  global $ilUser;
430 
431  $testresults = $result_array["pass"];
432  unset($result_array["test"]);
433  $user_id = $this->object->_getUserIdFromActiveId($active_id);
434 
435  $sort = ($_GET["sort"]) ? ($_GET["sort"]) : "nr";
436  $sortorder = ($_GET["sortorder"]) ? ($_GET["sortorder"]) : "asc";
437 
438  if (!$standard_header)
439  {
440  // change sortorder of result array
441  usort($result_array, "sortResults");
442  }
443  $color_class = array("tblrow1top", "tblrow2top");
444  $counter = 0;
445  $template = new ilTemplate("tpl.il_as_tst_pass_details_overview.html", TRUE, TRUE, "Modules/Test");
446  $this->ctrl->setParameterByClass($targetclass, "pass", "$pass");
447 
448  if (!$testresults["total_max_points"])
449  {
450  $percentage = 0;
451  }
452  else
453  {
454  $percentage = ($testresults["total_reached_points"]/$testresults["total_max_points"])*100;
455  }
456  $total_max = $testresults["total_max_points"];
457  $total_reached = $testresults["total_reached_points"];
458 
459  $img_title_percent = "";
460  $img_title_nr = "";
461  $hasSuggestedSolutions = FALSE;
462  if ($this->object->getShowSolutionSuggested())
463  {
464  foreach ($result_array as $key => $value)
465  {
466  if (strlen($value["solution"]))
467  {
468  $hasSuggestedSolutions = TRUE;
469  }
470  }
471  }
472  foreach ($result_array as $key => $value)
473  {
474  if (preg_match("/\d+/", $key))
475  {
476  if (strlen($targetclass) && strlen($targetcommanddetails))
477  {
478  $template->setCurrentBlock("linked_title");
479  $template->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
480  $template->setVariable("VALUE_QUESTION_TITLE", $value["title"]);
481  $this->ctrl->setParameterByClass($targetclass, "evaluation", $value["qid"]);
482  $this->ctrl->setParameterByClass($targetclass, "active_id", $active_id);
483  $template->setVariable("URL_QUESTION_TITLE", $this->ctrl->getLinkTargetByClass($targetclass, $targetcommanddetails));
484  $template->parseCurrentBlock();
485  }
486  else
487  {
488  $template->setCurrentBlock("plain_title");
489  $template->setVariable("VALUE_QUESTION_TITLE", $value["title"]);
490  $template->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
491  $template->parseCurrentBlock();
492  }
493  if ($hasSuggestedSolutions)
494  {
495  $template->setCurrentBlock("question_suggested_solution");
496  $template->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
497  $template->setVariable("SOLUTION_HINT", $value["solution"]);
498  $template->parseCurrentBlock();
499  }
500  $template->setCurrentBlock("question");
501  $template->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
502  $template->setVariable("VALUE_QUESTION_COUNTER", $value["nr"]);
503  $template->setVariable("VALUE_MAX_POINTS", $value["max"]);
504  $template->setVariable("VALUE_REACHED_POINTS", $value["reached"]);
505  $template->setVariable("VALUE_PERCENT_SOLVED", $value["percent"]);
506  $template->parseCurrentBlock();
507  $counter++;
508  }
509  }
510 
511  if ($hasSuggestedSolutions)
512  {
513  $template->touchBlock("footer_suggested_solution");
514  }
515  $template->setCurrentBlock("footer");
516  $template->setVariable("VALUE_QUESTION_COUNTER", "<strong>" . $this->lng->txt("total") . "</strong>");
517  $template->setVariable("VALUE_QUESTION_TITLE", "");
518  $template->setVariable("VALUE_MAX_POINTS", "<strong>$total_max</strong>");
519  $template->setVariable("VALUE_REACHED_POINTS", "<strong>$total_reached</strong>");
520  $template->setVariable("VALUE_PERCENT_SOLVED", "<strong>" . sprintf("%2.2f", $percentage) . " %" . "</strong>");
521  $template->parseCurrentBlock();
522 
523  if ($standard_header)
524  {
525  if ($hasSuggestedSolutions)
526  {
527  $template->setCurrentBlock("standard_header_suggested_solution");
528  $template->setVariable("SOLUTION_HINT_HEADER", $this->lng->txt("solution_hint"));
529  $template->parseCurrentBlock();
530  }
531  $template->setCurrentBlock("standard_header");
532  $template->setVariable("QUESTION_COUNTER", $this->lng->txt("tst_question_no"));
533  $template->setVariable("PERCENT_SOLVED", $this->lng->txt("tst_percent_solved"));
534  $template->setVariable("QUESTION_TITLE", $this->lng->txt("tst_question_title"));
535  $template->setVariable("MAX_POINTS", $this->lng->txt("tst_maximum_points"));
536  $template->setVariable("REACHED_POINTS", $this->lng->txt("tst_reached_points"));
537  $template->parseCurrentBlock();
538  }
539  else
540  {
541  if ($hasSuggestedSolutions)
542  {
543  $template->setCurrentBlock("linked_header_suggested_solution");
544  if (strcmp($sort, "solution") == 0)
545  {
546  $this->ctrl->setParameterByClass($targetclass, "sortorder", !strcmp($sortorder, "asc") ? "desc" : "asc");
547  }
548  else
549  {
550  $this->ctrl->setParameterByClass($targetclass, "sortorder", "asc");
551  }
552  $this->ctrl->setParameterByClass($targetclass, "sort", "solution");
553  $template->setVariable("URL_SOLUTION_HINT_HEADER", $this->ctrl->getLinkTargetByClass($targetclass, $targetcommandsort));
554  $template->setVariable("SOLUTION_HINT_HEADER", $this->lng->txt("solution_hint"));
555  if (strcmp($sort, "solution") == 0)
556  {
557  $image = new ilTemplate("tpl.image.html", TRUE, TRUE);
558  $image->setVariable("IMAGE_SOURCE", ilUtil::getImagePath($sortorder . "_order.gif"));
559  $image->setVariable("IMAGE_ALT", $this->lng->txt("change_sort_direction"));
560  $image->setVariable("IMAGE_TITLE", $this->lng->txt("change_sort_direction"));
561  $template->setVariable("IMAGE_SOLUTION_HINT_HEADER", $image->get());
562  }
563  $template->parseCurrentBlock();
564  }
565  $template->setCurrentBlock("linked_header");
566  $this->ctrl->setParameterByClass($targetclass, "sort", "nr");
567  if (strcmp($sort, "nr") == 0)
568  {
569  $this->ctrl->setParameterByClass($targetclass, "sortorder", !strcmp($sortorder, "asc") ? "desc" : "asc");
570  }
571  else
572  {
573  $this->ctrl->setParameterByClass($targetclass, "sortorder", "asc");
574  }
575  $template->setVariable("URL_QUESTION_COUNTER", $this->ctrl->getLinkTargetByClass($targetclass, $targetcommandsort));
576  $template->setVariable("QUESTION_COUNTER", $this->lng->txt("tst_question_no"));
577  if (strcmp($sort, "nr") == 0)
578  {
579  $image = new ilTemplate("tpl.image.html", TRUE, TRUE);
580  $image->setVariable("IMAGE_SOURCE", ilUtil::getImagePath($sortorder . "_order.gif"));
581  $image->setVariable("IMAGE_ALT", $this->lng->txt("change_sort_direction"));
582  $image->setVariable("IMAGE_TITLE", $this->lng->txt("change_sort_direction"));
583  $template->setVariable("IMAGE_QUESTION_COUNTER", $image->get());
584  }
585  $this->ctrl->setParameterByClass($targetclass, "sort", "percent");
586  if (strcmp($sort, "percent") == 0)
587  {
588  $this->ctrl->setParameterByClass($targetclass, "sortorder", !strcmp($sortorder, "asc") ? "desc" : "asc");
589  }
590  else
591  {
592  $this->ctrl->setParameterByClass($targetclass, "sortorder", "asc");
593  }
594  $template->setVariable("URL_PERCENT_SOLVED", $this->ctrl->getLinkTargetByClass($targetclass, $targetcommandsort));
595  $template->setVariable("PERCENT_SOLVED", $this->lng->txt("tst_percent_solved"));
596  if (strcmp($sort, "percent") == 0)
597  {
598  $image = new ilTemplate("tpl.image.html", TRUE, TRUE);
599  $image->setVariable("IMAGE_SOURCE", ilUtil::getImagePath($sortorder . "_order.gif"));
600  $image->setVariable("IMAGE_ALT", $this->lng->txt("change_sort_direction"));
601  $image->setVariable("IMAGE_TITLE", $this->lng->txt("change_sort_direction"));
602  $template->setVariable("IMAGE_PERCENT_SOLVED", $image->get());
603  }
604  $this->ctrl->setParameterByClass($targetclass, "sort", "title");
605  if (strcmp($sort, "title") == 0)
606  {
607  $this->ctrl->setParameterByClass($targetclass, "sortorder", !strcmp($sortorder, "asc") ? "desc" : "asc");
608  }
609  else
610  {
611  $this->ctrl->setParameterByClass($targetclass, "sortorder", "asc");
612  }
613  $template->setVariable("URL_QUESTION_TITLE", $this->ctrl->getLinkTargetByClass($targetclass, $targetcommandsort));
614  $template->setVariable("QUESTION_TITLE", $this->lng->txt("tst_question_title"));
615  if (strcmp($sort, "title") == 0)
616  {
617  $image = new ilTemplate("tpl.image.html", TRUE, TRUE);
618  $image->setVariable("IMAGE_SOURCE", ilUtil::getImagePath($sortorder . "_order.gif"));
619  $image->setVariable("IMAGE_ALT", $this->lng->txt("change_sort_direction"));
620  $image->setVariable("IMAGE_TITLE", $this->lng->txt("change_sort_direction"));
621  $template->setVariable("IMAGE_QUESTION_TITLE", $image->get());
622  }
623  $this->ctrl->setParameterByClass($targetclass, "sort", "max");
624  if (strcmp($sort, "max") == 0)
625  {
626  $this->ctrl->setParameterByClass($targetclass, "sortorder", strcmp($sortorder, "asc") ? "desc" : "asc");
627  }
628  else
629  {
630  $this->ctrl->setParameterByClass($targetclass, "sortorder", "asc");
631  }
632  $template->setVariable("URL_MAX_POINTS", $this->ctrl->getLinkTargetByClass($targetclass, $targetcommandsort));
633  $template->setVariable("MAX_POINTS", $this->lng->txt("tst_maximum_points"));
634  if (strcmp($sort, "max") == 0)
635  {
636  $image = new ilTemplate("tpl.image.html", TRUE, TRUE);
637  $image->setVariable("IMAGE_SOURCE", ilUtil::getImagePath($sortorder . "_order.gif"));
638  $image->setVariable("IMAGE_ALT", $this->lng->txt("change_sort_direction"));
639  $image->setVariable("IMAGE_TITLE", $this->lng->txt("change_sort_direction"));
640  $template->setVariable("IMAGE_MAX_POINTS", $image->get());
641  }
642  $this->ctrl->setParameterByClass($targetclass, "sort", "reached");
643  if (strcmp($sort, "reached") == 0)
644  {
645  $this->ctrl->setParameterByClass($targetclass, "sortorder", !strcmp($sortorder, "asc") ? "desc" : "asc");
646  }
647  else
648  {
649  $this->ctrl->setParameterByClass($targetclass, "sortorder", "asc");
650  }
651  $template->setVariable("URL_REACHED_POINTS", $this->ctrl->getLinkTargetByClass($targetclass, $targetcommandsort));
652  $template->setVariable("REACHED_POINTS", $this->lng->txt("tst_reached_points"));
653  if (strcmp($sort, "reached") == 0)
654  {
655  $image = new ilTemplate("tpl.image.html", TRUE, TRUE);
656  $image->setVariable("IMAGE_SOURCE", ilUtil::getImagePath($sortorder . "_order.gif"));
657  $image->setVariable("IMAGE_ALT", $this->lng->txt("change_sort_direction"));
658  $image->setVariable("IMAGE_TITLE", $this->lng->txt("change_sort_direction"));
659  $template->setVariable("IMAGE_REACHED_POINTS", $image->get());
660  }
661  $template->parseCurrentBlock();
662  }
663 
664  return $template->get();
665  }
666 
676  {
677  if ($this->object->getShowSolutionSignature() && !$this->object->getAnonymity())
678  {
679  // output of time/date and signature
680  $template = new ilTemplate("tpl.il_as_tst_results_userdata_signature.html", TRUE, TRUE, "Modules/Test");
681  $template->setVariable("TXT_DATE", $this->lng->txt("date"));
682  $template->setVariable("VALUE_DATE", strftime("%Y-%m-%d %H:%M:%S", time()));
683  $template->setVariable("TXT_SIGNATURE", $this->lng->txt("tst_signature"));
684  $template->setVariable("IMG_SPACER", ilUtil::getImagePath("spacer.gif"));
685  return $template->get();
686  }
687  else
688  {
689  return "";
690  }
691  }
692 
703  function getResultsUserdata($active_id, $overwrite_anonymity = FALSE)
704  {
705  $template = new ilTemplate("tpl.il_as_tst_results_userdata.html", TRUE, TRUE, "Modules/Test");
706  include_once './Services/User/classes/class.ilObjUser.php';
707  $user_id = $this->object->_getUserIdFromActiveId($active_id);
708  if (strlen(ilObjUser::_lookupLogin($user_id)) > 0)
709  {
710  $user = new ilObjUser($user_id);
711  }
712  else
713  {
714  $user = new ilObjUser();
715  $user->setLastname($this->lng->txt("deleted_user"));
716  }
717  $t = $this->object->getTestSession($active_id)->getSubmittedTimestamp();
718  if (!$t)
719  {
720  $t = $this->object->_getLastAccess($this->object->getTestSession()->getActiveId());
721  }
722  $print_date = mktime(date("H"), date("i"), date("s"), date("m") , date("d"), date("Y"));
723 
724  $title_matric = "";
725  if (strlen($user->getMatriculation()) && (($this->object->getAnonymity() == FALSE) || ($overwrite_anonymity)))
726  {
727  $template->setCurrentBlock("user_matric");
728  $template->setVariable("TXT_USR_MATRIC", $this->lng->txt("matriculation"));
729  $template->parseCurrentBlock();
730  $template->setCurrentBlock("user_matric_value");
731  $template->setVariable("VALUE_USR_MATRIC", $user->getMatriculation());
732  $template->parseCurrentBlock();
733  $template->touchBlock("user_matric_separator");
734  $title_matric = " - " . $this->lng->txt("matriculation") . ": " . $user->getMatriculation();
735  }
736 
737  $invited_user = array_pop($this->object->getInvitedUsers($user_id));
738  if (strlen($invited_user["clientip"]))
739  {
740  $template->setCurrentBlock("user_clientip");
741  $template->setVariable("TXT_CLIENT_IP", $this->lng->txt("client_ip"));
742  $template->parseCurrentBlock();
743  $template->setCurrentBlock("user_clientip_value");
744  $template->setVariable("VALUE_CLIENT_IP", $invited_user["clientip"]);
745  $template->parseCurrentBlock();
746  $template->touchBlock("user_clientip_separator");
747  $title_client = " - " . $this->lng->txt("clientip") . ": " . $invited_user["clientip"];
748  }
749 
750  $template->setVariable("TXT_TEST_TITLE", $this->lng->txt("title"));
751  $template->setVariable("VALUE_TEST_TITLE", $this->object->getTitle());
752  $template->setVariable("TXT_USR_NAME", $this->lng->txt("name"));
753  $uname = $this->object->userLookupFullName($user_id, $overwrite_anonymity);
754  $template->setVariable("VALUE_USR_NAME", $uname);
755  $template->setVariable("TXT_TEST_DATE", $this->lng->txt("tst_tst_date"));
756  $template->setVariable("VALUE_TEST_DATE", strftime("%Y-%m-%d %H:%M:%S",ilUtil::date_mysql2time($t)));
757  $template->setVariable("TXT_PRINT_DATE", $this->lng->txt("tst_print_date"));
758  $template->setVariable("VALUE_PRINT_DATE", strftime("%Y-%m-%d %H:%M:%S",$print_date));
759 
760  // change the pagetitle
761  $pagetitle = ": " . $this->object->getTitle() . $title_matric . $title_client;
762  $this->tpl->setHeaderPageTitle($pagetitle);
763 
764  return $template->get();
765  }
766 
778  function getCorrectSolutionOutput($question_id, $active_id, $pass)
779  {
780  global $ilUser;
781 
782  $test_id = $this->object->getTestId();
783  $question_gui = $this->object->createQuestionGUI("", $question_id);
784 
785  $template = new ilTemplate("tpl.il_as_tst_correct_solution_output.html", TRUE, TRUE, "Modules/Test");
786  $show_question_only = ($this->object->getShowSolutionAnswersOnly()) ? TRUE : FALSE;
787  $result_output = $question_gui->getSolutionOutput($active_id, $pass, TRUE, FALSE, $show_question_only, $this->object->getShowSolutionFeedback());
788  $best_output = $question_gui->getSolutionOutput($active_id, $pass, FALSE, FALSE, $show_question_only, FALSE, TRUE);
789  if (strlen($best_output))
790  {
791  $template->setCurrentBlock("best_solution");
792  $template->setVariable("TEXT_BEST_SOLUTION", $this->lng->txt("tst_best_solution_is"));
793  $template->setVariable("BEST_OUTPUT", $best_output);
794  $template->parseCurrentBlock();
795  }
796  $template->setVariable("TEXT_YOUR_SOLUTION", $this->lng->txt("tst_your_answer_was"));
797  $maxpoints = $question_gui->object->getMaximumPoints();
798  if ($maxpoints == 1)
799  {
800  $template->setVariable("QUESTION_TITLE", $this->object->getQuestionTitle($question_gui->object->getTitle()) . " (" . $maxpoints . " " . $this->lng->txt("point") . ")");
801  }
802  else
803  {
804  $template->setVariable("QUESTION_TITLE", $this->object->getQuestionTitle($question_gui->object->getTitle()) . " (" . $maxpoints . " " . $this->lng->txt("points") . ")");
805  }
806  $template->setVariable("SOLUTION_OUTPUT", $result_output);
807  $template->setVariable("RECEIVED_POINTS", sprintf($this->lng->txt("you_received_a_of_b_points"), $question_gui->object->getReachedPoints($active_id, $pass), $maxpoints));
808  $template->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
809  $template->setVariable("BACKLINK_TEXT", "&lt;&lt; " . $this->lng->txt("back"));
810  return $template->get();
811  }
812 
820  function getResultsOfUserOutput($active_id, $pass, $show_pass_details = TRUE, $show_answers = TRUE, $show_question_only = FALSE, $show_reached_points = FALSE)
821  {
822  global $ilias, $tpl;
823 
824  include_once("./classes/class.ilTemplate.php");
825  $template = new ilTemplate("tpl.il_as_tst_results_participant.html", TRUE, TRUE, "Modules/Test");
826 
827  $user_id = $this->object->_getUserIdFromActiveId($active_id);
828  $uname = $this->object->userLookupFullName($user_id, TRUE);
829 
830  if (((array_key_exists("pass", $_GET)) && (strlen($_GET["pass"]) > 0)) || (!is_null($pass)))
831  {
832  if (is_null($pass)) $pass = $_GET["pass"];
833  }
834 
835  $statement = $this->getFinalStatement($active_id);
836  $user_data = $this->getResultsUserdata($active_id, TRUE);
837 
838  if (!is_null($pass))
839  {
840  $result_array =& $this->object->getTestResult($active_id, $pass);
841  $command_solution_details = "";
842  if ($show_pass_details)
843  {
844  $detailsoverview = $this->getPassDetailsOverview($result_array, $active_id, $pass, "iltestservicegui", "getResultsOfUserOutput", $command_solution_details);
845  }
846 
847  $user_id = $this->object->_getUserIdFromActiveId($active_id);
848  $showAllAnswers = TRUE;
849  if ($this->object->isExecutable($user_id))
850  {
851  $showAllAnswers = FALSE;
852  }
853  if ($show_answers)
854  {
855  $list_of_answers = $this->getPassListOfAnswers($result_array, $active_id, $pass, FALSE, $showAllAnswers, $show_question_only, $show_reached_points);
856  }
857 
858  $template->setVariable("LIST_OF_ANSWERS", $list_of_answers);
859  //$template->setVariable("PASS_RESULTS_OVERVIEW", sprintf($this->lng->txt("tst_results_overview_pass"), $pass + 1));
860  $template->setVariable("PASS_DETAILS", $detailsoverview);
861 
862  $signature = $this->getResultsSignature();
863  $template->setVariable("SIGNATURE", $signature);
864  }
865  $template->setVariable("TEXT_HEADING", sprintf($this->lng->txt("tst_result_user_name"), $uname));
866  $template->setVariable("USER_DATA", $user_data);
867  $template->setVariable("USER_MARK", $statement["mark"]);
868  if (strlen($statement["markects"]))
869  {
870  $template->setVariable("USER_MARK_ECTS", $statement["markects"]);
871  }
872  $template->parseCurrentBlock();
873 
874  return $template->get();
875  }
876 
884  function getResultsHeadUserAndPass($active_id, $pass)
885  {
886  $template = new ilTemplate("tpl.il_as_tst_results_head_user_pass.html", TRUE, TRUE, "Modules/Test");
887  include_once './Services/User/classes/class.ilObjUser.php';
888  $user_id = $this->object->_getUserIdFromActiveId($active_id);
889  if (strlen(ilObjUser::_lookupLogin($user_id)) > 0)
890  {
891  $user = new ilObjUser($user_id);
892  }
893  else
894  {
895  $user = new ilObjUser();
896  $user->setLastname($this->lng->txt("deleted_user"));
897  }
898  $title_matric = "";
899  if (strlen($user->getMatriculation()) && (($this->object->getAnonymity() == FALSE)))
900  {
901  $template->setCurrentBlock("user_matric");
902  $template->setVariable("TXT_USR_MATRIC", $this->lng->txt("matriculation"));
903  $template->parseCurrentBlock();
904  $template->setCurrentBlock("user_matric_value");
905  $template->setVariable("VALUE_USR_MATRIC", $user->getMatriculation());
906  $template->parseCurrentBlock();
907  $template->touchBlock("user_matric_separator");
908  $title_matric = " - " . $this->lng->txt("matriculation") . ": " . $user->getMatriculation();
909  }
910 
911  $invited_user = array_pop($this->object->getInvitedUsers($user_id));
912  if (strlen($invited_user["clientip"]))
913  {
914  $template->setCurrentBlock("user_clientip");
915  $template->setVariable("TXT_CLIENT_IP", $this->lng->txt("client_ip"));
916  $template->parseCurrentBlock();
917  $template->setCurrentBlock("user_clientip_value");
918  $template->setVariable("VALUE_CLIENT_IP", $invited_user["clientip"]);
919  $template->parseCurrentBlock();
920  $template->touchBlock("user_clientip_separator");
921  $title_client = " - " . $this->lng->txt("clientip") . ": " . $invited_user["clientip"];
922  }
923 
924  $template->setVariable("TXT_USR_NAME", $this->lng->txt("name"));
925  $uname = $this->object->userLookupFullName($user_id, FALSE);
926  $template->setVariable("VALUE_USR_NAME", $uname);
927  $template->setVariable("TXT_PASS", $this->lng->txt("scored_pass"));
928  $template->setVariable("VALUE_PASS", $pass);
929  return $template->get();
930  }
931 
940  function getQuestionResultForTestUsers($question_id, $test_id)
941  {
942  $foundusers = $this->object->getParticipantsForTestAndQuestion($test_id, $question_id);
943  $output = "";
944  foreach ($foundusers as $active_id => $passes)
945  {
946  $resultpass = $this->object->_getResultPass($active_id);
947  for ($i = 0; $i < count($passes); $i++)
948  {
949  if (($resultpass != null) && ($resultpass == $passes[$i]["pass"]))
950  {
951  $question_gui =& $this->object->createQuestionGUI("", $passes[$i]["qid"]);
952  $output .= $this->getResultsHeadUserAndPass($active_id, $resultpass+1);
953  $output .= $question_gui->getSolutionOutput($active_id, $resultpass, $graphicalOutput = FALSE, $result_output = FALSE, $show_question_only = FALSE, $show_feedback = FALSE);
954  $output .= "<br /><br /><br />";
955  }
956  }
957  }
958  $this->object->deliverPDFfromHTML($output, $question_gui->object->getTitle());
959  }
960 }
961 
962 // internal sort function to sort the result array
963 function sortResults($a, $b)
964 {
965  $sort = ($_GET["sort"]) ? ($_GET["sort"]) : "nr";
966  $sortorder = ($_GET["sortorder"]) ? ($_GET["sortorder"]) : "asc";
967  if (strcmp($sortorder, "asc"))
968  {
969  $smaller = 1;
970  $greater = -1;
971  }
972  else
973  {
974  $smaller = -1;
975  $greater = 1;
976  }
977  if ($a[$sort] == $b[$sort]) return 0;
978  return ($a[$sort] < $b[$sort]) ? $smaller : $greater;
979 }
980 
981 ?>