ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilGlossaryExport.php
Go to the documentation of this file.
1 <?php
2 
25 {
26  protected ilXmlWriter $xml;
27  protected string $export_dir;
28  protected string $filename;
29  protected string $subdir;
30  protected string $mode;
31  protected ilSetting $settings;
34  public int $inst_id;
35 
36  public function __construct(
37  ilObjGlossary $a_glo_obj,
38  string $a_mode = "xml"
39  ) {
40  global $DIC;
41 
42  $this->settings = $DIC->settings();
43  $ilDB = $DIC->database();
44  $ilSetting = $DIC->settings();
45  $this->glo_obj = $a_glo_obj;
46  $this->db = $ilDB;
47  $this->mode = $a_mode;
48 
49  $settings = $ilSetting->getAll();
50  // The default '0' is required for the directory structure (smeyer)
51  $this->inst_id = $settings["inst_id"] ? $settings['inst_id'] : 0;
52 
53  $date = time();
54  switch ($this->mode) {
55  case "xml":
56  $this->export_dir = $this->glo_obj->getExportDirectory();
57  $this->subdir = $date . "__" . $this->inst_id . "__" .
58  $this->glo_obj->getType() . "_" . $this->glo_obj->getId();
59  $this->filename = $this->subdir . ".xml";
60  break;
61 
62  case "html":
63  $this->export_dir = $this->glo_obj->getExportDirectory("html");
64  $this->subdir = $this->glo_obj->getType() . "_" . $this->glo_obj->getId();
65  $this->filename = $this->subdir . ".zip";
66  break;
67  }
68  }
69 
70  public function getInstId(): int
71  {
72  return $this->inst_id;
73  }
74 
78  public function buildExportFile(): string
79  {
80  switch ($this->mode) {
81  case "html":
82  return $this->buildExportFileHTML();
83 
84  default:
85  return $this->buildExportFileXML();
86  }
87  }
88 
92  public function buildExportFileXML(): string
93  {
94  $this->xml = new ilXmlWriter();
95 
96  // set dtd definition
97  $this->xml->xmlSetDtdDef("<!DOCTYPE ContentObject SYSTEM \"https://www.ilias.uni-koeln.de/download/dtd/ilias_co_3_7.dtd\">");
98 
99  // set generated comment
100  $this->xml->xmlSetGenCmt("Export of ILIAS Glossary " .
101  $this->glo_obj->getId() . " of installation " . $this->inst_id . ".");
102 
103  // set xml header
104  $this->xml->xmlHeader();
105 
106  // create directories
107  $this->glo_obj->createExportDirectory();
108  ilFileUtils::makeDir($this->export_dir . "/" . $this->subdir);
109  ilFileUtils::makeDir($this->export_dir . "/" . $this->subdir . "/objects");
110 
111  // get Log File
112  $expDir = $this->glo_obj->getExportDirectory();
113  $expLog = new ilLog($expDir, "export.log");
114  $expLog->delete();
115  $expLog->setLogFormat("");
116  $expLog->write(date("[y-m-d H:i:s] ") . "Start Export");
117 
118  // get xml content
119  $this->glo_obj->exportXML(
120  $this->xml,
121  $this->inst_id,
122  $this->export_dir . "/" . $this->subdir,
123  $expLog
124  );
125 
126 
127 
128  // dump xml document to file
129  $this->xml->xmlDumpFile($this->export_dir . "/" . $this->subdir . "/" . $this->filename, false);
130 
131  // zip the file
133  $this->export_dir . "/" . $this->subdir,
134  $this->export_dir . "/" . $this->subdir . ".zip"
135  );
136 
137  $expLog->write(date("[y-m-d H:i:s] ") . "Finished Export");
138 
139  return $this->export_dir . "/" . $this->subdir . ".zip";
140  }
141 
145  public function buildExportFileHTML(): string
146  {
147  // create directories
148  $this->glo_obj->createExportDirectory("html");
149 
150  // get html content
151  $exp = new \ILIAS\Glossary\Export\GlossaryHtmlExport(
152  $this->glo_obj,
153  $this->export_dir,
154  $this->subdir
155  );
156  return $exp->exportHTML();
157  }
158 }
__construct(ilObjGlossary $a_glo_obj, string $a_mode="xml")
buildExportFileHTML()
build html export file
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: class.ilLog.php:30
global $DIC
Definition: feed.php:28
buildExportFileXML()
build export file (complete zip file)
buildExportFile()
build export file (complete zip file)
global $ilSetting
Definition: privfeed.php:18
static zip(string $a_dir, string $a_file, bool $compress_content=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static makeDir(string $a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...