ILIAS  release_7 Revision v7.30-3-g800a261c036
ilTestExport Class Reference

Export class for tests. More...

+ Inheritance diagram for ilTestExport:
+ Collaboration diagram for ilTestExport:

Public Member Functions

 __construct (&$a_test_obj, $a_mode="xml")
 Constructor. More...
 
 isResultExportingEnabledForTestExport ()
 
 setResultExportingEnabledForTestExport ($resultExprtingEnabledForTestExport)
 
 getForcedAccessFilteredParticipantList ()
 
 setForcedAccessFilteredParticipantList (ilTestParticipantList $forcedAccessFilteredParticipantList)
 
 getAccessFilteredParticipantList ()
 
 getExtension ()
 
 getInstId ()
 
 buildExportFile ()
 build export file (complete zip file) More...
 
 buildExportResultFile ()
 build xml export file More...
 
 exportToExcel ($deliver=true, $filterby="", $filtertext="", $passedonly=false)
 Exports the evaluation data to the Microsoft Excel file format. More...
 
 exportToCSV ($deliver=true, $filterby="", $filtertext="", $passedonly=false)
 Exports the evaluation data to the CSV file format. More...
 
 buildExportFileXML ()
 build xml export file More...
 
 exportXHTMLMediaObjects ($a_export_dir)
 

Data Fields

 $err
 
 $db
 
 $ilias
 
 $test_obj
 
 $inst_id
 
 $mode
 

Protected Member Functions

 aggregatedResultsToExcel ($deliver=true)
 Exports the aggregated results to the Microsoft Excel file format. More...
 
 aggregatedResultsToCSV ($deliver=true)
 Exports the aggregated results to CSV. More...
 
 orderQuestions (array $questions)
 
 initXmlExport ()
 
 getQuestionIds ()
 
 populateQuestionSetConfigXml (ilXmlWriter $xmlWriter)
 
 getQtiXml ()
 
 getQuestionsQtiXml ()
 
 getQuestionQtiXml ($questionId)
 
 populateQuestionSkillAssignmentsXml (ilXmlWriter $a_xml_writer, ilAssQuestionSkillAssignmentList $assignmentList, $questions)
 
 populateSkillLevelThresholdsXml (ilXmlWriter $a_xml_writer, ilAssQuestionSkillAssignmentList $assignmentList)
 
 buildQuestionSkillAssignmentList ()
 

Protected Attributes

 $resultExportingEnabledForTestExport = false
 
 $forcedAccessFilteredParticipantList = null
 

Private Attributes

 $lng
 
 $resultsfile
 

Detailed Description

Export class for tests.

Author
Helmut Schottmüller helmu.nosp@m.t.sc.nosp@m.hottm.nosp@m.uell.nosp@m.er@ma.nosp@m.c.co.nosp@m.m
Maximilian Becker mbeck.nosp@m.er@d.nosp@m.ataba.nosp@m.y.de
Björn Heyser bheys.nosp@m.er@d.nosp@m.ataba.nosp@m.y.de
Version
$Id$

Definition at line 17 of file class.ilTestExport.php.

Constructor & Destructor Documentation

◆ __construct()

ilTestExport::__construct ( $a_test_obj,
  $a_mode = "xml" 
)

Constructor.

Definition at line 49 of file class.ilTestExport.php.

50 {
51 global $DIC;
52 $ilErr = $DIC['ilErr'];
53 $ilDB = $DIC['ilDB'];
54 $ilias = $DIC['ilias'];
55 $lng = $DIC['lng'];
56
57 $this->test_obj = &$a_test_obj;
58
59 $this->err = &$ilErr;
60 $this->ilias = &$ilias;
61 $this->db = &$ilDB;
62 $this->mode = $a_mode;
63 $this->lng = &$lng;
64
65 $this->inst_id = IL_INST_ID;
66
67 $date = time();
68 $this->export_dir = $this->test_obj->getExportDirectory();
69
70 switch ($this->mode) {
71 case "results":
72 $this->subdir = $date . "__" . $this->inst_id . "__" .
73 "tst__results_" . $this->test_obj->getId();
74 break;
75 case "aggregated":
76 $this->subdir = $date . "__" . $this->inst_id . "__" .
77 "test__aggregated__results_" . $this->test_obj->getId();
78 break;
79 default:
80 $this->subdir = $date . "__" . $this->inst_id . "__" .
81 "tst" . "_" . $this->test_obj->getId();
82 $this->filename = $this->subdir . ".xml";
83 $this->resultsfile = $date . "__" . $this->inst_id . "__" .
84 "results" . "_" . $this->test_obj->getId() . ".xml";
85 $this->qti_filename = $date . "__" . $this->inst_id . "__" .
86 "qti" . "_" . $this->test_obj->getId() . ".xml";
87 break;
88 }
89 $this->filename = $this->subdir . "." . $this->getExtension();
90 }
const IL_INST_ID
Definition: constants.php:38
global $DIC
Definition: goto.php:24
redirection script todo: (a better solution should control the processing via a xml file)
$ilErr
Definition: raiseError.php:18
global $ilDB

References $DIC, $ilDB, $ilErr, $ilias, $lng, getExtension(), and IL_INST_ID.

+ Here is the call graph for this function:

Member Function Documentation

◆ aggregatedResultsToCSV()

ilTestExport::aggregatedResultsToCSV (   $deliver = true)
protected

Exports the aggregated results to CSV.

Parameters
boolean$deliverTRUE to directly deliver the file, FALSE to return the data

Definition at line 275 of file class.ilTestExport.php.

276 {
277 $data = $this->test_obj->getAggregatedResultsData();
278 $rows = array();
279 array_push($rows, array(
280 $this->lng->txt("result"),
281 $this->lng->txt("value")
282 ));
283 foreach ($data["overview"] as $key => $value) {
284 array_push($rows, array(
285 $key,
286 $value
287 ));
288 }
289 array_push($rows, array(
290 $this->lng->txt("question_id"),
291 $this->lng->txt("question_title"),
292 $this->lng->txt("average_reached_points"),
293 $this->lng->txt("points"),
294 $this->lng->txt("percentage"),
295 $this->lng->txt("number_of_answers")
296 ));
297 foreach ($data["questions"] as $key => $value) {
298 array_push($rows, array(
299 $key,
300 $value[0],
301 $value[4],
302 $value[5],
303 $value[6],
304 $value[3]
305 ));
306 }
307 $csv = "";
308 $separator = ";";
309 foreach ($rows as $evalrow) {
310 $csvrow = &$this->test_obj->processCSVRow($evalrow, true, $separator);
311 $csv .= join($separator, $csvrow) . "\n";
312 }
313 if ($deliver) {
314 ilUtil::deliverData($csv, ilUtil::getASCIIFilename($this->test_obj->getTitle() . "_aggregated.csv"));
315 exit;
316 } else {
317 return $csv;
318 }
319 }
static deliverData($a_data, $a_filename, $mime="application/octet-stream", $charset="")
deliver data for download via browser.
static getASCIIFilename($a_filename)
convert utf8 to ascii filename
exit
Definition: login.php:29
$data
Definition: storeScorm.php:23
$rows
Definition: xhr_table.php:10

References $data, $rows, ilUtil\deliverData(), exit, and ilUtil\getASCIIFilename().

Referenced by exportToCSV().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ aggregatedResultsToExcel()

ilTestExport::aggregatedResultsToExcel (   $deliver = true)
protected

Exports the aggregated results to the Microsoft Excel file format.

Parameters
boolean$deliverTRUE to directly deliver the file, FALSE to return the binary data
Returns
string

Definition at line 212 of file class.ilTestExport.php.

