ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilTestExport Class Reference

Export class for tests. More...

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

Public Member Functions

 __construct (public ilObjTest $test_obj, public string $mode="xml")
 
 isResultExportingEnabledForTestExport ()
 
 setResultExportingEnabledForTestExport (bool $resultExprtingEnabledForTestExport)
 
 getForcedAccessFilteredParticipantList ()
 
 setForcedAccessFilteredParticipantList (ilTestParticipantList $forcedAccessFilteredParticipantList)
 
 getAccessFilteredParticipantList ()
 
 getExtension ()
 
 getInstId ()
 
 buildExportFile ()
 
 buildExportResultFile ()
 
 buildExportFileXML ()
 
 exportXHTMLMediaObjects ($a_export_dir)
 

Protected Member Functions

 initXmlExport ()
 
 getQuestionIds ()
 
 populateQuestionSetConfigXml (ilXmlWriter $xmlWriter)
 
 getQtiXml ()
 
 getQuestionsQtiXml ()
 
 getQuestionQtiXml ($questionId)
 
 populateQuestionSkillAssignmentsXml (ilXmlWriter $a_xml_writer, ilAssQuestionSkillAssignmentList $assignmentList, array $questions)
 
 populateSkillLevelThresholdsXml (ilXmlWriter $a_xml_writer, ilAssQuestionSkillAssignmentList $assignmentList)
 
 buildQuestionSkillAssignmentList ()
 

Protected Attributes

bool $resultExportingEnabledForTestExport = false
 
ilTestParticipantList $forcedAccessFilteredParticipantList = null
 
ilBenchmark $bench
 
ilErrorHandling $err
 
ilDBInterface $db
 
ILIAS $ilias
 
string $inst_id
 

Private Attributes

string $export_dir
 
string $subdir
 
string $qti_filename
 
string $filename
 
string $resultsfile
 
ilXmlWriter $xml
 
ilLanguage $lng
 
ResourceStorage $irss
 

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 36 of file class.ilTestExport.php.

Constructor & Destructor Documentation

◆ __construct()

ilTestExport::__construct ( public ilObjTest  $test_obj,
public string  $mode = "xml" 
)

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

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

62  {
63  global $DIC;
64  $this->err = $DIC['ilErr'];
65  $this->ilias = $DIC['ilias'];
66  $this->db = $DIC['ilDB'];
67  $this->lng = $DIC['lng'];
68  $this->bench = $DIC['ilBench'];
69  $this->irss = $DIC['resource_storage'];
70 
71  $this->inst_id = (string) IL_INST_ID;
72 
73  $date = time();
74  $this->export_dir = $this->test_obj->getExportDirectory();
75 
76  switch ($this->mode) {
77  case "results":
78  $this->subdir = $date . "__" . $this->inst_id . "__" .
79  "tst__results_" . $this->test_obj->getId();
80  break;
81  case "aggregated":
82  $this->subdir = $date . "__" . $this->inst_id . "__" .
83  "test__aggregated__results_" . $this->test_obj->getId();
84  break;
85  default:
86  $this->subdir = $date . "__" . $this->inst_id . "__" .
87  "tst" . "_" . $this->test_obj->getId();
88  $this->filename = $this->subdir . ".xml";
89  $this->resultsfile = $date . "__" . $this->inst_id . "__" .
90  "results" . "_" . $this->test_obj->getId() . ".xml";
91  $this->qti_filename = $date . "__" . $this->inst_id . "__" .
92  "qti" . "_" . $this->test_obj->getId() . ".xml";
93  break;
94  }
95  $this->filename = $this->subdir . "." . $this->getExtension();
96  }
const IL_INST_ID
Definition: constants.php:40
global $DIC
Definition: feed.php:28
header include for all ilias files.
+ Here is the call graph for this function:

Member Function Documentation

◆ buildExportFile()

ilTestExport::buildExportFile ( )

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

References buildExportFileXML(), and buildExportResultFile().

144  : string
145  {
146  switch ($this->mode) {
147  case "results":
148  return $this->buildExportResultFile();
149  break;
150  default:
151  return $this->buildExportFileXML();
152  break;
153  }
154  }
+ Here is the call graph for this function:

◆ buildExportFileXML()

ilTestExport::buildExportFileXML ( )

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

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

Referenced by buildExportFile().

