Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 require_once("content/classes/class.ilObjGlossary.php");
00025
00035 class ilGlossaryExport
00036 {
00037 var $err;
00038 var $db;
00039 var $ilias;
00040 var $glo_obj;
00041 var $inst_id;
00042
00047 function ilGlossaryExport(&$a_glo_obj, $a_mode = "xml")
00048 {
00049 global $ilErr, $ilDB, $ilias;
00050
00051 $this->glo_obj =& $a_glo_obj;
00052
00053 $this->err =& $ilErr;
00054 $this->ilias =& $ilias;
00055 $this->db =& $ilDB;
00056 $this->mode = $a_mode;
00057
00058 $settings = $this->ilias->getAllSettings();
00059 $this->inst_id = $settings["inst_id"];
00060
00061 $date = time();
00062 switch($this->mode)
00063 {
00064 case "xml":
00065 $this->export_dir = $this->glo_obj->getExportDirectory();
00066 $this->subdir = $date."__".$this->inst_id."__".
00067 $this->glo_obj->getType()."_".$this->glo_obj->getId();
00068 $this->filename = $this->subdir.".xml";
00069 break;
00070
00071 case "html":
00072 $this->export_dir = $this->glo_obj->getExportDirectory("html");
00073 $this->subdir = $this->glo_obj->getType()."_".$this->glo_obj->getId();
00074 $this->filename = $this->subdir.".zip";
00075 break;
00076
00077 }
00078
00079 }
00080
00081 function getInstId()
00082 {
00083 return $this->inst_id;
00084 }
00085
00086 function exportRekursiv($depth, $left, $right)
00087 {
00088
00089 $query = "SELECT *
00090 FROM lm_tree, lm_data
00091 WHERE lm_tree.lm_id = ".$this->glo_obj->getId()."
00092 AND lm_tree.child = lm_data.obj_id
00093 AND ( lm_data.type = 'st' OR lm_data.type = 'pg' )
00094 AND lm_tree.depth = $depth
00095 AND lm_tree.lft>$left and lm_tree.rgt<$right
00096 ORDER BY lm_tree.lft";
00097
00098 $result = $this->db->query($query);
00099
00100 while (is_array($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) )
00101 {
00102 if ($row["type"] == "st")
00103 {
00104 $xml .= "<StructureObject>";
00105
00106 $nested = new ilNestedSetXML();
00107 $xml .= $nested->export($row["obj_id"],"st");
00108 $xml .= "\n";
00109
00110 $xml .= $this->exportRekursiv($depth+1, $row["lft"], $row["rgt"]);
00111
00112 $xml .= "</StructureObject>";
00113 }
00114
00115 if ($row["type"] == "pg")
00116 {
00117
00118 $query = "SELECT * FROM page_object WHERE page_id='".$row["obj_id"]."' ";
00119 $result2 = $this->db->query($query);
00120
00121 $row2 = $result2->fetchRow(DB_FETCHMODE_ASSOC);
00122
00123 $PO = $row2["content"]."\n";
00124
00125 if (stristr($PO,"MediaObject"))
00126 {
00127
00128 $dom = domxml_open_mem($PO);
00129 $xpc = xpath_new_context($dom);
00130 $path = "//MediaObject/MediaAlias";
00131 $res =& xpath_eval($xpc, $path);
00132 for($i = 0; $i < count($res->nodeset); $i++)
00133 {
00134 $id_arr = explode("_", $res->nodeset[$i]->get_attribute("OriginId"));
00135 $mob_id = $id_arr[count($id_arr) - 1];
00136 $this->mob_ids[$mob_id] = true;
00137 }
00138 }
00139
00140 $nested = new ilNestedSetXML();
00141 $mdxml = $nested->export($row["obj_id"],"pg");
00142
00143 $PO = str_replace("<PageObject>","<PageObject>\n$mdxml\n",$PO);
00144
00145 $xml .= $PO;
00146
00147 }
00148 }
00149 return($xml);
00150 }
00151
00158 function buildExportFile()
00159 {
00160 switch ($this->mode)
00161 {
00162 case "html":
00163 return $this->buildExportFileHTML();
00164 break;
00165
00166 default:
00167 return $this->buildExportFileXML();
00168 break;
00169 }
00170 }
00171
00175 function buildExportFileXML()
00176 {
00177 global $ilBench;
00178
00179 $ilBench->start("GlossaryExport", "buildExportFile");
00180
00181 require_once("classes/class.ilXmlWriter.php");
00182
00183 $this->xml = new ilXmlWriter;
00184
00185
00186 $this->xml->xmlSetDtdDef("<!DOCTYPE ContentObject SYSTEM \"http://www.ilias.uni-koeln.de/download/dtd/ilias_co_3_7.dtd\">");
00187
00188
00189 $this->xml->xmlSetGenCmt("Export of ILIAS Glossary ".
00190 $this->glo_obj->getId()." of installation ".$this->inst.".");
00191
00192
00193 $this->xml->xmlHeader();
00194
00195
00196 $this->glo_obj->createExportDirectory();
00197 ilUtil::makeDir($this->export_dir."/".$this->subdir);
00198 ilUtil::makeDir($this->export_dir."/".$this->subdir."/objects");
00199
00200
00201 $expDir = $this->glo_obj->getExportDirectory();
00202 $expLog = new ilLog($expDir, "export.log");
00203 $expLog->delete();
00204 $expLog->setLogFormat("");
00205 $expLog->write(date("[y-m-d H:i:s] ")."Start Export");
00206
00207
00208
00209 $ilBench->start("GlossaryExport", "buildExportFile_getXML");
00210 $this->glo_obj->exportXML($this->xml, $this->inst_id,
00211 $this->export_dir."/".$this->subdir, $expLog);
00212 $ilBench->stop("GlossaryExport", "buildExportFile_getXML");
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223 $ilBench->start("GlossaryExport", "buildExportFile_dumpToFile");
00224 $this->xml->xmlDumpFile($this->export_dir."/".$this->subdir."/".$this->filename
00225 , false);
00226 $ilBench->stop("GlossaryExport", "buildExportFile_dumpToFile");
00227
00228
00229 $ilBench->start("GlossaryExport", "buildExportFile_zipFile");
00230 ilUtil::zip($this->export_dir."/".$this->subdir,
00231 $this->export_dir."/".$this->subdir.".zip");
00232 $ilBench->stop("GlossaryExport", "buildExportFile_zipFile");
00233
00234
00235 $this->xml->_XmlWriter;
00236
00237 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export");
00238 $ilBench->stop("GlossaryExport", "buildExportFile");
00239
00240 return $this->export_dir."/".$this->subdir.".zip";
00241 }
00242
00246 function buildExportFileHTML()
00247 {
00248 global $ilBench;
00249
00250 $ilBench->start("GlossaryExport", "buildHTMLPackage");
00251
00252
00253 $this->glo_obj->createExportDirectory("html");
00254
00255
00256 $expDir = $this->glo_obj->getExportDirectory();
00257
00258
00259
00260
00261
00262
00263
00264 $ilBench->start("GlossaryExport", "buildExportFile_getHTML");
00265 $this->glo_obj->exportHTML($this->export_dir."/".$this->subdir, $expLog);
00266 $ilBench->stop("GlossaryExport", "buildExportFile_getHTML");
00267
00268 $ilBench->stop("GlossaryExport", "buildHTMLPackage");
00269 }
00270
00271 }
00272
00273 ?>