ILIAS  release_4-4 Revision
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 
93  function buildExportFile()
94  {
95  switch ($this->mode)
96  {
97  case "html":
98  return $this->buildExportFileHTML();
99  break;
100 
101  default:
102  return $this->buildExportFileXML();
103  break;
104  }
105  }
106 
111  {
112  global $ilBench;
113 
114  $ilBench->start("GlossaryExport", "buildExportFile");
115 
116  require_once("./Services/Xml/classes/class.ilXmlWriter.php");
117 
118  $this->xml = new ilXmlWriter;
119 
120  // set dtd definition
121  $this->xml->xmlSetDtdDef("<!DOCTYPE ContentObject SYSTEM \"http://www.ilias.uni-koeln.de/download/dtd/ilias_co_3_7.dtd\">");
122 
123  // set generated comment
124  $this->xml->xmlSetGenCmt("Export of ILIAS Glossary ".
125  $this->glo_obj->getId()." of installation ".$this->inst.".");
126 
127  // set xml header
128  $this->xml->xmlHeader();
129 
130  // create directories
131  $this->glo_obj->createExportDirectory();
132  ilUtil::makeDir($this->export_dir."/".$this->subdir);
133  ilUtil::makeDir($this->export_dir."/".$this->subdir."/objects");
134 
135  // get Log File
136  $expDir = $this->glo_obj->getExportDirectory();
137  $expLog = new ilLog($expDir, "export.log");
138  $expLog->delete();
139  $expLog->setLogFormat("");
140  $expLog->write(date("[y-m-d H:i:s] ")."Start Export");
141 
142  // get xml content
143 //echo "ContObjExport:".$this->inst_id.":<br>";
144  $ilBench->start("GlossaryExport", "buildExportFile_getXML");
145  $this->glo_obj->exportXML($this->xml, $this->inst_id,
146  $this->export_dir."/".$this->subdir, $expLog);
147  $ilBench->stop("GlossaryExport", "buildExportFile_getXML");
148 
149  // dump xml document to screen (only for debugging reasons)
150  /*
151  echo "<PRE>";
152  echo htmlentities($this->xml->xmlDumpMem($format));
153  echo "</PRE>";
154  */
155 
156 
157  // dump xml document to file
158  $ilBench->start("GlossaryExport", "buildExportFile_dumpToFile");
159  $this->xml->xmlDumpFile($this->export_dir."/".$this->subdir."/".$this->filename
160  , false);
161  $ilBench->stop("GlossaryExport", "buildExportFile_dumpToFile");
162 
163  // zip the file
164  $ilBench->start("GlossaryExport", "buildExportFile_zipFile");
165  ilUtil::zip($this->export_dir."/".$this->subdir,
166  $this->export_dir."/".$this->subdir.".zip");
167  $ilBench->stop("GlossaryExport", "buildExportFile_zipFile");
168 
169  // destroy writer object
170  $this->xml->_XmlWriter;
171 
172  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export");
173  $ilBench->stop("GlossaryExport", "buildExportFile");
174 
175  return $this->export_dir."/".$this->subdir.".zip";
176  }
177 
182  {
183  global $ilBench;
184 
185  // create directories
186  $this->glo_obj->createExportDirectory("html");
187 
188  // get Log File
189  $expDir = $this->glo_obj->getExportDirectory();
190 
191  // get xml content
192  $this->glo_obj->exportHTML($this->export_dir."/".$this->subdir, $expLog);
193  }
194 
195 }
196 
197 ?>
buildExportFileHTML()
build html export file
xmlSetDtdDef($dtdDef)
Sets dtd definition.
XML writer class.
logging
Definition: class.ilLog.php:18
buildExportFileXML()
build export file (complete zip file)
buildExportFile()
build export file (complete zip file)
ilGlossaryExport(&$a_glo_obj, $a_mode="xml")
Constructor public.
redirection script todo: (a better solution should control the processing via a xml file) ...
static zip($a_dir, $a_file, $compress_content=false)
zips given directory/file into given zip.file
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
global $ilBench
Definition: ilias.php:18
Export class for content objects.