ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilGlossaryExport.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 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/Glossary/classes/class.ilObjGlossary.php");
25 
36 {
37  var $err; // error object
38  var $db; // database object
39  var $ilias; // ilias object
40  var $glo_obj; // glossary
41  var $inst_id; // installation id
42 
47  function ilGlossaryExport(&$a_glo_obj, $a_mode = "xml")
48  {
49  global $ilErr, $ilDB, $ilias;
50 
51  $this->glo_obj =& $a_glo_obj;
52 
53  $this->err =& $ilErr;
54  $this->ilias =& $ilias;
55  $this->db =& $ilDB;
56  $this->mode = $a_mode;
57 
58  $settings = $this->ilias->getAllSettings();
59  // The default '0' is required for the directory structure (smeyer)
60  $this->inst_id = $settings["inst_id"] ? $settings['inst_id'] : 0;
61 
62  $date = time();
63  switch($this->mode)
64  {
65  case "xml":
66  $this->export_dir = $this->glo_obj->getExportDirectory();
67  $this->subdir = $date."__".$this->inst_id."__".
68  $this->glo_obj->getType()."_".$this->glo_obj->getId();
69  $this->filename = $this->subdir.".xml";
70  break;
71 
72  case "html":
73  $this->export_dir = $this->glo_obj->getExportDirectory("html");
74  $this->subdir = $this->glo_obj->getType()."_".$this->glo_obj->getId();
75  $this->filename = $this->subdir.".zip";
76  break;
77 
78  }
79 
80  }
81 
82  function getInstId()
83  {
84  return $this->inst_id;
85  }
86 
87 /*
88  function exportRekursiv($depth, $left, $right)
89  {
90  global $ilDB;
91 
92  // Jetzt alle lm_data anhand der obj_id auslesen.
93  $query = "SELECT *
94  FROM lm_tree, lm_data
95  WHERE lm_tree.lm_id = ".$ilDB->quote($this->glo_obj->getId())."
96  AND lm_tree.child = lm_data.obj_id
97  AND ( lm_data.type = 'st' OR lm_data.type = 'pg' )
98  AND lm_tree.depth = ".$ilDB->quote($depth)."
99  AND lm_tree.lft>".$ilDB->quote($left)." and lm_tree.rgt<".$ilDB->quote($right)."
100  ORDER BY lm_tree.lft";
101 
102  $result = $this->db->query($query);
103 
104  while (is_array($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) )
105  {
106  if ($row["type"] == "st")
107  {
108  $xml .= "<StructureObject>";
109 
110  $nested = new ilNestedSetXML();
111  $xml .= $nested->export($row["obj_id"],"st");
112  $xml .= "\n";
113 
114  $xml .= $this->exportRekursiv($depth+1, $row["lft"], $row["rgt"]);
115 
116  $xml .= "</StructureObject>";
117  }
118 
119  if ($row["type"] == "pg")
120  {
121 
122  $query = "SELECT * FROM page_object WHERE page_id='".$row["obj_id"]."' ";
123  $result2 = $this->db->query($query);
124 
125  $row2 = $result2->fetchRow(DB_FETCHMODE_ASSOC);
126 
127  $PO = $row2["content"]."\n";
128 
129  if (stristr($PO,"MediaObject"))
130  {
131 
132  $dom = domxml_open_mem($PO);
133  $xpc = xpath_new_context($dom);
134  $path = "//MediaObject/MediaAlias";
135  $res =& xpath_eval($xpc, $path);
136  for($i = 0; $i < count($res->nodeset); $i++)
137  {
138  $id_arr = explode("_", $res->nodeset[$i]->get_attribute("OriginId"));
139  $mob_id = $id_arr[count($id_arr) - 1];
140  $this->mob_ids[$mob_id] = true;
141  }
142  }
143 
144  $nested = new ilNestedSetXML();
145  $mdxml = $nested->export($row["obj_id"],"pg");
146 
147  $PO = str_replace("<PageObject>","<PageObject>\n$mdxml\n",$PO);
148 
149  $xml .= $PO;
150 
151  }
152  }
153  return($xml);
154  }
155 */
156 
163  function buildExportFile()
164  {
165  switch ($this->mode)
166  {
167  case "html":
168  return $this->buildExportFileHTML();
169  break;
170 
171  default:
172  return $this->buildExportFileXML();
173  break;
174  }
175  }
176 
181  {
182  global $ilBench;
183 
184  $ilBench->start("GlossaryExport", "buildExportFile");
185 
186  require_once("./Services/Xml/classes/class.ilXmlWriter.php");
187 
188  $this->xml = new ilXmlWriter;
189 
190  // set dtd definition
191  $this->xml->xmlSetDtdDef("<!DOCTYPE ContentObject SYSTEM \"http://www.ilias.uni-koeln.de/download/dtd/ilias_co_3_7.dtd\">");
192 
193  // set generated comment
194  $this->xml->xmlSetGenCmt("Export of ILIAS Glossary ".
195  $this->glo_obj->getId()." of installation ".$this->inst.".");
196 
197  // set xml header
198  $this->xml->xmlHeader();
199 
200  // create directories
201  $this->glo_obj->createExportDirectory();
202  ilUtil::makeDir($this->export_dir."/".$this->subdir);
203  ilUtil::makeDir($this->export_dir."/".$this->subdir."/objects");
204 
205  // get Log File
206  $expDir = $this->glo_obj->getExportDirectory();
207  $expLog = new ilLog($expDir, "export.log");
208  $expLog->delete();
209  $expLog->setLogFormat("");
210  $expLog->write(date("[y-m-d H:i:s] ")."Start Export");
211 
212  // get xml content
213 //echo "ContObjExport:".$this->inst_id.":<br>";
214  $ilBench->start("GlossaryExport", "buildExportFile_getXML");
215  $this->glo_obj->exportXML($this->xml, $this->inst_id,
216  $this->export_dir."/".$this->subdir, $expLog);
217  $ilBench->stop("GlossaryExport", "buildExportFile_getXML");
218 
219  // dump xml document to screen (only for debugging reasons)
220  /*
221  echo "<PRE>";
222  echo htmlentities($this->xml->xmlDumpMem($format));
223  echo "</PRE>";
224  */
225 
226 
227  // dump xml document to file
228  $ilBench->start("GlossaryExport", "buildExportFile_dumpToFile");
229  $this->xml->xmlDumpFile($this->export_dir."/".$this->subdir."/".$this->filename
230  , false);
231  $ilBench->stop("GlossaryExport", "buildExportFile_dumpToFile");
232 
233  // zip the file
234  $ilBench->start("GlossaryExport", "buildExportFile_zipFile");
235  ilUtil::zip($this->export_dir."/".$this->subdir,
236  $this->export_dir."/".$this->subdir.".zip");
237  $ilBench->stop("GlossaryExport", "buildExportFile_zipFile");
238 
239  // destroy writer object
240  $this->xml->_XmlWriter;
241 
242  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export");
243  $ilBench->stop("GlossaryExport", "buildExportFile");
244 
245  return $this->export_dir."/".$this->subdir.".zip";
246  }
247 
252  {
253  global $ilBench;
254 
255  // create directories
256  $this->glo_obj->createExportDirectory("html");
257 
258  // get Log File
259  $expDir = $this->glo_obj->getExportDirectory();
260 
261  // get xml content
262  $this->glo_obj->exportHTML($this->export_dir."/".$this->subdir, $expLog);
263  }
264 
265 }
266 
267 ?>