ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 $db; // database object
34  var $survey_obj; // survey object
35  var $inst_id; // installation id
36  var $mode;
37  var $subdir;
38  var $filename;
40 
45  function __construct($a_survey_obj, $a_mode = "xml")
46  {
47  global $ilDB;
48 
49  $this->survey_obj = $a_survey_obj;
50 
51  $this->db = $ilDB;
52  $this->mode = $a_mode;
53  $this->inst_id = IL_INST_ID;
54 
55  $date = time();
56  switch($this->mode)
57  {
58  default:
59  $this->export_dir = $this->survey_obj->getExportDirectory();
60  $this->subdir = $date."__".$this->inst_id."__".
61  "svy"."_".$this->survey_obj->getId();
62  $this->filename = $this->subdir.".xml";
63  break;
64  }
65  }
66 
67  function getInstId()
68  {
69  return $this->inst_id;
70  }
71 
72 
79  function buildExportFile()
80  {
81  switch ($this->mode)
82  {
83  default:
84  return $this->buildExportFileXML();
85  break;
86  }
87  }
88 
92  function buildExportFileXML()
93  {
94  global $ilBench;
95 
96  $ilBench->start("SurveyExport", "buildExportFile");
97 
98  // create directories
99  $this->survey_obj->createExportDirectory();
100  ilUtil::makeDir($this->export_dir."/".$this->subdir);
101  ilUtil::makeDir($this->export_dir."/".$this->subdir."/objects");
102 
103  // get Log File
104  $expDir = $this->survey_obj->getExportDirectory();
105  include_once "./Services/Logging/classes/class.ilLog.php";
106  $expLog = new ilLog($expDir, "export.log");
107  $expLog->delete();
108  $expLog->setLogFormat("");
109  $expLog->write(date("[y-m-d H:i:s] ")."Start Export");
110 
111  // write xml file
112  $xmlFile = fopen($this->export_dir."/".$this->subdir."/".$this->filename, "w");
113  fwrite($xmlFile, $this->survey_obj->toXML());
114  fclose($xmlFile);
115 
116  // add media objects which were added with tiny mce
117  $this->exportXHTMLMediaObjects($this->export_dir."/".$this->subdir);
118 
119  // zip the file
120  $ilBench->start("SurveyExport", "buildExportFileXML_zipFile");
121  ilUtil::zip($this->export_dir."/".$this->subdir, $this->export_dir."/".$this->subdir.".zip");
122  $ilBench->stop("SurveyExport", "buildExportFileXML_zipFile");
123 
124  if (@file_exists($this->export_dir."/".$this->subdir.".zip"))
125  {
126  // remove export directory and contents
127  if (@is_dir($this->export_dir."/".$this->subdir))
128  {
129  ilUtil::delDir($this->export_dir."/".$this->subdir);
130  }
131  }
132  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export");
133  $ilBench->stop("SurveyExport", "buildExportFile");
134 
135  return $this->export_dir."/".$this->subdir.".zip";
136  }
137 
138  function exportXHTMLMediaObjects($a_export_dir)
139  {
140  global $ilBench;
141  $ilBench->start("SurveyExport", "exportXHTMLMediaObjects");
142  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
143 
144  $mobs = ilObjMediaObject::_getMobsOfObject("svy:html", $this->survey_obj->getId());
145  foreach ($mobs as $mob)
146  {
147  $mob_obj = new ilObjMediaObject($mob);
148  $mob_obj->exportFiles($a_export_dir);
149  unset($mob_obj);
150  }
151  // #14850
152  foreach ($this->survey_obj->questions as $question_id)
153  {
154  $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $question_id);
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  }
162  $ilBench->stop("SurveyExport", "exportXHTMLMediaObjects");
163  }
164 
165 }
166 
167 ?>
static _getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
logging
Definition: class.ilLog.php:18
buildExportFileXML()
build xml export file
$mobs
Export class for surveys.
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
__construct($a_survey_obj, $a_mode="xml")
Constructor public.
Class ilObjMediaObject.
static zip($a_dir, $a_file, $compress_content=false)
zips given directory/file into given zip.file
exportXHTMLMediaObjects($a_export_dir)
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
global $ilDB
buildExportFile()
build export file (complete zip file)
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively