ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
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 
71  public function getInstId(): int
72  {
73  return $this->inst_id;
74  }
75 
79  public function buildExportFile(): string
80  {
81  switch ($this->mode) {
82  case "html":
83  return $this->buildExportFileHTML();
84 
85  default:
86  return $this->buildExportFileXML();
87  }
88  }
89 
93  public function buildExportFileXML(): string
94  {
95  $this->xml = new ilXmlWriter();
96 
97  // set dtd definition
98  $this->xml->xmlSetDtdDef("<!DOCTYPE ContentObject SYSTEM \"https://www.ilias.uni-koeln.de/download/dtd/ilias_co_3_7.dtd\">");
99 
100  // set generated comment
101  $this->xml->xmlSetGenCmt("Export of ILIAS Glossary " .
102  $this->glo_obj->getId() . " of installation " . $this->inst_id . ".");
103 
104  // set xml header
105  $this->xml->xmlHeader();
106 
107  // create directories
108  $this->glo_obj->createExportDirectory();
109  ilFileUtils::makeDir($this->export_dir . "/" . $this->subdir);
110  ilFileUtils::makeDir($this->export_dir . "/" . $this->subdir . "/objects");
111 
112  // get Log File
113  $expDir = $this->glo_obj->getExportDirectory();
114  $expLog = new ilLog($expDir, "export.log");
115  $expLog->delete();
116  $expLog->setLogFormat("");
117  $expLog->write(date("[y-m-d H:i:s] ") . "Start Export");
118 
119  // get xml content
120  $this->glo_obj->exportXML(
121  $this->xml,
122  $this->inst_id,
123  $this->export_dir . "/" . $this->subdir,
124  $expLog
125  );
126 
127 
128 
129  // dump xml document to file
130  $this->xml->xmlDumpFile($this->export_dir . "/" . $this->subdir . "/" . $this->filename, false);
131 
132  // zip the file
134  $this->export_dir . "/" . $this->subdir,
135  $this->export_dir . "/" . $this->subdir . ".zip"
136  );
137 
138  $expLog->write(date("[y-m-d H:i:s] ") . "Finished Export");
139 
140  return $this->export_dir . "/" . $this->subdir . ".zip";
141  }
142 
146  public function buildExportFileHTML(): string
147  {
148  // create directories
149  $this->glo_obj->createExportDirectory("html");
150 
151  // get html content
152  $exp = new \ILIAS\Glossary\Export\GlossaryHtmlExport(
153  $this->glo_obj,
154  $this->export_dir,
155  $this->subdir
156  );
157  return $exp->exportHTML();
158  }
159 }
__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:17
static zip(string $a_dir, string $a_file, bool $compress_content=false)
zips given directory/file into given zip.file
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 ...