213 {
214 $data = $this->test_obj->getAggregatedResultsData();
215
216 require_once 'Modules/TestQuestionPool/classes/class.ilAssExcelFormatHelper.php';
217 $worksheet = new ilAssExcelFormatHelper();
218 $worksheet->addSheet($this->lng->txt('tst_results_aggregated'));
219
220 $row = 1;
221 $col = 0;
222 $worksheet->setCell($row, $col++, $this->lng->txt('result'));
223 $worksheet->setCell($row, $col++, $this->lng->txt('value'));
224
225 $worksheet->setBold('A' . $row . ':' . $worksheet->getColumnCoord($col - 1) . $row);
226
227 $row++;
228 foreach ($data['overview'] as $key => $value) {
229 $col = 0;
230 $worksheet->setCell($row, $col++, $key);
231 $worksheet->setCell($row, $col++, $value);
232 $row++;
233 }
234
235 $row++;
236 $col = 0;
237
238 $worksheet->setCell($row, $col++, $this->lng->txt('question_id'));
239 $worksheet->setCell($row, $col++, $this->lng->txt('question_title'));
240 $worksheet->setCell($row, $col++, $this->lng->txt('average_reached_points'));
241 $worksheet->setCell($row, $col++, $this->lng->txt('points'));
242 $worksheet->setCell($row, $col++, $this->lng->txt('percentage'));
243 $worksheet->setCell($row, $col++, $this->lng->txt('number_of_answers'));
244
245 $worksheet->setBold('A' . $row . ':' . $worksheet->getColumnCoord($col - 1) . $row);
246
247 $row++;
248 foreach ($data['questions'] as $key => $value) {
249 $col = 0;
250 $worksheet->setCell($row, $col++, $key);
251 $worksheet->setCell($row, $col++, $value[0]);
252 $worksheet->setCell($row, $col++, $value[4]);
253 $worksheet->setCell($row, $col++, $value[5]);
254 $worksheet->setCell($row, $col++, $value[6]);
255 $worksheet->setCell($row, $col++, $value[3]);
256 $row++;
257 }
258
259 if ($deliver) {
260 $worksheet->sendToClient(
261 ilUtil::getASCIIFilename(preg_replace("/\s/", '_', $this->test_obj->getTitle() . '_aggregated')) . '.xlsx'
262 );
263 } else {
264 $excelfile = ilUtil::ilTempnam();
265 $worksheet->writeToFile($excelfile);
266 return $excelfile . '.xlsx';
267 }
268 }
Class ilAssExcelFormatHelper.
static ilTempnam($a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.

References $data, ilUtil\getASCIIFilename(), and ilUtil\ilTempnam().

Referenced by exportToExcel().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildExportFile()

ilTestExport::buildExportFile ( )

build export file (complete zip file)

@access public

Returns

Definition at line 158 of file class.ilTestExport.php.

159 {
160 switch ($this->mode) {
161 case "results":
162 return $this->buildExportResultFile();
163 break;
164 default:
165 return $this->buildExportFileXML();
166 break;
167 }
168 }
buildExportResultFile()
build xml export file
buildExportFileXML()
build xml export file

References buildExportFileXML(), and buildExportResultFile().

+ Here is the call graph for this function:

◆ buildExportFileXML()

ilTestExport::buildExportFileXML ( )

build xml export file

Definition at line 992 of file class.ilTestExport.php.

993 {
994 global $DIC;
995 $ilBench = $DIC['ilBench'];
996
997 $ilBench->start("TestExport", "buildExportFile");
998
999 $this->initXmlExport();
1000
1001 include_once("./Services/Xml/classes/class.ilXmlWriter.php");
1002 $this->xml = new ilXmlWriter;
1003
1004 // set dtd definition
1005 $this->xml->xmlSetDtdDef("<!DOCTYPE Test SYSTEM \"http://www.ilias.uni-koeln.de/download/dtd/ilias_co.dtd\">");
1006
1007 // set generated comment
1008 $this->xml->xmlSetGenCmt("Export of ILIAS Test " .
1009 $this->test_obj->getId() . " of installation " . $this->inst . ".");
1010
1011 // set xml header
1012 $this->xml->xmlHeader();
1013
1014 $this->xml->xmlStartTag("ContentObject", array('Type' => 'Test'));
1015
1016 // create directories
1017 $this->test_obj->createExportDirectory();
1018 include_once "./Services/Utilities/classes/class.ilUtil.php";
1019 ilUtil::makeDir($this->export_dir . "/" . $this->subdir);
1020 ilUtil::makeDir($this->export_dir . "/" . $this->subdir . "/objects");
1021
1022 // get Log File
1023 $expDir = $this->test_obj->getExportDirectory();
1024 include_once "./Services/Logging/classes/class.ilLog.php";
1025 $expLog = new ilLog($expDir, "export.log");
1026 $expLog->delete();
1027 $expLog->setLogFormat("");
1028 $expLog->write(date("[y-m-d H:i:s] ") . "Start Export");
1029
1030 // write qti file
1031 $qti_file = fopen($this->export_dir . "/" . $this->subdir . "/" . $this->qti_filename, "w");
1032 fwrite($qti_file, $this->getQtiXml());
1033 fclose($qti_file);
1034
1035 // get xml content
1036 $ilBench->start("TestExport", "buildExportFile_getXML");
1037 $this->test_obj->exportPagesXML(
1038 $this->xml,
1039 $this->inst_id,
1040 $this->export_dir . "/" . $this->subdir,
1041 $expLog
1042 );
1043 $ilBench->stop("TestExport", "buildExportFile_getXML");
1044
1045 $this->populateQuestionSetConfigXml($this->xml);
1046
1047 $assignmentList = $this->buildQuestionSkillAssignmentList();
1048 $this->populateQuestionSkillAssignmentsXml($this->xml, $assignmentList, $this->getQuestionIds());
1049 $this->populateSkillLevelThresholdsXml($this->xml, $assignmentList);
1050
1051 $this->xml->xmlEndTag("ContentObject");
1052
1053 // dump xml document to screen (only for debugging reasons)
1054 /*
1055 echo "<PRE>";
1056 echo htmlentities($this->xml->xmlDumpMem($format));
1057 echo "</PRE>";
1058 */
1059
1060 // dump xml document to file
1061 $ilBench->start("TestExport", "buildExportFile_dumpToFile");
1062 $this->xml->xmlDumpFile($this->export_dir . "/" . $this->subdir . "/" . $this->filename, false);
1063 $ilBench->stop("TestExport", "buildExportFile_dumpToFile");
1064
1065 if ($this->isResultExportingEnabledForTestExport() && @file_exists("./Modules/Test/classes/class.ilTestResultsToXML.php")) {
1066 // dump results xml document to file
1067 include_once "./Modules/Test/classes/class.ilTestResultsToXML.php";
1068 $resultwriter = new ilTestResultsToXML($this->test_obj->getTestId(), $this->test_obj->getAnonymity());
1069 $resultwriter->setIncludeRandomTestQuestionsEnabled($this->test_obj->isRandomTest());
1070 $ilBench->start("TestExport", "buildExportFile_results");
1071 $resultwriter->xmlDumpFile($this->export_dir . "/" . $this->subdir . "/" . $this->resultsfile, false);
1072 $ilBench->stop("TestExport", "buildExportFile_results");
1073 }
1074
1075 // add media objects which were added with tiny mce
1076 $ilBench->start("QuestionpoolExport", "buildExportFile_saveAdditionalMobs");
1077 $this->exportXHTMLMediaObjects($this->export_dir . "/" . $this->subdir);
1078 $ilBench->stop("QuestionpoolExport", "buildExportFile_saveAdditionalMobs");
1079
1080 // zip the file
1081 $ilBench->start("TestExport", "buildExportFile_zipFile");
1083 $this->export_dir . "/" . $this->subdir,
1084 $this->export_dir . "/" . $this->subdir . ".zip"
1085 );
1086 $ilBench->stop("TestExport", "buildExportFile_zipFile");
1087
1088 // destroy writer object
1089 $this->xml = null;
1090
1091 $expLog->write(date("[y-m-d H:i:s] ") . "Finished Export");
1092 $ilBench->stop("TestExport", "buildExportFile");
1093
1094 return $this->export_dir . "/" . $this->subdir . ".zip";
1095 }
logging
Definition: class.ilLog.php:19
populateQuestionSetConfigXml(ilXmlWriter $xmlWriter)
exportXHTMLMediaObjects($a_export_dir)
isResultExportingEnabledForTestExport()
populateSkillLevelThresholdsXml(ilXmlWriter $a_xml_writer, ilAssQuestionSkillAssignmentList $assignmentList)
populateQuestionSkillAssignmentsXml(ilXmlWriter $a_xml_writer, ilAssQuestionSkillAssignmentList $assignmentList, $questions)
Test results to XML class.
static zip($a_dir, $a_file, $compress_content=false)
zips given directory/file into given zip.file
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
XML writer class.
xmlSetDtdDef($dtdDef)
Sets dtd definition.
global $ilBench
Definition: ilias.php:21

