ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
32{
33 var $err; // error object
34 var $db; // database object
35 var $ilias; // ilias object
36 var $survey_obj; // survey object
37 var $inst_id; // installation id
38 var $mode;
42
47 function ilSurveyExport(&$a_survey_obj, $a_mode = "xml")
48 {
49 global $ilErr, $ilDB, $ilias;
50
51 $this->survey_obj =& $a_survey_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 //$this->inst_id = $settings["inst_id"];
60 $this->inst_id = IL_INST_ID;
61
62 $date = time();
63 switch($this->mode)
64 {
65 default:
66 $this->export_dir = $this->survey_obj->getExportDirectory();
67 $this->subdir = $date."__".$this->inst_id."__".
68 "svy"."_".$this->survey_obj->getId();
69 $this->filename = $this->subdir.".xml";
70 break;
71 }
72 }
73
74 function getInstId()
75 {
76 return $this->inst_id;
77 }
78
79
86 function buildExportFile()
87 {
88 switch ($this->mode)
89 {
90 default:
91 return $this->buildExportFileXML();
92 break;
93 }
94 }
95
100 {
101 global $ilBench;
102
103 $ilBench->start("SurveyExport", "buildExportFile");
104
105 // create directories
106 $this->survey_obj->createExportDirectory();
107 include_once "./Services/Utilities/classes/class.ilUtil.php";
108 ilUtil::makeDir($this->export_dir."/".$this->subdir);
109 ilUtil::makeDir($this->export_dir."/".$this->subdir."/objects");
110
111 // get Log File
112 $expDir = $this->survey_obj->getExportDirectory();
113 include_once "./Services/Logging/classes/class.ilLog.php";
114 $expLog = new ilLog($expDir, "export.log");
115 $expLog->delete();
116 $expLog->setLogFormat("");
117 $expLog->write(date("[y-m-d H:i:s] ")."Start Export");
118
119 // write xml file
120 $xmlFile = fopen($this->export_dir."/".$this->subdir."/".$this->filename, "w");
121 fwrite($xmlFile, $this->survey_obj->toXML());
122 fclose($xmlFile);
123
124 // add media objects which were added with tiny mce
125 $this->exportXHTMLMediaObjects($this->export_dir."/".$this->subdir);
126
127 // zip the file
128 $ilBench->start("SurveyExport", "buildExportFileXML_zipFile");
129 ilUtil::zip($this->export_dir."/".$this->subdir, $this->export_dir."/".$this->subdir.".zip");
130 $ilBench->stop("SurveyExport", "buildExportFileXML_zipFile");
131
132 if (@file_exists($this->export_dir."/".$this->subdir.".zip"))
133 {
134 // remove export directory and contents
135 if (@is_dir($this->export_dir."/".$this->subdir))
136 {
137 ilUtil::delDir($this->export_dir."/".$this->subdir);
138 }
139 }
140 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export");
141 $ilBench->stop("SurveyExport", "buildExportFile");
142
143 return $this->export_dir."/".$this->subdir.".zip";
144 }
145
146 function exportXHTMLMediaObjects($a_export_dir)
147 {
148 global $ilBench;
149 $ilBench->start("SurveyExport", "exportXHTMLMediaObjects");
150 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
151
152 $mobs = ilObjMediaObject::_getMobsOfObject("svy:html", $this->survey_obj->getId());
153 foreach ($mobs as $mob)
154 {
155 $mob_obj =& new ilObjMediaObject($mob);
156 $mob_obj->exportFiles($a_export_dir);
157 unset($mob_obj);
158 }
159 // #14850
160 foreach ($this->survey_obj->questions as $question_id)
161 {
162 $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $question_id);
163 foreach ($mobs as $mob)
164 {
165 $mob_obj =& new ilObjMediaObject($mob);
166 $mob_obj->exportFiles($a_export_dir);
167 unset($mob_obj);
168 }
169 }
170 $ilBench->stop("SurveyExport", "exportXHTMLMediaObjects");
171 }
172
173}
174
175?>
logging
Definition: class.ilLog.php:19
Class ilObjMediaObject.
_getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
Export class for surveys.
exportXHTMLMediaObjects($a_export_dir)
buildExportFileXML()
build xml export file
ilSurveyExport(&$a_survey_obj, $a_mode="xml")
Constructor @access public.
buildExportFile()
build export file (complete zip file)
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static zip($a_dir, $a_file, $compress_content=false)
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
redirection script todo: (a better solution should control the processing via a xml file)
global $ilDB
$mobs