Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 include_once "./assessment/classes/inc.AssessmentConstants.php";
00025
00034 class ilTestExport
00035 {
00036 var $err;
00037 var $db;
00038 var $ilias;
00039 var $test_obj;
00040 var $inst_id;
00041 var $mode;
00042
00047 function ilTestExport(&$a_test_obj, $a_mode = "xml")
00048 {
00049 global $ilErr, $ilDB, $ilias;
00050
00051 $this->test_obj =& $a_test_obj;
00052
00053 $this->err =& $ilErr;
00054 $this->ilias =& $ilias;
00055 $this->db =& $ilDB;
00056 $this->mode = $a_mode;
00057
00058 $settings = $this->ilias->getAllSettings();
00059
00060 $this->inst_id = IL_INST_ID;
00061
00062 $date = time();
00063 $this->export_dir = $this->test_obj->getExportDirectory();
00064 switch($this->mode)
00065 {
00066 case "results":
00067 $this->subdir = $date."__".$this->inst_id."__".
00068 "test__results__".$this->test_obj->getId();
00069 break;
00070 default:
00071 $this->subdir = $date."__".$this->inst_id."__".
00072 "test"."__".$this->test_obj->getId();
00073 $this->filename = $this->subdir.".xml";
00074 $this->qti_filename = $date."__".$this->inst_id."__".
00075 "qti"."__".$this->test_obj->getId().".xml";
00076 break;
00077 }
00078 $this->filename = $this->subdir.".".$this->getExtension();
00079 }
00080
00081 function getExtension () {
00082 switch ($this->mode) {
00083 case "results":
00084 return "csv"; break;
00085 default:
00086 return "xml"; break;
00087 }
00088 }
00089
00090 function getInstId()
00091 {
00092 return $this->inst_id;
00093 }
00094
00095
00102 function buildExportFile()
00103 {
00104 switch ($this->mode)
00105 {
00106 case "results":
00107 return $this->buildExportResultFile();
00108 break;
00109 default:
00110 return $this->buildExportFileXML();
00111 break;
00112 }
00113 }
00114
00118 function buildExportResultFile()
00119 {
00120 global $ilBench;
00121 global $log;
00122
00123 $expDir = $this->test_obj->getExportDirectory();
00124 $expLog = &$log;
00125 $expLog->delete();
00126 $expLog->setLogFormat("");
00127 $expLog->write(date("[y-m-d H:i:s] ")."Start Export Of Results");
00128
00129
00130 $this->test_obj->createExportDirectory();
00131 include_once "./classes/class.ilUtil.php";
00132 ilUtil::makeDir($this->export_dir);
00133
00134
00135 $participants = $this->test_obj->getInvitedUsers("matriculation");
00136 $data = $this->test_obj->getAllTestResults($participants);
00137
00138 $file = fopen($this->export_dir."/".$this->filename, "w");
00139 foreach ($data as $row) {
00140 fwrite($file, join (";",$row)."\n");
00141 }
00142 fclose($file);
00143
00144
00145 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export of Results");
00146
00147 return $this->export_dir."/".$this->filename;
00148 }
00149
00150
00154 function buildExportFileXML()
00155 {
00156 global $ilBench;
00157
00158 $ilBench->start("TestExport", "buildExportFile");
00159
00160 include_once("./classes/class.ilXmlWriter.php");
00161 $this->xml = new ilXmlWriter;
00162
00163
00164 $this->xml->xmlSetDtdDef("<!DOCTYPE Test SYSTEM \"http://www.ilias.uni-koeln.de/download/dtd/ilias_co.dtd\">");
00165
00166
00167 $this->xml->xmlSetGenCmt("Export of ILIAS Test ".
00168 $this->test_obj->getId()." of installation ".$this->inst.".");
00169
00170
00171 $this->xml->xmlHeader();
00172
00173
00174 $this->test_obj->createExportDirectory();
00175 include_once "./classes/class.ilUtil.php";
00176 ilUtil::makeDir($this->export_dir."/".$this->subdir);
00177 ilUtil::makeDir($this->export_dir."/".$this->subdir."/objects");
00178
00179
00180 $expDir = $this->test_obj->getExportDirectory();
00181 include_once "./classes/class.ilLog.php";
00182 $expLog = new ilLog($expDir, "export.log");
00183 $expLog->delete();
00184 $expLog->setLogFormat("");
00185 $expLog->write(date("[y-m-d H:i:s] ")."Start Export");
00186
00187
00188 $qti_file = fopen($this->export_dir."/".$this->subdir."/".$this->qti_filename, "w");
00189 fwrite($qti_file, $this->test_obj->to_xml());
00190 fclose($qti_file);
00191
00192
00193 $ilBench->start("TestExport", "buildExportFile_getXML");
00194 $this->test_obj->exportPagesXML($this->xml, $this->inst_id,
00195 $this->export_dir."/".$this->subdir, $expLog);
00196 $ilBench->stop("TestExport", "buildExportFile_getXML");
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206 $ilBench->start("TestExport", "buildExportFile_dumpToFile");
00207 $this->xml->xmlDumpFile($this->export_dir."/".$this->subdir."/".$this->filename
00208 , false);
00209 $ilBench->stop("TestExport", "buildExportFile_dumpToFile");
00210
00211
00212 $ilBench->start("QuestionpoolExport", "buildExportFile_saveAdditionalMobs");
00213 $this->exportXHTMLMediaObjects($this->export_dir."/".$this->subdir);
00214 $ilBench->stop("QuestionpoolExport", "buildExportFile_saveAdditionalMobs");
00215
00216
00217 $ilBench->start("TestExport", "buildExportFile_zipFile");
00218 ilUtil::zip($this->export_dir."/".$this->subdir,
00219 $this->export_dir."/".$this->subdir.".zip");
00220 $ilBench->stop("TestExport", "buildExportFile_zipFile");
00221
00222
00223 $this->xml->_XmlWriter;
00224
00225 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export");
00226 $ilBench->stop("TestExport", "buildExportFile");
00227
00228 return $this->export_dir."/".$this->subdir.".zip";
00229 }
00230
00231 function exportXHTMLMediaObjects($a_export_dir)
00232 {
00233 include_once("./content/classes/Media/class.ilObjMediaObject.php");
00234
00235 $mobs = ilObjMediaObject::_getMobsOfObject("tst:html", $this->test_obj->getId());
00236 foreach ($mobs as $mob)
00237 {
00238 $mob_obj =& new ilObjMediaObject($mob);
00239 $mob_obj->exportFiles($a_export_dir);
00240 unset($mob_obj);
00241 }
00242 foreach ($this->test_obj->questions as $question_id)
00243 {
00244 $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $question_id);
00245 foreach ($mobs as $mob)
00246 {
00247 $mob_obj =& new ilObjMediaObject($mob);
00248 $mob_obj->exportFiles($a_export_dir);
00249 unset($mob_obj);
00250 }
00251 }
00252 }
00253
00254 }
00255
00256 ?>