References $DIC, $ilBench, buildQuestionSkillAssignmentList(), exportXHTMLMediaObjects(), getQtiXml(), getQuestionIds(), initXmlExport(), isResultExportingEnabledForTestExport(), ilUtil\makeDir(), populateQuestionSetConfigXml(), populateQuestionSkillAssignmentsXml(), populateSkillLevelThresholdsXml(), ilXmlWriter\xmlSetDtdDef(), and ilUtil\zip().

Referenced by buildExportFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildExportResultFile()

ilTestExport::buildExportResultFile ( )

build xml export file

Definition at line 173 of file class.ilTestExport.php.

174 {
175 global $DIC;
176 $ilBench = $DIC['ilBench'];
177 $log = $DIC['log'];
178
179 //get Log File
180 $expDir = $this->test_obj->getExportDirectory();
181
182 // make_directories
183 $this->test_obj->createExportDirectory();
184 include_once "./Services/Utilities/classes/class.ilUtil.php";
185 ilUtil::makeDir($this->export_dir);
186
187 include_once './Services/Logging/classes/class.ilLog.php';
188 $expLog = new ilLog($expDir, "export.log");
189 $expLog->delete();
190 $expLog->setLogFormat("");
191 $expLog->write(date("[y-m-d H:i:s] ") . "Start Export Of Results");
192
193 $data = $this->exportToCSV($deliver = false);
194 $file = fopen($this->export_dir . "/" . $this->filename, "w");
195 fwrite($file, $data);
196 fclose($file);
197
198 $excelfile = $this->exportToExcel($deliver = false);
199 @copy($excelfile, $this->export_dir . "/" . str_replace($this->getExtension(), "xlsx", $this->filename));
200 @unlink($excelfile);
201 // end
202 $expLog->write(date("[y-m-d H:i:s] ") . "Finished Export of Results");
203
204 return $this->export_dir . "/" . $this->filename;
205 }
$filename
Definition: buildRTE.php:89
exportToCSV($deliver=true, $filterby="", $filtertext="", $passedonly=false)
Exports the evaluation data to the CSV file format.
exportToExcel($deliver=true, $filterby="", $filtertext="", $passedonly=false)
Exports the evaluation data to the Microsoft Excel file format.
$log
Definition: result.php:15

References $data, $DIC, $filename, $ilBench, $log, exportToCSV(), exportToExcel(), getExtension(), and ilUtil\makeDir().

Referenced by buildExportFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildQuestionSkillAssignmentList()

ilTestExport::buildQuestionSkillAssignmentList ( )
protected
Returns
ilAssQuestionSkillAssignmentList

Definition at line 1187 of file class.ilTestExport.php.

1188 {
1189 global $DIC;
1190 $ilDB = $DIC['ilDB'];
1191
1192 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionSkillAssignmentList.php';
1193 $assignmentList = new ilAssQuestionSkillAssignmentList($ilDB);
1194 $assignmentList->setParentObjId($this->test_obj->getId());
1195 $assignmentList->loadFromDb();
1196 $assignmentList->loadAdditionalSkillData();
1197
1198 return $assignmentList;
1199 }

References $DIC, and $ilDB.

Referenced by buildExportFileXML().

+ Here is the caller graph for this function:

◆ exportToCSV()

ilTestExport::exportToCSV (   $deliver = true,
  $filterby = "",
  $filtertext = "",
  $passedonly = false 
)

Exports the evaluation data to the CSV file format.

Exports the evaluation data to the CSV file format

Parameters
string$filtertextFilter text for the user data
boolean$passedonlyTRUE if only passed user datasets should be exported, FALSE otherwise @access public

Definition at line 758 of file class.ilTestExport.php.

