ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilFileXMLWriter.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once "./Services/Xml/classes/class.ilXmlWriter.php";
6 
22 {
23  static $CONTENT_ATTACH_NO = 0;
28 
35 
41  var $file;
42 
43  var $omit_header = false;
44 
52  function ilFileXMLWriter()
53  {
55  $this->attachFileContents = ilFileXMLWriter::$CONTENT_ATTACH_NO;
56  }
57 
58 
60  {
61  $this->file = & $file;
62  }
63 
64 
70  function setOmitHeader($a_val)
71  {
72  $this->omit_header = $a_val;
73  }
74 
80  function getOmitHeader()
81  {
82  return $this->omit_header;
83  }
84 
91  function setFileTargetDirectories($a_rel, $a_abs)
92  {
93  $this->target_dir_relative = $a_rel;
94  $this->target_dir_absolute = $a_abs;
95  }
96 
97 
105  {
106  if ($attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED && !function_exists("gzencode"))
107  {
108  throw new ilFileException ("Inflating with gzip is not supported", ilFileException::$ID_DEFLATE_METHOD_MISMATCH);
109  }
110  if ($attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED && !function_exists("gzcompress"))
111  {
112  throw new ilFileException ("Inflating with zlib (compress/uncompress) is not supported", ilFileException::$ID_DEFLATE_METHOD_MISMATCH);
113  }
114  $this->attachFileContents = $attachFileContents;
115  }
116 
117 
118  function start()
119  {
120  $this->__buildHeader();
121 
122  $attribs =array (
123  "obj_id" => "il_".IL_INST_ID."_file_".$this->file->getId(),
124  "version" => $this->file->getVersion(),
125  "size" => $this->file->getFileSize(),
126  "type" => $this->file->getFileType()
127  );
128 
129  $this->xmlStartTag("File", $attribs);
130  $this->xmlElement("Filename",null,$this->file->getFileName());
131 
132  $this->xmlElement("Title", null,$this->file->getTitle());
133  $this->xmlElement("Description", null,$this->file->getDescription());
134 
135 
136  if ($this->attachFileContents)
137  {
138  $filename = $this->file->getDirectory($this->file->getVersion())."/".$this->file->getFileName();
139  if (@is_file($filename))
140  {
141  if ($this->attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_COPY)
142  {
143  $attribs = array("mode" =>"COPY");
144  copy($filename, $this->target_dir_absolute."/".$this->file->getFileName());
145  $content = $this->target_dir_relative."/".$this->file->getFileName();
146  $this->xmlElement("Content",$attribs, $content);
147  }
148  else
149  {
150  $content = @file_get_contents($filename);
151  $attribs = array("mode" =>"PLAIN");
152  if ($this->attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED)
153  {
154  $attribs ["mode"] ="ZLIB";
155  $content = @gzcompress($content, 9);
156  }elseif ($this->attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED)
157  {
158  $attribs ["mode"] ="GZIP";
159  $content = @gzencode($content, 9);
160  }
161  $content = base64_encode($content);
162  $this->xmlElement("Content",$attribs, $content);
163  }
164  }
165 
166  }
167 
168  include_once("classes/class.ilHistory.php");
169 
170  $versions = ilHistory::_getEntriesForObject($this->file->getId(), $this->file->getType());
171 
172  if (count($versions)) {
173  $this->xmlStartTag("Versions");
174  foreach ($versions as $version) {
175  $info_params = $version["info_params"];
176  list($filename,$history_id) = split(",",$info_params);
177  $attribs = array (
178  "id" => $history_id,
179  "date" => ilUtil::date_mysql2time($version["date"]),
180  "usr_id" => "il_".IL_INST_ID."_usr_".$version["user_id"]
181  );
182  $this->xmlElement("Version", $attribs);
183  }
184  $this->xmlEndTag("Versions");
185 
186  }
187 
188  $this->xmlEndTag("File");
189 
190  $this->__buildFooter();
191 
192  return true;
193  }
194 
195  function getXML()
196  {
197  return $this->xmlDumpMem(false);
198  }
199 
200 
201  function __buildHeader()
202  {
203  if (!$this->getOmitHeader())
204  {
205  $this->xmlSetDtdDef("<!DOCTYPE File PUBLIC \"-//ILIAS//DTD FileAdministration//EN\" \"".ILIAS_HTTP_PATH."/xml/ilias_file_3_8.dtd\">");
206  $this->xmlSetGenCmt("Exercise Object");
207  $this->xmlHeader();
208  }
209 
210  return true;
211  }
212 
213  function __buildFooter()
214  {
215 
216  }
217 
218 }
219 
220 
221 ?>