ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 __construct(&$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  // init the mathjax rendering for HTML export
165  include_once './Services/MathJax/classes/class.ilMathJax.php';
167 
168  require_once("./Services/Xml/classes/class.ilXmlWriter.php");
169 
170  // create directories
171  $this->createExportDirectory();
172  ilUtil::makeDir($this->export_dir."/".$this->subdir);
173 
174  // get Log File
175  $expDir = $this->export_dir;
176  include_once './Services/Logging/classes/class.ilLog.php';
177  $expLog = new ilLog($expDir, "export.log");
178  $expLog->delete();
179  $expLog->setLogFormat("");
180  $expLog->write(date("[y-m-d H:i:s] ")."Start Export");
181 
182  // get xml content
183 
184  $ilBench->start("ContentObjectExport", "buildExportFile_getXML");
185  $this->cont_obj->exportScorm($this->inst_id, $this->export_dir."/".$this->subdir, $ver, $expLog);
186  $ilBench->stop("ContentObjectExport", "buildExportFile_getXML");
187 
188  // zip the file
189  $ilBench->start("ContentObjectExport", "buildExportFile_zipFile");
190  ilUtil::zip($this->export_dir."/".$this->subdir, $this->export_dir."/".$this->subdir.".zip", true);
191  $ilBench->stop("ContentObjectExport", "buildExportFile_zipFile");
192 
193  ilUtil::delDir($this->export_dir."/".$this->subdir);
194 
195  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export");
196  $ilBench->stop("ContentObjectExport", "buildExportFile");
197 
198  return $this->export_dir."/".$this->subdir.".zip";
199  }
200 
205  {
206  require_once("./Services/Xml/classes/class.ilXmlWriter.php");
207 
208  // init the mathjax rendering for HTML export
209  include_once './Services/MathJax/classes/class.ilMathJax.php';
211 
212  // create directories
213  $this->createExportDirectory();
214  ilUtil::makeDir($this->export_dir."/".$this->subdir);
215 
216  // get Log File
217  $expDir = $this->export_dir;
218  include_once './Services/Logging/classes/class.ilLog.php';
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  $this->cont_obj->exportHTML($this->inst_id, $this->export_dir."/".$this->subdir, $expLog);
226 
227  // zip the file
228  ilUtil::zip($this->export_dir."/".$this->subdir, $this->export_dir."/".$this->subdir.".zip", true);
229 
230  ilUtil::delDir($this->export_dir."/".$this->subdir);
231 
232  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export");
233 
234  return $this->export_dir."/".$this->subdir.".zip";
235  }
236 
241  {
242  require_once("./Services/Xml/classes/class.ilXmlWriter.php");
243 
244  // init the mathjax rendering for HTML export
245  include_once './Services/MathJax/classes/class.ilMathJax.php';
247 
248  // create directories
249  $this->createExportDirectory();
250  ilUtil::makeDir($this->export_dir."/".$this->subdir);
251 
252  // get Log File
253  $expDir = $this->export_dir;
254  include_once './Services/Logging/classes/class.ilLog.php';
255  $expLog = new ilLog($expDir, "export.log");
256  $expLog->delete();
257  $expLog->setLogFormat("");
258  $expLog->write(date("[y-m-d H:i:s] ")."Start Export");
259 
260  // get xml content
261  $this->cont_obj->exportHTMLOne($this->inst_id, $this->export_dir."/".$this->subdir, $expLog);
262 
263  // zip the file
264  ilUtil::zip($this->export_dir."/".$this->subdir, $this->export_dir."/".$this->subdir.".zip", true);
265 
266  ilUtil::delDir($this->export_dir."/".$this->subdir);
267 
268  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export");
269 
270  return $this->export_dir."/".$this->subdir.".zip";
271  }
272 
274  {
275  global $ilBench;
276  $result = "";
277  $ilBench->start("ContentObjectExport", "buildExportFile");
278 
279  // init the mathjax rendering for HTML export
280  include_once './Services/MathJax/classes/class.ilMathJax.php';
282 
283  require_once("./Services/Xml/classes/class.ilXmlWriter.php");
284 
285  // create directories
286  $this->createExportDirectory();
287  ilUtil::makeDir($this->export_dir."/".$this->subdir);
288 
289  // get Log File
290  $expDir = $this->export_dir;
291  include_once './Services/Logging/classes/class.ilLog.php';
292  $expLog = new ilLog($expDir, "export.log");
293  $expLog->delete();
294  $expLog->setLogFormat("");
295  $expLog->write(date("[y-m-d H:i:s] ")."Start Export");
296 
297  // get xml content
298 
299  $ilBench->start("ContentObjectExport", "buildExportFile_getXML");
300  $this->cont_obj->exportHTML($this->inst_id, $this->export_dir."/".$this->subdir, $expLog);
301  $ilBench->stop("ContentObjectExport", "buildExportFile_getXML");
302 
303  // zip the file
304  $ilBench->start("ContentObjectExport", "buildExportFile_zipFile");
305  if(ilUtil::CreateIsoFromFolder($this->export_dir."/".$this->subdir, $this->export_dir."/".$this->subdir.".iso"))
306  {
307  $result = $this->export_dir."/".$this->subdir.".iso";
308  }
309  $ilBench->stop("ContentObjectExport", "buildExportFile_zipFile");
310 
311  ilUtil::delDir($this->export_dir."/".$this->subdir);
312 
313  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export");
314  $ilBench->stop("ContentObjectExport", "buildExportFile");
315 
316  return $result;
317  }
318 
320  {
321  global $ilBench;
322  /*include_once('./Services/WebServices/RPC/classes/class.ilRPCServerSettings.php');
323  $pp = ilRPCServerSettings::getInstance();
324  if(!$pp->isEnabled()||!$pp->pingServer())
325  {
326  $this->ilias->raiseError("Xml Rpc Server is not running. Check Administration/Webservices/Java-Server settings", $this->ilias->error_obj->MESSAGE);
327  return;
328  }*/
329 
330  $ilBench->start("ContentObjectExport", "buildExportFile");
331 
332  // don't render mathjax before fo code is generated
333  include_once './Services/MathJax/classes/class.ilMathJax.php';
335 
336  require_once("./Services/Xml/classes/class.ilXmlWriter.php");
337 
338  // create directories
339  $this->createExportDirectory();
340  ilUtil::makeDir($this->export_dir."/".$this->subdir);
341 
342  // get Log File
343  $expDir = $this->export_dir;
344  include_once './Services/Logging/classes/class.ilLog.php';
345  $expLog = new ilLog($expDir, "export.log");
346  $expLog->delete();
347  $expLog->setLogFormat("");
348  $expLog->write(date("[y-m-d H:i:s] ")."Start Export");
349 
350  $ilBench->start("ContentObjectExport", "buildExportFile_getXML");
351  $fo_string = $this->cont_obj->exportPDF($this->inst_id, $this->export_dir."/".$this->subdir, $expLog);
352 
353  // now render mathjax for pdf generation
354  $fo_string = ilMathJax::getInstance()
355  ->init(ilMathJax::PURPOSE_PDF)
356  ->setRendering(ilMathJax::RENDER_PNG_AS_FO_FILE)
357  ->insertLatexImages($fo_string);
358 
359  $ilBench->stop("ContentObjectExport", "buildExportFile_getXML");
360 
361  $ilBench->start("ContentObjectExport", "buildExportFile_pdfFile");
362  fputs(fopen($this->export_dir."/".$this->subdir.'/temp.fo','w+'),$fo_string);
363 
364  global $ilLog;
365  include_once './Services/WebServices/RPC/classes/class.ilRpcClientFactory.php';
366  try
367  {
368  $pdf_base64 = ilRpcClientFactory::factory('RPCTransformationHandler')->ilFO2PDF($fo_string);
369  //ilUtil::deliverData($pdf_base64->scalar,'learning_progress.pdf','application/pdf');
370  fputs(fopen($this->export_dir.'/'.$this->subdir.'.pdf','w+'),$pdf_base64->scalar);
371  }
372  catch(Exception $e)
373  {
374  ilUtil::sendFailure($e->getMessage(),true);
375  return false;
376  }
377  $ilBench->stop("ContentObjectExport", "buildExportFile_pdfFile");
378 
379  ilUtil::delDir($this->export_dir."/".$this->subdir);
380 
381  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export");
382  $ilBench->stop("ContentObjectExport", "buildExportFile");
383 
384  return $this->export_dir."/".$this->subdir.".pdf";
385  }
386 
388  {
389  $lm_data_dir = ilUtil::getDataDir()."/lm_data";
390  if(!is_writable($lm_data_dir))
391  {
392  $this->ilias->raiseError("Content object Data Directory (".$lm_data_dir.") not writeable.",$this->ilias->error_obj->FATAL);
393  }
394  // create learning module directory (data_dir/lm_data/lm_<id>)
395  $lm_dir = $lm_data_dir."/lm_".$this->module_id;
396  ilUtil::makeDir($lm_dir);
397  if(!@is_dir($lm_dir))
398  {
399  $this->ilias->raiseError("Creation of Learning Module Directory failed.",$this->ilias->error_obj->FATAL);
400  }
401 
402  //$export_dir = $lm_dir."/export_".$this->mode;
403  ilUtil::makeDir($this->export_dir);
404 
405  if(!@is_dir($this->export_dir))
406  {
407  $this->ilias->raiseError("Creation of Export Directory failed.",$this->ilias->error_obj->FATAL);
408  }
409  }
410 
411 }
412 
413 ?>
global $ilErr
Definition: raiseError.php:16
buildExportFileHTML()
build xml export file
$result
static factory($a_package, $a_timeout=0)
Creates an ilRpcClient instance to our ilServer.
const PURPOSE_PDF
logging
Definition: class.ilLog.php:18
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
redirection script todo: (a better solution should control the processing via a xml file) ...
__construct(&$a_cont_obj, $a_mode="SCORM 2004 3rd")
Constructor public.
static CreateIsoFromFolder($a_dir, $a_file)
Export class for SCORM 2004 object.
static zip($a_dir, $a_file, $compress_content=false)
zips given directory/file into given zip.file
const PURPOSE_EXPORT
Create styles array
The data for the language used.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
const RENDER_PNG_AS_FO_FILE
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
static getDataDir()
get data directory (outside webspace)
static getInstance()
Singleton: get instance.
buildExportFileHTMLOne()
build xml export file
global $ilBench
Definition: ilias.php:18
global $ilDB
$ret
Definition: parser.php:6
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
buildExportFileSCORM($ver)
build xml export file
const PURPOSE_DEFERRED_PDF
buildExportFile()
build export file (complete zip file)