ILIAS  release_4-3 Revision
 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  // help export (workaround to use ref id here)
176  if (ilObjContentObject::isOnlineHelpModule((int) $_GET["ref_id"]))
177  {
178  include_once("./Services/Export/classes/class.ilExport.php");
179  $exp = new ilExport();
180  $exp->exportEntity("help", $this->cont_obj->getId(), "4.3.0", "Services/Help",
181  "OnlineHelp", $this->export_dir."/".$this->subdir);
182  }
183 
184  // zip the file
185  ilUtil::zip($this->export_dir."/".$this->subdir,
186  $this->export_dir."/".$this->subdir.".zip");
187 
188  // destroy writer object
189  $this->xml->_XmlWriter;
190 
191  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export");
192  $ilBench->stop("ContentObjectExport", "buildExportFile");
193 
194  return $this->export_dir."/".$this->subdir.".zip";
195  }
196 
201  {
202  die("deprecated.");
203  }
204 
209  {
210  global $ilBench;
211 
212  $ilBench->start("ContentObjectExport", "buildHTMLPackage");
213 
214  // create directories
215  $this->cont_obj->createExportDirectory("html");
216 
217  // get html content
218  $ilBench->start("ContentObjectExport", "buildHTMLPackage_getHTML");
219  $this->cont_obj->exportHTML($this->export_dir."/".$this->subdir, $expLog);
220  $ilBench->stop("ContentObjectExport", "buildHTMLPackage_getHTML");
221 
222  //$expLog->write(date("[y-m-d H:i:s] ")."Finished Export");
223  $ilBench->stop("ContentObjectExport", "buildHTMLPackage");
224  }
225 
230  {
231  global $ilBench;
232 
233  $ilBench->start("ContentObjectExport", "buildSCORMPackage");
234 
235  // create directories
236  $this->cont_obj->createExportDirectory("scorm");
237 
238  // get html content
239  $ilBench->start("ContentObjectExport", "buildSCORMPackage_getSCORM");
240  $this->cont_obj->exportSCORM($this->export_dir."/".$this->subdir, $expLog);
241  $ilBench->stop("ContentObjectExport", "buildSCORMPackage_getSCORM");
242 
243  //$expLog->write(date("[y-m-d H:i:s] ")."Finished Export");
244  $ilBench->stop("ContentObjectExport", "buildSCORMPackage");
245  }
246 
247 }
248 
249 ?>