ILIAS  release_8 Revision v8.23
ilTestExport Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. 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

string $export_dir
 
string $subdir
 
string $qti_filename
 
 $lng
 
 $resultsfile
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning 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 32 of file class.ilTestExport.php.

Constructor & Destructor Documentation

◆ __construct()

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

Constructor.

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

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

68  {
69  global $DIC;
70  $ilErr = $DIC['ilErr'];
71  $ilDB = $DIC['ilDB'];
72  $ilias = $DIC['ilias'];
73  $lng = $DIC['lng'];
74 
75  $this->test_obj = &$a_test_obj;
76 
77  $this->err = &$ilErr;
78  $this->ilias = &$ilias;
79  $this->db = &$ilDB;
80  $this->mode = $a_mode;
81  $this->lng = &$lng;
82 
83  $this->inst_id = IL_INST_ID;
84 
85  $date = time();
86  $this->export_dir = $this->test_obj->getExportDirectory();
87 
88  switch ($this->mode) {
89  case "results":
90  $this->subdir = $date . "__" . $this->inst_id . "__" .
91  "tst__results_" . $this->test_obj->getId();
92  break;
93  case "aggregated":
94  $this->subdir = $date . "__" . $this->inst_id . "__" .
95  "test__aggregated__results_" . $this->test_obj->getId();
96  break;
97  default:
98  $this->subdir = $date . "__" . $this->inst_id . "__" .
99  "tst" . "_" . $this->test_obj->getId();
100  $this->filename = $this->subdir . ".xml";
101  $this->resultsfile = $date . "__" . $this->inst_id . "__" .
102  "results" . "_" . $this->test_obj->getId() . ".xml";
103  $this->qti_filename = $date . "__" . $this->inst_id . "__" .
104  "qti" . "_" . $this->test_obj->getId() . ".xml";
105  break;
106  }
107  $this->filename = $this->subdir . "." . $this->getExtension();
108  }
const IL_INST_ID
Definition: constants.php:40
$ilErr
Definition: raiseError.php:17
global $DIC
Definition: feed.php:28
header include for all ilias files.
+ 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 291 of file class.ilTestExport.php.

References $data, ILIAS\LTI\ToolProvider\$key, $rows, ilUtil\deliverData(), exit, ilFileUtils\getASCIIFilename(), and ILIAS\Repository\lng().

Referenced by exportToCSV().

292  {
293  $data = $this->test_obj->getAggregatedResultsData();
294  $rows = array();
295  array_push($rows, array(
296  $this->lng->txt("result"),
297  $this->lng->txt("value")
298  ));
299  foreach ($data["overview"] as $key => $value) {
300  array_push($rows, array(
301  $key,
302  $value
303  ));
304  }
305  array_push($rows, array(
306  $this->lng->txt("question_id"),
307  $this->lng->txt("question_title"),
308  $this->lng->txt("average_reached_points"),
309  $this->lng->txt("points"),
310  $this->lng->txt("percentage"),
311  $this->lng->txt("number_of_answers")
312  ));
313  foreach ($data["questions"] as $key => $value) {
314  array_push($rows, array(
315  $key,
316  $value[0],
317  $value[4],
318  $value[5],
319  $value[6],
320  $value[3]
321  ));
322  }
323  $csv = "";
324  $separator = ";";
325  foreach ($rows as $evalrow) {
326  $csvrow = &$this->test_obj->processCSVRow($evalrow, true, $separator);
327  $csv .= join($separator, $csvrow) . "\n";
328  }
329  if ($deliver) {
330  ilUtil::deliverData($csv, ilFileUtils::getASCIIFilename($this->test_obj->getTitle() . "_aggregated.csv"));
331  exit;
332  } else {
333  return $csv;
334  }
335  }
exit
Definition: login.php:28
static deliverData(string $a_data, string $a_filename, string $mime="application/octet-stream")
static getASCIIFilename(string $a_filename)
string $key
Consumer key/client ID value.
Definition: System.php:193
$rows
Definition: xhr_table.php:10
+ 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

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

References $data, ILIAS\LTI\ToolProvider\$key, ilFileUtils\getASCIIFilename(), ilFileUtils\ilTempnam(), and ILIAS\Repository\lng().

Referenced by exportToExcel().

229  : string
230  {
231  $data = $this->test_obj->getAggregatedResultsData();
232 
233  require_once 'Modules/TestQuestionPool/classes/class.ilAssExcelFormatHelper.php';
234  $worksheet = new ilAssExcelFormatHelper();
235  $worksheet->addSheet($this->lng->txt('tst_results_aggregated'));
236 
237  $row = 1;
238  $col = 0;
239  $worksheet->setCell($row, $col++, $this->lng->txt('result'));
240  $worksheet->setCell($row, $col++, $this->lng->txt('value'));
241 
242  $worksheet->setBold('A' . $row . ':' . $worksheet->getColumnCoord($col - 1) . $row);
243 
244  $row++;
245  foreach ($data['overview'] as $key => $value) {
246  $col = 0;
247  $worksheet->setCell($row, $col++, $key);
248  $worksheet->setCell($row, $col++, $value);
249  $row++;
250  }
251 
252  $row++;
253  $col = 0;
254 
255  $worksheet->setCell($row, $col++, $this->lng->txt('question_id'));
256  $worksheet->setCell($row, $col++, $this->lng->txt('question_title'));
257  $worksheet->setCell($row, $col++, $this->lng->txt('average_reached_points'));
258  $worksheet->setCell($row, $col++, $this->lng->txt('points'));
259  $worksheet->setCell($row, $col++, $this->lng->txt('percentage'));
260  $worksheet->setCell($row, $col++, $this->lng->txt('number_of_answers'));
261 
262  $worksheet->setBold('A' . $row . ':' . $worksheet->getColumnCoord($col - 1) . $row);
263 
264  $row++;
265  foreach ($data['questions'] as $key => $value) {
266  $col = 0;
267  $worksheet->setCell($row, $col++, $key);
268  $worksheet->setCell($row, $col++, $value[0]);
269  $worksheet->setCell($row, $col++, $value[4]);
270  $worksheet->setCell($row, $col++, $value[5]);
271  $worksheet->setCell($row, $col++, $value[6]);
272  $worksheet->setCell($row, $col++, $value[3]);
273  $row++;
274  }
275 
276  if ($deliver) {
277  $worksheet->sendToClient(
278  ilFileUtils::getASCIIFilename(preg_replace("/\s/", '_', $this->test_obj->getTitle() . '_aggregated')) . '.xlsx'
279  );
280  }
281  $excelfile = ilFileUtils::ilTempnam();
282  $worksheet->writeToFile($excelfile);
283  return $excelfile . '.xlsx';
284  }
static getASCIIFilename(string $a_filename)
string $key
Consumer key/client ID value.
Definition: System.php:193
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ 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)

public

Returns

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

References buildExportFileXML(), and buildExportResultFile().

176  : string
177  {
178  switch ($this->mode) {
179  case "results":
180  return $this->buildExportResultFile();
181  break;
182  default:
183  return $this->buildExportFileXML();
184  break;
185  }
186  }
buildExportFileXML()
build xml export file
buildExportResultFile()
build xml export file
+ Here is the call graph for this function:

◆ buildExportFileXML()

ilTestExport::buildExportFileXML ( )

