ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSCORM2004Export.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 //require_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
6 
11 {
12  private $err; // error object
13  private $db; // database object
14  private $ilias; // ilias object
15  private $cont_obj; // content object (learning module or sco)
16  private $cont_obj_id; // content object id (learning module or sco)
17  private $inst_id; // installation id
18  private $mode; //current export mode
19  private $export_types; // list of supported export types
20  private $module_id;
21 
22  private $date;
23  private $settings;
24  private $export_dir;
25  private $subdir;
26  private $filename;
27 
32  function ilScorm2004Export(&$a_cont_obj, $a_mode = "SCORM 2004 3rd")
33  {
34  global $ilErr, $ilDB, $ilias;
35 
36  $this->export_types = array("SCORM 2004 3rd","SCORM 2004 4th","SCORM 1.2","HTML","ISO","PDF",
37  "HTMLOne");
38 
39  if(!in_array($a_mode,$this->export_types))
40  die("Unsupported format");
41 
42  $this->cont_obj =& $a_cont_obj;
43 
44  $this->err =& $ilErr;
45  $this->ilias =& $ilias;
46  $this->db =& $ilDB;
47  $this->mode = $a_mode;
48 
49  $settings = $this->ilias->getAllSettings();
50 
51  $this->inst_id = IL_INST_ID;
52 
53  switch ($this->cont_obj->getType())
54  {
55  case 'sahs':
56  $this->module_id = $this->cont_obj->getId();
57  $this->cont_obj_id = $this->cont_obj->getId();
58  break;
59  case 'sco':
60  $this->module_id = $this->cont_obj->slm_id;
61  $this->cont_obj_id = $this->cont_obj->getId();
62  break;
63  }
64 
65  $this->date = time();
66 
67  $this->export_dir = $this->getExportDirectory();
68  $this->subdir = $this->getExportSubDirectory();
69  $this->filename = $this->getExportFileName();
70  }
71 
72  function getExportDirectory()
73  {
74  return $this->getExportDirectoryForType($this->mode);
75  }
76 
77  function getExportDirectoryForType($type)
78  {
79  $ret = ilUtil::getDataDir()."/lm_data"."/lm_".$this->module_id."/export_";
80  switch($type)
81  {
82  case "ISO":
83  return $ret."_iso";
84  case "PDF":
85  return $ret."_pdf";
86  case "SCORM 2004 3rd":
87  return $ret."_scorm2004";
88  case "SCORM 2004 4th":
89  return $ret."_scorm2004_4th";
90  case "HTML":
91  return $ret."_html";
92  case "HTMLOne":
93  return $ret."_html_one";
94  case "SCORM 1.2":
95  return $ret."_scorm12";
96  }
97 
98  }
99 
101  {
102  return $this->date."__".$this->inst_id."__".$this->cont_obj->getType()."_".$this->cont_obj_id;
103  }
104 
105  function getExportFileName()
106  {
107  switch($this->mode)
108  {
109  case "ISO":
110  return $this->subdir.".iso";
111  case "PDF":
112  return $this->subdir.".pdf";
113  default:
114  return $this->subdir.".zip";
115  }
116  }
117 
119  {
120  return $this->export_types;
121  }
122 
123  function getInstId()
124  {
125  return $this->inst_id;
126  }
127 
134  function buildExportFile()
135  {
136  switch ($this->mode)
137  {
138  case "SCORM 2004 3rd":
139  return $this->buildExportFileSCORM("2004 3rd");
140  case "SCORM 2004 4th":
141  return $this->buildExportFileSCORM("2004 4th");
142  case "SCORM 1.2":
143  return $this->buildExportFileSCORM("12");
144  case "HTML":
145  return $this->buildExportFileHTML();
146  case "HTMLOne":
147  return $this->buildExportFileHTMLOne();
148  case "ISO":
149  return $this->buildExportFileISO();
150  case "PDF":
151  return $this->buildExportFilePDF();
152  }
153  }
154 
158  function buildExportFileSCORM($ver)
159  {
160  global $ilBench;
161 
162  $ilBench->start("ContentObjectExport", "buildExportFile");
163 
164  require_once("./Services/Xml/classes/class.ilXmlWriter.php");
165 
166  // create directories
167  $this->createExportDirectory();
168  ilUtil::makeDir($this->export_dir."/".$this->subdir);
169 
170  // get Log File
171  $expDir = $this->export_dir;
172  $expLog = new ilLog($expDir, "export.log");
173  $expLog->delete();
174  $expLog->setLogFormat("");
175  $expLog->write(date("[y-m-d H:i:s] ")."Start Export");
176 
177  // get xml content
178 
179  $ilBench->start("ContentObjectExport", "buildExportFile_getXML");
180  $this->cont_obj->exportScorm($this->inst_id, $this->export_dir."/".$this->subdir, $ver, $expLog);
181  $ilBench->stop("ContentObjectExport", "buildExportFile_getXML");
182 
183  // zip the file
184  $ilBench->start("ContentObjectExport", "buildExportFile_zipFile");
185  ilUtil::zip($this->export_dir."/".$this->subdir, $this->export_dir."/".$this->subdir.".zip", true);
186  $ilBench->stop("ContentObjectExport", "buildExportFile_zipFile");
187 
188  ilUtil::delDir($this->export_dir."/".$this->subdir);
189 
190  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export");
191  $ilBench->stop("ContentObjectExport", "buildExportFile");
192 
193  return $this->export_dir."/".$this->subdir.".zip";
194  }
195 
200  {
201  require_once("./Services/Xml/classes/class.ilXmlWriter.php");
202 
203  // create directories
204  $this->createExportDirectory();
205  ilUtil::makeDir($this->export_dir."/".$this->subdir);
206 
207  // get Log File
208  $expDir = $this->export_dir;
209  $expLog = new ilLog($expDir, "export.log");
210  $expLog->delete();
211  $expLog->setLogFormat("");
212  $expLog->write(date("[y-m-d H:i:s] ")."Start Export");
213 
214  // get xml content
215  $this->cont_obj->exportHTML($this->inst_id, $this->export_dir."/".$this->subdir, $expLog);
216 
217  // zip the file
218  ilUtil::zip($this->export_dir."/".$this->subdir, $this->export_dir."/".$this->subdir.".zip", true);
219 
220  ilUtil::delDir($this->export_dir."/".$this->subdir);
221 
222  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export");
223 
224  return $this->export_dir."/".$this->subdir.".zip";
225  }
226 
231  {
232  require_once("./Services/Xml/classes/class.ilXmlWriter.php");
233 
234  // create directories
235  $this->createExportDirectory();
236  ilUtil::makeDir($this->export_dir."/".$this->subdir);
237 
238  // get Log File
239  $expDir = $this->export_dir;
240  $expLog = new ilLog($expDir, "export.log");
241  $expLog->delete();
242  $expLog->setLogFormat("");
243  $expLog->write(date("[y-m-d H:i:s] ")."Start Export");
244 
245  // get xml content
246  $this->cont_obj->exportHTMLOne($this->inst_id, $this->export_dir."/".$this->subdir, $expLog);
247 
248  // zip the file
249  ilUtil::zip($this->export_dir."/".$this->subdir, $this->export_dir."/".$this->subdir.".zip", true);
250 
251  ilUtil::delDir($this->export_dir."/".$this->subdir);
252 
253  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export");
254 
255  return $this->export_dir."/".$this->subdir.".zip";
256  }
257 
259  {
260  global $ilBench;
261  $result = "";
262  $ilBench->start("ContentObjectExport", "buildExportFile");
263 
264  require_once("./Services/Xml/classes/class.ilXmlWriter.php");
265 
266  // create directories
267  $this->createExportDirectory();
268  ilUtil::makeDir($this->export_dir."/".$this->subdir);
269 
270  // get Log File
271  $expDir = $this->export_dir;
272  $expLog = new ilLog($expDir, "export.log");
273  $expLog->delete();
274  $expLog->setLogFormat("");
275  $expLog->write(date("[y-m-d H:i:s] ")."Start Export");
276 
277  // get xml content
278 
279  $ilBench->start("ContentObjectExport", "buildExportFile_getXML");
280  $this->cont_obj->exportHTML($this->inst_id, $this->export_dir."/".$this->subdir, $expLog);
281  $ilBench->stop("ContentObjectExport", "buildExportFile_getXML");
282 
283  // zip the file
284  $ilBench->start("ContentObjectExport", "buildExportFile_zipFile");
285  if(ilUtil::CreateIsoFromFolder($this->export_dir."/".$this->subdir, $this->export_dir."/".$this->subdir.".iso"))
286  {
287  $result = $this->export_dir."/".$this->subdir.".iso";
288  }
289  $ilBench->stop("ContentObjectExport", "buildExportFile_zipFile");
290 
291  ilUtil::delDir($this->export_dir."/".$this->subdir);
292 
293  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export");
294  $ilBench->stop("ContentObjectExport", "buildExportFile");
295 
296  return $result;
297  }
298 
300  {
301  global $ilBench;
302  /*include_once('./Services/WebServices/RPC/classes/class.ilRPCServerSettings.php');
303  $pp = ilRPCServerSettings::getInstance();
304  if(!$pp->isEnabled()||!$pp->pingServer())
305  {
306  $this->ilias->raiseError("Xml Rpc Server is not running. Check Administration/Webservices/Java-Server settings", $this->ilias->error_obj->MESSAGE);
307  return;
308  }*/
309 
310  $ilBench->start("ContentObjectExport", "buildExportFile");
311 
312  require_once("./Services/Xml/classes/class.ilXmlWriter.php");
313 
314  // create directories
315  $this->createExportDirectory();
316  ilUtil::makeDir($this->export_dir."/".$this->subdir);
317 
318  // get Log File
319  $expDir = $this->export_dir;
320  $expLog = new ilLog($expDir, "export.log");
321  $expLog->delete();
322  $expLog->setLogFormat("");
323  $expLog->write(date("[y-m-d H:i:s] ")."Start Export");
324 
325  $ilBench->start("ContentObjectExport", "buildExportFile_getXML");
326  $fo_string = $this->cont_obj->exportPDF($this->inst_id, $this->export_dir."/".$this->subdir, $expLog);
327 
328  $ilBench->stop("ContentObjectExport", "buildExportFile_getXML");
329 
330  $ilBench->start("ContentObjectExport", "buildExportFile_pdfFile");
331  fputs(fopen($this->export_dir."/".$this->subdir.'/temp.fo','w+'),$fo_string);
332 
333  global $ilLog;
334  include_once './Services/WebServices/RPC/classes/class.ilRpcClientFactory.php';
335  try
336  {
337  $pdf_base64 = ilRpcClientFactory::factory('RPCTransformationHandler')->ilFO2PDF($fo_string);
338  //ilUtil::deliverData($pdf_base64->scalar,'learning_progress.pdf','application/pdf');
339  fputs(fopen($this->export_dir.'/'.$this->subdir.'.pdf','w+'),$pdf_base64->scalar);
340  }
341  catch(XML_RPC2_FaultException $e)
342  {
343  ilUtil::sendFailure($e->getMessage(),true);
344  return false;
345  }
346  catch(Exception $e)
347  {
348  ilUtil::sendFailure($e->getMessage(),true);
349  return false;
350  }
351  $ilBench->stop("ContentObjectExport", "buildExportFile_pdfFile");
352 
353  ilUtil::delDir($this->export_dir."/".$this->subdir);
354 
355  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export");
356  $ilBench->stop("ContentObjectExport", "buildExportFile");
357 
358  return $this->export_dir."/".$this->subdir.".pdf";
359  }
360 
362  {
363  $lm_data_dir = ilUtil::getDataDir()."/lm_data";
364  if(!is_writable($lm_data_dir))
365  {
366  $this->ilias->raiseError("Content object Data Directory (".$lm_data_dir.") not writeable.",$this->ilias->error_obj->FATAL);
367  }
368  // create learning module directory (data_dir/lm_data/lm_<id>)
369  $lm_dir = $lm_data_dir."/lm_".$this->module_id;
370  ilUtil::makeDir($lm_dir);
371  if(!@is_dir($lm_dir))
372  {
373  $this->ilias->raiseError("Creation of Learning Module Directory failed.",$this->ilias->error_obj->FATAL);
374  }
375 
376  //$export_dir = $lm_dir."/export_".$this->mode;
377  ilUtil::makeDir($this->export_dir);
378 
379  if(!@is_dir($this->export_dir))
380  {
381  $this->ilias->raiseError("Creation of Export Directory failed.",$this->ilias->error_obj->FATAL);
382  }
383  }
384 
385 }
386 
387 ?>