ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSurveyExport.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 include_once "./Modules/Survey/classes/inc.SurveyConstants.php";
25 
34 {
35  var $err; // error object
36  var $db; // database object
37  var $ilias; // ilias object
38  var $survey_obj; // survey object
39  var $inst_id; // installation id
40  var $mode;
41  var $subdir;
42  var $filename;
44 
49  function ilSurveyExport(&$a_survey_obj, $a_mode = "xml")
50  {
51  global $ilErr, $ilDB, $ilias;
52 
53  $this->survey_obj =& $a_survey_obj;
54 
55  $this->err =& $ilErr;
56  $this->ilias =& $ilias;
57  $this->db =& $ilDB;
58  $this->mode = $a_mode;
59 
60  $settings = $this->ilias->getAllSettings();
61  //$this->inst_id = $settings["inst_id"];
62  $this->inst_id = IL_INST_ID;
63 
64  $date = time();
65  switch($this->mode)
66  {
67  default:
68  $this->export_dir = $this->survey_obj->getExportDirectory();
69  $this->subdir = $date."__".$this->inst_id."__".
70  "survey"."__".$this->survey_obj->getId();
71  $this->filename = $this->subdir.".xml";
72  break;
73  }
74  }
75 
76  function getInstId()
77  {
78  return $this->inst_id;
79  }
80 
81 
88  function buildExportFile()
89  {
90  switch ($this->mode)
91  {
92  default:
93  return $this->buildExportFileXML();
94  break;
95  }
96  }
97 
102  {
103  global $ilBench;
104 
105  $ilBench->start("SurveyExport", "buildExportFile");
106 
107  // create directories
108  $this->survey_obj->createExportDirectory();
109  include_once "./Services/Utilities/classes/class.ilUtil.php";
110  ilUtil::makeDir($this->export_dir."/".$this->subdir);
111  ilUtil::makeDir($this->export_dir."/".$this->subdir."/objects");
112 
113  // get Log File
114  $expDir = $this->survey_obj->getExportDirectory();
115  include_once "./Services/Logging/classes/class.ilLog.php";
116  $expLog = new ilLog($expDir, "export.log");
117  $expLog->delete();
118  $expLog->setLogFormat("");
119  $expLog->write(date("[y-m-d H:i:s] ")."Start Export");
120 
121  // write xml file
122  $xmlFile = fopen($this->export_dir."/".$this->subdir."/".$this->filename, "w");
123  fwrite($xmlFile, $this->survey_obj->toXML());
124  fclose($xmlFile);
125 
126  // add media objects which were added with tiny mce
127  $this->exportXHTMLMediaObjects($this->export_dir."/".$this->subdir);
128 
129  // zip the file
130  $ilBench->start("SurveyExport", "buildExportFileXML_zipFile");
131  ilUtil::zip($this->export_dir."/".$this->subdir, $this->export_dir."/".$this->subdir.".zip");
132  $ilBench->stop("SurveyExport", "buildExportFileXML_zipFile");
133 
134  if (@file_exists($this->export_dir."/".$this->subdir.".zip"))
135  {
136  // remove export directory and contents
137  if (@is_dir($this->export_dir."/".$this->subdir))
138  {
139  ilUtil::delDir($this->export_dir."/".$this->subdir);
140  }
141  }
142  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export");
143  $ilBench->stop("SurveyExport", "buildExportFile");
144 
145  return $this->export_dir."/".$this->subdir.".zip";
146  }
147 
148  function exportXHTMLMediaObjects($a_export_dir)
149  {
150  global $ilBench;
151  $ilBench->start("SurveyExport", "exportXHTMLMediaObjects");
152  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
153 
154  $mobs = ilObjMediaObject::_getMobsOfObject("svy:html", $this->survey_obj->getId());
155  foreach ($mobs as $mob)
156  {
157  $mob_obj =& new ilObjMediaObject($mob);
158  $mob_obj->exportFiles($a_export_dir);
159  unset($mob_obj);
160  }
161  /* maybe this will be used later
162  foreach ($this->survey_obj->questions as $question_id)
163  {
164  $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $question_id);
165  foreach ($mobs as $mob)
166  {
167  $mob_obj =& new ilObjMediaObject($mob);
168  $mob_obj->exportFiles($a_export_dir);
169  unset($mob_obj);
170  }
171  }*/
172  $ilBench->stop("SurveyExport", "exportXHTMLMediaObjects");
173  }
174 
175 }
176 
177 ?>