build xml export file

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

References $DIC, buildQuestionSkillAssignmentList(), exportXHTMLMediaObjects(), getQtiXml(), getQuestionIds(), initXmlExport(), isResultExportingEnabledForTestExport(), ilFileUtils\makeDir(), populateQuestionSetConfigXml(), populateQuestionSkillAssignmentsXml(), populateSkillLevelThresholdsXml(), ilTestResultsToXML\setIncludeRandomTestQuestionsEnabled(), and ilFileUtils\zip().

Referenced by buildExportFile().

1110  : string
1111  {
1112  global $DIC;
1113  $ilBench = $DIC['ilBench'];
1114 
1115  $ilBench->start("TestExport", "buildExportFile");
1116 
1117  $this->initXmlExport();
1118 
1119  include_once("./Services/Xml/classes/class.ilXmlWriter.php");
1120  $this->xml = new ilXmlWriter();
1121 
1122  // set dtd definition
1123  $this->xml->xmlSetDtdDef("<!DOCTYPE Test SYSTEM \"http://www.ilias.uni-koeln.de/download/dtd/ilias_co.dtd\">");
1124 
1125  // set generated comment
1126  $this->xml->xmlSetGenCmt("Export of ILIAS Test " .
1127  $this->test_obj->getId() . " of installation " . $this->inst_id . ".");
1128 
1129  // set xml header
1130  $this->xml->xmlHeader();
1131 
1132  $this->xml->xmlStartTag("ContentObject", array('Type' => 'Test'));
1133 
1134  // create directories
1135  $this->test_obj->createExportDirectory();
1136  include_once "./Services/Utilities/classes/class.ilUtil.php";
1137  ilFileUtils::makeDir($this->export_dir . "/" . $this->subdir);
1138  ilFileUtils::makeDir($this->export_dir . "/" . $this->subdir . "/objects");
1139 
1140  // get Log File
1141  $expDir = $this->test_obj->getExportDirectory();
1142  include_once "./Services/Logging/classes/class.ilLog.php";
1143  $expLog = new ilLog($expDir, "export.log");
1144  $expLog->delete();
1145  $expLog->setLogFormat("");
1146  $expLog->write(date("[y-m-d H:i:s] ") . "Start Export");
1147 
1148  // write qti file
1149  $qti_file = fopen($this->export_dir . "/" . $this->subdir . "/" . $this->qti_filename, "w");
1150  fwrite($qti_file, $this->getQtiXml());
1151  fclose($qti_file);
1152 
1153  // get xml content
1154  $ilBench->start("TestExport", "buildExportFile_getXML");
1155  $this->test_obj->exportPagesXML(
1156  $this->xml,
1157  $this->inst_id,
1158  $this->export_dir . "/" . $this->subdir,
1159  $expLog
1160  );
1161  $ilBench->stop("TestExport", "buildExportFile_getXML");
1162 
1163  $this->populateQuestionSetConfigXml($this->xml);
1164 
1165  $assignmentList = $this->buildQuestionSkillAssignmentList();
1166  $this->populateQuestionSkillAssignmentsXml($this->xml, $assignmentList, $this->getQuestionIds());
1167  $this->populateSkillLevelThresholdsXml($this->xml, $assignmentList);
1168 
1169  $this->xml->xmlEndTag("ContentObject");
1170 
1171  // dump xml document to screen (only for debugging reasons)
1172  /*
1173  echo "<PRE>";
1174  echo htmlentities($this->xml->xmlDumpMem($format));
1175  echo "</PRE>";
1176  */
1177 
1178  // dump xml document to file
1179  $ilBench->start("TestExport", "buildExportFile_dumpToFile");
1180  $this->xml->xmlDumpFile($this->export_dir . "/" . $this->subdir . "/" . $this->filename, false);
1181  $ilBench->stop("TestExport", "buildExportFile_dumpToFile");
1182 
1183  if ($this->isResultExportingEnabledForTestExport() && @file_exists("./Modules/Test/classes/class.ilTestResultsToXML.php")) {
1184  // dump results xml document to file
1185  include_once "./Modules/Test/classes/class.ilTestResultsToXML.php";
1186  $resultwriter = new ilTestResultsToXML($this->test_obj->getTestId(), $this->test_obj->getAnonymity());
1187  $resultwriter->setIncludeRandomTestQuestionsEnabled($this->test_obj->isRandomTest());
1188  $ilBench->start("TestExport", "buildExportFile_results");
1189  $resultwriter->xmlDumpFile($this->export_dir . "/" . $this->subdir . "/" . $this->resultsfile, false);
1190  $ilBench->stop("TestExport", "buildExportFile_results");
1191  }
1192 
1193  // add media objects which were added with tiny mce
1194  $ilBench->start("QuestionpoolExport", "buildExportFile_saveAdditionalMobs");
1195  $this->exportXHTMLMediaObjects($this->export_dir . "/" . $this->subdir);
1196  $ilBench->stop("QuestionpoolExport", "buildExportFile_saveAdditionalMobs");
1197 
1198  // zip the file
1199  $ilBench->start("TestExport", "buildExportFile_zipFile");
1201  $this->export_dir . "/" . $this->subdir,
1202  $this->export_dir . "/" . $this->subdir . ".zip"
1203  );
1204  $ilBench->stop("TestExport", "buildExportFile_zipFile");
1205 
1206  // destroy writer object
1207  $this->xml = null;
1208 
1209  $expLog->write(date("[y-m-d H:i:s] ") . "Finished Export");
1210  $ilBench->stop("TestExport", "buildExportFile");
1211 
1212  return $this->export_dir . "/" . $this->subdir . ".zip";
1213  }
populateQuestionSkillAssignmentsXml(ilXmlWriter $a_xml_writer, ilAssQuestionSkillAssignmentList $assignmentList, $questions)
setIncludeRandomTestQuestionsEnabled(bool $includeRandomTestQuestionsEnabled)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: class.ilLog.php:30
isResultExportingEnabledForTestExport()
global $DIC
Definition: feed.php:28
exportXHTMLMediaObjects($a_export_dir)
populateSkillLevelThresholdsXml(ilXmlWriter $a_xml_writer, ilAssQuestionSkillAssignmentList $assignmentList)
static zip(string $a_dir, string $a_file, bool $compress_content=false)
zips given directory/file into given zip.file
static makeDir(string $a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
populateQuestionSetConfigXml(ilXmlWriter $xmlWriter)
+ 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 191 of file class.ilTestExport.php.

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

Referenced by buildExportFile().

191  : string
192  {
193  global $DIC;
194  $ilBench = $DIC['ilBench'];
195  $log = $DIC['log'];
196 
197  //get Log File
198  $expDir = $this->test_obj->getExportDirectory();
199 
200  // make_directories
201  $this->test_obj->createExportDirectory();
202  include_once "./Services/Utilities/classes/class.ilUtil.php";
203  ilFileUtils::makeDir($this->export_dir);
204 
205  include_once './Services/Logging/classes/class.ilLog.php';
206  $expLog = new ilLog($expDir, "export.log");
207  $expLog->delete();
208  $expLog->setLogFormat("");
209  $expLog->write(date("[y-m-d H:i:s] ") . "Start Export Of Results");
210 
211  $data = $this->exportToCSV($deliver = false);
212  $file = fopen($this->export_dir . "/" . $this->filename, "w");
213  fwrite($file, $data);
214  fclose($file);
215 
216  $excelfile = $this->exportToExcel($deliver = false);
217  @copy($excelfile, $this->export_dir . "/" . str_replace($this->getExtension(), "xlsx", $this->filename));
218  @unlink($excelfile);
219  // end
220  $expLog->write(date("[y-m-d H:i:s] ") . "Finished Export of Results");
221 
222  return $this->export_dir . "/" . $this->filename;
223  }
exportToCSV($deliver=true, $filterby="", $filtertext="", $passedonly=false)
Exports the evaluation data to the CSV file format.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: class.ilLog.php:30
global $DIC
Definition: feed.php:28
$log
Definition: result.php:33
$filename
Definition: buildRTE.php:78
exportToExcel($deliver=true, $filterby="", $filtertext="", $passedonly=false)
Exports the evaluation data to the Microsoft Excel file format.
static makeDir(string $a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
+ 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 1306 of file class.ilTestExport.php.

References $DIC, and $ilDB.

Referenced by buildExportFileXML().

1307  {
1308  global $DIC;
1309  $ilDB = $DIC['ilDB'];
1310 
1311  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionSkillAssignmentList.php';
1312  $assignmentList = new ilAssQuestionSkillAssignmentList($ilDB);
1313  $assignmentList->setParentObjId($this->test_obj->getId());
1314  $assignmentList->loadFromDb();
1315  $assignmentList->loadAdditionalSkillData();
1316 
1317  return $assignmentList;
1318  }
global $DIC
Definition: feed.php:28
+ 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 public

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

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

Referenced by buildExportResultFile().

874  {
875  $this->test_obj->setAccessFilteredParticipantList(
876  $this->test_obj->buildStatisticsAccessFilteredParticipantList()
877  );
878 
879  if (strcmp($this->mode, "aggregated") == 0) {
880  return $this->aggregatedResultsToCSV($deliver);
881  }
882 
883  $rows = array();
884  $datarow = array();
885  $col = 1;
886  if ($this->test_obj->getAnonymity()) {
887  array_push($datarow, $this->lng->txt("counter"));
888  $col++;
889  } else {
890  array_push($datarow, $this->lng->txt("name"));
891  $col++;
892  array_push($datarow, $this->lng->txt("login"));
893  $col++;
894  }
895  $additionalFields = $this->test_obj->getEvaluationAdditionalFields();
896  if (count($additionalFields)) {
897  foreach ($additionalFields as $fieldname) {
898  if (strcmp($fieldname, "exam_id") == 0) {
899  array_push($datarow, $this->lng->txt('exam_id_label'));
900  $col++;
901  continue;
902  }
903  array_push($datarow, $this->lng->txt($fieldname));
904  $col++;
905  }
906  }
907  array_push($datarow, $this->lng->txt("tst_stat_result_resultspoints"));
908  $col++;
909  array_push($datarow, $this->lng->txt("maximum_points"));
910  $col++;
911  array_push($datarow, $this->lng->txt("tst_stat_result_resultsmarks"));
912  $col++;
913  if ($this->test_obj->getECTSOutput()) {
914  array_push($datarow, $this->lng->txt("ects_grade"));
915  $col++;
916  }
917  array_push($datarow, $this->lng->txt("tst_stat_result_qworkedthrough"));
918  $col++;
919  array_push($datarow, $this->lng->txt("tst_stat_result_qmax"));
920  $col++;
921  array_push($datarow, $this->lng->txt("tst_stat_result_pworkedthrough"));
922  $col++;
923  array_push($datarow, $this->lng->txt("tst_stat_result_timeofwork"));
924  $col++;
925  array_push($datarow, $this->lng->txt("tst_stat_result_atimeofwork"));
926  $col++;
927  array_push($datarow, $this->lng->txt("tst_stat_result_firstvisit"));
928  $col++;
929  array_push($datarow, $this->lng->txt("tst_stat_result_lastvisit"));
930  $col++;
931 
932  array_push($datarow, $this->lng->txt("tst_stat_result_mark_median"));
933  $col++;
934  array_push($datarow, $this->lng->txt("tst_stat_result_rank_participant"));
935  $col++;
936  array_push($datarow, $this->lng->txt("tst_stat_result_rank_median"));
937  $col++;
938  array_push($datarow, $this->lng->txt("tst_stat_result_total_participants"));
939  $col++;
940  array_push($datarow, $this->lng->txt("tst_stat_result_median"));
941  $col++;
942  array_push($datarow, $this->lng->txt("tst_tbl_col_started_passes"));
943  $col++;
944  array_push($datarow, $this->lng->txt("tst_tbl_col_finished_passes"));
945  $col++;
946 
947  array_push($datarow, $this->lng->txt("scored_pass"));
948  $col++;
949 
950  array_push($datarow, $this->lng->txt("pass"));
951  $col++;
952 
953  $data = &$this->test_obj->getCompleteEvaluationData(true, $filterby, $filtertext);
954  $headerrow = $datarow;
955  $counter = 1;
956  foreach ($data->getParticipants() as $active_id => $userdata) {
957  $datarow = $headerrow;
958  $remove = false;
959  if ($passedonly) {
960  if ($data->getParticipant($active_id)->getPassed() == false) {
961  $remove = true;
962  }
963  }
964  if (!$remove) {
965  $datarow2 = array();
966  if ($this->test_obj->getAnonymity()) {
967  array_push($datarow2, $counter);
968  } else {
969  array_push($datarow2, $data->getParticipant($active_id)->getName());
970  array_push($datarow2, $data->getParticipant($active_id)->getLogin());
971  }
972  if (count($additionalFields)) {
973  $userfields = ilObjUser::_lookupFields($userdata->getUserID());
974  foreach ($additionalFields as $fieldname) {
975  if (strcmp($fieldname, "gender") == 0) {
976  array_push($datarow2, strlen($userfields[$fieldname]) ? $this->lng->txt('gender_' . $userfields[$fieldname]) : '');
977  } elseif (strcmp($fieldname, "exam_id") == 0) {
978  array_push($datarow2, $userdata->getExamIdFromScoredPass());
979  } else {
980  array_push($datarow2, $userfields[$fieldname]);
981  }
982  }
983  }
984  array_push($datarow2, $data->getParticipant($active_id)->getReached());
985  array_push($datarow2, $data->getParticipant($active_id)->getMaxpoints());
986  array_push($datarow2, $data->getParticipant($active_id)->getMark());
987  if ($this->test_obj->getECTSOutput()) {
988  array_push($datarow2, $data->getParticipant($active_id)->getECTSMark());
989  }
990  array_push($datarow2, $data->getParticipant($active_id)->getQuestionsWorkedThrough());
991  array_push($datarow2, $data->getParticipant($active_id)->getNumberOfQuestions());
992  array_push($datarow2, $data->getParticipant($active_id)->getQuestionsWorkedThroughInPercent() / 100.0);
993  $time = $data->getParticipant($active_id)->getTimeOfWork();
994  $time_seconds = $time;
995  $time_hours = floor($time_seconds / 3600);
996  $time_seconds -= $time_hours * 3600;
997  $time_minutes = floor($time_seconds / 60);
998  $time_seconds -= $time_minutes * 60;
999  array_push($datarow2, sprintf("%02d:%02d:%02d", $time_hours, $time_minutes, $time_seconds));
1000  $time = $data->getParticipant($active_id)->getQuestionsWorkedThrough() ? $data->getParticipant($active_id)->getTimeOfWork() / $data->getParticipant($active_id)->getQuestionsWorkedThrough() : 0;
1001  $time_seconds = $time;
1002  $time_hours = floor($time_seconds / 3600);
1003  $time_seconds -= $time_hours * 3600;
1004  $time_minutes = floor($time_seconds / 60);
1005  $time_seconds -= $time_minutes * 60;
1006  array_push($datarow2, sprintf("%02d:%02d:%02d", $time_hours, $time_minutes, $time_seconds));
1007 
1008  $fv = $data->getParticipant($active_id)->getFirstVisit();
1009  $lv = $data->getParticipant($active_id)->getLastVisit();
1010  foreach (array($fv, $lv) as $ts) {
1011  if ($ts) {
1013  array_push($datarow2, $visit);
1014  } else {
1015  array_push($datarow2, "");
1016  }
1017  }
1018 
1019  $median = $data->getStatistics()->getStatistics()->median();
1020  $pct = $data->getParticipant($active_id)->getMaxpoints() ? $median / $data->getParticipant($active_id)->getMaxpoints() * 100.0 : 0;
1021  $mark = $this->test_obj->mark_schema->getMatchingMark($pct);
1022  $mark_short_name = "";
1023  if (is_object($mark)) {
1024  $mark_short_name = $mark->getShortName();
1025  }
1026  array_push($datarow2, $mark_short_name);
1027  array_push($datarow2, $data->getStatistics()->getStatistics()->rank($data->getParticipant($active_id)->getReached()));
1028  array_push($datarow2, $data->getStatistics()->getStatistics()->rank_median());
1029  array_push($datarow2, $data->getStatistics()->getStatistics()->count());
1030  array_push($datarow2, $median);
1031 
1032  array_push($datarow2, $data->getParticipant($active_id)->getPassCount());
1033  array_push($datarow2, $data->getParticipant($active_id)->getFinishedPasses());
1034  if ($this->test_obj->getPassScoring() == SCORE_BEST_PASS) {
1035  array_push($datarow2, $data->getParticipant($active_id)->getBestPass() + 1);
1036  } else {
1037  array_push($datarow2, $data->getParticipant($active_id)->getLastPass() + 1);
1038  }
1039  for ($pass = 0; $pass <= $data->getParticipant($active_id)->getLastPass(); $pass++) {
1040  $finishdate = ilObjTest::lookupPassResultsUpdateTimestamp($active_id, $pass);
1041  if ($finishdate > 0) {
1042  if ($pass > 0) {
1043  for ($i = 1; $i < $col - 1; $i++) {
1044  array_push($datarow2, "");
1045  array_push($datarow, "");
1046  }
1047  array_push($datarow, "");
1048  }
1049  array_push($datarow2, $pass + 1);
1050  if (is_object($data->getParticipant($active_id)) && is_array($evaluated_questions = $data->getParticipant($active_id)->getQuestions($pass))) {
1051  $questions = $this->orderQuestions($evaluated_questions);
1052  foreach ($questions as $question) {
1053  $question_data = $data->getParticipant($active_id)->getPass($pass)->getAnsweredQuestionByQuestionId($question["id"]);
1054  if (is_null($question_data)) {
1055  $question_data = ['reached' => 0];
1056  }
1057  array_push($datarow2, $question_data["reached"]);
1058  array_push($datarow, preg_replace("/<.*?>/", "", $data->getQuestionTitle($question["id"])));
1059  }
1060  }
1061  if ($this->test_obj->isRandomTest() ||
1062  $counter == 1 && $pass == 0) {
1063  array_push($rows, $datarow);
1064  }
1065  $datarow = array();
1066  array_push($rows, $datarow2);
1067  $datarow2 = array();
1068  }
1069  }
1070  $counter++;
1071  }
1072  }
1073  $csv = "";
1074  $separator = ";";
1075  foreach ($rows as $evalrow) {
1076  $csvrow = &$this->test_obj->processCSVRow($evalrow, true, $separator);
1077  $csv .= join($separator, $csvrow) . "\n";
1078  }
1079  if ($deliver) {
1080  ilUtil::deliverData($csv, ilFileUtils::getASCIIFilename($this->test_obj->getTitle() . "_results.csv"));
1081  exit;
1082  } else {
1083  return $csv;
1084  }
1085  }
exit
Definition: login.php:28
static lookupPassResultsUpdateTimestamp($active_id, $pass)
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
orderQuestions(array $questions)
static deliverData(string $a_data, string $a_filename, string $mime="application/octet-stream")
const IL_CAL_UNIX
static getASCIIFilename(string $a_filename)
static _lookupFields(int $a_user_id)
lookup fields (deprecated; use more specific methods instead)
$rows
Definition: xhr_table.php:10
aggregatedResultsToCSV($deliver=true)
Exports the aggregated results to CSV.
const SCORE_BEST_PASS
$i
Definition: metadata.php:41
+ 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

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

References $data, $id, ilObjTest\_instanciateQuestion(), assQuestion\_instantiateQuestion(), ilObjUser\_lookupFields(), aggregatedResultsToExcel(), getAccessFilteredParticipantList(), ilFileUtils\getASCIIFilename(), IL_CAL_UNIX, ilFileUtils\ilTempnam(), assQuestion\instantiateQuestion(), ILIAS\Repository\lng(), ilObjTest\lookupPassResultsUpdateTimestamp(), orderQuestions(), and SCORE_BEST_PASS.

Referenced by buildExportResultFile().

346  {
347  $this->test_obj->setAccessFilteredParticipantList($this->getAccessFilteredParticipantList());
348 
349  if (strcmp($this->mode, "aggregated") == 0) {
350  return $this->aggregatedResultsToExcel($deliver);
351  }
352 
353  require_once 'Modules/TestQuestionPool/classes/class.ilAssExcelFormatHelper.php';
354 
355  $worksheet = new ilAssExcelFormatHelper();
356  $worksheet->addSheet($this->lng->txt('tst_results'));
357 
358  $additionalFields = $this->test_obj->getEvaluationAdditionalFields();
359 
360  $row = 1;
361  $col = 0;
362 
363  if ($this->test_obj->getAnonymity()) {
364  $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('counter'));
365  } else {
366  $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('name'));
367  $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('login'));
368  }
369 
370  if (count($additionalFields)) {
371  foreach ($additionalFields as $fieldname) {
372  if (strcmp($fieldname, "exam_id") == 0) {
373  $worksheet->setFormattedExcelTitle(
374  $worksheet->getColumnCoord($col++) . $row,
375  $this->lng->txt('exam_id_label')
376  );
377  continue;
378  }
379  $worksheet->setFormattedExcelTitle(
380  $worksheet->getColumnCoord($col++) . $row,
381  $this->lng->txt($fieldname)
382  );
383  }
384  }
385 
386  $worksheet->setFormattedExcelTitle(
387  $worksheet->getColumnCoord($col++) . $row,
388  $this->lng->txt('tst_stat_result_resultspoints')
389  );
390  $worksheet->setFormattedExcelTitle(
391  $worksheet->getColumnCoord($col++) . $row,
392  $this->lng->txt('maximum_points')
393  );
394  $worksheet->setFormattedExcelTitle(
395  $worksheet->getColumnCoord($col++) . $row,
396  $this->lng->txt('tst_stat_result_resultsmarks')
397  );
398 
399  if ($this->test_obj->getECTSOutput()) {
400  $worksheet->setFormattedExcelTitle(
401  $worksheet->getColumnCoord($col++) . $row,
402  $this->lng->txt('ects_grade')
403  );
404  }
405 
406  $worksheet->setFormattedExcelTitle(
407  $worksheet->getColumnCoord($col++) . $row,
408  $this->lng->txt('tst_stat_result_qworkedthrough')
409  );
410  $worksheet->setFormattedExcelTitle(
411  $worksheet->getColumnCoord($col++) . $row,
412  $this->lng->txt('tst_stat_result_qmax')
413  );
414  $worksheet->setFormattedExcelTitle(
415  $worksheet->getColumnCoord($col++) . $row,
416  $this->lng->txt('tst_stat_result_pworkedthrough')
417  );
418  $worksheet->setFormattedExcelTitle(
419  $worksheet->getColumnCoord($col++) . $row,
420  $this->lng->txt('tst_stat_result_timeofwork')
421  );
422  $worksheet->setFormattedExcelTitle(
423  $worksheet->getColumnCoord($col++) . $row,
424  $this->lng->txt('tst_stat_result_atimeofwork')
425  );
426  $worksheet->setFormattedExcelTitle(
427  $worksheet->getColumnCoord($col++) . $row,
428  $this->lng->txt('tst_stat_result_firstvisit')
429  );
430  $worksheet->setFormattedExcelTitle(
431  $worksheet->getColumnCoord($col++) . $row,
432  $this->lng->txt('tst_stat_result_lastvisit')
433  );
434  $worksheet->setFormattedExcelTitle(
435  $worksheet->getColumnCoord($col++) . $row,
436  $this->lng->txt('tst_stat_result_mark_median')
437  );
438  $worksheet->setFormattedExcelTitle(
439  $worksheet->getColumnCoord($col++) . $row,
440  $this->lng->txt('tst_stat_result_rank_participant')
441  );
442  $worksheet->setFormattedExcelTitle(
443  $worksheet->getColumnCoord($col++) . $row,
444  $this->lng->txt('tst_stat_result_rank_median')
445  );
446  $worksheet->setFormattedExcelTitle(
447  $worksheet->getColumnCoord($col++) . $row,
448  $this->lng->txt('tst_stat_result_total_participants')
449  );
450  $worksheet->setFormattedExcelTitle(
451  $worksheet->getColumnCoord($col++) . $row,
452  $this->lng->txt('tst_stat_result_median')
453  );
454  $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('tst_tbl_col_started_passes'));
455  $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('tst_tbl_col_finished_passes'));
456  $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('tst_tbl_col_started_passes'));
457  $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('tst_tbl_col_finished_passes'));
458  $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('scored_pass'));
459  $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('pass'));
460 
461  $worksheet->setBold('A' . $row . ':' . $worksheet->getColumnCoord($col - 1) . $row);
462 
463  $counter = 1;
464  $data = $this->test_obj->getCompleteEvaluationData(true, $filterby, $filtertext);
465  $firstrowwritten = false;
466  foreach ($data->getParticipants() as $active_id => $userdata) {
467  if ($passedonly && $data->getParticipant($active_id)->getPassed() == false) {
468  continue;
469  }
470 
471  $row++;
472  $col = 0;
473 
474  // each participant gets an own row for question column headers
475  if ($this->test_obj->isRandomTest() && $firstrowwritten) {
476  $row++;
477  }
478 
479  if ($this->test_obj->getAnonymity()) {
480  $worksheet->setCell($row, $col++, $counter);
481  } else {
482  $worksheet->setCell($row, $col++, $data->getParticipant($active_id)->getName());
483  $worksheet->setCell($row, $col++, $data->getParticipant($active_id)->getLogin());
484  }
485 
486  if (count($additionalFields)) {
487  $userfields = ilObjUser::_lookupFields($userdata->getUserId());
488  foreach ($additionalFields as $fieldname) {
489  if (strcmp($fieldname, 'gender') == 0) {
490  $worksheet->setCell($row, $col++, strlen($userfields[$fieldname]) ? $this->lng->txt('gender_' . $userfields[$fieldname]) : '');
491  } elseif (strcmp($fieldname, "exam_id") == 0) {
492  $worksheet->setCell($row, $col++, $userdata->getExamIdFromScoredPass());
493  } else {
494  $worksheet->setCell($row, $col++, $userfields[$fieldname]);
495  }
496  }
497  }
498 
499  $worksheet->setCell($row, $col++, $data->getParticipant($active_id)->getReached());
500  $worksheet->setCell($row, $col++, $data->getParticipant($active_id)->getMaxpoints());
501  $worksheet->setCell($row, $col++, $data->getParticipant($active_id)->getMark());
502 
503  if ($this->test_obj->getECTSOutput()) {
504  $worksheet->setCell($row, $col++, $data->getParticipant($active_id)->getECTSMark());
505  }
506 
507  $worksheet->setCell($row, $col++, $data->getParticipant($active_id)->getQuestionsWorkedThrough());
508  $worksheet->setCell($row, $col++, $data->getParticipant($active_id)->getNumberOfQuestions());
509  $worksheet->setCell(
510  $row,
511  $col++,
512  $data->getParticipant($active_id)->getQuestionsWorkedThroughInPercent() . '%'
513  );
514 
515  $time = $data->getParticipant($active_id)->getTimeOfWork();
516  $time_seconds = $time;
517  $time_hours = floor($time_seconds / 3600);
518  $time_seconds -= $time_hours * 3600;
519  $time_minutes = floor($time_seconds / 60);
520  $time_seconds -= $time_minutes * 60;
521  $worksheet->setCell($row, $col++, sprintf("%02d:%02d:%02d", $time_hours, $time_minutes, $time_seconds));
522  $time = $data->getParticipant($active_id)->getQuestionsWorkedThrough() ? $data->getParticipant($active_id)->getTimeOfWork() / $data->getParticipant($active_id)->getQuestionsWorkedThrough() : 0;
523  $time_seconds = $time;
524  $time_hours = floor($time_seconds / 3600);
525  $time_seconds -= $time_hours * 3600;
526  $time_minutes = floor($time_seconds / 60);
527  $time_seconds -= $time_minutes * 60;
528  $worksheet->setCell($row, $col++, sprintf("%02d:%02d:%02d", $time_hours, $time_minutes, $time_seconds));
529  $worksheet->setCell(
530  $row,
531  $col++,
532  new ilDateTime($data->getParticipant($active_id)->getFirstVisit(), IL_CAL_UNIX)
533  );
534  $worksheet->setCell(
535  $row,
536  $col++,
537  new ilDateTime($data->getParticipant($active_id)->getLastVisit(), IL_CAL_UNIX)
538  );
539 
540  $median = $data->getStatistics()->getStatistics()->median();
541  $pct = $data->getParticipant($active_id)->getMaxpoints() ? $median / $data->getParticipant($active_id)->getMaxpoints() * 100.0 : 0;
542  $mark = $this->test_obj->mark_schema->getMatchingMark($pct);
543  $mark_short_name = "";
544 
545  if (is_object($mark)) {
546  $mark_short_name = $mark->getShortName();
547  }
548 
549  $worksheet->setCell($row, $col++, $mark_short_name);
550  $worksheet->setCell(
551  $row,
552  $col++,
553  $data->getStatistics()->getStatistics()->rank($data->getParticipant($active_id)->getReached())
554  );
555  $worksheet->setCell($row, $col++, $data->getStatistics()->getStatistics()->rank_median());
556  $worksheet->setCell($row, $col++, $data->getStatistics()->getStatistics()->count());
557  $worksheet->setCell($row, $col++, $median);
558  $worksheet->setCell($row, $col++, $data->getParticipant($active_id)->getPassCount());
559  $worksheet->setCell($row, $col++, $data->getParticipant($active_id)->getFinishedPasses());
560  if ($this->test_obj->getPassScoring() == SCORE_BEST_PASS) {
561  $worksheet->setCell($row, $col++, $data->getParticipant($active_id)->getBestPass() + 1);
562  } else {
563  $worksheet->setCell($row, $col++, $data->getParticipant($active_id)->getLastPass() + 1);
564  }
565 
566  $startcol = $col;
567 
568  for ($pass = 0; $pass <= $data->getParticipant($active_id)->getLastPass(); $pass++) {
569  $col = $startcol;
570  $finishdate = ilObjTest::lookupPassResultsUpdateTimestamp($active_id, $pass);
571  if ($finishdate > 0) {
572  if ($pass > 0) {
573  $row++;
574  if ($this->test_obj->isRandomTest()) {
575  $row++;
576  }
577  }
578  $worksheet->setCell($row, $col++, $pass + 1);
579  if (is_object($data->getParticipant($active_id)) && is_array($data->getParticipant($active_id)->getQuestions($pass))) {
580  $evaluated_questions = $data->getParticipant($active_id)->getQuestions($pass);
581  $questions = $this->orderQuestions($evaluated_questions);
582 
583  foreach ($questions as $question) {
584  $question_data = $data->getParticipant($active_id)->getPass($pass)->getAnsweredQuestionByQuestionId($question["id"]);
585  if (is_null($question_data)) {
586  $question_data = ['reached' => 0];
587  }
588  $worksheet->setCell($row, $col, $question_data["reached"]);
589  if ($this->test_obj->isRandomTest()) {
590  // random test requires question headers for every participant
591  // and we allready skipped a row for that reason ( --> row - 1)
592  $worksheet->setFormattedExcelTitle(
593  $worksheet->getColumnCoord($col) . ($row - 1),
594  preg_replace("/<.*?>/", "", $data->getQuestionTitle($question["id"]))
595  );
596  } else {
597  if ($pass == 0 && !$firstrowwritten) {
598  $worksheet->setFormattedExcelTitle(
599  $worksheet->getColumnCoord($col) . 1,
600  $data->getQuestionTitle($question["id"])
601  );
602  }
603  }
604  $col++;
605  }
606  $firstrowwritten = true;
607  }
608  }
609  }
610  $counter++;
611  }
612 
613  if ($this->test_obj->getExportSettingsSingleChoiceShort() && !$this->test_obj->isRandomTest() && $this->test_obj->hasSingleChoiceQuestions()) {
614  // special tab for single choice tests
615  $titles = $this->test_obj->getQuestionTitlesAndIndexes();
616  $positions = array();
617  $pos = 0;
618  $row = 1;
619  foreach ($titles as $id => $title) {
620  $positions[$id] = $pos;
621  $pos++;
622  }
623 
624  $usernames = array();
625  $participantcount = count($data->getParticipants());
626  $allusersheet = false;
627  $pages = 0;
628 
629  $worksheet->addSheet($this->lng->txt('eval_all_users'));
630 
631  $col = 0;
632  $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('name'));
633  $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('login'));
634  if (count($additionalFields)) {
635  foreach ($additionalFields as $fieldname) {
636  if (strcmp($fieldname, "matriculation") == 0) {
637  $worksheet->setFormattedExcelTitle(
638  $worksheet->getColumnCoord($col++) . $row,
639  $this->lng->txt('matriculation')
640  );
641  }
642  if (strcmp($fieldname, "exam_id") == 0) {
643  $worksheet->setFormattedExcelTitle(
644  $worksheet->getColumnCoord($col++) . $row,
645  $this->lng->txt('exam_id_label')
646  );
647  }
648  }
649  }
650  $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('test'));
651  foreach ($titles as $title) {
652  $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $title);
653  }
654  $worksheet->setBold('A' . $row . ':' . $worksheet->getColumnCoord($col - 1) . $row);
655 
656  $row++;
657  foreach ($data->getParticipants() as $active_id => $userdata) {
658  $username = (!is_null($userdata) && $userdata->getName()) ? $userdata->getName() : "ID $active_id";
659  if (array_key_exists($username, $usernames)) {
660  $usernames[$username]++;
661  $username .= " ($usernames[$username])";
662  } else {
663  $usernames[$username] = 1;
664  }
665  $col = 0;
666  $worksheet->setCell($row, $col++, $username);
667  $worksheet->setCell($row, $col++, $userdata->getLogin());
668  if (count($additionalFields)) {
669  $userfields = ilObjUser::_lookupFields($userdata->getUserID());
670  foreach ($additionalFields as $fieldname) {
671  if (strcmp($fieldname, "matriculation") == 0) {
672  if (strlen($userfields[$fieldname])) {
673  $worksheet->setCell($row, $col++, $userfields[$fieldname]);
674  } else {
675  $col++;
676  }
677  }
678  if (strcmp($fieldname, "exam_id") == 0) {
679  if (strlen($userfields[$fieldname])) {
680  $worksheet->setCell($row, $col++, $userdata->getExamIdFromScoredPass());
681  } else {
682  $col++;
683  }
684  }
685  }
686  }
687  $worksheet->setCell($row, $col++, $this->test_obj->getTitle());
688  $pass = $userdata->getScoredPass();
689  if (is_object($userdata) && is_array($userdata->getQuestions($pass))) {
690  foreach ($userdata->getQuestions($pass) as $question) {
691  $objQuestion = assQuestion::_instantiateQuestion($question["id"]);
692  if (is_object($objQuestion) && strcmp(
693  $objQuestion->getQuestionType(),
694  'assSingleChoice'
695  ) == 0) {
696  $solution = $objQuestion->getSolutionValues($active_id, $pass);
697  $pos = $positions[$question["id"]];
698  $selectedanswer = "x";
699  foreach ($objQuestion->getAnswers() as $id => $answer) {
700  if (strlen($solution[0]["value1"]) && $id == $solution[0]["value1"]) {
701  $selectedanswer = $answer->getAnswertext();
702  }
703  }
704  $worksheet->setCell($row, $col + $pos, $selectedanswer);
705  }
706  }
707  }
708  $row++;
709  }
710 
711  if ($this->test_obj->isSingleChoiceTestWithoutShuffle()) {
712  // special tab for single choice tests without shuffle option
713  $pos = 0;
714  $row = 1;
715  $usernames = array();
716  $allusersheet = false;
717  $pages = 0;
718 
719  $worksheet->addSheet($this->lng->txt('eval_all_users') . ' (2)');
720 
721  $col = 0;
722  $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('name'));
723  $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('login'));
724  if (count($additionalFields)) {
725  foreach ($additionalFields as $fieldname) {
726  if (strcmp($fieldname, "matriculation") == 0) {
727  $worksheet->setFormattedExcelTitle(
728  $worksheet->getColumnCoord($col++) . $row,
729  $this->lng->txt('matriculation')
730  );
731  }
732  if (strcmp($fieldname, "exam_id") == 0) {
733  $worksheet->setFormattedExcelTitle(
734  $worksheet->getColumnCoord($col++) . $row,
735  $this->lng->txt('exam_id_label')
736  );
737  }
738  }
739  }
740  $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt('test'));
741  foreach ($titles as $title) {
742  $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $title);
743  }
744  $worksheet->setBold('A' . $row . ':' . $worksheet->getColumnCoord($col - 1) . $row);
745 
746  $row++;
747  foreach ($data->getParticipants() as $active_id => $userdata) {
748  $username = (!is_null($userdata) && $userdata->getName()) ? $userdata->getName() : "ID $active_id";
749  if (array_key_exists($username, $usernames)) {
750  $usernames[$username]++;
751  $username .= " ($usernames[$username])";
752  } else {
753  $usernames[$username] = 1;
754  }
755  $col = 0;
756  $worksheet->setCell($row, $col++, $username);
757  $worksheet->setCell($row, $col++, $userdata->getLogin());
758  if (count($additionalFields)) {
759  $userfields = ilObjUser::_lookupFields($userdata->getUserId());
760  foreach ($additionalFields as $fieldname) {
761  if (strcmp($fieldname, "matriculation") == 0) {
762  if (strlen($userfields[$fieldname])) {
763  $worksheet->setCell($row, $col++, $userfields[$fieldname]);
764  } else {
765  $col++;
766  }
767  }
768  if (strcmp($fieldname, "exam_id") == 0) {
769  if (strlen($userfields[$fieldname])) {
770  $worksheet->setCell($row, $col++, $userdata->getExamIdFromScoredPass());
771  } else {
772  $col++;
773  }
774  }
775  }
776  }
777  $worksheet->setCell($row, $col++, $this->test_obj->getTitle());
778  $pass = $userdata->getScoredPass();
779  if (is_object($userdata) && is_array($userdata->getQuestions($pass))) {
780  foreach ($userdata->getQuestions($pass) as $question) {
781  $objQuestion = ilObjTest::_instanciateQuestion($question["aid"]);
782  if (is_object($objQuestion) && strcmp(
783  $objQuestion->getQuestionType(),
784  'assSingleChoice'
785  ) == 0) {
786  $solution = $objQuestion->getSolutionValues($active_id, $pass);
787  $pos = $positions[$question["aid"]];
788  $selectedanswer = chr(65 + $solution[0]["value1"]);
789  $worksheet->setCell($row, $col + $pos, $selectedanswer);
790  }
791  }
792  }
793  $row++;
794  }
795  }
796  } else {
797  // test participant result export
798  $usernames = array();
799  $participantcount = count($data->getParticipants());
800  $allusersheet = false;
801  $pages = 0;
802  foreach ($data->getParticipants() as $active_id => $userdata) {
803  $username = (!is_null($userdata) && $userdata->getName())
804  ? $userdata->getName()
805  : "ID $active_id";
806  $username = mb_substr($username, 0, 26);
807  $username_to_lower = strtolower($username);
808  if (array_key_exists($username_to_lower, $usernames)) {
809  $usernames[$username_to_lower]++;
810  $username .= " (" . $usernames[$username_to_lower] . ")";
811  } else {
812  $usernames[$username_to_lower] = 0;
813  }
814 
815  if ($participantcount > 250) {
816  if (!$allusersheet || ($pages - 1) < floor($row / 64000)) {
817  $worksheet->addSheet($this->lng->txt("eval_all_users") . (($pages > 0) ? " (" . ($pages + 1) . ")" : ""));
818  $allusersheet = true;
819  $row = 1;
820  $pages++;
821  }
822  } else {
823  $resultsheet = $worksheet->addSheet($username);
824  }
825 
826  $pass = $userdata->getScoredPass();
827  $row = ($allusersheet) ? $row : 1;
828  $worksheet->setCell(
829  $row,
830  0,
831  sprintf($this->lng->txt("tst_result_user_name_pass"), $pass + 1, $userdata->getName())
832  );
833  $worksheet->setBold($worksheet->getColumnCoord(0) . $row);
834  $row += 2;
835  if (is_object($userdata) && is_array($userdata->getQuestions($pass))) {
836  foreach ($userdata->getQuestions($pass) as $question) {
837  require_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
838  $question = assQuestion::instantiateQuestion($question["id"]);
839  if (is_object($question)) {
840  $row = $question->setExportDetailsXLS($worksheet, $row, $active_id, $pass);
841  }
842  }
843  }
844  }
845  }
846 
847  if ($deliver) {
848  $testname = $this->test_obj->getTitle();
849  switch ($this->mode) {
850  case 'results':
851  $testname .= '_results';
852  break;
853  }
854  $testname = ilFileUtils::getASCIIFilename(preg_replace("/\s/", "_", $testname)) . '.xlsx';
855  $worksheet->sendToClient($testname);
856  }
857  $excelfile = ilFileUtils::ilTempnam();
858  $worksheet->writeToFile($excelfile);
859  return $excelfile . '.xlsx';
860  }
aggregatedResultsToExcel($deliver=true)
Exports the aggregated results to the Microsoft Excel file format.
static lookupPassResultsUpdateTimestamp($active_id, $pass)
orderQuestions(array $questions)
const IL_CAL_UNIX
static _instanciateQuestion($question_id)
Creates an instance of a question with a given question id.
static getASCIIFilename(string $a_filename)
static instantiateQuestion(int $question_id)
static _lookupFields(int $a_user_id)
lookup fields (deprecated; use more specific methods instead)
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
static _instantiateQuestion(int $question_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
const SCORE_BEST_PASS
+ 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 1246 of file class.ilTestExport.php.

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

Referenced by buildExportFileXML().

1247  {
1248  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1249 
1250  $mobs = ilObjMediaObject::_getMobsOfObject("tst:html", $this->test_obj->getId());
1251  foreach ($mobs as $mob) {
1252  if (ilObjMediaObject::_exists($mob)) {
1253  $mob_obj = new ilObjMediaObject($mob);
1254  $mob_obj->exportFiles($a_export_dir);
1255  unset($mob_obj);
1256  }
1257  }
1258  foreach ($this->getQuestionIds() as $question_id) {
1259  $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $question_id);
1260  foreach ($mobs as $mob) {
1261  if (ilObjMediaObject::_exists($mob)) {
1262  $mob_obj = new ilObjMediaObject($mob);
1263  $mob_obj->exportFiles($a_export_dir);
1264  unset($mob_obj);
1265  }
1266  }
1267  }
1268  }
$mobs
Definition: imgupload.php:70
static _exists(int $id, bool $reference=false, ?string $type=null)
static _getMobsOfObject(string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAccessFilteredParticipantList()

ilTestExport::getAccessFilteredParticipantList ( )
Returns
ilTestParticipantList

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

References getForcedAccessFilteredParticipantList().

Referenced by exportToExcel().

146  {
149  }
150 
151  return $this->test_obj->buildStatisticsAccessFilteredParticipantList();
152  }
getForcedAccessFilteredParticipantList()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getExtension()

ilTestExport::getExtension ( )

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

Referenced by __construct(), and buildExportResultFile().

154  : string
155  {
156  switch ($this->mode) {
157  case "results":
158  return "csv"; break;
159  default:
160  return "xml"; break;
161  }
162  }
+ Here is the caller graph for this function:

◆ getForcedAccessFilteredParticipantList()

ilTestExport::getForcedAccessFilteredParticipantList ( )
Returns
ilTestParticipantList

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

References $forcedAccessFilteredParticipantList.

Referenced by getAccessFilteredParticipantList().

+ Here is the caller graph for this function:

◆ getInstId()

ilTestExport::getInstId ( )

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

References $inst_id.

165  {
166  return $this->inst_id;
167  }

◆ getQtiXml()

ilTestExport::getQtiXml ( )
protected

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

References getQuestionsQtiXml().

Referenced by buildExportFileXML().

1218  {
1219  $tstQtiXml = $this->test_obj->toXML();
1220  $qstQtiXml = $this->getQuestionsQtiXml();
1221 
1222  if (strpos($tstQtiXml, "</section>") !== false) {
1223  $qtiXml = str_replace("</section>", "$qstQtiXml</section>", $tstQtiXml);
1224  } else {
1225  $qtiXml = str_replace("<section ident=\"1\"/>", "<section ident=\"1\">\n$qstQtiXml</section>", $tstQtiXml);
1226  }
1227 
1228  return $qtiXml;
1229  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getQuestionIds()

ilTestExport::getQuestionIds ( )
abstractprotected

Referenced by buildExportFileXML(), exportXHTMLMediaObjects(), and orderQuestions().

+ Here is the caller graph for this function:

◆ getQuestionQtiXml()

ilTestExport::getQuestionQtiXml (   $questionId)
protected

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

References $xml, and assQuestion\_instantiateQuestion().

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

1234  {
1235  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
1236  $questionOBJ = assQuestion::_instantiateQuestion($questionId);
1237  $xml = $questionOBJ->toXML(false);
1238 
1239  // still neccessary? there is an include header flag!?
1240  $xml = preg_replace("/<questestinterop>/", "", $xml);
1241  $xml = preg_replace("/<\/questestinterop>/", "", $xml);
1242 
1243  return $xml;
1244  }
$xml
Definition: metadata.php:351
static _instantiateQuestion(int $question_id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getQuestionsQtiXml()

ilTestExport::getQuestionsQtiXml ( )
abstractprotected

Referenced by getQtiXml().

+ Here is the caller graph for this function:

◆ initXmlExport()

ilTestExport::initXmlExport ( )
abstractprotected

Referenced by buildExportFileXML(), and orderQuestions().

+ Here is the caller graph for this function:

◆ isResultExportingEnabledForTestExport()

ilTestExport::isResultExportingEnabledForTestExport ( )
Returns
boolean

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

References $resultExportingEnabledForTestExport.

Referenced by buildExportFileXML().

113  : bool
114  {
116  }
+ Here is the caller graph for this function:

◆ orderQuestions()

ilTestExport::orderQuestions ( array  $questions)
protected

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

References Vendor\Package\$a, Vendor\Package\$b, ILIAS\LTI\ToolProvider\$key, getQuestionIds(), and initXmlExport().

Referenced by exportToCSV(), and exportToExcel().

1088  : array
1089  {
1090  $key = $this->test_obj->isRandomTest() ? 'qid' : 'sequence';
1091  usort(
1092  $questions,
1093  function ($a, $b) use ($key) {
1094  if (isset($a[$key], $b[$key]) && $a[$key] > $b[$key]) {
1095  return 1;
1096  }
1097  return -1;
1098  }
1099  );
1100  return $questions;
1101  }
string $key
Consumer key/client ID value.
Definition: System.php:193
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ populateQuestionSetConfigXml()

ilTestExport::populateQuestionSetConfigXml ( ilXmlWriter  $xmlWriter)
abstractprotected

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
ilAssQuestionSkillAssignmentList$assignmentList
$questions

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

Referenced by buildExportFileXML().

1276  {
1277  require_once 'Modules/TestQuestionPool/classes/questions/class.ilAssQuestionSkillAssignmentExporter.php';
1278  $skillQuestionAssignmentExporter = new ilAssQuestionSkillAssignmentExporter();
1279  $skillQuestionAssignmentExporter->setXmlWriter($a_xml_writer);
1280  $skillQuestionAssignmentExporter->setQuestionIds($questions);
1281  $skillQuestionAssignmentExporter->setAssignmentList($assignmentList);
1282  $skillQuestionAssignmentExporter->export();
1283  }
+ Here is the caller graph for this function:

◆ populateSkillLevelThresholdsXml()

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

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

References $DIC, and $ilDB.

Referenced by buildExportFileXML().

1286  {
1287  global $DIC;
1288  $ilDB = $DIC['ilDB'];
1289 
1290  require_once 'Modules/Test/classes/class.ilTestSkillLevelThresholdList.php';
1291  $thresholdList = new ilTestSkillLevelThresholdList($ilDB);
1292  $thresholdList->setTestId($this->test_obj->getTestId());
1293  $thresholdList->loadFromDb();
1294 
1295  require_once 'Modules/Test/classes/class.ilTestSkillLevelThresholdExporter.php';
1296  $skillLevelThresholdExporter = new ilTestSkillLevelThresholdExporter();
1297  $skillLevelThresholdExporter->setXmlWriter($a_xml_writer);
1298  $skillLevelThresholdExporter->setAssignmentList($assignmentList);
1299  $skillLevelThresholdExporter->setThresholdList($thresholdList);
1300  $skillLevelThresholdExporter->export();
1301  }
global $DIC
Definition: feed.php:28
+ Here is the caller graph for this function:

◆ setForcedAccessFilteredParticipantList()

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

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

References $forcedAccessFilteredParticipantList.

138  {
139  $this->forcedAccessFilteredParticipantList = $forcedAccessFilteredParticipantList;
140  }

◆ setResultExportingEnabledForTestExport()

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

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

122  {
123  $this->resultExportingEnabledForTestExport = $resultExprtingEnabledForTestExport;
124  }

Field Documentation

◆ $db

ilTestExport::$db

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

◆ $err

ilTestExport::$err

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

◆ $export_dir

string ilTestExport::$export_dir
private

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

◆ $forcedAccessFilteredParticipantList

ilTestExport::$forcedAccessFilteredParticipantList = null
protected

◆ $ilias

ilTestExport::$ilias

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

Referenced by __construct().

◆ $inst_id

ilTestExport::$inst_id

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

Referenced by getInstId().

◆ $lng

ilTestExport::$lng
private

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

Referenced by __construct().

◆ $mode

ilTestExport::$mode

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

◆ $qti_filename

string ilTestExport::$qti_filename
private

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

◆ $resultExportingEnabledForTestExport

ilTestExport::$resultExportingEnabledForTestExport = false
protected

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

Referenced by isResultExportingEnabledForTestExport().

◆ $resultsfile

ilTestExport::$resultsfile
private

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

◆ $subdir

string ilTestExport::$subdir
private

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

◆ $test_obj

ilTestExport::$test_obj

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


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