ILIAS  release_8 Revision v8.25-1-g13de6a5eca6
class.ilContObjectExport.php
Go to the documentation of this file.
1<?php
2
26{
27 protected int $inst;
28 protected ilXmlWriter $xml;
29 protected string $filename;
30 protected string $subdir;
31 protected string $export_dir;
32 protected string $lang;
35 public int $inst_id;
36 public string $mode;
37
38 public function __construct(
39 ilObjLearningModule $a_cont_obj,
40 string $a_mode = "xml",
41 string $a_lang = ""
42 ) {
43 global $DIC;
44
45 $ilDB = $DIC->database();
46
47 $this->cont_obj = $a_cont_obj;
48
49 $this->db = $ilDB;
50 $this->mode = $a_mode;
51 $this->lang = $a_lang;
52
53 $this->inst_id = (int) IL_INST_ID;
54
55 $date = time();
56 switch ($this->mode) {
57 case "html":
58 if ($this->lang == "") {
59 $this->export_dir = $this->cont_obj->getExportDirectory("html");
60 } else {
61 $this->export_dir = $this->cont_obj->getExportDirectory("html_" . $this->lang);
62 }
63 $this->subdir = $this->cont_obj->getType() . "_" . $this->cont_obj->getId();
64 $this->filename = $this->subdir . ".zip";
65 break;
66
67 default:
68 $this->export_dir = $this->cont_obj->getExportDirectory();
69 $this->subdir = $date . "__" . $this->inst_id . "__" .
70 $this->cont_obj->getType() . "_" . $this->cont_obj->getId();
71 $this->filename = $this->subdir . ".xml";
72 break;
73 }
74 }
75
76 public function getInstId(): int
77 {
78 return $this->inst_id;
79 }
80
81 public function buildExportFile(
82 string $a_mode = ""
83 ): void {
84 switch ($this->mode) {
85 case "html":
86 $this->buildExportFileHTML();
87 break;
88
89 default:
90 $this->buildExportFileXML($a_mode);
91 break;
92 }
93 }
94
98 public function buildExportFileXML(
99 string $a_mode = ""
100 ): string {
101 if (in_array($a_mode, array("master", "masternomedia"))) {
102 $exp = new ilExport();
103 $conf = $exp->getConfig("Modules/LearningModule");
104 $conf->setMasterLanguageOnly(true, ($a_mode == "master"));
105 $exp->exportObject($this->cont_obj->getType(), $this->cont_obj->getId(), "5.1.0");
106 return "";
107 }
108
109 $this->xml = new ilXmlWriter();
110
111 // set dtd definition
112 $this->xml->xmlSetDtdDef("<!DOCTYPE ContentObject SYSTEM \"https://www.ilias.de/download/dtd/ilias_co_3_7.dtd\">");
113
114 // set generated comment
115 $this->xml->xmlSetGenCmt("Export of ILIAS Content Module " .
116 $this->cont_obj->getId() . " of installation " . $this->inst . ".");
117
118 // set xml header
119 $this->xml->xmlHeader();
120
121 // create directories
122 $this->cont_obj->createExportDirectory();
123 ilFileUtils::makeDir($this->export_dir . "/" . $this->subdir);
124 ilFileUtils::makeDir($this->export_dir . "/" . $this->subdir . "/objects");
125
126 // get Log File
127 $expDir = $this->cont_obj->getExportDirectory();
128 $expLog = new ilLog($expDir, "export.log");
129 $expLog->delete();
130 $expLog->setLogFormat("");
131 $expLog->write(date("[y-m-d H:i:s] ") . "Start Export");
132
133 // get xml content
134 $this->cont_obj->exportXML(
135 $this->xml,
136 $this->inst_id,
137 $this->export_dir . "/" . $this->subdir,
138 $expLog
139 );
140
141 // export style
142 /*
143 if ($this->cont_obj->getStyleSheetId() > 0) {
144 $style_obj = new ilObjStyleSheet($this->cont_obj->getStyleSheetId(), false);
145 $style_obj->setExportSubDir("style");
146 $style_file = $style_obj->export();
147 if (is_file($style_file)) {
148 copy($style_file, $this->export_dir . "/" . $this->subdir . "/style.zip");
149 }
150 }*/
151
152 // dump xml document to file
153 $this->xml->xmlDumpFile($this->export_dir . "/" . $this->subdir . "/" . $this->filename, false);
154
155 // help export (workaround to use ref id here)
157 $this->cont_obj->getRefId()
158 )) {
159 $exp = new ilExport();
160 $exp->exportEntity(
161 "help",
162 $this->cont_obj->getId(),
163 "4.3.0",
164 "Services/Help",
165 "OnlineHelp",
166 $this->export_dir . "/" . $this->subdir
167 );
168 }
169
170 // zip the file
172 $this->export_dir . "/" . $this->subdir,
173 $this->export_dir . "/" . $this->subdir . ".zip"
174 );
175
176 $expLog->write(date("[y-m-d H:i:s] ") . "Finished Export");
177
178 return $this->export_dir . "/" . $this->subdir . ".zip";
179 }
180
181 public function buildExportFileHTML(): void
182 {
183 // create directories
184 if ($this->lang == "") {
185 $this->cont_obj->createExportDirectory("html");
186 } else {
187 $this->cont_obj->createExportDirectory("html_" . $this->lang);
188 }
189
190 // get html content
191 $exp = new \ILIAS\LearningModule\Export\LMHtmlExport(
192 $this->cont_obj,
193 $this->export_dir,
194 $this->subdir,
195 "html",
196 $this->lang
197 );
198 $exp->exportHTML(true);
199 }
200}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(ilObjLearningModule $a_cont_obj, string $a_mode="xml", string $a_lang="")
buildExportFile(string $a_mode="")
buildExportFileXML(string $a_mode="")
build xml export file
ilObjLearningModule $cont_obj
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static zip(string $a_dir, string $a_file, bool $compress_content=false)
zips given directory/file into given zip.file
static makeDir(string $a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: class.ilLog.php:31
static isOnlineHelpModule(int $a_id, bool $a_as_obj_id=false)
Is module an online module.
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...
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
const IL_INST_ID
Definition: constants.php:40
global $DIC
Definition: feed.php:28
Interface ilDBInterface.