190  : string
191  {
192  $this->bench->start("TestExport", "buildExportFile");
193 
194  $this->initXmlExport();
195 
196  $this->xml = new ilXmlWriter();
197 
198  // set dtd definition
199  $this->xml->xmlSetDtdDef("<!DOCTYPE Test SYSTEM \"http://www.ilias.uni-koeln.de/download/dtd/ilias_co.dtd\">");
200 
201  // set generated comment
202  $this->xml->xmlSetGenCmt("Export of ILIAS Test " .
203  $this->test_obj->getId() . " of installation " . $this->inst_id . ".");
204 
205  // set xml header
206  $this->xml->xmlHeader();
207 
208  $this->xml->xmlStartTag("ContentObject", array('Type' => 'Test'));
209 
210  // create directories
211  $this->test_obj->createExportDirectory();
212  ilFileUtils::makeDir($this->export_dir . "/" . $this->subdir);
213  ilFileUtils::makeDir($this->export_dir . "/" . $this->subdir . "/objects");
214 
215  // get Log File
216  $expDir = $this->test_obj->getExportDirectory();
217  $expLog = new ilLog($expDir, "export.log");
218  $expLog->delete();
219  $expLog->setLogFormat("");
220  $expLog->write(date("[y-m-d H:i:s] ") . "Start Export");
221 
222  // write qti file
223  $qti_file = fopen($this->export_dir . "/" . $this->subdir . "/" . $this->qti_filename, "wb");
224  fwrite($qti_file, $this->getQtiXml());
225  fclose($qti_file);
226 
227  // get xml content
228  $this->bench->start("TestExport", "buildExportFile_getXML");
229  $this->test_obj->exportPagesXML(
230  $this->xml,
231  $this->inst_id,
232  $this->export_dir . "/" . $this->subdir,
233  $expLog
234  );
235  $this->bench->stop("TestExport", "buildExportFile_getXML");
236 
237  $this->populateQuestionSetConfigXml($this->xml);
238 
239  $assignmentList = $this->buildQuestionSkillAssignmentList();
240  $this->populateQuestionSkillAssignmentsXml($this->xml, $assignmentList, $this->getQuestionIds());
241  $this->populateSkillLevelThresholdsXml($this->xml, $assignmentList);
242 
243  $this->xml->xmlEndTag("ContentObject");
244 
245  $this->bench->start("TestExport", "buildExportFile_dumpToFile");
246  $this->xml->xmlDumpFile($this->export_dir . "/" . $this->subdir . "/" . $this->filename, false);
247  $this->bench->stop("TestExport", "buildExportFile_dumpToFile");
248 
250  $resultwriter = new ilTestResultsToXML(
251  $this->test_obj->getTestId(),
252  $this->db,
253  $this->irss,
254  $this->export_dir . "/" . $this->subdir . "/objects",
255  $this->test_obj->getAnonymity()
256  );
257  $resultwriter->setIncludeRandomTestQuestionsEnabled($this->test_obj->isRandomTest());
258  $this->bench->start("TestExport", "buildExportFile_results");
259  $resultwriter->xmlDumpFile($this->export_dir . "/" . $this->subdir . "/" . $this->resultsfile, false);
260  $this->bench->stop("TestExport", "buildExportFile_results");
261  }
262 
263  // add media objects which were added with tiny mce
264  $this->bench->start("QuestionpoolExport", "buildExportFile_saveAdditionalMobs");
265  $this->exportXHTMLMediaObjects($this->export_dir . "/" . $this->subdir);
266  $this->bench->stop("QuestionpoolExport", "buildExportFile_saveAdditionalMobs");
267 
268  // zip the file
269  $this->bench->start("TestExport", "buildExportFile_zipFile");
271  $this->export_dir . "/" . $this->subdir,
272  $this->export_dir . "/" . $this->subdir . ".zip"
273  );
274  $this->bench->stop("TestExport", "buildExportFile_zipFile");
275 
276  // destroy writer object
277  $this->xml = null;
278 
279  $expLog->write(date("[y-m-d H:i:s] ") . "Finished Export");
280  $this->bench->stop("TestExport", "buildExportFile");
281 
282  return $this->export_dir . "/" . $this->subdir . ".zip";
283  }
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()
ilDBInterface $db
setIncludeRandomTestQuestionsEnabled(bool $include_random_test_questions_enabled)
exportXHTMLMediaObjects($a_export_dir)
populateQuestionSkillAssignmentsXml(ilXmlWriter $a_xml_writer, ilAssQuestionSkillAssignmentList $assignmentList, array $questions)
populateSkillLevelThresholdsXml(ilXmlWriter $a_xml_writer, ilAssQuestionSkillAssignmentList $assignmentList)
static zip(string $a_dir, string $a_file, bool $compress_content=false)
ResourceStorage $irss
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 ( )

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

