ILIAS  release_8 Revision v8.24
class.ilSurveyExport.php
Go to the documentation of this file.
1<?php
2
24{
25 public ilDBInterface $db; // database object
26 public ilObjSurvey $survey_obj; // survey object
27 public int $inst_id; // installation id
28 public string $mode;
29 public string $subdir;
30 public string $filename;
31 public string $export_dir;
32
33 public function __construct(
34 ilObjSurvey $a_survey_obj,
35 $a_mode = "xml"
36 ) {
37 global $DIC;
38
39 $ilDB = $DIC->database();
40
41 $this->survey_obj = $a_survey_obj;
42
43 $this->db = $ilDB;
44 $this->mode = $a_mode;
45 $this->inst_id = (int) IL_INST_ID;
46
47 $date = time();
48 switch ($this->mode) {
49 default:
50 $this->export_dir = $this->survey_obj->getExportDirectory();
51 $this->subdir = $date . "__" . $this->inst_id . "__" .
52 "svy" . "_" . $this->survey_obj->getId();
53 $this->filename = $this->subdir . ".xml";
54 break;
55 }
56 }
57
58 public function getInstId(): int
59 {
60 return $this->inst_id;
61 }
62
63
67 public function buildExportFile(): string
68 {
69 switch ($this->mode) {
70 default:
71 return $this->buildExportFileXML();
72 }
73 }
74
81 public function buildExportFileXML(): string
82 {
83
84 // create directories
85 $this->survey_obj->createExportDirectory();
86 ilFileUtils::makeDir($this->export_dir . "/" . $this->subdir);
87 ilFileUtils::makeDir($this->export_dir . "/" . $this->subdir . "/objects");
88
89 // get Log File
90 $expDir = $this->survey_obj->getExportDirectory();
91 $expLog = new ilLog($expDir, "export.log");
92 $expLog->delete();
93 $expLog->setLogFormat("");
94 $expLog->write(date("[y-m-d H:i:s] ") . "Start Export");
95
96 // write xml file
97 $xmlFile = fopen($this->export_dir . "/" . $this->subdir . "/" . $this->filename, 'wb');
98 fwrite($xmlFile, $this->survey_obj->toXML());
99 fclose($xmlFile);
100
101 // add media objects which were added with tiny mce
102 $this->exportXHTMLMediaObjects($this->export_dir . "/" . $this->subdir);
103
104 // zip the file
105 ilFileUtils::zip($this->export_dir . "/" . $this->subdir, $this->export_dir . "/" . $this->subdir . ".zip");
106
107 if (file_exists($this->export_dir . "/" . $this->subdir . ".zip")) {
108 // remove export directory and contents
109 if (is_dir($this->export_dir . "/" . $this->subdir)) {
110 ilFileUtils::delDir($this->export_dir . "/" . $this->subdir);
111 }
112 }
113 $expLog->write(date("[y-m-d H:i:s] ") . "Finished Export");
114
115 return $this->export_dir . "/" . $this->subdir . ".zip";
116 }
117
118 public function exportXHTMLMediaObjects(
119 string $a_export_dir
120 ): void {
121 $mobs = ilObjMediaObject::_getMobsOfObject("svy:html", $this->survey_obj->getId());
122 foreach ($mobs as $mob) {
123 $mob_obj = new ilObjMediaObject($mob);
124 $mob_obj->exportFiles($a_export_dir);
125 unset($mob_obj);
126 }
127 // #14850
128 foreach ($this->survey_obj->questions as $question_id) {
129 $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $question_id);
130 foreach ($mobs as $mob) {
131 $mob_obj = new ilObjMediaObject($mob);
132 $mob_obj->exportFiles($a_export_dir);
133 unset($mob_obj);
134 }
135 }
136 }
137}
static zip(string $a_dir, string $a_file, bool $compress_content=false)
zips given directory/file into given zip.file
static makeDir(string $a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: class.ilLog.php:31
static _getMobsOfObject(string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(ilObjSurvey $a_survey_obj, $a_mode="xml")
exportXHTMLMediaObjects(string $a_export_dir)
buildExportFileXML()
build xml export file
const IL_INST_ID
Definition: constants.php:40
global $DIC
Definition: feed.php:28
$mobs
Definition: imgupload.php:70
Interface ilDBInterface.