759 {
760 $this->test_obj->setAccessFilteredParticipantList(
761 $this->test_obj->buildStatisticsAccessFilteredParticipantList()
762 );
763
764 if (strcmp($this->mode, "aggregated") == 0) {
765 return $this->aggregatedResultsToCSV($deliver);
766 }
767
768 $rows = array();
769 $datarow = array();
770 $col = 1;
771 if ($this->test_obj->getAnonymity()) {
772 array_push($datarow, $this->lng->txt("counter"));
773 $col++;
774 } else {
775 array_push($datarow, $this->lng->txt("name"));
776 $col++;
777 array_push($datarow, $this->lng->txt("login"));
778 $col++;
779 }
780 $additionalFields = $this->test_obj->getEvaluationAdditionalFields();
781 if (count($additionalFields)) {
782 foreach ($additionalFields as $fieldname) {
783 if (strcmp($fieldname, "exam_id") == 0) {
784 array_push($datarow, $this->lng->txt('exam_id_label'));
785 $col++;
786 continue;
787 }
788 array_push($datarow, $this->lng->txt($fieldname));
789 $col++;
790 }
791 }
792 array_push($datarow, $this->lng->txt("tst_stat_result_resultspoints"));
793 $col++;
794 array_push($datarow, $this->lng->txt("maximum_points"));
795 $col++;
796 array_push($datarow, $this->lng->txt("tst_stat_result_resultsmarks"));
797 $col++;
798 if ($this->test_obj->getECTSOutput()) {
799 array_push($datarow, $this->lng->txt("ects_grade"));
800 $col++;
801 }
802 array_push($datarow, $this->lng->txt("tst_stat_result_qworkedthrough"));
803 $col++;
804 array_push($datarow, $this->lng->txt("tst_stat_result_qmax"));
805 $col++;
806 array_push($datarow, $this->lng->txt("tst_stat_result_pworkedthrough"));
807 $col++;
808 array_push($datarow, $this->lng->txt("tst_stat_result_timeofwork"));
809 $col++;
810 array_push($datarow, $this->lng->txt("tst_stat_result_atimeofwork"));
811 $col++;
812 array_push($datarow, $this->lng->txt("tst_stat_result_firstvisit"));
813 $col++;
814 array_push($datarow, $this->lng->txt("tst_stat_result_lastvisit"));
815 $col++;
816
817 array_push($datarow, $this->lng->txt("tst_stat_result_mark_median"));
818 $col++;
819 array_push($datarow, $this->lng->txt("tst_stat_result_rank_participant"));
820 $col++;
821 array_push($datarow, $this->lng->txt("tst_stat_result_rank_median"));
822 $col++;
823 array_push($datarow, $this->lng->txt("tst_stat_result_total_participants"));
824 $col++;
825 array_push($datarow, $this->lng->txt("tst_stat_result_median"));
826 $col++;
827 array_push($datarow, $this->lng->txt("tst_tbl_col_started_passes"));
828 $col++;
829 array_push($datarow, $this->lng->txt("tst_tbl_col_finished_passes"));
830 $col++;
831
832 array_push($datarow, $this->lng->txt("scored_pass"));
833 $col++;
834
835 array_push($datarow, $this->lng->txt("pass"));
836 $col++;
837
838 $data = &$this->test_obj->getCompleteEvaluationData(true, $filterby, $filtertext);
839 $headerrow = $datarow;
840 $counter = 1;
841 foreach ($data->getParticipants() as $active_id => $userdata) {
842 $datarow = $headerrow;
843 $remove = false;
844 if ($passedonly) {
845 if ($data->getParticipant($active_id)->getPassed() == false) {
846 $remove = true;
847 }
848 }
849 if (!$remove) {
850 $datarow2 = array();
851 if ($this->test_obj->getAnonymity()) {
852 array_push($datarow2, $counter);
853 } else {
854 array_push($datarow2, $data->getParticipant($active_id)->getName());
855 array_push($datarow2, $data->getParticipant($active_id)->getLogin());
856 }
857 if (count($additionalFields)) {
858 $userfields = ilObjUser::_lookupFields($userdata->getUserID());
859 foreach ($additionalFields as $fieldname) {
860 if (strcmp($fieldname, "gender") == 0) {
861 array_push($datarow2, strlen($userfields[$fieldname]) ? $this->lng->txt('gender_' . $userfields[$fieldname]) : '');
862 } elseif (strcmp($fieldname, "exam_id") == 0) {
863 array_push($datarow2, $userdata->getExamIdFromScoredPass());
864 } else {
865 array_push($datarow2, $userfields[$fieldname]);
866 }
867 }
868 }
869 array_push($datarow2, $data->getParticipant($active_id)->getReached());
870 array_push($datarow2, $data->getParticipant($active_id)->getMaxpoints());
871 array_push($datarow2, $data->getParticipant($active_id)->getMark());
872 if ($this->test_obj->getECTSOutput()) {
873 array_push($datarow2, $data->getParticipant($active_id)->getECTSMark());
874 }
875 array_push($datarow2, $data->getParticipant($active_id)->getQuestionsWorkedThrough());
876 array_push($datarow2, $data->getParticipant($active_id)->getNumberOfQuestions());
877 array_push($datarow2, $data->getParticipant($active_id)->getQuestionsWorkedThroughInPercent() / 100.0);
878 $time = $data->getParticipant($active_id)->getTimeOfWork();
879 $time_seconds = $time;
880 $time_hours = floor($time_seconds / 3600);
881 $time_seconds -= $time_hours * 3600;
882 $time_minutes = floor($time_seconds / 60);
883 $time_seconds -= $time_minutes * 60;
884 array_push($datarow2, sprintf("%02d:%02d:%02d", $time_hours, $time_minutes, $time_seconds));
885 $time = $data->getParticipant($active_id)->getQuestionsWorkedThrough() ? $data->getParticipant($active_id)->getTimeOfWork() / $data->getParticipant($active_id)->getQuestionsWorkedThrough() : 0;
886 $time_seconds = $time;
887 $time_hours = floor($time_seconds / 3600);
888 $time_seconds -= $time_hours * 3600;
889 $time_minutes = floor($time_seconds / 60);
890 $time_seconds -= $time_minutes * 60;
891 array_push($datarow2, sprintf("%02d:%02d:%02d", $time_hours, $time_minutes, $time_seconds));
892
893 $fv = $data->getParticipant($active_id)->getFirstVisit();
894 $lv = $data->getParticipant($active_id)->getLastVisit();
895 foreach (array($fv, $lv) as $ts) {
896 if ($ts) {
898 array_push($datarow2, $visit);
899 } else {
900 array_push($datarow2, "");
901 }
902 }
903
904 $median = $data->getStatistics()->getStatistics()->median();
905 $pct = $data->getParticipant($active_id)->getMaxpoints() ? $median / $data->getParticipant($active_id)->getMaxpoints() * 100.0 : 0;
906 $mark = $this->test_obj->mark_schema->getMatchingMark($pct);
907 $mark_short_name = "";
908 if (is_object($mark)) {
909 $mark_short_name = $mark->getShortName();
910 }
911 array_push($datarow2, $mark_short_name);
912 array_push($datarow2, $data->getStatistics()->getStatistics()->rank($data->getParticipant($active_id)->getReached()));
913 array_push($datarow2, $data->getStatistics()->getStatistics()->rank_median());
914 array_push($datarow2, $data->getStatistics()->getStatistics()->count());
915 array_push($datarow2, $median);
916
917 array_push($datarow2, $data->getParticipant($active_id)->getPassCount());
918 array_push($datarow2, $data->getParticipant($active_id)->getFinishedPasses());
919 if ($this->test_obj->getPassScoring() == SCORE_BEST_PASS) {
920 array_push($datarow2, $data->getParticipant($active_id)->getBestPass() + 1);
921 } else {
922 array_push($datarow2, $data->getParticipant($active_id)->getLastPass() + 1);
923 }
924 for ($pass = 0; $pass <= $data->getParticipant($active_id)->getLastPass(); $pass++) {
925 $finishdate = ilObjTest::lookupPassResultsUpdateTimestamp($active_id, $pass);
926 if ($finishdate > 0) {
927 if ($pass > 0) {
928 for ($i = 1; $i < $col - 1; $i++) {
929 array_push($datarow2, "");
930 array_push($datarow, "");
931 }
932 array_push($datarow, "");
933 }
934 array_push($datarow2, $pass + 1);
935 if (is_object($data->getParticipant($active_id)) && is_array($evaluated_questions = $data->getParticipant($active_id)->getQuestions($pass))) {
936 $questions = $this->orderQuestions($evaluated_questions);
937 foreach ($questions as $question) {
938 $question_data = $data->getParticipant($active_id)->getPass($pass)->getAnsweredQuestionByQuestionId($question["id"]);
939 array_push($datarow2, $question_data["reached"]);
940 array_push($datarow, preg_replace("/<.*?>/", "", $data->getQuestionTitle($question["id"])));
941 }
942 }
943 if ($this->test_obj->isRandomTest() ||
944 $counter == 1 && $pass == 0) {
945 array_push($rows, $datarow);
946 }
947 $datarow = array();
948 array_push($rows, $datarow2);
949 $datarow2 = array();
950 }
951 }
952 $counter++;
953 }
954 }
955 $csv = "";
956 $separator = ";";
957 foreach ($rows as $evalrow) {
958 $csvrow = &$this->test_obj->processCSVRow($evalrow, true, $separator);
959 $csv .= join($separator, $csvrow) . "\n";
960 }
961 if ($deliver) {
962 ilUtil::deliverData($csv, ilUtil::getASCIIFilename($this->test_obj->getTitle() . "_results.csv"));
963 exit;
964 } else {
965 return $csv;
966 }
967 }
const IL_CAL_UNIX
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
@classDescription Date and time handling
static lookupPassResultsUpdateTimestamp($active_id, $pass)
static _lookupFields($a_user_id)
lookup fields (deprecated; use more specific methods instead)
aggregatedResultsToCSV($deliver=true)
Exports the aggregated results to CSV.
orderQuestions(array $questions)
const SCORE_BEST_PASS
$i
Definition: metadata.php:24

