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