ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSCORM2004Export.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 //require_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
25 
30 {
31  private $err; // error object
32  private $db; // database object
33  private $ilias; // ilias object
34  private $cont_obj; // content object (learning module or sco)
35  private $cont_obj_id; // content object id (learning module or sco)
36  private $inst_id; // installation id
37  private $mode; //current export mode
38  private $export_types; // list of supported export types
39  private $module_id;
40 
41  private $date;
42  private $settings;
43  private $export_dir;
44  private $subdir;
45  private $filename;
46 
51  function ilScorm2004Export(&$a_cont_obj, $a_mode = "SCORM 2004 3rd")
52  {
53  global $ilErr, $ilDB, $ilias;
54 
55  $this->export_types = array("SCORM 2004 3rd","SCORM 2004 4th","SCORM 1.2","HTML","ISO","PDF");
56 
57  if(!in_array($a_mode,$this->export_types))
58  die("Unsupported format");
59 
60  $this->cont_obj =& $a_cont_obj;
61 
62  $this->err =& $ilErr;
63  $this->ilias =& $ilias;
64  $this->db =& $ilDB;
65  $this->mode = $a_mode;
66 
67  $settings = $this->ilias->getAllSettings();
68 
69  $this->inst_id = IL_INST_ID;
70 
71  switch ($this->cont_obj->getType())
72  {
73  case 'sahs':
74  $this->module_id = $this->cont_obj->getId();
75  $this->cont_obj_id = $this->cont_obj->getId();
76  break;
77  case 'sco':
78  $this->module_id = $this->cont_obj->slm_id;
79  $this->cont_obj_id = $this->cont_obj->getId();
80  break;
81  }
82 
83  $this->date = time();
84 
85  $this->export_dir = $this->getExportDirectory();
86  $this->subdir = $this->getExportSubDirectory();
87  $this->filename = $this->getExportFileName();
88  }
89 
90  function getExportDirectory()
91  {
92  return $this->getExportDirectoryForType($this->mode);
93  }
94 
96  {
97  $ret = ilUtil::getDataDir()."/lm_data"."/lm_".$this->module_id."/export_";
98  switch($type)
99  {
100  case "ISO":
101  return $ret."_iso";
102  case "PDF":
103  return $ret."_pdf";
104  case "SCORM 2004 3rd":
105  return $ret."_scorm2004";
106  case "SCORM 2004 4th":
107  return $ret."_scorm2004_4th";
108  case "HTML":
109  return $ret."_html";
110  case "SCORM 1.2":
111  return $ret."_scorm12";
112  }
113 
114  }
115 
117  {
118  return $this->date."__".$this->inst_id."__".$this->cont_obj->getType()."_".$this->cont_obj_id;
119  }
120 
121  function getExportFileName()
122  {
123  switch($this->mode)
124  {
125  case "ISO":
126  return $this->subdir.".iso";
127  case "PDF":
128  return $this->subdir.".pdf";
129  default:
130  return $this->subdir.".zip";
131  }
132  }
133 
135  {
136  return $this->export_types;
137  }
138 
139  function getInstId()
140  {
141  return $this->inst_id;
142  }
143 
150  function buildExportFile()
151  {
152  switch ($this->mode)
153  {
154  case "SCORM 2004 3rd":
155  return $this->buildExportFileSCORM("2004 3rd");
156  case "SCORM 2004 4th":
157  return $this->buildExportFileSCORM("2004 4th");
158  case "SCORM 1.2":
159  return $this->buildExportFileSCORM("12");
160  case "HTML":
161  return $this->buildExportFileHTML();
162  case "ISO":
163  return $this->buildExportFileISO();
164  case "PDF":
165  return $this->buildExportFilePDF();
166  }
167  }
168 
172  function buildExportFileSCORM($ver)
173  {
174  global $ilBench;
175 
176  $ilBench->start("ContentObjectExport", "buildExportFile");
177 
178  require_once("./Services/Xml/classes/class.ilXmlWriter.php");
179 
180  // create directories
181  $this->createExportDirectory();
182  ilUtil::makeDir($this->export_dir."/".$this->subdir);
183 
184  // get Log File
185  $expDir = $this->export_dir;
186  $expLog = new ilLog($expDir, "export.log");
187  $expLog->delete();
188  $expLog->setLogFormat("");
189  $expLog->write(date("[y-m-d H:i:s] ")."Start Export");
190 
191  // get xml content
192 
193  $ilBench->start("ContentObjectExport", "buildExportFile_getXML");
194  $this->cont_obj->exportScorm($this->inst_id, $this->export_dir."/".$this->subdir, $ver, $expLog);
195  $ilBench->stop("ContentObjectExport", "buildExportFile_getXML");
196 
197  // zip the file
198  $ilBench->start("ContentObjectExport", "buildExportFile_zipFile");
199  ilUtil::zip($this->export_dir."/".$this->subdir, $this->export_dir."/".$this->subdir.".zip", true);
200  $ilBench->stop("ContentObjectExport", "buildExportFile_zipFile");
201 
202  ilUtil::delDir($this->export_dir."/".$this->subdir);
203 
204  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export");
205  $ilBench->stop("ContentObjectExport", "buildExportFile");
206 
207  return $this->export_dir."/".$this->subdir.".zip";
208  }
209 
214  {
215  global $ilBench;
216 
217  $ilBench->start("ContentObjectExport", "buildExportFile");
218 
219  require_once("./Services/Xml/classes/class.ilXmlWriter.php");
220 
221  // create directories
222  $this->createExportDirectory();
223  ilUtil::makeDir($this->export_dir."/".$this->subdir);
224 
225  // get Log File
226  $expDir = $this->export_dir;
227  $expLog = new ilLog($expDir, "export.log");
228  $expLog->delete();
229  $expLog->setLogFormat("");
230  $expLog->write(date("[y-m-d H:i:s] ")."Start Export");
231 
232  // get xml content
233 
234  $ilBench->start("ContentObjectExport", "buildExportFile_getXML");
235  $this->cont_obj->exportHTML($this->inst_id, $this->export_dir."/".$this->subdir, $expLog);
236  $ilBench->stop("ContentObjectExport", "buildExportFile_getXML");
237 
238  // zip the file
239  $ilBench->start("ContentObjectExport", "buildExportFile_zipFile");
240  ilUtil::zip($this->export_dir."/".$this->subdir, $this->export_dir."/".$this->subdir.".zip", true);
241  $ilBench->stop("ContentObjectExport", "buildExportFile_zipFile");
242 
243  ilUtil::delDir($this->export_dir."/".$this->subdir);
244 
245  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export");
246  $ilBench->stop("ContentObjectExport", "buildExportFile");
247 
248  return $this->export_dir."/".$this->subdir.".zip";
249  }
250 
252  {
253  global $ilBench;
254  $result = "";
255  $ilBench->start("ContentObjectExport", "buildExportFile");
256 
257  require_once("./Services/Xml/classes/class.ilXmlWriter.php");
258 
259  // create directories
260  $this->createExportDirectory();
261  ilUtil::makeDir($this->export_dir."/".$this->subdir);
262 
263  // get Log File
264  $expDir = $this->export_dir;
265  $expLog = new ilLog($expDir, "export.log");
266  $expLog->delete();
267  $expLog->setLogFormat("");
268  $expLog->write(date("[y-m-d H:i:s] ")."Start Export");
269 
270  // get xml content
271 
272  $ilBench->start("ContentObjectExport", "buildExportFile_getXML");
273  $this->cont_obj->exportHTML($this->inst_id, $this->export_dir."/".$this->subdir, $expLog);
274  $ilBench->stop("ContentObjectExport", "buildExportFile_getXML");
275 
276  // zip the file
277  $ilBench->start("ContentObjectExport", "buildExportFile_zipFile");
278  if(ilUtil::CreateIsoFromFolder($this->export_dir."/".$this->subdir, $this->export_dir."/".$this->subdir.".iso"))
279  {
280  $result = $this->export_dir."/".$this->subdir.".iso";
281  }
282  $ilBench->stop("ContentObjectExport", "buildExportFile_zipFile");
283 
284  ilUtil::delDir($this->export_dir."/".$this->subdir);
285 
286  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export");
287  $ilBench->stop("ContentObjectExport", "buildExportFile");
288 
289  return $result;
290  }
291 
293  {
294  global $ilBench;
295  /*include_once('./Services/WebServices/RPC/classes/class.ilRPCServerSettings.php');
296  $pp = ilRPCServerSettings::getInstance();
297  if(!$pp->isEnabled()||!$pp->pingServer())
298  {
299  $this->ilias->raiseError("Xml Rpc Server is not running. Check Administration/Webservices/Java-Server settings", $this->ilias->error_obj->MESSAGE);
300  return;
301  }*/
302 
303  $ilBench->start("ContentObjectExport", "buildExportFile");
304 
305  require_once("./Services/Xml/classes/class.ilXmlWriter.php");
306 
307  // create directories
308  $this->createExportDirectory();
309  ilUtil::makeDir($this->export_dir."/".$this->subdir);
310 
311  // get Log File
312  $expDir = $this->export_dir;
313  $expLog = new ilLog($expDir, "export.log");
314  $expLog->delete();
315  $expLog->setLogFormat("");
316  $expLog->write(date("[y-m-d H:i:s] ")."Start Export");
317 
318  $ilBench->start("ContentObjectExport", "buildExportFile_getXML");
319  $fo_string = $this->cont_obj->exportPDF($this->inst_id, $this->export_dir."/".$this->subdir, $expLog);
320 
321  $ilBench->stop("ContentObjectExport", "buildExportFile_getXML");
322 
323  $ilBench->start("ContentObjectExport", "buildExportFile_pdfFile");
324  fputs(fopen($this->export_dir."/".$this->subdir.'/temp.fo','w+'),$fo_string);
325  //include_once("classes/class.ilFOPUtil.php");
326  //ilFOPUtil::makePDF($this->export_dir."/".$this->subdir.'/temp.fo', $this->export_dir."/".$this->subdir.".pdf");
327  /*include_once "./Services/Transformation/classes/class.ilFO2PDF.php";
328  $fo2pdf = new ilFO2PDF();
329  $fo2pdf->setFOString($fo_string);
330  $result = $fo2pdf->send();
331  if(!$result)
332  $this->ilias->raiseError('Error creating PDF ('.$fo2pdf->err->getLastError()->getMessage().')', $this->ilias->error_obj->MESSAGE);
333  else
334  fputs(fopen($this->export_dir.'/'.$this->subdir.'.pdf','w+'),$result);*/
335  global $ilLog;
336  include_once './Services/WebServices/RPC/classes/class.ilRpcClientFactory.php';
337  try
338  {
339  $pdf_base64 = ilRpcClientFactory::factory('RPCTransformationHandler')->ilFO2PDF($fo_string);
340  //ilUtil::deliverData($pdf_base64->scalar,'learning_progress.pdf','application/pdf');
341  fputs(fopen($this->export_dir.'/'.$this->subdir.'.pdf','w+'),$pdf_base64->scalar);
342  }
343  catch(XML_RPC2_FaultException $e)
344  {
345  ilUtil::sendFailure($e->getMessage(),true);
346  return false;
347  }
348  catch(Exception $e)
349  {
350  ilUtil::sendFailure($e->getMessage(),true);
351  return false;
352  }
353  $ilBench->stop("ContentObjectExport", "buildExportFile_pdfFile");
354 
355  ilUtil::delDir($this->export_dir."/".$this->subdir);
356 
357  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export");
358  $ilBench->stop("ContentObjectExport", "buildExportFile");
359 
360  return $this->export_dir."/".$this->subdir.".pdf";
361  }
362 
364  {
365  $lm_data_dir = ilUtil::getDataDir()."/lm_data";
366  if(!is_writable($lm_data_dir))
367  {
368  $this->ilias->raiseError("Content object Data Directory (".$lm_data_dir.") not writeable.",$this->ilias->error_obj->FATAL);
369  }
370  // create learning module directory (data_dir/lm_data/lm_<id>)
371  $lm_dir = $lm_data_dir."/lm_".$this->module_id;
372  ilUtil::makeDir($lm_dir);
373  if(!@is_dir($lm_dir))
374  {
375  $this->ilias->raiseError("Creation of Learning Module Directory failed.",$this->ilias->error_obj->FATAL);
376  }
377 
378  //$export_dir = $lm_dir."/export_".$this->mode;
379  ilUtil::makeDir($this->export_dir);
380 
381  if(!@is_dir($this->export_dir))
382  {
383  $this->ilias->raiseError("Creation of Export Directory failed.",$this->ilias->error_obj->FATAL);
384  }
385  }
386 
387 }
388 
389 ?>