ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules 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 
32 {
33  public $db; // database object
34  public $survey_obj; // survey object
35  public $inst_id; // installation id
36  public $mode;
37  public $subdir;
38  public $filename;
39  public $export_dir;
40 
45  public function __construct($a_survey_obj, $a_mode = "xml")
46  {
47  global $DIC;
48 
49  $ilDB = $DIC->database();
50 
51  $this->survey_obj = $a_survey_obj;
52 
53  $this->db = $ilDB;
54  $this->mode = $a_mode;
55  $this->inst_id = IL_INST_ID;
56 
57  $date = time();
58  switch ($this->mode) {
59  default:
60  $this->export_dir = $this->survey_obj->getExportDirectory();
61  $this->subdir = $date . "__" . $this->inst_id . "__" .
62  "svy" . "_" . $this->survey_obj->getId();
63  $this->filename = $this->subdir . ".xml";
64  break;
65  }
66  }
67 
68  public function getInstId()
69  {
70  return $this->inst_id;
71  }
72 
73 
80  public function buildExportFile()
81  {
82  switch ($this->mode) {
83  default:
84  return $this->buildExportFileXML();
85  break;
86  }
87  }
88 
92  public function buildExportFileXML()
93  {
94 
95  // create directories
96  $this->survey_obj->createExportDirectory();
97  ilUtil::makeDir($this->export_dir . "/" . $this->subdir);
98  ilUtil::makeDir($this->export_dir . "/" . $this->subdir . "/objects");
99 
100  // get Log File
101  $expDir = $this->survey_obj->getExportDirectory();
102  $expLog = new ilLog($expDir, "export.log");
103  $expLog->delete();
104  $expLog->setLogFormat("");
105  $expLog->write(date("[y-m-d H:i:s] ") . "Start Export");
106 
107  // write xml file
108  $xmlFile = fopen($this->export_dir . "/" . $this->subdir . "/" . $this->filename, "w");
109  fwrite($xmlFile, $this->survey_obj->toXML());
110  fclose($xmlFile);
111 
112  // add media objects which were added with tiny mce
113  $this->exportXHTMLMediaObjects($this->export_dir . "/" . $this->subdir);
114 
115  // zip the file
116  ilUtil::zip($this->export_dir . "/" . $this->subdir, $this->export_dir . "/" . $this->subdir . ".zip");
117 
118  if (@file_exists($this->export_dir . "/" . $this->subdir . ".zip")) {
119  // remove export directory and contents
120  if (@is_dir($this->export_dir . "/" . $this->subdir)) {
121  ilUtil::delDir($this->export_dir . "/" . $this->subdir);
122  }
123  }
124  $expLog->write(date("[y-m-d H:i:s] ") . "Finished Export");
125 
126  return $this->export_dir . "/" . $this->subdir . ".zip";
127  }
128 
129  public function exportXHTMLMediaObjects($a_export_dir)
130  {
131  $mobs = ilObjMediaObject::_getMobsOfObject("svy:html", $this->survey_obj->getId());
132  foreach ($mobs as $mob) {
133  $mob_obj = new ilObjMediaObject($mob);
134  $mob_obj->exportFiles($a_export_dir);
135  unset($mob_obj);
136  }
137  // #14850
138  foreach ($this->survey_obj->questions as $question_id) {
139  $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $question_id);
140  foreach ($mobs as $mob) {
141  $mob_obj = new ilObjMediaObject($mob);
142  $mob_obj->exportFiles($a_export_dir);
143  unset($mob_obj);
144  }
145  }
146  }
147 }
static _getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
const IL_INST_ID
Definition: constants.php:38
$mobs
Definition: imgupload.php:54
logging
Definition: class.ilLog.php:18
buildExportFileXML()
build xml export file
Export class for surveys.
global $DIC
Definition: goto.php:24
__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 $ilDB
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