References $data, $filename, ilTestEvaluationData\FILTER_BY_NONE, getExtension(), getQuestionIds(), initXmlExport(), and ilFileUtils\makeDir().

Referenced by buildExportFile().

156  : string
157  {
158  //get Log File
159  $expDir = $this->test_obj->getExportDirectory();
160 
161  // make_directories
162  $this->test_obj->createExportDirectory();
163  ilFileUtils::makeDir($this->export_dir);
164 
165  $expLog = new ilLog($expDir, "export.log");
166  $expLog->delete();
167  $expLog->setLogFormat("");
168  $expLog->write(date("[y-m-d H:i:s] ") . "Start Export Of Results");
169 
170  $data = (new ilCSVTestExport($this->test_obj, ilTestEvaluationData::FILTER_BY_NONE, '', false))->withAllResults()->getContent();
171  $file = fopen($this->export_dir . "/" . $this->filename, "wb");
172  fwrite($file, $data);
173  fclose($file);
174 
175  $worksheet = (new ilExcelTestExport($this->test_obj, ilTestEvaluationData::FILTER_BY_NONE, '', false, true))
176  ->withResultsPage()
177  ->withUserPages()
178  ->getContent();
179  $worksheet->writeToFile($this->export_dir . "/" . str_replace($this->getExtension(), "xlsx", $this->filename));
180  // end
181  $expLog->write(date("[y-m-d H:i:s] ") . "Finished Export of Results");
182 
183  return $this->export_dir . "/" . $this->filename;
184  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: class.ilLog.php:30
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

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

Referenced by buildExportFileXML().

366  {
367  $assignmentList = new ilAssQuestionSkillAssignmentList($this->db);
368  $assignmentList->setParentObjId($this->test_obj->getId());
369  $assignmentList->loadFromDb();
370  $assignmentList->loadAdditionalSkillData();
371 
372  return $assignmentList;
373  }
+ Here is the caller graph for this function:

◆ exportXHTMLMediaObjects()

ilTestExport::exportXHTMLMediaObjects (   $a_export_dir)

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

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

Referenced by buildExportFileXML().

315  : void
316  {
317  $mobs = ilObjMediaObject::_getMobsOfObject("tst:html", $this->test_obj->getId());
318 
319  foreach ($mobs as $mob) {
320  if (ilObjMediaObject::_exists($mob)) {
321  $mob_obj = new ilObjMediaObject($mob);
322  $mob_obj->exportFiles($a_export_dir);
323  unset($mob_obj);
324  }
325  }
326  foreach ($this->getQuestionIds() as $question_id) {
327  $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $question_id);
328  foreach ($mobs as $mob) {
329  if (ilObjMediaObject::_exists($mob)) {
330  $mob_obj = new ilObjMediaObject($mob);
331  $mob_obj->exportFiles($a_export_dir);
332  unset($mob_obj);
333  }
334  }
335  }
336  }
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 ( )

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

References getForcedAccessFilteredParticipantList().

119  {
122  }
123 
124  return $this->test_obj->buildStatisticsAccessFilteredParticipantList();
125  }
getForcedAccessFilteredParticipantList()
+ Here is the call graph for this function:

◆ getExtension()

ilTestExport::getExtension ( )

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

Referenced by __construct(), and buildExportResultFile().

127  : string
128  {
129  switch ($this->mode) {
130  case "results":
131  return "csv";
132  break;
133  default:
134  return "xml";
135  break;
136  }
137  }
+ Here is the caller graph for this function:

◆ getForcedAccessFilteredParticipantList()

ilTestExport::getForcedAccessFilteredParticipantList ( )

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

References $forcedAccessFilteredParticipantList.

Referenced by getAccessFilteredParticipantList().

+ Here is the caller graph for this function:

◆ getInstId()

ilTestExport::getInstId ( )

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

References $inst_id.

140  {
141  return $this->inst_id;
142  }

◆ getQtiXml()

ilTestExport::getQtiXml ( )
protected

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

References getQuestionsQtiXml().

Referenced by buildExportFileXML().

288  {
289  $tstQtiXml = $this->test_obj->toXML();
290  $qstQtiXml = $this->getQuestionsQtiXml();
291 
292  if (strpos($tstQtiXml, "</section>") !== false) {
293  $qtiXml = str_replace("</section>", "$qstQtiXml</section>", $tstQtiXml);
294  } else {
295  $qtiXml = str_replace("<section ident=\"1\"/>", "<section ident=\"1\">\n$qstQtiXml</section>", $tstQtiXml);
296  }
297 
298  return $qtiXml;
299  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getQuestionIds()

ilTestExport::getQuestionIds ( )
abstractprotected

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

+ Here is the caller graph for this function:

◆ getQuestionQtiXml()

ilTestExport::getQuestionQtiXml (   $questionId)
protected

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

References $xml, and assQuestion\instantiateQuestion().

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

303  : string
304  {
305  $questionOBJ = assQuestion::instantiateQuestion($questionId);
306  $xml = $questionOBJ->toXML(false);
307 
308  // still neccessary? there is an include header flag!?
309  $xml = preg_replace("/<questestinterop>/", "", $xml);
310  $xml = preg_replace("/<\/questestinterop>/", "", $xml);
311 
312  return $xml;
313  }
static instantiateQuestion(int $question_id)
ilXmlWriter $xml
+ 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 buildExportResultFile().

+ Here is the caller graph for this function:

◆ isResultExportingEnabledForTestExport()

ilTestExport::isResultExportingEnabledForTestExport ( )

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

References $resultExportingEnabledForTestExport.

Referenced by buildExportFileXML().

98  : bool
99  {
101  }
bool $resultExportingEnabledForTestExport
+ 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,
array  $questions 
)
protected

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

Referenced by buildExportFileXML().

342  {
343  $skillQuestionAssignmentExporter = new ilAssQuestionSkillAssignmentExporter();
344  $skillQuestionAssignmentExporter->setXmlWriter($a_xml_writer);
345  $skillQuestionAssignmentExporter->setQuestionIds($questions);
346  $skillQuestionAssignmentExporter->setAssignmentList($assignmentList);
347  $skillQuestionAssignmentExporter->export();
348  }
+ Here is the caller graph for this function:

◆ populateSkillLevelThresholdsXml()

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

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

Referenced by buildExportFileXML().

353  {
354  $thresholdList = new ilTestSkillLevelThresholdList($this->db);
355  $thresholdList->setTestId($this->test_obj->getTestId());
356  $thresholdList->loadFromDb();
357 
358  $skillLevelThresholdExporter = new ilTestSkillLevelThresholdExporter();
359  $skillLevelThresholdExporter->setXmlWriter($a_xml_writer);
360  $skillLevelThresholdExporter->setAssignmentList($assignmentList);
361  $skillLevelThresholdExporter->setThresholdList($thresholdList);
362  $skillLevelThresholdExporter->export();
363  }
+ Here is the caller graph for this function:

◆ setForcedAccessFilteredParticipantList()

ilTestExport::setForcedAccessFilteredParticipantList ( ilTestParticipantList  $forcedAccessFilteredParticipantList)

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

References $forcedAccessFilteredParticipantList.

113  : void
114  {
115  $this->forcedAccessFilteredParticipantList = $forcedAccessFilteredParticipantList;
116  }
ilTestParticipantList $forcedAccessFilteredParticipantList

◆ setResultExportingEnabledForTestExport()

ilTestExport::setResultExportingEnabledForTestExport ( bool  $resultExprtingEnabledForTestExport)

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

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

Field Documentation

◆ $bench

ilBenchmark ilTestExport::$bench
protected

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

◆ $db

ilDBInterface ilTestExport::$db
protected

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

Referenced by buildExportFileXML().

◆ $err

ilErrorHandling ilTestExport::$err
protected

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

◆ $export_dir

string ilTestExport::$export_dir
private

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

◆ $filename

string ilTestExport::$filename
private

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

Referenced by buildExportResultFile().

◆ $forcedAccessFilteredParticipantList

ilTestParticipantList ilTestExport::$forcedAccessFilteredParticipantList = null
protected

◆ $ilias

ILIAS ilTestExport::$ilias
protected

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

◆ $inst_id

string ilTestExport::$inst_id
protected

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

Referenced by getInstId().

◆ $irss

ResourceStorage ilTestExport::$irss
private

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

Referenced by buildExportFileXML().

◆ $lng

ilLanguage ilTestExport::$lng
private

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

◆ $qti_filename

string ilTestExport::$qti_filename
private

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

◆ $resultExportingEnabledForTestExport

bool ilTestExport::$resultExportingEnabledForTestExport = false
protected

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

Referenced by isResultExportingEnabledForTestExport().

◆ $resultsfile

string ilTestExport::$resultsfile
private

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

◆ $subdir

string ilTestExport::$subdir
private

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

◆ $xml

ilXmlWriter ilTestExport::$xml
private

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

Referenced by getQuestionQtiXml().


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