ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 {
15  protected $log;
16 
17  private $err; // error object
18  private $db; // database object
19  private $cont_obj; // content object (learning module or sco)
20  private $cont_obj_id; // content object id (learning module or sco)
21  private $inst_id; // installation id
22  private $mode; //current export mode
23  private $export_types; // list of supported export types
24  private $module_id;
25 
26  private $date;
27  private $settings;
28  private $export_dir;
29  private $subdir;
30  private $filename;
31 
36  public function __construct(&$a_cont_obj, $a_mode = "SCORM 2004 3rd")
37  {
38  global $DIC;
39 
40  $this->settings = $DIC->settings();
41  $this->log = $DIC["ilLog"];
42  $ilErr = $DIC["ilErr"];
43  $ilDB = $DIC->database();
44  $ilSetting = $DIC->settings();
45 
46  $this->export_types = array("SCORM 2004 3rd","SCORM 2004 4th","SCORM 1.2","HTML","ISO","PDF",
47  "HTMLOne");
48 
49  if (!in_array($a_mode, $this->export_types)) {
50  die("Unsupported format");
51  }
52 
53  $this->cont_obj = $a_cont_obj;
54 
55  $this->err = $ilErr;
56  $this->db = $ilDB;
57  $this->mode = $a_mode;
58 
59  $settings = $ilSetting->getAll();
60 
61  $this->inst_id = IL_INST_ID;
62 
63  switch ($this->cont_obj->getType()) {
64  case 'sahs':
65  $this->module_id = $this->cont_obj->getId();
66  $this->cont_obj_id = $this->cont_obj->getId();
67  break;
68  case 'sco':
69  $this->module_id = $this->cont_obj->slm_id;
70  $this->cont_obj_id = $this->cont_obj->getId();
71  break;
72  }
73 
74  $this->date = time();
75 
76  $this->export_dir = $this->getExportDirectory();
77  $this->subdir = $this->getExportSubDirectory();
78  $this->filename = $this->getExportFileName();
79  }
80 
81  public function getExportDirectory()
82  {
83  return $this->getExportDirectoryForType($this->mode);
84  }
85 
87  {
88  $ret = ilUtil::getDataDir() . "/lm_data" . "/lm_" . $this->module_id . "/export_";
89  switch ($type) {
90  case "ISO":
91  return $ret . "_iso";
92  case "PDF":
93  return $ret . "_pdf";
94  case "SCORM 2004 3rd":
95  return $ret . "_scorm2004";
96  case "SCORM 2004 4th":
97  return $ret . "_scorm2004_4th";
98  case "HTML":
99  return $ret . "_html";
100  case "HTMLOne":
101  return $ret . "_html_one";
102  case "SCORM 1.2":
103  return $ret . "_scorm12";
104  }
105  }
106 
107  public function getExportSubDirectory()
108  {
109  return $this->date . "__" . $this->inst_id . "__" . $this->cont_obj->getType() . "_" . $this->cont_obj_id;
110  }
111 
112  public function getExportFileName()
113  {
114  switch ($this->mode) {
115  case "ISO":
116  return $this->subdir . ".iso";
117  case "PDF":
118  return $this->subdir . ".pdf";
119  default:
120  return $this->subdir . ".zip";
121  }
122  }
123 
124  public function getSupportedExportTypes()
125  {
126  return $this->export_types;
127  }
128 
129  public function getInstId()
130  {
131  return $this->inst_id;
132  }
133 
140  public function buildExportFile()
141  {
142  switch ($this->mode) {
143  case "SCORM 2004 3rd":
144  return $this->buildExportFileSCORM("2004 3rd");
145  case "SCORM 2004 4th":
146  return $this->buildExportFileSCORM("2004 4th");
147  case "SCORM 1.2":
148  return $this->buildExportFileSCORM("12");
149  case "HTML":
150  return $this->buildExportFileHTML();
151  case "HTMLOne":
152  return $this->buildExportFileHTMLOne();
153  case "ISO":
154  return $this->buildExportFileISO();
155  case "PDF":
156  return $this->buildExportFilePDF();
157  }
158  }
159 
163  public function buildExportFileSCORM($ver)
164  {
165 
166  // init the mathjax rendering for HTML export
167  include_once './Services/MathJax/classes/class.ilMathJax.php';
169 
170  require_once("./Services/Xml/classes/class.ilXmlWriter.php");
171 
172  // create directories
173  $this->createExportDirectory();
174  ilUtil::makeDir($this->export_dir . "/" . $this->subdir);
175 
176  // get Log File
177  $expDir = $this->export_dir;
178  include_once './Services/Logging/classes/class.ilLog.php';
179  $expLog = new ilLog($expDir, "export.log");
180  $expLog->delete();
181  $expLog->setLogFormat("");
182  $expLog->write(date("[y-m-d H:i:s] ") . "Start Export");
183 
184  // get xml content
185 
186  $this->cont_obj->exportScorm($this->inst_id, $this->export_dir . "/" . $this->subdir, $ver, $expLog);
187 
188  // zip the file
189  ilUtil::zip($this->export_dir . "/" . $this->subdir, $this->export_dir . "/" . $this->subdir . ".zip", true);
190 
191  ilUtil::delDir($this->export_dir . "/" . $this->subdir);
192 
193  $expLog->write(date("[y-m-d H:i:s] ") . "Finished Export");
194 
195  return $this->export_dir . "/" . $this->subdir . ".zip";
196  }
197 
201  public function buildExportFileHTML()
202  {
203  require_once("./Services/Xml/classes/class.ilXmlWriter.php");
204 
205  // init the mathjax rendering for HTML export
206  include_once './Services/MathJax/classes/class.ilMathJax.php';
208 
209  // create directories
210  $this->createExportDirectory();
211  ilUtil::makeDir($this->export_dir . "/" . $this->subdir);
212 
213  // get Log File
214  $expDir = $this->export_dir;
215  include_once './Services/Logging/classes/class.ilLog.php';
216  $expLog = new ilLog($expDir, "export.log");
217  $expLog->delete();
218  $expLog->setLogFormat("");
219  $expLog->write(date("[y-m-d H:i:s] ") . "Start Export");
220 
221  // get xml content
222  $this->cont_obj->exportHTML($this->inst_id, $this->export_dir . "/" . $this->subdir, $expLog);
223 
224  // zip the file
225  ilUtil::zip($this->export_dir . "/" . $this->subdir, $this->export_dir . "/" . $this->subdir . ".zip", true);
226 
227  ilUtil::delDir($this->export_dir . "/" . $this->subdir);
228 
229  $expLog->write(date("[y-m-d H:i:s] ") . "Finished Export");
230 
231  return $this->export_dir . "/" . $this->subdir . ".zip";
232  }
233 
237  public function buildExportFileHTMLOne()
238  {
239  require_once("./Services/Xml/classes/class.ilXmlWriter.php");
240 
241  // init the mathjax rendering for HTML export
242  include_once './Services/MathJax/classes/class.ilMathJax.php';
244 
245  // create directories
246  $this->createExportDirectory();
247  ilUtil::makeDir($this->export_dir . "/" . $this->subdir);
248 
249  // get Log File
250  $expDir = $this->export_dir;
251  include_once './Services/Logging/classes/class.ilLog.php';
252  $expLog = new ilLog($expDir, "export.log");
253  $expLog->delete();
254  $expLog->setLogFormat("");
255  $expLog->write(date("[y-m-d H:i:s] ") . "Start Export");
256 
257  // get xml content
258  $this->cont_obj->exportHTMLOne($this->inst_id, $this->export_dir . "/" . $this->subdir, $expLog);
259 
260  // zip the file
261  ilUtil::zip($this->export_dir . "/" . $this->subdir, $this->export_dir . "/" . $this->subdir . ".zip", true);
262 
263  ilUtil::delDir($this->export_dir . "/" . $this->subdir);
264 
265  $expLog->write(date("[y-m-d H:i:s] ") . "Finished Export");
266 
267  return $this->export_dir . "/" . $this->subdir . ".zip";
268  }
269 
270  public function buildExportFileISO()
271  {
272  $result = "";
273 
274  // init the mathjax rendering for HTML export
275  include_once './Services/MathJax/classes/class.ilMathJax.php';
277 
278  require_once("./Services/Xml/classes/class.ilXmlWriter.php");
279 
280  // create directories
281  $this->createExportDirectory();
282  ilUtil::makeDir($this->export_dir . "/" . $this->subdir);
283 
284  // get Log File
285  $expDir = $this->export_dir;
286  include_once './Services/Logging/classes/class.ilLog.php';
287  $expLog = new ilLog($expDir, "export.log");
288  $expLog->delete();
289  $expLog->setLogFormat("");
290  $expLog->write(date("[y-m-d H:i:s] ") . "Start Export");
291 
292  // get xml content
293 
294  $this->cont_obj->exportHTML($this->inst_id, $this->export_dir . "/" . $this->subdir, $expLog);
295 
296  // zip the file
297  if (ilUtil::CreateIsoFromFolder($this->export_dir . "/" . $this->subdir, $this->export_dir . "/" . $this->subdir . ".iso")) {
298  $result = $this->export_dir . "/" . $this->subdir . ".iso";
299  }
300 
301  ilUtil::delDir($this->export_dir . "/" . $this->subdir);
302 
303  $expLog->write(date("[y-m-d H:i:s] ") . "Finished Export");
304 
305  return $result;
306  }
307 
308  public function buildExportFilePDF()
309  {
310 
311  // don't render mathjax before fo code is generated
312  include_once './Services/MathJax/classes/class.ilMathJax.php';
314 
315  require_once("./Services/Xml/classes/class.ilXmlWriter.php");
316 
317  // create directories
318  $this->createExportDirectory();
319  ilUtil::makeDir($this->export_dir . "/" . $this->subdir);
320 
321  // get Log File
322  $expDir = $this->export_dir;
323  include_once './Services/Logging/classes/class.ilLog.php';
324  $expLog = new ilLog($expDir, "export.log");
325  $expLog->delete();
326  $expLog->setLogFormat("");
327  $expLog->write(date("[y-m-d H:i:s] ") . "Start Export");
328 
329  $fo_string = $this->cont_obj->exportPDF($this->inst_id, $this->export_dir . "/" . $this->subdir, $expLog);
330 
331  // now render mathjax for pdf generation
332  $fo_string = ilMathJax::getInstance()
333  ->init(ilMathJax::PURPOSE_PDF)
334  ->setRendering(ilMathJax::RENDER_PNG_AS_FO_FILE)
335  ->insertLatexImages($fo_string);
336 
337 
338  fputs(fopen($this->export_dir . "/" . $this->subdir . '/temp.fo', 'w+'), $fo_string);
339 
340  $ilLog = $this->log;
341  include_once './Services/WebServices/RPC/classes/class.ilRpcClientFactory.php';
342  try {
343  $pdf_base64 = ilRpcClientFactory::factory('RPCTransformationHandler')->ilFO2PDF($fo_string);
344  //ilUtil::deliverData($pdf_base64->scalar,'learning_progress.pdf','application/pdf');
345  fputs(fopen($this->export_dir . '/' . $this->subdir . '.pdf', 'w+'), $pdf_base64->scalar);
346  } catch (Exception $e) {
347  ilUtil::sendFailure($e->getMessage(), true);
348  return false;
349  }
350 
351  ilUtil::delDir($this->export_dir . "/" . $this->subdir);
352 
353  $expLog->write(date("[y-m-d H:i:s] ") . "Finished Export");
354 
355  return $this->export_dir . "/" . $this->subdir . ".pdf";
356  }
357 
358  public function createExportDirectory()
359  {
360  $ilErr = $this->err;
361 
362  $lm_data_dir = ilUtil::getDataDir() . "/lm_data";
363  if (!is_writable($lm_data_dir)) {
364  $ilErr->raiseError("Content object Data Directory (" . $lm_data_dir . ") not writeable.", $ilErr->FATAL);
365  }
366  // create learning module directory (data_dir/lm_data/lm_<id>)
367  $lm_dir = $lm_data_dir . "/lm_" . $this->module_id;
368  ilUtil::makeDir($lm_dir);
369  if (!@is_dir($lm_dir)) {
370  $ilErr->raiseError("Creation of Learning Module Directory failed.", $ilErr->FATAL);
371  }
372 
373  //$export_dir = $lm_dir."/export_".$this->mode;
374  ilUtil::makeDir($this->export_dir);
375 
376  if (!@is_dir($this->export_dir)) {
377  $ilErr->raiseError("Creation of Export Directory failed.", $ilErr->FATAL);
378  }
379  }
380 }
global $ilErr
Definition: raiseError.php:16
buildExportFileHTML()
build xml export file
$result
$type
global $DIC
Definition: saml.php:7
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())
__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 ...
settings()
Definition: settings.php:2
static getDataDir()
get data directory (outside webspace)
static getInstance()
Singleton: get instance.
buildExportFileHTMLOne()
build xml export file
global $ilSetting
Definition: privfeed.php:17
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)