References $data, $i, $pass, $rows, ilObjUser\_lookupFields(), aggregatedResultsToCSV(), ilUtil\deliverData(), exit, ilDatePresentation\formatDate(), ilUtil\getASCIIFilename(), IL_CAL_UNIX, ilObjTest\lookupPassResultsUpdateTimestamp(), orderQuestions(), and SCORE_BEST_PASS.

Referenced by buildExportResultFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ exportToExcel()

ilTestExport::exportToExcel (   $deliver = true,
  $filterby = "",
  $filtertext = "",
  $passedonly = false 
)

Exports the evaluation data to the Microsoft Excel file format.

Parameters
bool$deliver
string$filterby
string$filtertextFilter text for the user data
boolean$passedonlyTRUE if only passed user datasets should be exported, FALSE otherwise
Returns
string

Definition at line 331 of file class.ilTestExport.php.

332 {
333 $this->test_obj->setAccessFilteredParticipantList($this->getAccessFilteredParticipantList());
334
335 if (strcmp($this->mode, "aggregated") == 0) {
336 return $this->aggregatedResultsToExcel($deliver);
337 }
338
339 require_once 'Modules/TestQuestionPool/classes/class.ilAssExcelFormatHelper.php';
340
341 $worksheet = new ilAssExcelFormatHelper();
342 $worksheet->addSheet($this->lng->txt('tst_results'));
343
344 $additionalFields = $this->test_obj->getEvaluationAdditionalFields();
345
346 $row = 1;
347 $col = 0;
348
349 if ($this->test_obj->getAnonymity()) {
350 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('counter'));
351 } else {
352 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('name'));
353 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('login'));
354 }
355
356 if (count($additionalFields)) {
357 foreach ($additionalFields as $fieldname) {
358 if (strcmp($fieldname, "exam_id") == 0) {
359 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('exam_id_label'));
360 continue;
361 }
362 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt($fieldname));
363 }
364 }
365
366 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('tst_stat_result_resultspoints'));
367 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('maximum_points'));
368 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('tst_stat_result_resultsmarks'));
369
370 if ($this->test_obj->getECTSOutput()) {
371 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('ects_grade'));
372 }
373
374 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('tst_stat_result_qworkedthrough'));
375 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('tst_stat_result_qmax'));
376 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('tst_stat_result_pworkedthrough'));
377 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('tst_stat_result_timeofwork'));
378 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('tst_stat_result_atimeofwork'));
379 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('tst_stat_result_firstvisit'));
380 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('tst_stat_result_lastvisit'));
381 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('tst_stat_result_mark_median'));
382 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('tst_stat_result_rank_participant'));
383 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('tst_stat_result_rank_median'));
384 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('tst_stat_result_total_participants'));
385 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('tst_stat_result_median'));
386 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('tst_tbl_col_started_passes'));
387 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('tst_tbl_col_finished_passes'));
388 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('scored_pass'));
389 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('pass'));
390
391 $worksheet->setBold('A' . $row . ':' . $worksheet->getColumnCoord($col - 1) . $row);
392
393 $counter = 1;
394 $data = $this->test_obj->getCompleteEvaluationData(true, $filterby, $filtertext);
395 $firstrowwritten = false;
396 foreach ($data->getParticipants() as $active_id => $userdata) {
397 if ($passedonly && $data->getParticipant($active_id)->getPassed() == false) {
398 continue;
399 }
400
401 $row++;
402 $col = 0;
403
404 // each participant gets an own row for question column headers
405 if ($this->test_obj->isRandomTest() && $firstrowwritten) {
406 $row++;
407 }
408
409 if ($this->test_obj->getAnonymity()) {
410 $worksheet->setCell($row, $col++, $counter);
411 } else {
412 $worksheet->setCell($row, $col++, $data->getParticipant($active_id)->getName());
413 $worksheet->setCell($row, $col++, $data->getParticipant($active_id)->getLogin());
414 }
415
416 if (count($additionalFields)) {
417 $userfields = ilObjUser::_lookupFields($userdata->getUserId());
418 foreach ($additionalFields as $fieldname) {
419 if (strcmp($fieldname, 'gender') == 0) {
420 $worksheet->setCell($row, $col++, strlen($userfields[$fieldname]) ? $this->lng->txt('gender_' . $userfields[$fieldname]) : '');
421 } elseif (strcmp($fieldname, "exam_id") == 0) {
422 $worksheet->setCell($row, $col++, $userdata->getExamIdFromScoredPass());
423 } else {
424 $worksheet->setCell($row, $col++, $userfields[$fieldname]);
425 }
426 }
427 }
428
429 $worksheet->setCell($row, $col++, $data->getParticipant($active_id)->getReached());
430 $worksheet->setCell($row, $col++, $data->getParticipant($active_id)->getMaxpoints());
431 $worksheet->setCell($row, $col++, $data->getParticipant($active_id)->getMark());
432
433 if ($this->test_obj->getECTSOutput()) {
434 $worksheet->setCell($row, $col++, $data->getParticipant($active_id)->getECTSMark());
435 }
436
437 $worksheet->setCell($row, $col++, $data->getParticipant($active_id)->getQuestionsWorkedThrough());
438 $worksheet->setCell($row, $col++, $data->getParticipant($active_id)->getNumberOfQuestions());
439 $worksheet->setCell($row, $col++, $data->getParticipant($active_id)->getQuestionsWorkedThroughInPercent() . '%');
440
441 $time = $data->getParticipant($active_id)->getTimeOfWork();
442 $time_seconds = $time;
443 $time_hours = floor($time_seconds / 3600);
444 $time_seconds -= $time_hours * 3600;
445 $time_minutes = floor($time_seconds / 60);
446 $time_seconds -= $time_minutes * 60;
447 $worksheet->setCell($row, $col++, sprintf("%02d:%02d:%02d", $time_hours, $time_minutes, $time_seconds));
448 $time = $data->getParticipant($active_id)->getQuestionsWorkedThrough() ? $data->getParticipant($active_id)->getTimeOfWork() / $data->getParticipant($active_id)->getQuestionsWorkedThrough() : 0;
449 $time_seconds = $time;
450 $time_hours = floor($time_seconds / 3600);
451 $time_seconds -= $time_hours * 3600;
452 $time_minutes = floor($time_seconds / 60);
453 $time_seconds -= $time_minutes * 60;
454 $worksheet->setCell($row, $col++, sprintf("%02d:%02d:%02d", $time_hours, $time_minutes, $time_seconds));
455 $worksheet->setCell($row, $col++, new ilDateTime($data->getParticipant($active_id)->getFirstVisit(), IL_CAL_UNIX));
456 $worksheet->setCell($row, $col++, new ilDateTime($data->getParticipant($active_id)->getLastVisit(), IL_CAL_UNIX));
457
458 $median = $data->getStatistics()->getStatistics()->median();
459 $pct = $data->getParticipant($active_id)->getMaxpoints() ? $median / $data->getParticipant($active_id)->getMaxpoints() * 100.0 : 0;
460 $mark = $this->test_obj->mark_schema->getMatchingMark($pct);
461 $mark_short_name = "";
462
463 if (is_object($mark)) {
464 $mark_short_name = $mark->getShortName();
465 }
466
467 $worksheet->setCell($row, $col++, $mark_short_name);
468 $worksheet->setCell($row, $col++, $data->getStatistics()->getStatistics()->rank($data->getParticipant($active_id)->getReached()));
469 $worksheet->setCell($row, $col++, $data->getStatistics()->getStatistics()->rank_median());
470 $worksheet->setCell($row, $col++, $data->getStatistics()->getStatistics()->count());
471 $worksheet->setCell($row, $col++, $median);
472 $worksheet->setCell($row, $col++, $data->getParticipant($active_id)->getPassCount());
473 $worksheet->setCell($row, $col++, $data->getParticipant($active_id)->getFinishedPasses());
474 if ($this->test_obj->getPassScoring() == SCORE_BEST_PASS) {
475 $worksheet->setCell($row, $col++, $data->getParticipant($active_id)->getBestPass() + 1);
476 } else {
477 $worksheet->setCell($row, $col++, $data->getParticipant($active_id)->getLastPass() + 1);
478 }
479
480 $startcol = $col;
481
482 for ($pass = 0; $pass <= $data->getParticipant($active_id)->getLastPass(); $pass++) {
483 $col = $startcol;
484 $finishdate = ilObjTest::lookupPassResultsUpdateTimestamp($active_id, $pass);
485 if ($finishdate > 0) {
486 if ($pass > 0) {
487 $row++;
488 if ($this->test_obj->isRandomTest()) {
489 $row++;
490 }
491 }
492 $worksheet->setCell($row, $col++, $pass + 1);
493 if (is_object($data->getParticipant($active_id)) && is_array($data->getParticipant($active_id)->getQuestions($pass))) {
494 $evaluated_questions = $data->getParticipant($active_id)->getQuestions($pass);
495 $questions = $this->orderQuestions($evaluated_questions);
496
497 foreach ($questions as $question) {
498 $question_data = $data->getParticipant($active_id)->getPass($pass)->getAnsweredQuestionByQuestionId($question["id"]);
499 $worksheet->setCell($row, $col, $question_data["reached"]);
500 if ($this->test_obj->isRandomTest()) {
501 // random test requires question headers for every participant
502 // and we allready skipped a row for that reason ( --> row - 1)
503 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col) . ($row - 1), preg_replace("/<.*?>/", "", $data->getQuestionTitle($question["id"])));
504 } else {
505 if ($pass == 0 && !$firstrowwritten) {
506 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col) . 1, $data->getQuestionTitle($question["id"]));
507 }
508 }
509 $col++;
510 }
511 $firstrowwritten = true;
512 }
513 }
514 }
515 $counter++;
516 }
517
518 if ($this->test_obj->getExportSettingsSingleChoiceShort() && !$this->test_obj->isRandomTest() && $this->test_obj->hasSingleChoiceQuestions()) {
519 // special tab for single choice tests
520 $titles = $this->test_obj->getQuestionTitlesAndIndexes();
521 $positions = array();
522 $pos = 0;
523 $row = 1;
524 foreach ($titles as $id => $title) {
525 $positions[$id] = $pos;
526 $pos++;
527 }
528
529 $usernames = array();
530 $participantcount = count($data->getParticipants());
531 $allusersheet = false;
532 $pages = 0;
533
534 $worksheet->addSheet($this->lng->txt('eval_all_users'));
535
536 $col = 0;
537 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('name'));
538 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('login'));
539 if (count($additionalFields)) {
540 foreach ($additionalFields as $fieldname) {
541 if (strcmp($fieldname, "matriculation") == 0) {
542 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('matriculation'));
543 }
544 if (strcmp($fieldname, "exam_id") == 0) {
545 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('exam_id_label'));
546 }
547 }
548 }
549 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('test'));
550 foreach ($titles as $title) {
551 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $title);
552 }
553 $worksheet->setBold('A' . $row . ':' . $worksheet->getColumnCoord($col - 1) . $row);
554
555 $row++;
556 foreach ($data->getParticipants() as $active_id => $userdata) {
557 $username = (!is_null($userdata) && $userdata->getName()) ? $userdata->getName() : "ID $active_id";
558 if (array_key_exists($username, $usernames)) {
559 $usernames[$username]++;
560 $username .= " ($usernames[$username])";
561 } else {
562 $usernames[$username] = 1;
563 }
564 $col = 0;
565 $worksheet->setCell($row, $col++, $username);
566 $worksheet->setCell($row, $col++, $userdata->getLogin());
567 if (count($additionalFields)) {
568 $userfields = ilObjUser::_lookupFields($userdata->getUserID());
569 foreach ($additionalFields as $fieldname) {
570 if (strcmp($fieldname, "matriculation") == 0) {
571 if (strlen($userfields[$fieldname])) {
572 $worksheet->setCell($row, $col++, $userfields[$fieldname]);
573 } else {
574 $col++;
575 }
576 }
577 if (strcmp($fieldname, "exam_id") == 0) {
578 if (strlen($userfields[$fieldname])) {
579 $worksheet->setCell($row, $col++, $userdata->getExamIdFromScoredPass());
580 } else {
581 $col++;
582 }
583 }
584 }
585 }
586 $worksheet->setCell($row, $col++, $this->test_obj->getTitle());
587 $pass = $userdata->getScoredPass();
588 if (is_object($userdata) && is_array($userdata->getQuestions($pass))) {
589 foreach ($userdata->getQuestions($pass) as $question) {
590 $objQuestion = assQuestion::_instantiateQuestion($question["id"]);
591 if (is_object($objQuestion) && strcmp($objQuestion->getQuestionType(), 'assSingleChoice') == 0) {
592 $solution = $objQuestion->getSolutionValues($active_id, $pass);
593 $pos = $positions[$question["id"]];
594 $selectedanswer = "x";
595 foreach ($objQuestion->getAnswers() as $id => $answer) {
596 if (strlen($solution[0]["value1"]) && $id == $solution[0]["value1"]) {
597 $selectedanswer = $answer->getAnswertext();
598 }
599 }
600 $worksheet->setCell($row, $col + $pos, $selectedanswer);
601 }
602 }
603 }
604 $row++;
605 }
606
607 if ($this->test_obj->isSingleChoiceTestWithoutShuffle()) {
608 // special tab for single choice tests without shuffle option
609 $pos = 0;
610 $row = 1;
611 $usernames = array();
612 $allusersheet = false;
613 $pages = 0;
614
615 $worksheet->addSheet($this->lng->txt('eval_all_users') . ' (2)');
616
617 $col = 0;
618 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('name'));
619 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('login'));
620 if (count($additionalFields)) {
621 foreach ($additionalFields as $fieldname) {
622 if (strcmp($fieldname, "matriculation") == 0) {
623 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('matriculation'));
624 }
625 if (strcmp($fieldname, "exam_id") == 0) {
626 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('exam_id_label'));
627 }
628 }
629 }
630 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('test'));
631 foreach ($titles as $title) {
632 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $title);
633 }
634 $worksheet->setBold('A' . $row . ':' . $worksheet->getColumnCoord($col - 1) . $row);
635
636 $row++;
637 foreach ($data->getParticipants() as $active_id => $userdata) {
638 $username = (!is_null($userdata) && $userdata->getName()) ? $userdata->getName() : "ID $active_id";
639 if (array_key_exists($username, $usernames)) {
640 $usernames[$username]++;
641 $username .= " ($usernames[$username])";
642 } else {
643 $usernames[$username] = 1;
644 }
645 $col = 0;
646 $worksheet->setCell($row, $col++, $username);
647 $worksheet->setCell($row, $col++, $userdata->getLogin());
648 if (count($additionalFields)) {
649 $userfields = ilObjUser::_lookupFields($userdata->getUserId());
650 foreach ($additionalFields as $fieldname) {
651 if (strcmp($fieldname, "matriculation") == 0) {
652 if (strlen($userfields[$fieldname])) {
653 $worksheet->setCell($row, $col++, $userfields[$fieldname]);
654 } else {
655 $col++;
656 }
657 }
658 if (strcmp($fieldname, "exam_id") == 0) {
659 if (strlen($userfields[$fieldname])) {
660 $worksheet->setCell($row, $col++, $userdata->getExamIdFromScoredPass());
661 } else {
662 $col++;
663 }
664 }
665 }
666 }
667 $worksheet->setCell($row, $col++, $this->test_obj->getTitle());
668 $pass = $userdata->getScoredPass();
669 if (is_object($userdata) && is_array($userdata->getQuestions($pass))) {
670 foreach ($userdata->getQuestions($pass) as $question) {
671 $objQuestion = ilObjTest::_instanciateQuestion($question["aid"]);
672 if (is_object($objQuestion) && strcmp($objQuestion->getQuestionType(), 'assSingleChoice') == 0) {
673 $solution = $objQuestion->getSolutionValues($active_id, $pass);
674 $pos = $positions[$question["aid"]];
675 $selectedanswer = chr(65 + $solution[0]["value1"]);
676 $worksheet->setCell($row, $col + $pos, $selectedanswer);
677 }
678 }
679 }
680 $row++;
681 }
682 }
683 } else {
684 // test participant result export
685 $usernames = array();
686 $participantcount = count($data->getParticipants());
687 $allusersheet = false;
688 $pages = 0;
689 foreach ($data->getParticipants() as $active_id => $userdata) {
690 $username = (!is_null($userdata) && $userdata->getName())
691 ? $userdata->getName()
692 : "ID $active_id";
693 $username = mb_substr($username, 0, 26);
694
695 $username_to_lower = strtolower($username);
696 if (array_key_exists($username_to_lower, $usernames)) {
697 $usernames[$username_to_lower]++;
698 $username .= " (" . $usernames[$username_to_lower] . ")";
699 } else {
700 $usernames[$username_to_lower] = 0;
701 }
702
703 if ($participantcount > 250) {
704 if (!$allusersheet || ($pages - 1) < floor($row / 64000)) {
705 $worksheet->addSheet($this->lng->txt("eval_all_users") . (($pages > 0) ? " (" . ($pages + 1) . ")" : ""));
706 $allusersheet = true;
707 $row = 1;
708 $pages++;
709 }
710 } else {
711 $resultsheet = $worksheet->addSheet($username);
712 }
713
714 $pass = $userdata->getScoredPass();
715 $row = ($allusersheet) ? $row : 1;
716 $worksheet->setCell($row, 0, sprintf($this->lng->txt("tst_result_user_name_pass"), $pass + 1, $userdata->getName()));
717 $worksheet->setBold($worksheet->getColumnCoord(0) . $row);
718 $row += 2;
719 if (is_object($userdata) && is_array($userdata->getQuestions($pass))) {
720 foreach ($userdata->getQuestions($pass) as $question) {
721 require_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
722 $question = assQuestion::_instanciateQuestion($question["id"]);
723 if (is_object($question)) {
724 $row = $question->setExportDetailsXLS($worksheet, $row, $active_id, $pass);
725 }
726 }
727 }
728 }
729 }
730
731 if ($deliver) {
732 $testname = $this->test_obj->getTitle();
733 switch ($this->mode) {
734 case 'results':
735 $testname .= '_results';
736 break;
737 }
738 $testname = ilUtil::getASCIIFilename(preg_replace("/\s/", "_", $testname)) . '.xlsx';
739 $worksheet->sendToClient($testname);
740 } else {
741 $excelfile = ilUtil::ilTempnam();
742 $worksheet->writeToFile($excelfile);
743 return $excelfile . '.xlsx';
744 }
745 }
static _instantiateQuestion($question_id)
static _instanciateQuestion($question_id)
Creates an instance of a question with a given question id.
static _instanciateQuestion($question_id)
Creates an instance of a question with a given question id.
aggregatedResultsToExcel($deliver=true)
Exports the aggregated results to the Microsoft Excel file format.

