ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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;
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 include_once "./Services/Logging/classes/class.ilLog.php";
103 $expLog = new ilLog($expDir, "export.log");
104 $expLog->delete();
105 $expLog->setLogFormat("");
106 $expLog->write(date("[y-m-d H:i:s] ") . "Start Export");
107
108 // write xml file
109 $xmlFile = fopen($this->export_dir . "/" . $this->subdir . "/" . $this->filename, "w");
110 fwrite($xmlFile, $this->survey_obj->toXML());
111 fclose($xmlFile);
112
113 // add media objects which were added with tiny mce
114 $this->exportXHTMLMediaObjects($this->export_dir . "/" . $this->subdir);
115
116 // zip the file
117 ilUtil::zip($this->export_dir . "/" . $this->subdir, $this->export_dir . "/" . $this->subdir . ".zip");
118
119 if (@file_exists($this->export_dir . "/" . $this->subdir . ".zip")) {
120 // remove export directory and contents
121 if (@is_dir($this->export_dir . "/" . $this->subdir)) {
122 ilUtil::delDir($this->export_dir . "/" . $this->subdir);
123 }
124 }
125 $expLog->write(date("[y-m-d H:i:s] ") . "Finished Export");
126
127 return $this->export_dir . "/" . $this->subdir . ".zip";
128 }
129
130 public function exportXHTMLMediaObjects($a_export_dir)
131 {
132 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
133
134 $mobs = ilObjMediaObject::_getMobsOfObject("svy:html", $this->survey_obj->getId());
135 foreach ($mobs as $mob) {
136 $mob_obj = new ilObjMediaObject($mob);
137 $mob_obj->exportFiles($a_export_dir);
138 unset($mob_obj);
139 }
140 // #14850
141 foreach ($this->survey_obj->questions as $question_id) {
142 $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $question_id);
143 foreach ($mobs as $mob) {
144 $mob_obj = new ilObjMediaObject($mob);
145 $mob_obj->exportFiles($a_export_dir);
146 unset($mob_obj);
147 }
148 }
149 }
150}
An exception for terminatinating execution or to throw for unit testing.
logging
Definition: class.ilLog.php:19
Class ilObjMediaObject.
static _getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
Export class for surveys.
exportXHTMLMediaObjects($a_export_dir)
__construct($a_survey_obj, $a_mode="xml")
Constructor @access public.
buildExportFileXML()
build xml export file
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)
zips given directory/file into given zip.file
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
global $DIC
Definition: saml.php:7
global $ilDB
$mobs