ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilGlossaryExport.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 
5 
12 {
16  protected $settings;
17 
18  public $err; // error object
19  public $db; // database object
20  public $glo_obj; // glossary
21  public $inst_id; // installation id
22 
27  public function __construct(&$a_glo_obj, $a_mode = "xml")
28  {
29  global $DIC;
30 
31  $this->settings = $DIC->settings();
32  $ilErr = $DIC["ilErr"];
33  $ilDB = $DIC->database();
34  $ilSetting = $DIC->settings();
35 
36  $this->glo_obj = $a_glo_obj;
37 
38  $this->err = $ilErr;
39  $this->db = $ilDB;
40  $this->mode = $a_mode;
41 
42  $settings = $ilSetting->getAll();
43  // The default '0' is required for the directory structure (smeyer)
44  $this->inst_id = $settings["inst_id"] ? $settings['inst_id'] : 0;
45 
46  $date = time();
47  switch ($this->mode) {
48  case "xml":
49  $this->export_dir = $this->glo_obj->getExportDirectory();
50  $this->subdir = $date . "__" . $this->inst_id . "__" .
51  $this->glo_obj->getType() . "_" . $this->glo_obj->getId();
52  $this->filename = $this->subdir . ".xml";
53  break;
54 
55  case "html":
56  $this->export_dir = $this->glo_obj->getExportDirectory("html");
57  $this->subdir = $this->glo_obj->getType() . "_" . $this->glo_obj->getId();
58  $this->filename = $this->subdir . ".zip";
59  break;
60 
61  }
62  }
63 
64  public function getInstId()
65  {
66  return $this->inst_id;
67  }
68 
75  public function buildExportFile()
76  {
77  switch ($this->mode) {
78  case "html":
79  return $this->buildExportFileHTML();
80  break;
81 
82  default:
83  return $this->buildExportFileXML();
84  break;
85  }
86  }
87 
91  public function buildExportFileXML()
92  {
93  $this->xml = new ilXmlWriter;
94 
95  // set dtd definition
96  $this->xml->xmlSetDtdDef("<!DOCTYPE ContentObject SYSTEM \"http://www.ilias.uni-koeln.de/download/dtd/ilias_co_3_7.dtd\">");
97 
98  // set generated comment
99  $this->xml->xmlSetGenCmt("Export of ILIAS Glossary " .
100  $this->glo_obj->getId() . " of installation " . $this->inst . ".");
101 
102  // set xml header
103  $this->xml->xmlHeader();
104 
105  // create directories
106  $this->glo_obj->createExportDirectory();
107  ilUtil::makeDir($this->export_dir . "/" . $this->subdir);
108  ilUtil::makeDir($this->export_dir . "/" . $this->subdir . "/objects");
109 
110  // get Log File
111  $expDir = $this->glo_obj->getExportDirectory();
112  $expLog = new ilLog($expDir, "export.log");
113  $expLog->delete();
114  $expLog->setLogFormat("");
115  $expLog->write(date("[y-m-d H:i:s] ") . "Start Export");
116 
117  // get xml content
118  $this->glo_obj->exportXML(
119  $this->xml,
120  $this->inst_id,
121  $this->export_dir . "/" . $this->subdir,
122  $expLog
123  );
124 
125 
126 
127  // dump xml document to file
128  $this->xml->xmlDumpFile($this->export_dir . "/" . $this->subdir . "/" . $this->filename, false);
129 
130  // zip the file
131  ilUtil::zip(
132  $this->export_dir . "/" . $this->subdir,
133  $this->export_dir . "/" . $this->subdir . ".zip"
134  );
135 
136  // destroy writer object
137  $this->xml->_XmlWriter;
138 
139  $expLog->write(date("[y-m-d H:i:s] ") . "Finished Export");
140 
141  return $this->export_dir . "/" . $this->subdir . ".zip";
142  }
143 
147  public function buildExportFileHTML()
148  {
149  // create directories
150  $this->glo_obj->createExportDirectory("html");
151 
152  // get html content
153  $exp = new \ILIAS\Glossary\Export\GlossaryHtmlExport(
154  $this->glo_obj,
155  $this->export_dir,
156  $this->subdir
157  );
158  $exp->exportHTML();
159  }
160 }
settings()
Definition: settings.php:2
buildExportFileHTML()
build html export file
xmlSetDtdDef($dtdDef)
Sets dtd definition.
XML writer class.
logging
Definition: class.ilLog.php:18
$ilErr
Definition: raiseError.php:18
buildExportFileXML()
build export file (complete zip file)
buildExportFile()
build export file (complete zip file)
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 ...
global $ilSetting
Definition: privfeed.php:17
global $ilDB
$DIC
Definition: xapitoken.php:46
__construct(&$a_glo_obj, $a_mode="xml")
Constructor public.
Export class for content objects.