ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilContObjectExport.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
5 
17 {
18  var $err; // error object
19  var $db; // database object
20  var $ilias; // ilias object
21  var $cont_obj; // content object (learning module | digilib book)
22  var $inst_id; // installation id
23  var $mode;
24 
29  function ilContObjectExport(&$a_cont_obj, $a_mode = "xml")
30  {
31  global $ilErr, $ilDB, $ilias;
32 
33  $this->cont_obj =& $a_cont_obj;
34 
35  $this->err =& $ilErr;
36  $this->ilias =& $ilias;
37  $this->db =& $ilDB;
38  $this->mode = $a_mode;
39 
40  $settings = $this->ilias->getAllSettings();
41  //$this->inst_id = $settings["inst_id"];
42  $this->inst_id = IL_INST_ID;
43 
44  $date = time();
45  switch($this->mode)
46  {
47  case "html":
48  $this->export_dir = $this->cont_obj->getExportDirectory("html");
49  $this->subdir = $this->cont_obj->getType()."_".$this->cont_obj->getId();
50  $this->filename = $this->subdir.".zip";
51  break;
52 
53  case "scorm":
54  $this->export_dir = $this->cont_obj->getExportDirectory("scorm");
55  $this->subdir = $this->cont_obj->getType()."_".$this->cont_obj->getId();
56  $this->filename = $this->subdir.".zip";
57  break;
58 
59  case "pdf":
60  $this->export_dir = $this->cont_obj->getOfflineDirectory();
61  $this->subdir = $date."__".$this->inst_id."__".
62  $this->cont_obj->getType()."_".$this->cont_obj->getId();
63  $this->filename = $this->subdir.".fo";
64  break;
65 
66  default:
67  $this->export_dir = $this->cont_obj->getExportDirectory();
68  $this->subdir = $date."__".$this->inst_id."__".
69  $this->cont_obj->getType()."_".$this->cont_obj->getId();
70  $this->filename = $this->subdir.".xml";
71  break;
72  }
73  }
74 
75  function getInstId()
76  {
77  return $this->inst_id;
78  }
79 
86  function buildExportFile()
87  {
88  switch ($this->mode)
89  {
90  case "html":
91  return $this->buildExportFileHTML();
92  break;
93 
94  case "scorm":
95  return $this->buildExportFileSCORM();
96  break;
97 
98  case "pdf":
99  return $this->buildExportFilePDF();
100  break;
101 
102  default:
103  return $this->buildExportFileXML();
104  break;
105  }
106  }
107 
112  {
113  global $ilBench;
114 
115  $ilBench->start("ContentObjectExport", "buildExportFile");
116 
117  require_once("./Services/Xml/classes/class.ilXmlWriter.php");
118 
119  $this->xml = new ilXmlWriter;
120 
121  // set dtd definition
122  $this->xml->xmlSetDtdDef("<!DOCTYPE ContentObject SYSTEM \"http://www.ilias.de/download/dtd/ilias_co_3_7.dtd\">");
123 
124  // set generated comment
125  $this->xml->xmlSetGenCmt("Export of ILIAS Content Module ".
126  $this->cont_obj->getId()." of installation ".$this->inst.".");
127 
128  // set xml header
129  $this->xml->xmlHeader();
130 
131  // create directories
132  $this->cont_obj->createExportDirectory();
133  ilUtil::makeDir($this->export_dir."/".$this->subdir);
134  ilUtil::makeDir($this->export_dir."/".$this->subdir."/objects");
135 
136  // get Log File
137  $expDir = $this->cont_obj->getExportDirectory();
138  $expLog = new ilLog($expDir, "export.log");
139  $expLog->delete();
140  $expLog->setLogFormat("");
141  $expLog->write(date("[y-m-d H:i:s] ")."Start Export");
142 
143  // get xml content
144 //echo "ContObjExport:".$this->inst_id.":<br>";
145  $ilBench->start("ContentObjectExport", "buildExportFile_getXML");
146  $this->cont_obj->exportXML($this->xml, $this->inst_id,
147  $this->export_dir."/".$this->subdir, $expLog);
148  $ilBench->stop("ContentObjectExport", "buildExportFile_getXML");
149 
150  // export style
151  if ($this->cont_obj->getStyleSheetId() > 0)
152  {
153  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
154  $style_obj = new ilObjStyleSheet($this->cont_obj->getStyleSheetId(), false);
155  //$style_obj->exportXML($this->export_dir."/".$this->subdir);
156  $style_obj->setExportSubDir("style");
157  $style_file = $style_obj->export();
158  if (is_file($style_file))
159  {
160  copy($style_file, $this->export_dir."/".$this->subdir."/style.zip");
161  }
162  }
163 
164  // dump xml document to screen (only for debugging reasons)
165  /*
166  echo "<PRE>";
167  echo htmlentities($this->xml->xmlDumpMem($format));
168  echo "</PRE>";
169  */
170 
171  // dump xml document to file
172  $this->xml->xmlDumpFile($this->export_dir."/".$this->subdir."/".$this->filename
173  , false);
174 
175  // zip the file
176  ilUtil::zip($this->export_dir."/".$this->subdir,
177  $this->export_dir."/".$this->subdir.".zip");
178 
179  // destroy writer object
180  $this->xml->_XmlWriter;
181 
182  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export");
183  $ilBench->stop("ContentObjectExport", "buildExportFile");
184 
185  return $this->export_dir."/".$this->subdir.".zip";
186  }
187 
192  {
193  global $ilBench;
194 
195  $ilBench->start("ContentObjectExport", "buildPDFFile");
196 
197  require_once("./Services/Xml/classes/class.ilXmlWriter.php");
198 
199  $this->xml = new ilXmlWriter;
200 
201  // set dtd definition
202  //$this->xml->xmlSetDtdDef("<!DOCTYPE LearningModule SYSTEM \"http://www.ilias.uni-koeln.de/download/dtd/ilias_co.dtd\">");
203 
204  // set generated comment
205  //$this->xml->xmlSetGenCmt("Export of ILIAS Content Module ".
206  // $this->cont_obj->getId()." of installation ".$this->inst.".");
207 
208  // set xml header
209  $this->xml->xmlHeader();
210 
211  // create directories
212  //$this->cont_obj->createExportDirectory("pdf"); //not implemened!
213  //ilUtil::makeDir($this->export_dir."/".$this->subdir);
214  //ilUtil::makeDir($this->export_dir."/".$this->subdir."/objects");
215 
216  // get Log File
217  /*
218  $expDir = $this->cont_obj->getExportDirectory();
219  $expLog = new ilLog($expDir, "export.log");
220  $expLog->delete();
221  $expLog->setLogFormat("");
222  $expLog->write(date("[y-m-d H:i:s] ")."Start Export");*/
223 
224  // get xml content
225  $ilBench->start("ContentObjectExport", "buildPDFFile_getFO");
226  $this->cont_obj->exportFO($this->xml,
227  $this->export_dir."/".$this->subdir, $expLog);
228  $ilBench->stop("ContentObjectExport", "buildPDFFile_getFO");
229 
230 
231  // dump fo document to file
232  $ilBench->start("ContentObjectExport", "buildPDFFile_dumpToFile");
233 //echo "dumping:".$this->export_dir."/".$this->filename;
234  $this->xml->xmlDumpFile($this->export_dir."/".$this->filename
235  , false);
236  $ilBench->stop("ContentObjectExport", "buildPDFFile_dumpToFile");
237 
238  // convert fo to pdf file
239  //$ilBench->start("ContentObjectExport", "buildExportFile_zipFile");
240  include_once("classes/class.ilFOPUtil.php");
241  ilFOPUtil::makePDF($this->export_dir."/".$this->filename,
242  $this->export_dir."/".$this->subdir.".pdf");
243  //$ilBench->stop("ContentObjectExport", "buildExportFile_zipFile");
244 
245  // destroy writer object
246  $this->xml->_XmlWriter;
247 
248  //$expLog->write(date("[y-m-d H:i:s] ")."Finished Export");
249  $ilBench->stop("ContentObjectExport", "buildPDFFile");
250  }
251 
256  {
257  global $ilBench;
258 
259  $ilBench->start("ContentObjectExport", "buildHTMLPackage");
260 
261  // create directories
262  $this->cont_obj->createExportDirectory("html");
263 
264  // get html content
265  $ilBench->start("ContentObjectExport", "buildHTMLPackage_getHTML");
266  $this->cont_obj->exportHTML($this->export_dir."/".$this->subdir, $expLog);
267  $ilBench->stop("ContentObjectExport", "buildHTMLPackage_getHTML");
268 
269  //$expLog->write(date("[y-m-d H:i:s] ")."Finished Export");
270  $ilBench->stop("ContentObjectExport", "buildHTMLPackage");
271  }
272 
277  {
278  global $ilBench;
279 
280  $ilBench->start("ContentObjectExport", "buildSCORMPackage");
281 
282  // create directories
283  $this->cont_obj->createExportDirectory("scorm");
284 
285  // get html content
286  $ilBench->start("ContentObjectExport", "buildSCORMPackage_getSCORM");
287  $this->cont_obj->exportSCORM($this->export_dir."/".$this->subdir, $expLog);
288  $ilBench->stop("ContentObjectExport", "buildSCORMPackage_getSCORM");
289 
290  //$expLog->write(date("[y-m-d H:i:s] ")."Finished Export");
291  $ilBench->stop("ContentObjectExport", "buildSCORMPackage");
292  }
293 
294 }
295 
296 ?>