• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

content/classes/class.ilContObjectExport.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2006 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 require_once("content/classes/class.ilObjContentObject.php");
00025 
00036 class ilContObjectExport
00037 {
00038         var $err;                       // error object
00039         var $db;                        // database object
00040         var $ilias;                     // ilias object
00041         var $cont_obj;          // content object (learning module | digilib book)
00042         var $inst_id;           // installation id
00043         var $mode;
00044 
00049         function ilContObjectExport(&$a_cont_obj, $a_mode = "xml")
00050         {
00051                 global $ilErr, $ilDB, $ilias;
00052 
00053                 $this->cont_obj =& $a_cont_obj;
00054 
00055                 $this->err =& $ilErr;
00056                 $this->ilias =& $ilias;
00057                 $this->db =& $ilDB;
00058                 $this->mode = $a_mode;
00059 
00060                 $settings = $this->ilias->getAllSettings();
00061                 //$this->inst_id = $settings["inst_id"];
00062                 $this->inst_id = IL_INST_ID;
00063 
00064                 $date = time();
00065                 switch($this->mode)
00066                 {
00067                         case "html":
00068                                 $this->export_dir = $this->cont_obj->getExportDirectory("html");
00069                                 $this->subdir = $this->cont_obj->getType()."_".$this->cont_obj->getId();
00070                                 $this->filename = $this->subdir.".zip";
00071                                 break;
00072 
00073                         case "scorm":
00074                                 $this->export_dir = $this->cont_obj->getExportDirectory("scorm");
00075                                 $this->subdir = $this->cont_obj->getType()."_".$this->cont_obj->getId();
00076                                 $this->filename = $this->subdir.".zip";
00077                                 break;
00078                         
00079                         case "pdf":
00080                                 $this->export_dir = $this->cont_obj->getOfflineDirectory();
00081                                 $this->subdir = $date."__".$this->inst_id."__".
00082                                         $this->cont_obj->getType()."_".$this->cont_obj->getId();
00083                                 $this->filename = $this->subdir.".fo";
00084                                 break;
00085 
00086                         default:
00087                                 $this->export_dir = $this->cont_obj->getExportDirectory();
00088                                 $this->subdir = $date."__".$this->inst_id."__".
00089                                         $this->cont_obj->getType()."_".$this->cont_obj->getId();
00090                                 $this->filename = $this->subdir.".xml";
00091                                 break;
00092                 }
00093         }
00094 
00095         function getInstId()
00096         {
00097                 return $this->inst_id;
00098         }
00099 
00109     function exportRekursiv($depth, $left, $right)
00110         {
00111                 // Jetzt alle lm_data anhand der obj_id auslesen.
00112                 $query = "SELECT  *
00113                         FROM lm_tree, lm_data
00114                         WHERE lm_tree.lm_id = ".$this->cont_obj->getId()."
00115                         AND   lm_tree.child = lm_data.obj_id
00116                         AND   ( lm_data.type =  'st' OR lm_data.type =  'pg' )
00117                         AND lm_tree.depth = $depth
00118                         AND lm_tree.lft>$left and lm_tree.rgt<$right
00119                         ORDER BY lm_tree.lft";
00120 
00121         $result = $this->db->query($query);
00122 
00123         while (is_array($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) )
00124                 {
00125                         if ($row["type"] == "st")
00126                         {
00127                                 $xml .= "<StructureObject>";
00128 
00129                                 $nested = new ilNestedSetXML();
00130                                 $xml .= $nested->export($row["obj_id"],"st");
00131                                 $xml .= "\n";
00132 
00133                                 $xml .= $this->exportRekursiv($depth+1, $row["lft"], $row["rgt"]);
00134 
00135                                 $xml .= "</StructureObject>";
00136                         }
00137 
00138                         if ($row["type"] == "pg")
00139                         {
00140 
00141                 $query = "SELECT * FROM page_object WHERE page_id='".$row["obj_id"]."' ";
00142                                 $result2 = $this->db->query($query);
00143 
00144                                 $row2 = $result2->fetchRow(DB_FETCHMODE_ASSOC);
00145 
00146                                 $PO = $row2["content"]."\n";
00147 
00148                                 if (stristr($PO,"MediaObject"))
00149                                 {
00150 
00151                                         $dom = domxml_open_mem($PO);
00152                                         $xpc = xpath_new_context($dom);
00153                                         $path = "//MediaObject/MediaAlias";
00154                                         $res =& xpath_eval($xpc, $path);
00155                                         for($i = 0; $i < count($res->nodeset); $i++)
00156                                         {
00157                                                 $id_arr = explode("_", $res->nodeset[$i]->get_attribute("OriginId"));
00158                                                 $mob_id = $id_arr[count($id_arr) - 1];
00159                                                 $this->mob_ids[$mob_id] = true;
00160                                         }
00161                                 }
00162 
00163                                 $nested = new ilNestedSetXML();
00164                                 $mdxml = $nested->export($row["obj_id"],"pg");
00165 
00166                                 $PO = str_replace("<PageObject>","<PageObject>\n$mdxml\n",$PO);
00167 
00168                                 $xml .= $PO;
00169 
00170                         }
00171                 }
00172                 return($xml);
00173         }
00174 
00175 
00182         function buildExportFile()
00183         {
00184                 switch ($this->mode)
00185                 {
00186                         case "html":
00187                                 return $this->buildExportFileHTML();
00188                                 break;
00189                                 
00190                         case "scorm":
00191                                 return $this->buildExportFileSCORM();
00192                                 break;
00193 
00194                         case "pdf":
00195                                 return $this->buildExportFilePDF();
00196                                 break;
00197 
00198                         default:
00199                                 return $this->buildExportFileXML();
00200                                 break;
00201                 }
00202         }
00203 
00207         function buildExportFileXML()
00208         {
00209                 global $ilBench;
00210 
00211                 $ilBench->start("ContentObjectExport", "buildExportFile");
00212 
00213                 require_once("classes/class.ilXmlWriter.php");
00214 
00215                 $this->xml = new ilXmlWriter;
00216 
00217                 // set dtd definition
00218                 $this->xml->xmlSetDtdDef("<!DOCTYPE ContentObject SYSTEM \"http://www.ilias.de/download/dtd/ilias_co_3_7.dtd\">");
00219 
00220                 // set generated comment
00221                 $this->xml->xmlSetGenCmt("Export of ILIAS Content Module ".
00222                         $this->cont_obj->getId()." of installation ".$this->inst.".");
00223 
00224                 // set xml header
00225                 $this->xml->xmlHeader();
00226 
00227                 // create directories
00228                 $this->cont_obj->createExportDirectory();
00229                 ilUtil::makeDir($this->export_dir."/".$this->subdir);
00230                 ilUtil::makeDir($this->export_dir."/".$this->subdir."/objects");
00231 
00232                 // get Log File
00233                 $expDir = $this->cont_obj->getExportDirectory();
00234                 $expLog = new ilLog($expDir, "export.log");
00235                 $expLog->delete();
00236                 $expLog->setLogFormat("");
00237                 $expLog->write(date("[y-m-d H:i:s] ")."Start Export");
00238 
00239                 // get xml content
00240 //echo "ContObjExport:".$this->inst_id.":<br>";
00241                 $ilBench->start("ContentObjectExport", "buildExportFile_getXML");
00242                 $this->cont_obj->exportXML($this->xml, $this->inst_id,
00243                         $this->export_dir."/".$this->subdir, $expLog);
00244                 $ilBench->stop("ContentObjectExport", "buildExportFile_getXML");
00245 
00246                 // export style
00247                 if ($this->cont_obj->getStyleSheetId() > 0)
00248                 {
00249                         include_once("classes/class.ilObjStyleSheet.php");
00250                         $style_obj = new ilObjStyleSheet($this->cont_obj->getStyleSheetId(), false);
00251                         $style_obj->exportXML($this->export_dir."/".$this->subdir);
00252                 }
00253 
00254                 // dump xml document to screen (only for debugging reasons)
00255                 /*
00256                 echo "<PRE>";
00257                 echo htmlentities($this->xml->xmlDumpMem($format));
00258                 echo "</PRE>";
00259                 */
00260 
00261                 // dump xml document to file
00262                 $ilBench->start("ContentObjectExport", "buildExportFile_dumpToFile");
00263                 $this->xml->xmlDumpFile($this->export_dir."/".$this->subdir."/".$this->filename
00264                         , false);
00265                 $ilBench->stop("ContentObjectExport", "buildExportFile_dumpToFile");
00266 
00267                 // zip the file
00268                 $ilBench->start("ContentObjectExport", "buildExportFile_zipFile");
00269 //echo "-".$this->export_dir."/".$this->subdir."-";
00270                 ilUtil::zip($this->export_dir."/".$this->subdir,
00271                         $this->export_dir."/".$this->subdir.".zip");
00272                 $ilBench->stop("ContentObjectExport", "buildExportFile_zipFile");
00273 
00274                 // destroy writer object
00275                 $this->xml->_XmlWriter;
00276 
00277                 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export");
00278                 $ilBench->stop("ContentObjectExport", "buildExportFile");
00279 
00280                 return $this->export_dir."/".$this->subdir.".zip";
00281         }
00282 
00286         function buildExportFilePDF()
00287         {
00288                 global $ilBench;
00289 
00290                 $ilBench->start("ContentObjectExport", "buildPDFFile");
00291 
00292                 require_once("classes/class.ilXmlWriter.php");
00293 
00294                 $this->xml = new ilXmlWriter;
00295 
00296                 // set dtd definition
00297                 //$this->xml->xmlSetDtdDef("<!DOCTYPE LearningModule SYSTEM \"http://www.ilias.uni-koeln.de/download/dtd/ilias_co.dtd\">");
00298 
00299                 // set generated comment
00300                 //$this->xml->xmlSetGenCmt("Export of ILIAS Content Module ".
00301                 //      $this->cont_obj->getId()." of installation ".$this->inst.".");
00302 
00303                 // set xml header
00304                 $this->xml->xmlHeader();
00305 
00306                 // create directories
00307         //$this->cont_obj->createExportDirectory("pdf");   //not implemened!
00308                 //ilUtil::makeDir($this->export_dir."/".$this->subdir);
00309                 //ilUtil::makeDir($this->export_dir."/".$this->subdir."/objects");
00310 
00311                 // get Log File
00312                 /*
00313                 $expDir = $this->cont_obj->getExportDirectory();
00314                 $expLog = new ilLog($expDir, "export.log");
00315                 $expLog->delete();
00316                 $expLog->setLogFormat("");
00317                 $expLog->write(date("[y-m-d H:i:s] ")."Start Export");*/
00318 
00319                 // get xml content
00320                 $ilBench->start("ContentObjectExport", "buildPDFFile_getFO");
00321                 $this->cont_obj->exportFO($this->xml,
00322                         $this->export_dir."/".$this->subdir, $expLog);
00323                 $ilBench->stop("ContentObjectExport", "buildPDFFile_getFO");
00324 
00325 
00326                 // dump fo document to file
00327                 $ilBench->start("ContentObjectExport", "buildPDFFile_dumpToFile");
00328 //echo "dumping:".$this->export_dir."/".$this->filename;
00329                 $this->xml->xmlDumpFile($this->export_dir."/".$this->filename
00330                         , false);
00331                 $ilBench->stop("ContentObjectExport", "buildPDFFile_dumpToFile");
00332 
00333                 // convert fo to pdf file
00334                 //$ilBench->start("ContentObjectExport", "buildExportFile_zipFile");
00335                 include_once("classes/class.ilFOPUtil.php");
00336                 ilFOPUtil::makePDF($this->export_dir."/".$this->filename,
00337                         $this->export_dir."/".$this->subdir.".pdf");
00338                 //$ilBench->stop("ContentObjectExport", "buildExportFile_zipFile");
00339 
00340                 // destroy writer object
00341                 $this->xml->_XmlWriter;
00342 
00343                 //$expLog->write(date("[y-m-d H:i:s] ")."Finished Export");
00344                 $ilBench->stop("ContentObjectExport", "buildPDFFile");
00345         }
00346 
00350         function buildExportFileHTML()
00351         {
00352                 global $ilBench;
00353 
00354                 $ilBench->start("ContentObjectExport", "buildHTMLPackage");
00355 
00356                 // create directories
00357                 $this->cont_obj->createExportDirectory("html");
00358 
00359                 // get html content
00360                 $ilBench->start("ContentObjectExport", "buildHTMLPackage_getHTML");
00361                 $this->cont_obj->exportHTML($this->export_dir."/".$this->subdir, $expLog);
00362                 $ilBench->stop("ContentObjectExport", "buildHTMLPackage_getHTML");
00363 
00364                 //$expLog->write(date("[y-m-d H:i:s] ")."Finished Export");
00365                 $ilBench->stop("ContentObjectExport", "buildHTMLPackage");
00366         }
00367 
00371         function buildExportFileSCORM()
00372         {
00373                 global $ilBench;
00374 
00375                 $ilBench->start("ContentObjectExport", "buildSCORMPackage");
00376 
00377                 // create directories
00378                 $this->cont_obj->createExportDirectory("scorm");
00379 
00380                 // get html content
00381                 $ilBench->start("ContentObjectExport", "buildSCORMPackage_getSCORM");
00382                 $this->cont_obj->exportSCORM($this->export_dir."/".$this->subdir, $expLog);
00383                 $ilBench->stop("ContentObjectExport", "buildSCORMPackage_getSCORM");
00384 
00385                 //$expLog->write(date("[y-m-d H:i:s] ")."Finished Export");
00386                 $ilBench->stop("ContentObjectExport", "buildSCORMPackage");
00387         }
00388 
00389 }
00390 
00391 ?>

Generated on Fri Dec 13 2013 13:52:09 for ILIAS Release_3_7_x_branch .rev 46817 by  doxygen 1.7.1