References $data, $pass, ilObjTest\_instanciateQuestion(), assQuestion\_instanciateQuestion(), assQuestion\_instantiateQuestion(), ilObjUser\_lookupFields(), aggregatedResultsToExcel(), getAccessFilteredParticipantList(), ilUtil\getASCIIFilename(), IL_CAL_UNIX, ilUtil\ilTempnam(), ilObjTest\lookupPassResultsUpdateTimestamp(), orderQuestions(), and SCORE_BEST_PASS.

Referenced by buildExportResultFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ exportXHTMLMediaObjects()

ilTestExport::exportXHTMLMediaObjects (   $a_export_dir)

Definition at line 1128 of file class.ilTestExport.php.

1129 {
1130 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1131
1132 $mobs = ilObjMediaObject::_getMobsOfObject("tst:html", $this->test_obj->getId());
1133 foreach ($mobs as $mob) {
1134 if (ilObjMediaObject::_exists($mob)) {
1135 $mob_obj = new ilObjMediaObject($mob);
1136 $mob_obj->exportFiles($a_export_dir);
1137 unset($mob_obj);
1138 }
1139 }
1140 foreach ($this->getQuestionIds() as $question_id) {
1141 $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $question_id);
1142 foreach ($mobs as $mob) {
1143 if (ilObjMediaObject::_exists($mob)) {
1144 $mob_obj = new ilObjMediaObject($mob);
1145 $mob_obj->exportFiles($a_export_dir);
1146 unset($mob_obj);
1147 }
1148 }
1149 }
1150 }
Class ilObjMediaObject.
static _getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
static _exists($a_id, $a_reference=false, $a_type=null)
checks wether a lm content object with specified id exists or not
$mobs
Definition: imgupload.php:54

