ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 // create directories
84 $this->survey_obj->createExportDirectory();
85 ilFileUtils::makeDir($this->export_dir . "/" . $this->subdir);
86 ilFileUtils::makeDir($this->export_dir . "/" . $this->subdir . "/objects");
87
88 // get Log File
89 $expDir = $this->survey_obj->getExportDirectory();
90 $expLog = new ilLog($expDir, "export.log");
91 $expLog->delete();
92 $expLog->setLogFormat("");
93 $expLog->write(date("[y-m-d H:i:s] ") . "Start Export");
94
95 // write xml file
96 $xmlFile = fopen($this->export_dir . "/" . $this->subdir . "/" . $this->filename, 'wb');
97 fwrite($xmlFile, $this->survey_obj->toXML());
98 fclose($xmlFile);
99
100 // add media objects which were added with tiny mce
101 $this->exportXHTMLMediaObjects($this->export_dir . "/" . $this->subdir);
102
103 // zip the file
104 ilFileUtils::zip($this->export_dir . "/" . $this->subdir, $this->export_dir . "/" . $this->subdir . ".zip");
105
106 if (file_exists($this->export_dir . "/" . $this->subdir . ".zip")) {
107 // remove export directory and contents
108 if (is_dir($this->export_dir . "/" . $this->subdir)) {
109 ilFileUtils::delDir($this->export_dir . "/" . $this->subdir);
110 }
111 }
112 $expLog->write(date("[y-m-d H:i:s] ") . "Finished Export");
113
114 return $this->export_dir . "/" . $this->subdir . ".zip";
115 }
116
117 public function exportXHTMLMediaObjects(
118 string $a_export_dir
119 ): void {
120 $mobs = ilObjMediaObject::_getMobsOfObject("svy:html", $this->survey_obj->getId());
121 foreach ($mobs as $mob) {
122 $mob_obj = new ilObjMediaObject($mob);
123 $mob_obj->exportFiles($a_export_dir);
124 unset($mob_obj);
125 }
126 // #14850
127 foreach ($this->survey_obj->questions as $question_id) {
128 $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $question_id);
129 foreach ($mobs as $mob) {
130 $mob_obj = new ilObjMediaObject($mob);
131 $mob_obj->exportFiles($a_export_dir);
132 unset($mob_obj);
133 }
134 }
135 }
136}
static zip(string $a_dir, string $a_file, bool $compress_content=false)
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
Interface ilDBInterface.
global $DIC
Definition: shib_login.php:26