24 include_once
"./Modules/Test/classes/inc.AssessmentConstants.php";
53 $this->test_obj =& $a_test_obj;
58 $this->mode = $a_mode;
61 $settings = $this->ilias->getAllSettings();
62 $this->inst_id = IL_INST_ID;
65 $this->export_dir = $this->test_obj->getExportDirectory();
69 $this->subdir = $date.
"__".$this->inst_id.
"__".
70 "test__results__".$this->test_obj->getId();
73 $this->subdir = $date.
"__".$this->inst_id.
"__".
74 "test__aggregated__results__".$this->test_obj->getId();
77 $this->subdir = $date.
"__".$this->inst_id.
"__".
78 "test".
"__".$this->test_obj->getId();
79 $this->filename = $this->subdir.
".xml";
80 $this->resultsfile = $date.
"__".$this->inst_id.
"__".
81 "results".
"__".$this->test_obj->getId().
".xml";
82 $this->qti_filename = $date.
"__".$this->inst_id.
"__".
83 "qti".
"__".$this->test_obj->getId().
".xml";
86 $this->filename = $this->subdir.
".".$this->
getExtension();
90 switch ($this->mode) {
132 $expDir = $this->test_obj->getExportDirectory();
134 $expLog =
new ilLog($expDir,
"export.log");
136 $expLog->setLogFormat(
"");
137 $expLog->write(date(
"[y-m-d H:i:s] ").
"Start Export Of Results");
140 $this->test_obj->createExportDirectory();
141 include_once
"./Services/Utilities/classes/class.ilUtil.php";
145 $file = fopen($this->export_dir.
"/".$this->filename,
"w");
150 include_once
"./Services/Excel/classes/class.ilExcelUtils.php";
155 $expLog->write(date(
"[y-m-d H:i:s] ").
"Finished Export of Results");
167 $data = $this->test_obj->getAggregatedResultsData();
168 include_once
"./Services/Excel/classes/class.ilExcelUtils.php";
170 $outputfilename =
ilUtil::getASCIIFilename(preg_replace(
"/\s/",
"_", $this->test_obj->getTitle())) .
"-aggregated." . $adapter->getFileExtension();
171 $adapter->setWorksheetTitle($this->lng->txt(
"tst_results_aggregated"));
172 $additionalFields = $this->test_obj->getEvaluationAdditionalFields();
178 foreach (
$data[
"overview"] as $key => $value)
181 $adapter->setCellValue(
$row, $col++, $key);
182 $adapter->setCellValue(
$row, $col++, $value);
194 foreach (
$data[
"questions"] as $key => $value)
197 $adapter->setCellValue(
$row, $col++, $key);
198 $adapter->setCellValue(
$row, $col++, $value[0]);
199 $adapter->setCellValue(
$row, $col++, $value[4]);
200 $adapter->setCellValue(
$row, $col++, $value[5]);
202 $adapter->setCellValue(
$row, $col++, $value[3]);
207 $adapter->deliver($outputfilename);
212 return $adapter->save();
223 $data = $this->test_obj->getAggregatedResultsData();
225 array_push($rows, array(
226 $this->lng->txt(
"result"),
227 $this->lng->txt(
"value")
229 foreach (
$data[
"overview"] as $key => $value)
231 array_push($rows, array(
236 array_push($rows, array(
237 $this->lng->txt(
"question_title"),
238 $this->lng->txt(
"average_reached_points"),
239 $this->lng->txt(
"points"),
240 $this->lng->txt(
"percentage"),
241 $this->lng->txt(
"number_of_answers")
243 foreach (
$data[
"questions"] as $key => $value)
245 array_push($rows, array(
255 foreach ($rows as $evalrow)
257 $csvrow =& $this->test_obj->processCSVRow($evalrow, TRUE,
$separator);
282 if ($a[
"id"] == $b[
"id"]) {
285 return ($a[
"id"] < $b[
"id"]) ? -1 : 1;
295 function exportToExcel($deliver = TRUE, $filterby =
"", $filtertext =
"", $passedonly = FALSE)
301 include_once
"./Services/Excel/classes/class.ilExcelUtils.php";
303 $outputfilename =
ilUtil::getASCIIFilename(preg_replace(
"/\s/",
"_", $this->test_obj->getTitle())) .
"-detailed." . $adapter->getFileExtension();
304 $adapter->setWorksheetTitle($this->lng->txt(
"tst_results"));
305 $additionalFields = $this->test_obj->getEvaluationAdditionalFields();
309 if ($this->test_obj->getAnonymity())
318 if (count($additionalFields))
320 foreach ($additionalFields as $fieldname)
325 $adapter->setCellValue(
$row, $col++, $this->lng->txt(
"tst_stat_result_resultspoints"),
CELL_FORMAT_TITLE);
327 $adapter->setCellValue(
$row, $col++, $this->lng->txt(
"tst_stat_result_resultsmarks"),
CELL_FORMAT_TITLE);
328 if ($this->test_obj->ects_output)
332 $adapter->setCellValue(
$row, $col++, $this->lng->txt(
"tst_stat_result_qworkedthrough"),
CELL_FORMAT_TITLE);
334 $adapter->setCellValue(
$row, $col++, $this->lng->txt(
"tst_stat_result_pworkedthrough"),
CELL_FORMAT_TITLE);
335 $adapter->setCellValue(
$row, $col++, $this->lng->txt(
"tst_stat_result_timeofwork"),
CELL_FORMAT_TITLE);
336 $adapter->setCellValue(
$row, $col++, $this->lng->txt(
"tst_stat_result_atimeofwork"),
CELL_FORMAT_TITLE);
337 $adapter->setCellValue(
$row, $col++, $this->lng->txt(
"tst_stat_result_firstvisit"),
CELL_FORMAT_TITLE);
338 $adapter->setCellValue(
$row, $col++, $this->lng->txt(
"tst_stat_result_lastvisit"),
CELL_FORMAT_TITLE);
339 $adapter->setCellValue(
$row, $col++, $this->lng->txt(
"tst_stat_result_mark_median"),
CELL_FORMAT_TITLE);
340 $adapter->setCellValue(
$row, $col++, $this->lng->txt(
"tst_stat_result_rank_participant"),
CELL_FORMAT_TITLE);
341 $adapter->setCellValue(
$row, $col++, $this->lng->txt(
"tst_stat_result_rank_median"),
CELL_FORMAT_TITLE);
342 $adapter->setCellValue(
$row, $col++, $this->lng->txt(
"tst_stat_result_total_participants"),
CELL_FORMAT_TITLE);
347 include_once
"./Services/Excel/classes/class.ilExcelUtils.php";
350 include_once
"./Modules/Test/classes/class.ilTestEvaluationData.php";
351 include_once
"./Modules/Test/classes/class.ilTestEvaluationPassData.php";
352 include_once
"./Modules/Test/classes/class.ilTestEvaluationUserData.php";
354 unset($this->test_obj->ilias);
355 unset($this->test_obj->lng);
358 $data->calculateStatistics();
359 $data->setFilter($filterby, $filtertext);
362 $firstrowwritten =
false;
363 $ilLog->write(
"Export Test Results");
364 foreach (
$data->getParticipants() as $active_id => $userdata)
366 $data->getCompleteDataForParticipant($active_id);
370 if (
$data->getParticipant($active_id)->getPassed() == FALSE)
378 if (($this->test_obj->isRandomTest() || $this->test_obj->getShuffleQuestions()) && $this->test_obj->getExportSettingsRespectShuffle())
383 if ($this->test_obj->getAnonymity())
385 $adapter->setCellValue(
$row, $col++, $counter);
389 $adapter->setCellValue(
$row, $col++,
$data->getParticipant($active_id)->getName());
390 $adapter->setCellValue(
$row, $col++,
$data->getParticipant($active_id)->getLogin());
393 if (count($additionalFields))
396 foreach ($additionalFields as $fieldname)
398 if (strcmp($fieldname,
"gender") == 0)
400 $adapter->setCellValue(
$row, $col++, $this->lng->txt(
"gender_" . $userfields[$fieldname]));
404 $adapter->setCellValue(
$row, $col++, $userfields[$fieldname]);
408 $adapter->setCellValue(
$row, $col++,
$data->getParticipant($active_id)->getReached());
409 $adapter->setCellValue(
$row, $col++,
$data->getParticipant($active_id)->getMaxpoints());
410 $adapter->setCellValue(
$row, $col++,
$data->getParticipant($active_id)->getMark());
411 if ($this->test_obj->ects_output)
413 $adapter->setCellValue(
$row, $col++,
$data->getParticipant($active_id)->getECTSMark());
415 $adapter->setCellValue(
$row, $col++,
$data->getParticipant($active_id)->getQuestionsWorkedThrough());
416 $adapter->setCellValue(
$row, $col++,
$data->getParticipant($active_id)->getNumberOfQuestions());
417 $adapter->setCellValue(
$row, $col++,
$data->getParticipant($active_id)->getQuestionsWorkedThroughInPercent() / 100.0,
CELL_FORMAT_PERCENT);
418 $time =
$data->getParticipant($active_id)->getTimeOfWork();
419 $time_seconds = $time;
420 $time_hours = floor($time_seconds/3600);
421 $time_seconds -= $time_hours * 3600;
422 $time_minutes = floor($time_seconds/60);
423 $time_seconds -= $time_minutes * 60;
424 $adapter->setCellValue(
$row, $col++, sprintf(
"%02d:%02d:%02d", $time_hours, $time_minutes, $time_seconds));
425 $time =
$data->getParticipant($active_id)->getQuestionsWorkedThrough() ?
$data->getParticipant($active_id)->getTimeOfWork() /
$data->getParticipant($active_id)->getQuestionsWorkedThrough() : 0;
426 $time_seconds = $time;
427 $time_hours = floor($time_seconds/3600);
428 $time_seconds -= $time_hours * 3600;
429 $time_minutes = floor($time_seconds/60);
430 $time_seconds -= $time_minutes * 60;
431 $adapter->setCellValue(
$row, $col++, sprintf(
"%02d:%02d:%02d", $time_hours, $time_minutes, $time_seconds));
432 $fv = getdate(
$data->getParticipant($active_id)->getFirstVisit());
442 $lv = getdate(
$data->getParticipant($active_id)->getLastVisit());
453 $median =
$data->getStatistics()->getStatistics()->median();
454 $pct =
$data->getParticipant($active_id)->getMaxpoints() ? $median /
$data->getParticipant($active_id)->getMaxpoints() * 100.0 : 0;
455 $mark = $this->test_obj->mark_schema->getMatchingMark($pct);
456 $mark_short_name =
"";
457 if (is_object($mark))
459 $mark_short_name = $mark->getShortName();
461 $adapter->setCellValue(
$row, $col++, $mark_short_name);
462 $adapter->setCellValue(
$row, $col++,
$data->getStatistics()->getStatistics()->rank(
$data->getParticipant($active_id)->getReached()));
463 $adapter->setCellValue(
$row, $col++,
$data->getStatistics()->getStatistics()->rank_median());
464 $adapter->setCellValue(
$row, $col++,
$data->getStatistics()->getStatistics()->count());
465 $adapter->setCellValue(
$row, $col++, $median);
468 $adapter->setCellValue(
$row, $col++,
$data->getParticipant($active_id)->getBestPass() + 1);
472 $adapter->setCellValue(
$row, $col++,
$data->getParticipant($active_id)->getLastPass() + 1);
479 $finishdate = $this->test_obj->getPassFinishDate($active_id,
$pass);
485 if (($this->test_obj->isRandomTest() || $this->test_obj->getShuffleQuestions()) && $this->test_obj->getExportSettingsRespectShuffle())
490 $adapter->setCellValue(
$row, $col++,
$pass+1);
491 if (is_object(
$data->getParticipant($active_id)) && is_array(
$data->getParticipant($active_id)->getQuestions(
$pass)))
493 $questions =
$data->getParticipant($active_id)->getQuestions(
$pass);
495 if (!$this->test_obj->getExportSettingsRespectShuffle())
497 usort($questions, array(&$this,
"compareQuestionsByOID"));
499 foreach ($questions as $question)
501 $question_data =
$data->getParticipant($active_id)->getPass(
$pass)->getAnsweredQuestionByQuestionId($question[
"id"]);
502 $adapter->setCellValue(
$row, $col, $question_data[
"reached"]);
503 if (($this->test_obj->isRandomTest() || $this->test_obj->getShuffleQuestions()) && $this->test_obj->getExportSettingsRespectShuffle())
505 $adapter->setCellValue(
$row-1, $col, preg_replace(
"/<.*?>/",
"",
"[" . $question[
"id"] .
"] " .
$data->getQuestionTitle($question[
"id"])),
CELL_FORMAT_TITLE);
509 if (
$pass == 0 && !$firstrowwritten)
511 $adapter->setCellValue(0, $col, preg_replace(
"/<.*?>/",
"",
"[" . $question[
"id"] .
"] " .
$data->getQuestionTitle($question[
"id"])),
CELL_FORMAT_TITLE);
516 $firstrowwritten =
true;
519 if ($col > $maxcol) $maxcol = $col;
523 $data->getParticipant($active_id)->unsetPasses();
524 $data->getParticipant($active_id)->unsetQuestions();
526 for ($colnr = 0; $colnr <= $maxcol; $colnr++)
528 $adapter->setColumnWidth($colnr,
'auto');
530 if ($this->test_obj->getExportSettingsSingleChoiceShort() && !$this->test_obj->isRandomTest() && $this->test_obj->hasSingleChoiceQuestions())
534 $data->calculateStatistics();
535 $data->setFilter($filterby, $filtertext);
537 $ilLog->write(
"Export Single Choice Results");
539 $titles =& $this->test_obj->getQuestionTitlesAndIndexes();
540 $positions = array();
543 foreach ($titles as $id =>
$title)
545 $positions[$id] =
$pos;
549 $usernames = array();
550 $participantcount = count(
$data->getParticipants());
551 $allusersheet =
false;
553 $adapter->addWorksheet($this->lng->txt(
"export_result_overview"));
554 $adapter->setActiveWorksheet($adapter->getWorksheetCount()-1);
559 if (count($additionalFields))
561 foreach ($additionalFields as $fieldname)
563 if (strcmp($fieldname,
"matriculation") == 0)
570 foreach ($titles as $aid =>
$title)
577 foreach (
$data->getParticipants() as $active_id => $userdata)
579 $data->getCompleteDataForParticipant($active_id);
581 if (array_key_exists($username, $usernames))
583 $usernames[$username]++;
584 $username .=
" ($i)";
588 $usernames[$username] = 1;
592 $adapter->setCellValue(
$row, $col++, $username);
593 $adapter->setCellValue(
$row, $col++, $userdata->getLogin());
594 if (count($additionalFields))
597 foreach ($additionalFields as $fieldname)
599 if (strcmp($fieldname,
"matriculation") == 0)
601 if (strlen($userfields[$fieldname]))
603 $adapter->setCellValue(
$row, $col++, $userfields[$fieldname]);
612 $adapter->setCellValue(
$row, $col++, $this->test_obj->getTitle());
613 $pass = $userdata->getScoredPass();
614 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
615 include_once
"./Modules/TestQuestionPool/classes/class.assSingleChoice.php";
616 if (is_object($userdata) && is_array($userdata->getQuestions(
$pass)))
618 foreach ($userdata->getQuestions(
$pass) as $question)
622 $pos = $positions[$question[
"id"]];
623 $selectedanswer =
"x";
624 foreach ($answers as $id => $answer)
626 if (strlen($solution[0][
"value1"]) && $id == $solution[0][
"value1"])
628 $selectedanswer = $answer;
632 $adapter->setCellValue(
$row, $col+
$pos, $selectedanswer);
633 if ($col+
$pos > $maxcol) $maxcol = $col+
$pos;
637 $data->getParticipant($active_id)->unsetPasses();
638 $data->getParticipant($active_id)->unsetQuestions();
640 for ($colnr = 0; $colnr <= $maxcol; $colnr++)
642 $adapter->setColumnWidth($colnr,
'auto');
644 if ($this->test_obj->isSingleChoiceTestWithoutShuffle())
647 $ilLog->write(
"Export Compact Single Choice Results");
649 $data->calculateStatistics();
650 $data->setFilter($filterby, $filtertext);
654 $usernames = array();
655 $allusersheet =
false;
657 $adapter->addWorksheet($this->lng->txt(
"export_result_overview") .
" (2)");
658 $adapter->setActiveWorksheet($adapter->getWorksheetCount()-1);
663 if (count($additionalFields))
665 foreach ($additionalFields as $fieldname)
667 if (strcmp($fieldname,
"matriculation") == 0)
674 foreach ($titles as $aid =>
$title)
681 foreach (
$data->getParticipants() as $active_id => $userdata)
683 $data->getCompleteDataForParticipant($active_id);
685 if (array_key_exists($username, $usernames))
687 $usernames[$username]++;
688 $username .=
" ($i)";
692 $usernames[$username] = 1;
696 $adapter->setCellValue(
$row, $col++, $username);
697 $adapter->setCellValue(
$row, $col++, $userdata->getLogin());
698 if (count($additionalFields))
701 foreach ($additionalFields as $fieldname)
703 if (strcmp($fieldname,
"matriculation") == 0)
705 if (strlen($userfields[$fieldname]))
707 $adapter->setCellValue(
$row, $col++, $userfields[$fieldname]);
716 $adapter->setCellValue(
$row, $col++, $this->test_obj->getTitle());
717 $pass = $userdata->getScoredPass();
718 if (is_object($userdata) && is_array($userdata->getQuestions(
$pass)))
720 foreach ($userdata->getQuestions(
$pass) as $question)
723 $pos = $positions[$question[
"id"]];
724 if (strlen($solution[0][
"value1"]))
726 $selectedanswer = chr(65+$solution[0][
"value1"]);
730 $selectedanswer =
'x';
732 $adapter->setCellValue(
$row, $col+
$pos, $selectedanswer);
733 if ($col+
$pos > $maxcol) $maxcol = $col+
$pos;
737 $data->getParticipant($active_id)->unsetPasses();
738 $data->getParticipant($active_id)->unsetQuestions();
741 for ($colnr = 0; $colnr <= $maxcol; $colnr++)
743 $adapter->setColumnWidth($colnr,
'auto');
748 $ilLog->write(
"Test participant result export");
751 $data->calculateStatistics();
752 $data->setFilter($filterby, $filtertext);
755 $usernames = array();
756 $participantcount = count(
$data->getParticipants());
757 $allusersheet =
false;
760 foreach (
$data->getParticipants() as $active_id => $userdata)
762 $data->getCompleteDataForParticipant($active_id);
764 if (array_key_exists($username, $usernames))
766 $i=$usernames[$username]++;
767 $username .=
" ($i)";
771 $usernames[$username] = 1;
774 if (strcmp($adapter->getFileExtension(),
'xls') == 0)
776 if ($participantcount > 250)
778 if (!$allusersheet || ($pages-1) < floor(
$row / 64000))
780 $adapter->addWorksheet($this->lng->txt(
"export_result_overview") . (($pages > 0) ?
" (".($pages+1).
")" :
""));
781 $adapter->setActiveWorksheet($adapter->getWorksheetCount()-1);
782 $allusersheet =
true;
789 $adapter->addWorksheet($username);
790 $adapter->setActiveWorksheet($adapter->getWorksheetCount()-1);
795 $adapter->addWorksheet($username);
796 $adapter->setActiveWorksheet($adapter->getWorksheetCount()-1);
798 $pass = $userdata->getScoredPass();
800 $adapter->setCellValue(
$row, 0, sprintf($this->lng->txt(
"tst_result_user_name_pass"),
$pass+1, $userdata->getName()),
CELL_FORMAT_BOLD);
802 if (is_object($userdata) && is_array($userdata->getQuestions(
$pass)))
804 foreach ($userdata->getQuestions(
$pass) as $question)
806 $question =& $this->test_obj->_instanciateQuestion($question[
"id"]);
807 if (is_object($question))
809 $row = $question->setExportDetailsXLS($adapter,
$row, $active_id,
$pass);
813 $data->getParticipant($active_id)->unsetPasses();
814 $data->getParticipant($active_id)->unsetQuestions();
820 $adapter->deliver($outputfilename);
825 return $adapter->save($outputfilename);
832 $ilLog->write(
"Export Question Time Usage");
833 $adapter->addWorksheet($this->lng->txt(
'tst_question_time_usage'));
834 $adapter->setActiveWorksheet($adapter->getWorksheetCount()-1);
835 include_once
"./Modules/Test/classes/class.ilTestEvaluationData.php";
837 $titles =& $this->test_obj->getQuestionTitlesAndIndexes();
839 $adapter->setCellValue(0, 0, $this->lng->txt(
'question_title'),
CELL_FORMAT_TITLE);
843 foreach ($times as $question_id => $passes)
845 if ($question_id > 0)
850 foreach ($passes as
$pass => $participants)
852 foreach ($participants as $active_id => $questiontimes)
854 foreach ($questiontimes as $timeInSeconds)
856 $totaltime += $timeInSeconds;
857 $adapter->setCellValue(
$row, $col, $timeInSeconds);
862 $adapter->setCellValue(
$row, 1, $totaltime);
878 function exportToCSV($deliver = TRUE, $filterby =
"", $filtertext =
"", $passedonly = FALSE)
887 if ($this->test_obj->getAnonymity())
889 array_push($datarow, $this->lng->txt(
"counter"));
894 array_push($datarow, $this->lng->txt(
"name"));
896 array_push($datarow, $this->lng->txt(
"login"));
899 $additionalFields = $this->test_obj->getEvaluationAdditionalFields();
900 if (count($additionalFields))
902 foreach ($additionalFields as $fieldname)
904 array_push($datarow, $this->lng->txt($fieldname));
908 array_push($datarow, $this->lng->txt(
"tst_stat_result_resultspoints"));
910 array_push($datarow, $this->lng->txt(
"maximum_points"));
912 array_push($datarow, $this->lng->txt(
"tst_stat_result_resultsmarks"));
914 if ($this->test_obj->ects_output)
916 array_push($datarow, $this->lng->txt(
"ects_grade"));
919 array_push($datarow, $this->lng->txt(
"tst_stat_result_qworkedthrough"));
921 array_push($datarow, $this->lng->txt(
"tst_stat_result_qmax"));
923 array_push($datarow, $this->lng->txt(
"tst_stat_result_pworkedthrough"));
925 array_push($datarow, $this->lng->txt(
"tst_stat_result_timeofwork"));
927 array_push($datarow, $this->lng->txt(
"tst_stat_result_atimeofwork"));
929 array_push($datarow, $this->lng->txt(
"tst_stat_result_firstvisit"));
931 array_push($datarow, $this->lng->txt(
"tst_stat_result_lastvisit"));
934 array_push($datarow, $this->lng->txt(
"tst_stat_result_mark_median"));
936 array_push($datarow, $this->lng->txt(
"tst_stat_result_rank_participant"));
938 array_push($datarow, $this->lng->txt(
"tst_stat_result_rank_median"));
940 array_push($datarow, $this->lng->txt(
"tst_stat_result_total_participants"));
942 array_push($datarow, $this->lng->txt(
"tst_stat_result_median"));
944 array_push($datarow, $this->lng->txt(
"scored_pass"));
947 array_push($datarow, $this->lng->txt(
"pass"));
950 $data =& $this->test_obj->getCompleteEvaluationData(TRUE, $filterby, $filtertext);
951 $headerrow = $datarow;
953 foreach (
$data->getParticipants() as $active_id => $userdata)
955 $datarow = $headerrow;
959 if (
$data->getParticipant($active_id)->getPassed() == FALSE)
967 if ($this->test_obj->getAnonymity())
969 array_push($datarow2, $counter);
973 array_push($datarow2,
$data->getParticipant($active_id)->getName());
974 array_push($datarow2,
$data->getParticipant($active_id)->getLogin());
976 if (count($additionalFields))
979 foreach ($additionalFields as $fieldname)
981 if (strcmp($fieldname,
"gender") == 0)
983 array_push($datarow2, $this->lng->txt(
"gender_" . $userfields[$fieldname]));
987 array_push($datarow2, $userfields[$fieldname]);
991 array_push($datarow2,
$data->getParticipant($active_id)->getReached());
992 array_push($datarow2,
$data->getParticipant($active_id)->getMaxpoints());
993 array_push($datarow2,
$data->getParticipant($active_id)->getMark());
994 if ($this->test_obj->ects_output)
996 array_push($datarow2,
$data->getParticipant($active_id)->getECTSMark());
998 array_push($datarow2,
$data->getParticipant($active_id)->getQuestionsWorkedThrough());
999 array_push($datarow2,
$data->getParticipant($active_id)->getNumberOfQuestions());
1000 array_push($datarow2,
$data->getParticipant($active_id)->getQuestionsWorkedThroughInPercent() / 100.0);
1001 $time =
$data->getParticipant($active_id)->getTimeOfWork();
1002 $time_seconds = $time;
1003 $time_hours = floor($time_seconds/3600);
1004 $time_seconds -= $time_hours * 3600;
1005 $time_minutes = floor($time_seconds/60);
1006 $time_seconds -= $time_minutes * 60;
1007 array_push($datarow2, sprintf(
"%02d:%02d:%02d", $time_hours, $time_minutes, $time_seconds));
1008 $time =
$data->getParticipant($active_id)->getQuestionsWorkedThrough() ?
$data->getParticipant($active_id)->getTimeOfWork() /
$data->getParticipant($active_id)->getQuestionsWorkedThrough() : 0;
1009 $time_seconds = $time;
1010 $time_hours = floor($time_seconds/3600);
1011 $time_seconds -= $time_hours * 3600;
1012 $time_minutes = floor($time_seconds/60);
1013 $time_seconds -= $time_minutes * 60;
1014 array_push($datarow2, sprintf(
"%02d:%02d:%02d", $time_hours, $time_minutes, $time_seconds));
1015 $fv = getdate(
$data->getParticipant($active_id)->getFirstVisit());
1024 array_push($datarow2, $firstvisit);
1025 $lv = getdate(
$data->getParticipant($active_id)->getLastVisit());
1034 array_push($datarow2, $lastvisit);
1036 $median =
$data->getStatistics()->getStatistics()->median();
1037 $pct =
$data->getParticipant($active_id)->getMaxpoints() ? $median /
$data->getParticipant($active_id)->getMaxpoints() * 100.0 : 0;
1038 $mark = $this->test_obj->mark_schema->getMatchingMark($pct);
1039 $mark_short_name =
"";
1040 if (is_object($mark))
1042 $mark_short_name = $mark->getShortName();
1044 array_push($datarow2, $mark_short_name);
1045 array_push($datarow2,
$data->getStatistics()->getStatistics()->rank(
$data->getParticipant($active_id)->getReached()));
1046 array_push($datarow2,
$data->getStatistics()->getStatistics()->rank_median());
1047 array_push($datarow2,
$data->getStatistics()->getStatistics()->count());
1048 array_push($datarow2, $median);
1051 array_push($datarow2,
$data->getParticipant($active_id)->getBestPass() + 1);
1055 array_push($datarow2,
$data->getParticipant($active_id)->getLastPass() + 1);
1060 $finishdate = $this->test_obj->getPassFinishDate($active_id,
$pass);
1061 if ($finishdate > 0)
1065 for ($i = 1; $i < $col-1; $i++)
1067 array_push($datarow2,
"");
1068 array_push($datarow,
"");
1070 array_push($datarow,
"");
1072 array_push($datarow2,
$pass+1);
1073 if (is_object(
$data->getParticipant($active_id)) && is_array(
$data->getParticipant($active_id)->getQuestions(
$pass)))
1075 $questions =
$data->getParticipant($active_id)->getQuestions(
$pass);
1076 if (!$this->test_obj->getExportSettingsRespectShuffle())
1078 usort($questions, array(&$this,
"compareQuestionsByOID"));
1080 foreach ($questions as $question)
1082 $question_data =
$data->getParticipant($active_id)->getPass(
$pass)->getAnsweredQuestionByQuestionId($question[
"id"]);
1083 array_push($datarow2, $question_data[
"reached"]);
1084 array_push($datarow, preg_replace(
"/<.*?>/",
"",
$data->getQuestionTitle($question[
"id"])));
1087 if ((($this->test_obj->isRandomTest()
1088 || $this->test_obj->getShuffleQuestions())
1089 && $this->test_obj->getExportSettingsRespectShuffle())
1090 || ($counter == 1 &&
$pass == 0))
1092 array_push($rows, $datarow);
1095 array_push($rows, $datarow2);
1096 $datarow2 = array();
1104 foreach ($rows as $evalrow)
1106 $csvrow =& $this->test_obj->processCSVRow($evalrow, TRUE,
$separator);
1136 function exportToImsCSV($deliver = TRUE, $filterby =
"", $filtertext =
"", $passedonly = FALSE)
1139 include_once
"./Services/Excel/classes/class.ilExcelUtils.php";
1140 $data =& $this->test_obj->getCompleteEvaluationData(TRUE, $filterby, $filtertext);
1141 $titles =& $this->test_obj->getQuestionTitlesAndIndexes();
1142 $oids =& $this->test_obj->getQuestions();
1145 $positions = array();
1148 foreach ($oids as $aid => $oid)
1150 $positions[$oid] =
$pos;
1154 $usernames = array();
1155 $participantcount = count(
$data->getParticipants());
1158 $a_csv_header_row=array();
1166 foreach ($titles as $aid =>
$title)
1168 $question=$this->test_obj->_instanciateQuestion($aid);
1169 $imsm_id=$question->getExternalID();
1175 $a_csv_data_rows=array();
1176 $a_csv_data_rows[
$row++]=$a_csv_header_row;
1178 foreach (
$data->getParticipants() as $active_id => $userdata)
1189 $a_csv_row[$col++]=
"lastname_".$anon_id;
1190 $a_csv_row[$col++]=
"firstname_".$anon_id;
1191 $a_csv_row[$col++]=
"1111".$anon_id;
1192 $a_csv_row[$col++]=
"id_".$anon_id;
1196 $pass = $userdata->getScoredPass();
1197 if (is_object($userdata) && is_array($userdata->getQuestions(
$pass)))
1199 foreach ($userdata->getQuestions(
$pass) as $question)
1201 $objQuestion =& $this->test_obj->_instanciateQuestion($question[
"id"]);
1202 $is_sc=strcmp($objQuestion->getQuestionType(),
'assSingleChoice')==0;
1203 $is_mc=strcmp($objQuestion->getQuestionType(),
'assMultipleChoice')==0;
1204 if (is_object($objQuestion) && ($is_sc || $is_mc))
1206 $solutions = $objQuestion->getSolutionValues($active_id,
$pass);
1208 for ($i=0;$i<count($solutions);$i++){
1209 $selectedanswer = chr(65+$solutions[$i][
"value1"]);
1210 array_push($answers,$selectedanswer);
1213 $pos = $positions[$question[
"id"]];
1214 $a_csv_row[$col+
$pos]=implode($answers,
",");
1218 $lv = getdate(
$data->getParticipant($active_id)->getLastVisit());
1219 $tstamp=mktime($lv[
'hours'],$lv[
'minutes'],$lv[
'seconds'],$lv[
'mon'],$lv[
'mday'],$lv[
'year']);
1220 $lastvisit = date(
"d.m.Y G:i:s",$tstamp);
1221 $a_csv_row[count($a_csv_row)]=$lastvisit;
1223 $a_csv_data_rows[
$row]=$a_csv_row;
1230 foreach ($a_csv_data_rows as $evalrow)
1232 $csvrow =& $this->test_obj->processCSVRow($evalrow, FALSE,
$separator);
1254 $ilBench->start(
"TestExport",
"buildExportFile");
1256 include_once(
"./Services/Xml/classes/class.ilXmlWriter.php");
1260 $this->xml->
xmlSetDtdDef(
"<!DOCTYPE Test SYSTEM \"http://www.ilias.uni-koeln.de/download/dtd/ilias_co.dtd\">");
1263 $this->xml->xmlSetGenCmt(
"Export of ILIAS Test ".
1264 $this->test_obj->getId().
" of installation ".$this->inst.
".");
1267 $this->xml->xmlHeader();
1270 $this->test_obj->createExportDirectory();
1271 include_once
"./Services/Utilities/classes/class.ilUtil.php";
1276 $expDir = $this->test_obj->getExportDirectory();
1277 include_once
"./Services/Logging/classes/class.ilLog.php";
1278 $expLog =
new ilLog($expDir,
"export.log");
1280 $expLog->setLogFormat(
"");
1281 $expLog->write(date(
"[y-m-d H:i:s] ").
"Start Export");
1284 include_once
"./Modules/Test/classes/class.ilTestExportQTI.php";
1286 $qti_file = fopen($this->export_dir.
"/".$this->subdir.
"/".$this->qti_filename,
"w");
1287 fwrite($qti_file, $exportObject->toXML());
1291 $ilBench->start(
"TestExport",
"buildExportFile_getXML");
1292 $this->test_obj->exportPagesXML($this->xml, $this->inst_id,
1293 $this->export_dir.
"/".$this->subdir, $expLog);
1294 $ilBench->stop(
"TestExport",
"buildExportFile_getXML");
1304 $ilBench->start(
"TestExport",
"buildExportFile_dumpToFile");
1305 $this->xml->xmlDumpFile($this->export_dir.
"/".$this->subdir.
"/".$this->filename
1307 $ilBench->stop(
"TestExport",
"buildExportFile_dumpToFile");
1310 include_once
"./Modules/Test/classes/class.ilTestResultsToXML.php";
1311 $resultwriter =
new ilTestResultsToXML($this->test_obj->getTestId(), $this->test_obj->getAnonymity());
1312 $ilBench->start(
"TestExport",
"buildExportFile_results");
1313 $resultwriter->
xmlDumpFile($this->export_dir.
"/".$this->subdir.
"/".$this->resultsfile,
false);
1314 $ilBench->stop(
"TestExport",
"buildExportFile_results");
1317 $ilBench->start(
"QuestionpoolExport",
"buildExportFile_saveAdditionalMobs");
1319 $ilBench->stop(
"QuestionpoolExport",
"buildExportFile_saveAdditionalMobs");
1322 $ilBench->start(
"TestExport",
"buildExportFile_zipFile");
1324 $this->export_dir.
"/".$this->subdir.
".zip");
1325 $ilBench->stop(
"TestExport",
"buildExportFile_zipFile");
1328 $this->xml->_XmlWriter;
1330 $expLog->write(date(
"[y-m-d H:i:s] ").
"Finished Export");
1331 $ilBench->stop(
"TestExport",
"buildExportFile");
1333 return $this->export_dir.
"/".$this->subdir.
".zip";
1338 include_once(
"./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1341 foreach (
$mobs as $mob)
1346 $mob_obj->exportFiles($a_export_dir);
1350 foreach ($this->test_obj->questions as $question_id)
1353 foreach (
$mobs as $mob)
1358 $mob_obj->exportFiles($a_export_dir);
1365 public function singleChoiceExport($adapter = null, $deliver =
true, $filterby =
"", $filtertext =
"", $passedonly = FALSE)
1368 include_once
"./Services/Excel/classes/class.ilExcelUtils.php";
1369 if ($adapter == null)
1372 $adapter->setWorksheetTitle($this->lng->txt(
"export_result_overview"));
1376 $adapter->addWorksheet($this->lng->txt(
"export_result_overview"));
1377 $adapter->setActiveWorksheet($adapter->getWorksheetCount()-1);
1379 include_once
"./Modules/Test/classes/class.ilTestEvaluationData.php";
1381 $data->calculateStatistics();
1382 $data->setFilter($filterby, $filtertext);
1384 $ilLog->write(
"Export Single Choice Results");
1386 $titles =& $this->test_obj->getQuestionTitlesAndIndexes();
1387 $positions = array();
1390 foreach ($titles as $id =>
$title)
1392 $positions[$id] =
$pos;
1396 $usernames = array();
1397 $participantcount = count(
$data->getParticipants());
1398 $allusersheet =
false;
1404 if (count($additionalFields))
1406 foreach ($additionalFields as $fieldname)
1408 if (strcmp($fieldname,
"matriculation") == 0)
1415 foreach ($titles as $aid =>
$title)
1423 $rangeto = $participantcount;
1425 foreach (
$data->getParticipants() as $active_id => $userdata)
1427 if ($rangecounter >= $rangefrom && $rangecounter <= $rangeto)
1429 $data->getCompleteDataForParticipant($active_id);
1431 if (array_key_exists($username, $usernames))
1433 $usernames[$username]++;
1434 $username .=
" ($i)";
1438 $usernames[$username] = 1;
1442 $adapter->setCellValue(
$row, $col++, $username);
1443 $adapter->setCellValue(
$row, $col++, $userdata->getLogin());
1444 if (count($additionalFields))
1447 foreach ($additionalFields as $fieldname)
1449 if (strcmp($fieldname,
"matriculation") == 0)
1451 if (strlen($userfields[$fieldname]))
1453 $adapter->setCellValue(
$row, $col++, $userfields[$fieldname]);
1462 $adapter->setCellValue(
$row, $col++, $this->test_obj->getTitle());
1463 $pass = $userdata->getScoredPass();
1464 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
1465 include_once
"./Modules/TestQuestionPool/classes/class.assSingleChoice.php";
1466 if (is_object($userdata) && is_array($userdata->getQuestions(
$pass)))
1468 foreach ($userdata->getQuestions(
$pass) as $question)
1472 $pos = $positions[$question[
"id"]];
1473 $selectedanswer =
"x";
1474 foreach ($answers as $id => $answer)
1476 if (strlen($solution[0][
"value1"]) && $id == $solution[0][
"value1"])
1478 $selectedanswer = $answer;
1482 $adapter->setCellValue(
$row, $col+
$pos, $selectedanswer);
1483 if ($col+
$pos > $maxcol) $maxcol = $col+
$pos;
1487 $data->getParticipant($active_id)->unsetPasses();
1488 $data->getParticipant($active_id)->unsetQuestions();
1493 for ($colnr = 0; $colnr <= $maxcol; $colnr++)
1495 $adapter->setColumnWidth($colnr,
'auto');
1497 if ($this->test_obj->isSingleChoiceTestWithoutShuffle())
1499 $ilLog->write(
"Export Compact Single Choice Results");
1504 $usernames = array();
1505 $allusersheet =
false;
1507 $adapter->addWorksheet($this->lng->txt(
"export_result_overview") .
" (2)");
1508 $adapter->setActiveWorksheet($adapter->getWorksheetCount()-1);
1513 if (count($additionalFields))
1515 foreach ($additionalFields as $fieldname)
1517 if (strcmp($fieldname,
"matriculation") == 0)
1524 foreach ($titles as $aid =>
$title)
1532 foreach (
$data->getParticipants() as $active_id => $userdata)
1534 if ($rangecounter >= $rangefrom && $rangecounter <= $rangeto)
1536 $data->getCompleteDataForParticipant($active_id);
1538 if (array_key_exists($username, $usernames))
1540 $usernames[$username]++;
1541 $username .=
" ($i)";
1545 $usernames[$username] = 1;
1549 $adapter->setCellValue(
$row, $col++, $username);
1550 $adapter->setCellValue(
$row, $col++, $userdata->getLogin());
1551 if (count($additionalFields))
1554 foreach ($additionalFields as $fieldname)
1556 if (strcmp($fieldname,
"matriculation") == 0)
1558 if (strlen($userfields[$fieldname]))
1560 $adapter->setCellValue(
$row, $col++, $userfields[$fieldname]);
1569 $adapter->setCellValue(
$row, $col++, $this->test_obj->getTitle());
1570 $pass = $userdata->getScoredPass();
1571 if (is_object($userdata) && is_array($userdata->getQuestions(
$pass)))
1573 foreach ($userdata->getQuestions(
$pass) as $question)
1576 $pos = $positions[$question[
"id"]];
1577 if (strlen($solution[0][
"value1"]))
1579 $selectedanswer = chr(65+$solution[0][
"value1"]);
1583 $selectedanswer =
'x';
1585 $adapter->setCellValue(
$row, $col+
$pos, $selectedanswer);
1586 if ($col+
$pos > $maxcol) $maxcol = $col+
$pos;
1590 $data->getParticipant($active_id)->unsetPasses();
1591 $data->getParticipant($active_id)->unsetQuestions();
1596 for ($colnr = 0; $colnr <= $maxcol; $colnr++)
1598 $adapter->setColumnWidth($colnr,
'auto');
1603 $outputfilename =
ilUtil::getASCIIFilename(preg_replace(
"/\s/",
"_", $this->test_obj->getTitle())) .
"-singlechoice." . $adapter->getFileExtension();
1604 $adapter->deliver($outputfilename);