ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilContObjectExport.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
16{
17 public $err; // error object
18 public $db; // database object
19 public $cont_obj; // content object (learning module | digilib book)
20 public $inst_id; // installation id
21 public $mode;
22
27 public function __construct(&$a_cont_obj, $a_mode = "xml", $a_lang = "")
28 {
29 global $DIC;
30
31 $ilErr = $DIC["ilErr"];
32 $ilDB = $DIC->database();
33
34 $this->cont_obj = $a_cont_obj;
35
36 $this->err = $ilErr;
37 $this->db = $ilDB;
38 $this->mode = $a_mode;
39 $this->lang = $a_lang;
40
41 $this->inst_id = IL_INST_ID;
42
43 $date = time();
44 switch ($this->mode) {
45 case "html":
46 if ($this->lang == "") {
47 $this->export_dir = $this->cont_obj->getExportDirectory("html");
48 } else {
49 $this->export_dir = $this->cont_obj->getExportDirectory("html_" . $this->lang);
50 }
51 $this->subdir = $this->cont_obj->getType() . "_" . $this->cont_obj->getId();
52 $this->filename = $this->subdir . ".zip";
53 break;
54
55 case "scorm":
56 $this->export_dir = $this->cont_obj->getExportDirectory("scorm");
57 $this->subdir = $this->cont_obj->getType() . "_" . $this->cont_obj->getId();
58 $this->filename = $this->subdir . ".zip";
59 break;
60
61 case "pdf":
62 $this->export_dir = $this->cont_obj->getOfflineDirectory();
63 $this->subdir = $date . "__" . $this->inst_id . "__" .
64 $this->cont_obj->getType() . "_" . $this->cont_obj->getId();
65 $this->filename = $this->subdir . ".fo";
66 break;
67
68 default:
69 $this->export_dir = $this->cont_obj->getExportDirectory();
70 $this->subdir = $date . "__" . $this->inst_id . "__" .
71 $this->cont_obj->getType() . "_" . $this->cont_obj->getId();
72 $this->filename = $this->subdir . ".xml";
73 break;
74 }
75 }
76
77 public function getInstId()
78 {
79 return $this->inst_id;
80 }
81
88 public function buildExportFile($a_mode = "")
89 {
90 switch ($this->mode) {
91 case "html":
92 $this->buildExportFileHTML();
93 break;
94
95 case "scorm":
96 $this->buildExportFileSCORM();
97 break;
98
99 case "pdf":
100 $this->buildExportFilePDF();
101 break;
102
103 default:
104 return $this->buildExportFileXML($a_mode);
105 break;
106 }
107 }
108
112 public function buildExportFileXML($a_mode = "")
113 {
114 if (in_array($a_mode, array("master", "masternomedia"))) {
115 $exp = new ilExport();
116 $conf = $exp->getConfig("Modules/LearningModule");
117 $conf->setMasterLanguageOnly(true, ($a_mode == "master"));
118 $exp->exportObject($this->cont_obj->getType(), $this->cont_obj->getId(), "5.1.0");
119 return;
120 }
121
122 $this->xml = new ilXmlWriter;
123
124 // set dtd definition
125 $this->xml->xmlSetDtdDef("<!DOCTYPE ContentObject SYSTEM \"http://www.ilias.de/download/dtd/ilias_co_3_7.dtd\">");
126
127 // set generated comment
128 $this->xml->xmlSetGenCmt("Export of ILIAS Content Module " .
129 $this->cont_obj->getId() . " of installation " . $this->inst . ".");
130
131 // set xml header
132 $this->xml->xmlHeader();
133
134 // create directories
135 $this->cont_obj->createExportDirectory();
136 ilUtil::makeDir($this->export_dir . "/" . $this->subdir);
137 ilUtil::makeDir($this->export_dir . "/" . $this->subdir . "/objects");
138
139 // get Log File
140 $expDir = $this->cont_obj->getExportDirectory();
141 $expLog = new ilLog($expDir, "export.log");
142 $expLog->delete();
143 $expLog->setLogFormat("");
144 $expLog->write(date("[y-m-d H:i:s] ") . "Start Export");
145
146 // get xml content
147 $this->cont_obj->exportXML(
148 $this->xml,
149 $this->inst_id,
150 $this->export_dir . "/" . $this->subdir,
151 $expLog
152 );
153
154 // export style
155 if ($this->cont_obj->getStyleSheetId() > 0) {
156 $style_obj = new ilObjStyleSheet($this->cont_obj->getStyleSheetId(), false);
157 //$style_obj->exportXML($this->export_dir."/".$this->subdir);
158 $style_obj->setExportSubDir("style");
159 $style_file = $style_obj->export();
160 if (is_file($style_file)) {
161 copy($style_file, $this->export_dir . "/" . $this->subdir . "/style.zip");
162 }
163 }
164
165 // dump xml document to screen (only for debugging reasons)
166 /*
167 echo "<PRE>";
168 echo htmlentities($this->xml->xmlDumpMem($format));
169 echo "</PRE>";
170 */
171
172 // dump xml document to file
173 $this->xml->xmlDumpFile($this->export_dir . "/" . $this->subdir . "/" . $this->filename, false);
174
175 // help export (workaround to use ref id here)
176 if (ilObjContentObject::isOnlineHelpModule((int) $_GET["ref_id"])) {
177 $exp = new ilExport();
178 $exp->exportEntity(
179 "help",
180 $this->cont_obj->getId(),
181 "4.3.0",
182 "Services/Help",
183 "OnlineHelp",
184 $this->export_dir . "/" . $this->subdir
185 );
186 }
187
188 // zip the file
190 $this->export_dir . "/" . $this->subdir,
191 $this->export_dir . "/" . $this->subdir . ".zip"
192 );
193
194 // destroy writer object
195 $this->xml->_XmlWriter;
196
197 $expLog->write(date("[y-m-d H:i:s] ") . "Finished Export");
198
199 return $this->export_dir . "/" . $this->subdir . ".zip";
200 }
201
205 public function buildExportFilePDF()
206 {
207 die("deprecated.");
208 }
209
213 public function buildExportFileHTML()
214 {
215 // create directories
216 if ($this->lang == "") {
217 $this->cont_obj->createExportDirectory("html");
218 } else {
219 $this->cont_obj->createExportDirectory("html_" . $this->lang);
220 }
221
222
223 // get html content
224 $exp = new \ILIAS\LearningModule\Export\LMHtmlExport(
225 $this->cont_obj,
226 $this->export_dir,
227 $this->subdir,
228 "html",
229 $this->lang
230 );
231 $exp->exportHTML(true);
232 }
233
237 public function buildExportFileSCORM()
238 {
239 // create directories
240 $this->cont_obj->createExportDirectory("scorm");
241
242 $target_dir = $this->export_dir . "/" . $this->subdir;
243
244 ilUtil::delDir($target_dir);
245 ilUtil::makeDir($target_dir);
246
247 // export everything to html
248// $this->exportHTML($a_target_dir . "/res", $log, false, "scorm");
249 // get html content
250 $exp = new \ILIAS\LearningModule\Export\LMHtmlExport(
251 $this->cont_obj,
252 $target_dir,
253 "res",
254 "scorm",
255 $this->lang
256 );
257 $exp->exportHTML(false);
258
259 // build manifest file
260 $man_builder = new ilLMContObjectManifestBuilder($this->cont_obj);
261 $man_builder->buildManifest();
262 $man_builder->dump($target_dir);
263
264 // copy scorm 1.2 schema definitions
265 copy("Modules/LearningModule/scorm_xsd/adlcp_rootv1p2.xsd", $target_dir . "/adlcp_rootv1p2.xsd");
266 copy("Modules/LearningModule/scorm_xsd/imscp_rootv1p1p2.xsd", $target_dir . "/imscp_rootv1p1p2.xsd");
267 copy("Modules/LearningModule/scorm_xsd/imsmd_rootv1p2p1.xsd", $target_dir . "/imsmd_rootv1p2p1.xsd");
268 copy("Modules/LearningModule/scorm_xsd/ims_xml.xsd", $target_dir . "/ims_xml.xsd");
269
270 // zip it all
271 $date = time();
272 $zip_file = $target_dir . "/" . $date . "__" . IL_INST_ID . "__" .
273 $this->cont_obj->getType() . "_" . $this->cont_obj->getId() . ".zip";
274 //echo "zip-".$a_target_dir."-to-".$zip_file;
275 ilUtil::zip(array($target_dir . "/res",
276 $target_dir . "/imsmanifest.xml",
277 $target_dir . "/adlcp_rootv1p2.xsd",
278 $target_dir . "/imscp_rootv1p1p2.xsd",
279 $target_dir . "/ims_xml.xsd",
280 $target_dir . "/imsmd_rootv1p2p1.xsd"), $zip_file);
281
282 $dest_file = $this->cont_obj->getExportDirectory("scorm") . "/" . $date . "__" . IL_INST_ID . "__" .
283 $this->cont_obj->getType() . "_" . $this->cont_obj->getId() . ".zip";
284
285 rename($zip_file, $dest_file);
286 ilUtil::delDir($target_dir);
287
288 // get html content
289// $this->cont_obj->exportSCORM($this->export_dir . "/" . $this->subdir, $expLog);
290 }
291}
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
Export class for content objects.
buildExportFileXML($a_mode="")
build xml export file
buildExportFilePDF()
build pdf offline file
__construct(&$a_cont_obj, $a_mode="xml", $a_lang="")
Constructor @access public.
buildExportFile($a_mode="")
build export file (complete zip file)
buildExportFileSCORM()
build scorm package
buildExportFileHTML()
build html package
Content Object (ILIAS native learning module / digilib book) Manifest export class.
logging
Definition: class.ilLog.php:19
static isOnlineHelpModule($a_id, $a_as_obj_id=false)
Is module an online module.
Class ilObjStyleSheet.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static zip($a_dir, $a_file, $compress_content=false)
zips given directory/file into given zip.file
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
$ilErr
Definition: raiseError.php:18
global $ilDB