References $mobs, ilObjMediaObject\_exists(), ilObjMediaObject\_getMobsOfObject(), and getQuestionIds().

Referenced by buildExportFileXML().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAccessFilteredParticipantList()

ilTestExport::getAccessFilteredParticipantList ( )
Returns
ilTestParticipantList

Definition at line 127 of file class.ilTestExport.php.

128 {
131 }
132
133 return $this->test_obj->buildStatisticsAccessFilteredParticipantList();
134 }
getForcedAccessFilteredParticipantList()

References getForcedAccessFilteredParticipantList().

Referenced by exportToExcel().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getExtension()

ilTestExport::getExtension ( )

Definition at line 136 of file class.ilTestExport.php.

137 {
138 switch ($this->mode) {
139 case "results":
140 return "csv"; break;
141 default:
142 return "xml"; break;
143 }
144 }

Referenced by __construct(), and buildExportResultFile().

+ Here is the caller graph for this function:

◆ getForcedAccessFilteredParticipantList()

ilTestExport::getForcedAccessFilteredParticipantList ( )
Returns
ilTestParticipantList

Definition at line 111 of file class.ilTestExport.php.

References $forcedAccessFilteredParticipantList.

Referenced by getAccessFilteredParticipantList().

+ Here is the caller graph for this function:

◆ getInstId()

ilTestExport::getInstId ( )

Definition at line 146 of file class.ilTestExport.php.

147 {
148 return $this->inst_id;
149 }

References $inst_id.

◆ getQtiXml()

ilTestExport::getQtiXml ( )
protected

Definition at line 1099 of file class.ilTestExport.php.

1100 {
1101 $tstQtiXml = $this->test_obj->toXML();
1102 $qstQtiXml = $this->getQuestionsQtiXml();
1103
1104 if (strpos($tstQtiXml, "</section>") !== false) {
1105 $qtiXml = str_replace("</section>", "$qstQtiXml</section>", $tstQtiXml);
1106 } else {
1107 $qtiXml = str_replace("<section ident=\"1\"/>", "<section ident=\"1\">\n$qstQtiXml</section>", $tstQtiXml);
1108 }
1109
1110 return $qtiXml;
1111 }

References getQuestionsQtiXml().

Referenced by buildExportFileXML().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getQuestionIds()

ilTestExport::getQuestionIds ( )
abstractprotected

