ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilQuestionpoolExport.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once "./Modules/Test/classes/inc.AssessmentConstants.php";
5
16{
17 public $err; // error object
18 public $db; // database object
19 public $ilias; // ilias object
23 public $qpl_obj; // questionpool object
24 public $questions; // array with question ids to export
25 public $inst_id; // installation id
26 public $mode;
27 public $lng;
28
33 public function __construct($a_qpl_obj, $a_mode = "xml", $array_questions = null)
34 {
35 global $ilErr, $ilDB, $ilias, $lng;
36
37 $this->qpl_obj =&$a_qpl_obj;
38 if (!is_array($array_questions)) {
39 $array_questions =&$a_qpl_obj->getAllQuestionIds();
40 }
41
42 $this->err =&$ilErr;
43 $this->ilias =&$ilias;
44 $this->db =&$ilDB;
45 $this->mode = $a_mode;
46 $this->lng =&$lng;
47
48 $settings = $this->ilias->getAllSettings();
49 $this->inst_id = IL_INST_ID;
50 $this->questions = $array_questions;
51 $date = time();
52 $this->qpl_obj->createExportDirectory();
53 switch ($this->mode) {
54 case "xml":
55 $this->export_dir = $this->qpl_obj->getExportDirectory('xml');
56 $this->subdir = $date . "__" . $this->inst_id . "__" .
57 "qpl" . "_" . $this->qpl_obj->getId();
58 $this->filename = $this->subdir . ".xml";
59 $this->qti_filename = $date . "__" . $this->inst_id . "__" .
60 "qti" . "_" . $this->qpl_obj->getId() . ".xml";
61 break;
62 case "xls":
63 $this->export_dir = $this->qpl_obj->getExportDirectory('xls');
64 $this->filename = $date . "__" . $this->inst_id . "__" .
65 "qpl" . "_" . $this->qpl_obj->getId() . ".xlsx";
66 $this->zipfilename = $date . "__" . $this->inst_id . "__" .
67 "qpl" . "_" . $this->qpl_obj->getId() . ".zip";
68 break;
69 default:
70 $this->export_dir = $this->qpl_obj->getExportDirectory('zip');
71 $this->subdir = $date . "__" . $this->inst_id . "__" .
72 "qpl" . "_" . $this->qpl_obj->getId();
73 $this->filename = $this->subdir . ".xml";
74 $this->qti_filename = $date . "__" . $this->inst_id . "__" .
75 "qti" . "_" . $this->qpl_obj->getId() . ".xml";
76 break;
77 }
78 }
79
80 public function getInstId()
81 {
82 return $this->inst_id;
83 }
84
85
92 public function buildExportFile()
93 {
94 switch ($this->mode) {
95 case "xls":
96 return $this->buildExportFileXLS();
97 break;
98 case "xml":
99 default:
100 return $this->buildExportFileXML();
101 break;
102 }
103 }
104
108 public function buildExportFileXML()
109 {
110 global $ilBench;
111
112 $ilBench->start("QuestionpoolExport", "buildExportFile");
113
114 include_once("./Services/Xml/classes/class.ilXmlWriter.php");
115 $this->xml = new ilXmlWriter;
116
117 // set dtd definition
118 $this->xml->xmlSetDtdDef("<!DOCTYPE Test SYSTEM \"http://www.ilias.uni-koeln.de/download/dtd/ilias_co.dtd\">");
119
120 // set generated comment
121 $this->xml->xmlSetGenCmt("Export of ILIAS Test Questionpool " .
122 $this->qpl_obj->getId() . " of installation " . $this->inst . ".");
123
124 // set xml header
125 $this->xml->xmlHeader();
126
127 // create directories
128 include_once "./Services/Utilities/classes/class.ilUtil.php";
129 ilUtil::makeDir($this->export_dir . "/" . $this->subdir);
130 ilUtil::makeDir($this->export_dir . "/" . $this->subdir . "/objects");
131
132 // get Log File
133 $expDir = $this->qpl_obj->getExportDirectory();
134 ilUtil::makeDirParents($expDir);
135
136 include_once "./Services/Logging/classes/class.ilLog.php";
137 $expLog = new ilLog($expDir, "export.log");
138 $expLog->delete();
139 $expLog->setLogFormat("");
140 $expLog->write(date("[y-m-d H:i:s] ") . "Start Export");
141
142 // write qti file
143 $qti_file = fopen($this->export_dir . "/" . $this->subdir . "/" . $this->qti_filename, "w");
144 fwrite($qti_file, $this->qpl_obj->questionsToXML($this->questions));
145 fclose($qti_file);
146
147 // get xml content
148 $ilBench->start("QuestionpoolExport", "buildExportFile_getXML");
149 $this->qpl_obj->objectToXmlWriter(
150 $this->xml,
151 $this->inst_id,
152 $this->export_dir . "/" . $this->subdir,
153 $expLog,
154 $this->questions
155 );
156 $ilBench->stop("QuestionpoolExport", "buildExportFile_getXML");
157
158 // dump xml document to screen (only for debugging reasons)
159 /*
160 echo "<PRE>";
161 echo htmlentities($this->xml->xmlDumpMem($format));
162 echo "</PRE>";
163 */
164
165 // dump xml document to file
166 $ilBench->start("QuestionpoolExport", "buildExportFile_dumpToFile");
167 $this->xml->xmlDumpFile($this->export_dir . "/" . $this->subdir . "/" . $this->filename, false);
168 $ilBench->stop("QuestionpoolExport", "buildExportFile_dumpToFile");
169
170 // add media objects which were added with tiny mce
171 $ilBench->start("QuestionpoolExport", "buildExportFile_saveAdditionalMobs");
172 $this->exportXHTMLMediaObjects($this->export_dir . "/" . $this->subdir);
173 $ilBench->stop("QuestionpoolExport", "buildExportFile_saveAdditionalMobs");
174
175 // zip the file
176 $ilBench->start("QuestionpoolExport", "buildExportFile_zipFile");
177 ilUtil::zip($this->export_dir . "/" . $this->subdir, $this->export_dir . "/" . $this->subdir . ".zip");
178 if (@is_dir($this->export_dir . "/" . $this->subdir)) {
179 // Do not delete this dir, since it is required for container exports
180 #ilUtil::delDir($this->export_dir."/".$this->subdir);
181 }
182
183 $ilBench->stop("QuestionpoolExport", "buildExportFile_zipFile");
184
185 // destroy writer object
186 $this->xml->_XmlWriter;
187
188 $expLog->write(date("[y-m-d H:i:s] ") . "Finished Export");
189 $ilBench->stop("QuestionpoolExport", "buildExportFile");
190
191 return $this->export_dir . "/" . $this->subdir . ".zip";
192 }
193
194 public function exportXHTMLMediaObjects($a_export_dir)
195 {
196 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
197
198 foreach ($this->questions as $question_id) {
199 $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $question_id);
200 foreach ($mobs as $mob) {
201 if (ilObjMediaObject::_exists($mob)) {
202 $mob_obj = new ilObjMediaObject($mob);
203 $mob_obj->exportFiles($a_export_dir);
204 unset($mob_obj);
205 }
206 }
207 }
208 }
209
213 protected function buildExportFileXLS()
214 {
215 require_once 'Modules/TestQuestionPool/classes/class.ilAssExcelFormatHelper.php';
216 require_once 'Modules/TestQuestionPool/classes/class.assQuestion.php';
217
219 $worksheet->addSheet('Sheet 1');
220 $row = 1;
221 $col = 0;
222
223 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("title"));
224 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("description"));
225 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("question_type"));
226 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("author"));
227 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("create_date"));
228 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col) . $row, $this->lng->txt("last_update"));
229
230 $col = 0;
231 $row++;
232 $questions = $this->qpl_obj->getQuestionList();
233 foreach ($questions as $question) {
234 $worksheet->setCell($row, $col++, $question["title"]);
235 $worksheet->setCell($row, $col++, $question["description"]);
236 $worksheet->setCell($row, $col++, $this->lng->txt($question["type_tag"]));
237 $worksheet->setCell($row, $col++, $question["author"]);
238 $created = new ilDate($question["created"], IL_CAL_UNIX);
239 $worksheet->setCell($row, $col++, $created);
240 $updated = new ilDate($question["tstamp"], IL_CAL_UNIX);
241 $worksheet->setCell($row, $col++, $updated);
242 $col = 0;
243 $row++;
244 }
245
246 $excelfile = $this->export_dir . '/' . $this->filename;
247 $worksheet->writeToFile($excelfile);
248 ilUtil::zip($excelfile, $this->export_dir . "/" . $this->zipfilename);
249 if (@file_exists($this->export_dir . "/" . $this->filename)) {
250 @unlink($this->export_dir . "/" . $this->filename);
251 }
252 }
253}
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
$worksheet
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
Class ilAssExcelFormatHelper.
Class for single dates.
logging
Definition: class.ilLog.php:19
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
Export class for questionpools.
buildExportFileXLS()
build xml export file
__construct($a_qpl_obj, $a_mode="xml", $array_questions=null)
Constructor @access public.
buildExportFileXML()
build xml export file
buildExportFile()
build export file (complete zip file)
static zip($a_dir, $a_file, $compress_content=false)
zips given directory/file into given zip.file
static makeDirParents($a_dir)
Create a new directory and all parent directories.
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:18
redirection script todo: (a better solution should control the processing via a xml file)
global $ilErr
Definition: raiseError.php:16
global $ilDB
$mobs