ILIAS  release_7 Revision v7.30-3-g800a261c036
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 $DIC;
36 $ilErr = $DIC['ilErr'];
37 $ilDB = $DIC['ilDB'];
38 $ilias = $DIC['ilias'];
39 $lng = $DIC['lng'];
40
41 $this->qpl_obj = &$a_qpl_obj;
42 if (!is_array($array_questions)) {
43 $array_questions = &$a_qpl_obj->getAllQuestionIds();
44 }
45
46 $this->err = &$ilErr;
47 $this->ilias = &$ilias;
48 $this->db = &$ilDB;
49 $this->mode = $a_mode;
50 $this->lng = &$lng;
51
52 $settings = $this->ilias->getAllSettings();
53 $this->inst_id = IL_INST_ID;
54 $this->questions = $array_questions;
55 $date = time();
56 $this->qpl_obj->createExportDirectory();
57 switch ($this->mode) {
58 case "xml":
59 $this->export_dir = $this->qpl_obj->getExportDirectory('xml');
60 $this->subdir = $date . "__" . $this->inst_id . "__" .
61 "qpl" . "_" . $this->qpl_obj->getId();
62 $this->filename = $this->subdir . ".xml";
63 $this->qti_filename = $date . "__" . $this->inst_id . "__" .
64 "qti" . "_" . $this->qpl_obj->getId() . ".xml";
65 break;
66 case "xls":
67 $this->export_dir = $this->qpl_obj->getExportDirectory('xls');
68 $this->filename = $date . "__" . $this->inst_id . "__" .
69 "qpl" . "_" . $this->qpl_obj->getId() . ".xlsx";
70 $this->zipfilename = $date . "__" . $this->inst_id . "__" .
71 "qpl" . "_" . $this->qpl_obj->getId() . ".zip";
72 break;
73 default:
74 $this->export_dir = $this->qpl_obj->getExportDirectory('zip');
75 $this->subdir = $date . "__" . $this->inst_id . "__" .
76 "qpl" . "_" . $this->qpl_obj->getId();
77 $this->filename = $this->subdir . ".xml";
78 $this->qti_filename = $date . "__" . $this->inst_id . "__" .
79 "qti" . "_" . $this->qpl_obj->getId() . ".xml";
80 break;
81 }
82 }
83
84 public function getInstId()
85 {
86 return $this->inst_id;
87 }
88
89
96 public function buildExportFile()
97 {
98 switch ($this->mode) {
99 case "xls":
100 return $this->buildExportFileXLS();
101 break;
102 case "xml":
103 default:
104 return $this->buildExportFileXML();
105 break;
106 }
107 }
108
112 public function buildExportFileXML()
113 {
114 global $DIC;
115 $ilBench = $DIC['ilBench'];
116
117 $ilBench->start("QuestionpoolExport", "buildExportFile");
118
119 include_once("./Services/Xml/classes/class.ilXmlWriter.php");
120 $this->xml = new ilXmlWriter;
121
122 // set dtd definition
123 $this->xml->xmlSetDtdDef("<!DOCTYPE Test SYSTEM \"http://www.ilias.uni-koeln.de/download/dtd/ilias_co.dtd\">");
124
125 // set generated comment
126 $this->xml->xmlSetGenCmt("Export of ILIAS Test Questionpool " .
127 $this->qpl_obj->getId() . " of installation " . $this->inst . ".");
128
129 // set xml header
130 $this->xml->xmlHeader();
131
132 // create directories
133 include_once "./Services/Utilities/classes/class.ilUtil.php";
134 ilUtil::makeDir($this->export_dir . "/" . $this->subdir);
135 ilUtil::makeDir($this->export_dir . "/" . $this->subdir . "/objects");
136
137 // get Log File
138 $expDir = $this->qpl_obj->getExportDirectory();
139 ilUtil::makeDirParents($expDir);
140
141 include_once "./Services/Logging/classes/class.ilLog.php";
142 $expLog = new ilLog($expDir, "export.log");
143 $expLog->delete();
144 $expLog->setLogFormat("");
145 $expLog->write(date("[y-m-d H:i:s] ") . "Start Export");
146
147 // write qti file
148 $qti_file = fopen($this->export_dir . "/" . $this->subdir . "/" . $this->qti_filename, "w");
149 fwrite($qti_file, $this->qpl_obj->questionsToXML($this->questions));
150 fclose($qti_file);
151
152 // get xml content
153 $ilBench->start("QuestionpoolExport", "buildExportFile_getXML");
154 $this->qpl_obj->objectToXmlWriter(
155 $this->xml,
156 $this->inst_id,
157 $this->export_dir . "/" . $this->subdir,
158 $expLog,
159 $this->questions
160 );
161 $ilBench->stop("QuestionpoolExport", "buildExportFile_getXML");
162 $ilBench->start("QuestionpoolExport", "buildExportFile_dumpToFile");
163 $this->xml->xmlDumpFile($this->export_dir . "/" . $this->subdir . "/" . $this->filename, false);
164 $ilBench->stop("QuestionpoolExport", "buildExportFile_dumpToFile");
165
166 // add media objects which were added with tiny mce
167 $ilBench->start("QuestionpoolExport", "buildExportFile_saveAdditionalMobs");
168 $this->exportXHTMLMediaObjects($this->export_dir . "/" . $this->subdir);
169 $ilBench->stop("QuestionpoolExport", "buildExportFile_saveAdditionalMobs");
170
171 // zip the file
172 $ilBench->start("QuestionpoolExport", "buildExportFile_zipFile");
173 ilUtil::zip($this->export_dir . "/" . $this->subdir, $this->export_dir . "/" . $this->subdir . ".zip");
174 $ilBench->stop("QuestionpoolExport", "buildExportFile_zipFile");
175
176 // destroy writer object
177 $this->xml->_XmlWriter;
178 $expLog->write(date("[y-m-d H:i:s] ") . "Finished Export");
179 $ilBench->stop("QuestionpoolExport", "buildExportFile");
180
181 return $this->export_dir . "/" . $this->subdir . ".zip";
182 }
183
184 public function exportXHTMLMediaObjects($a_export_dir)
185 {
186 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
187
188 foreach ($this->questions as $question_id) {
189 $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $question_id);
190 foreach ($mobs as $mob) {
191 if (ilObjMediaObject::_exists($mob)) {
192 $mob_obj = new ilObjMediaObject($mob);
193 $mob_obj->exportFiles($a_export_dir);
194 unset($mob_obj);
195 }
196 }
197 }
198 }
199
203 protected function buildExportFileXLS()
204 {
205 require_once 'Modules/TestQuestionPool/classes/class.ilAssExcelFormatHelper.php';
206 require_once 'Modules/TestQuestionPool/classes/class.assQuestion.php';
207
208 $worksheet = new ilAssExcelFormatHelper();
209 $worksheet->addSheet('Sheet 1');
210 $row = 1;
211 $col = 0;
212
213 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("title"));
214 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("description"));
215 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("question_type"));
216 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("author"));
217 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("create_date"));
218 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col) . $row, $this->lng->txt("last_update"));
219
220 $col = 0;
221 $row++;
222 $questions = $this->qpl_obj->getQuestionList();
223 foreach ($questions as $question) {
224 $worksheet->setCell($row, $col++, $question["title"]);
225 $worksheet->setCell($row, $col++, $question["description"]);
226 $worksheet->setCell($row, $col++, $this->lng->txt($question["type_tag"]));
227 $worksheet->setCell($row, $col++, $question["author"]);
228 $created = new ilDate($question["created"], IL_CAL_UNIX);
229 $worksheet->setCell($row, $col++, $created);
230 $updated = new ilDate($question["tstamp"], IL_CAL_UNIX);
231 $worksheet->setCell($row, $col++, $updated);
232 $col = 0;
233 $row++;
234 }
235
236 $excelfile = $this->export_dir . '/' . $this->filename;
237 $worksheet->writeToFile($excelfile);
238 ilUtil::zip($excelfile, $this->export_dir . "/" . $this->zipfilename);
239 if (@file_exists($this->export_dir . "/" . $this->filename)) {
240 @unlink($this->export_dir . "/" . $this->filename);
241 }
242 }
243}
$filename
Definition: buildRTE.php:89
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.
const IL_INST_ID
Definition: constants.php:38
global $DIC
Definition: goto.php:24
global $ilBench
Definition: ilias.php:21
$mobs
Definition: imgupload.php:54
redirection script todo: (a better solution should control the processing via a xml file)
$ilErr
Definition: raiseError.php:18
global $ilDB