Reimplemented in ilTestExportDynamicQuestionSet, ilTestExportFixedQuestionSet, and ilTestExportRandomQuestionSet.

Referenced by buildExportFileXML(), and exportXHTMLMediaObjects().

+ Here is the caller graph for this function:

◆ getQuestionQtiXml()

ilTestExport::getQuestionQtiXml (   $questionId)
protected

Definition at line 1115 of file class.ilTestExport.php.

1116 {
1117 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
1118 $questionOBJ = assQuestion::_instantiateQuestion($questionId);
1119 $xml = $questionOBJ->toXML(false);
1120
1121 // still neccessary? there is an include header flag!?
1122 $xml = preg_replace("/<questestinterop>/", "", $xml);
1123 $xml = preg_replace("/<\/questestinterop>/", "", $xml);
1124
1125 return $xml;
1126 }
$xml
Definition: metadata.php:332

References $xml, and assQuestion\_instantiateQuestion().

Referenced by ilTestExportFixedQuestionSet\getQuestionsQtiXml(), and ilTestExportRandomQuestionSet\getQuestionsQtiXml().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getQuestionsQtiXml()

ilTestExport::getQuestionsQtiXml ( )
abstractprotected

Reimplemented in ilTestExportDynamicQuestionSet, ilTestExportFixedQuestionSet, and ilTestExportRandomQuestionSet.

Referenced by getQtiXml().

+ Here is the caller graph for this function:

◆ initXmlExport()

ilTestExport::initXmlExport ( )
abstractprotected

Reimplemented in ilTestExportDynamicQuestionSet, ilTestExportFixedQuestionSet, and ilTestExportRandomQuestionSet.

Referenced by buildExportFileXML().

+ Here is the caller graph for this function:

◆ isResultExportingEnabledForTestExport()

ilTestExport::isResultExportingEnabledForTestExport ( )
Returns
boolean

Definition at line 95 of file class.ilTestExport.php.

References $resultExportingEnabledForTestExport.

Referenced by buildExportFileXML().

+ Here is the caller graph for this function:

◆ orderQuestions()

ilTestExport::orderQuestions ( array  $questions)
protected

Definition at line 970 of file class.ilTestExport.php.

970 : array
971 {
972 $key = $this->test_obj->isRandomTest() ? 'qid' : 'sequence';
973 usort(
974 $questions,
975 function ($a, $b) use ($key) {
976 if (isset($a[$key], $b[$key]) && $a[$key] > $b[$key]) {
977 return 1;
978 }
979 return -1;
980 }
981 );
982 return $questions;
983 }
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples

References Vendor\Package\$a, and Vendor\Package\$b.

Referenced by exportToCSV(), and exportToExcel().

+ Here is the caller graph for this function:

◆ populateQuestionSetConfigXml()

ilTestExport::populateQuestionSetConfigXml ( ilXmlWriter  $xmlWriter)
abstractprotected

Reimplemented in ilTestExportDynamicQuestionSet, ilTestExportFixedQuestionSet, and ilTestExportRandomQuestionSet.

Referenced by buildExportFileXML().

+ Here is the caller graph for this function:

◆ populateQuestionSkillAssignmentsXml()

ilTestExport::populateQuestionSkillAssignmentsXml ( ilXmlWriter  $a_xml_writer,
ilAssQuestionSkillAssignmentList  $assignmentList,
  $questions 
)
protected
Parameters
ilXmlWriter$a_xml_writer
$questions

Definition at line 1156 of file class.ilTestExport.php.

1157 {
1158 require_once 'Modules/TestQuestionPool/classes/questions/class.ilAssQuestionSkillAssignmentExporter.php';
1159 $skillQuestionAssignmentExporter = new ilAssQuestionSkillAssignmentExporter();
1160 $skillQuestionAssignmentExporter->setXmlWriter($a_xml_writer);
1161 $skillQuestionAssignmentExporter->setQuestionIds($questions);
1162 $skillQuestionAssignmentExporter->setAssignmentList($assignmentList);
1163 $skillQuestionAssignmentExporter->export();
1164 }

Referenced by buildExportFileXML().

+ Here is the caller graph for this function:

◆ populateSkillLevelThresholdsXml()

ilTestExport::populateSkillLevelThresholdsXml ( ilXmlWriter  $a_xml_writer,
ilAssQuestionSkillAssignmentList  $assignmentList 
)
protected

Definition at line 1166 of file class.ilTestExport.php.

1167 {
1168 global $DIC;
1169 $ilDB = $DIC['ilDB'];
1170
1171 require_once 'Modules/Test/classes/class.ilTestSkillLevelThresholdList.php';
1172 $thresholdList = new ilTestSkillLevelThresholdList($ilDB);
1173 $thresholdList->setTestId($this->test_obj->getTestId());
1174 $thresholdList->loadFromDb();
1175
1176 require_once 'Modules/Test/classes/class.ilTestSkillLevelThresholdExporter.php';
1177 $skillLevelThresholdExporter = new ilTestSkillLevelThresholdExporter();
1178 $skillLevelThresholdExporter->setXmlWriter($a_xml_writer);
1179 $skillLevelThresholdExporter->setAssignmentList($assignmentList);
1180 $skillLevelThresholdExporter->setThresholdList($thresholdList);
1181 $skillLevelThresholdExporter->export();
1182 }

References $DIC, and $ilDB.

Referenced by buildExportFileXML().

+ Here is the caller graph for this function:

◆ setForcedAccessFilteredParticipantList()

ilTestExport::setForcedAccessFilteredParticipantList ( ilTestParticipantList  $forcedAccessFilteredParticipantList)
Parameters
ilTestParticipantList$forcedAccessFilteredParticipantList

Definition at line 119 of file class.ilTestExport.php.

120 {
121 $this->forcedAccessFilteredParticipantList = $forcedAccessFilteredParticipantList;
122 }

References $forcedAccessFilteredParticipantList.

◆ setResultExportingEnabledForTestExport()

ilTestExport::setResultExportingEnabledForTestExport (   $resultExprtingEnabledForTestExport)
Parameters
boolean$resultExprtingEnabledForTestExport

Definition at line 103 of file class.ilTestExport.php.

104 {
105 $this->resultExportingEnabledForTestExport = $resultExprtingEnabledForTestExport;
106 }

Field Documentation

◆ $db

ilDBInterface ilTestExport::$db

Definition at line 23 of file class.ilTestExport.php.

◆ $err

ilErrorHandling ilTestExport::$err

Definition at line 20 of file class.ilTestExport.php.

◆ $forcedAccessFilteredParticipantList

ilTestExport::$forcedAccessFilteredParticipantList = null
protected

◆ $ilias

ILIAS ilTestExport::$ilias

Definition at line 26 of file class.ilTestExport.php.

Referenced by __construct().

◆ $inst_id

ilTestExport::$inst_id

Definition at line 31 of file class.ilTestExport.php.

Referenced by getInstId().

◆ $lng

ilLanguage ilTestExport::$lng
private

Definition at line 35 of file class.ilTestExport.php.

Referenced by __construct().

◆ $mode

ilTestExport::$mode

Definition at line 32 of file class.ilTestExport.php.

◆ $resultExportingEnabledForTestExport

ilTestExport::$resultExportingEnabledForTestExport = false
protected

Definition at line 39 of file class.ilTestExport.php.

Referenced by isResultExportingEnabledForTestExport().

◆ $resultsfile

ilTestExport::$resultsfile
private

Definition at line 37 of file class.ilTestExport.php.

◆ $test_obj

ilObjTest ilTestExport::$test_obj

Definition at line 29 of file class.ilTestExport.php.


The documentation for this class was generated from the following file: