ILIAS  release_7 Revision v7.30-3-g800a261c036
ilQuestionpoolExport Class Reference

Export class for questionpools. More...

+ Collaboration diagram for ilQuestionpoolExport:

Public Member Functions

 __construct ($a_qpl_obj, $a_mode="xml", $array_questions=null)
 Constructor @access public. More...
 
 getInstId ()
 
 buildExportFile ()
 build export file (complete zip file) More...
 
 buildExportFileXML ()
 build xml export file More...
 
 exportXHTMLMediaObjects ($a_export_dir)
 

Data Fields

 $err
 
 $db
 
 $ilias
 
 $qpl_obj
 
 $questions
 
 $inst_id
 
 $mode
 
 $lng
 

Protected Member Functions

 buildExportFileXLS ()
 build xml export file More...
 

Detailed Description

Export class for questionpools.

Author
Helmut Schottmüller helmu.nosp@m.t.sc.nosp@m.hottm.nosp@m.uell.nosp@m.er@ma.nosp@m.c.co.nosp@m.m
Version
$Id$

Definition at line 15 of file class.ilQuestionpoolExport.php.

Constructor & Destructor Documentation

◆ __construct()

ilQuestionpoolExport::__construct (   $a_qpl_obj,
  $a_mode = "xml",
  $array_questions = null 
)

Constructor @access public.

Definition at line 33 of file class.ilQuestionpoolExport.php.

34 {
35 global $DIC;
36 $ilErr = $DIC['ilErr'];
37 $ilDB = $DIC['ilDB'];
38 $ilias = $DIC['ilias'];
39 $lng = $DIC['lng'];
40
41 $this->qpl_obj = &$a_qpl_obj;
42 if (!is_array($array_questions)) {
43 $array_questions = &$a_qpl_obj->getAllQuestionIds();
44 }
45
46 $this->err = &$ilErr;
47 $this->ilias = &$ilias;
48 $this->db = &$ilDB;
49 $this->mode = $a_mode;
50 $this->lng = &$lng;
51
52 $settings = $this->ilias->getAllSettings();
53 $this->inst_id = IL_INST_ID;
54 $this->questions = $array_questions;
55 $date = time();
56 $this->qpl_obj->createExportDirectory();
57 switch ($this->mode) {
58 case "xml":
59 $this->export_dir = $this->qpl_obj->getExportDirectory('xml');
60 $this->subdir = $date . "__" . $this->inst_id . "__" .
61 "qpl" . "_" . $this->qpl_obj->getId();
62 $this->filename = $this->subdir . ".xml";
63 $this->qti_filename = $date . "__" . $this->inst_id . "__" .
64 "qti" . "_" . $this->qpl_obj->getId() . ".xml";
65 break;
66 case "xls":
67 $this->export_dir = $this->qpl_obj->getExportDirectory('xls');
68 $this->filename = $date . "__" . $this->inst_id . "__" .
69 "qpl" . "_" . $this->qpl_obj->getId() . ".xlsx";
70 $this->zipfilename = $date . "__" . $this->inst_id . "__" .
71 "qpl" . "_" . $this->qpl_obj->getId() . ".zip";
72 break;
73 default:
74 $this->export_dir = $this->qpl_obj->getExportDirectory('zip');
75 $this->subdir = $date . "__" . $this->inst_id . "__" .
76 "qpl" . "_" . $this->qpl_obj->getId();
77 $this->filename = $this->subdir . ".xml";
78 $this->qti_filename = $date . "__" . $this->inst_id . "__" .
79 "qti" . "_" . $this->qpl_obj->getId() . ".xml";
80 break;
81 }
82 }
const IL_INST_ID
Definition: constants.php:38
global $DIC
Definition: goto.php:24
redirection script todo: (a better solution should control the processing via a xml file)
$ilErr
Definition: raiseError.php:18
global $ilDB

References $DIC, $ilDB, $ilErr, $ilias, $lng, and IL_INST_ID.

Member Function Documentation

◆ buildExportFile()

ilQuestionpoolExport::buildExportFile ( )

build export file (complete zip file)

@access public

Returns

Definition at line 96 of file class.ilQuestionpoolExport.php.

97 {
98 switch ($this->mode) {
99 case "xls":
100 return $this->buildExportFileXLS();
101 break;
102 case "xml":
103 default:
104 return $this->buildExportFileXML();
105 break;
106 }
107 }
buildExportFileXLS()
build xml export file
buildExportFileXML()
build xml export file

References buildExportFileXLS(), and buildExportFileXML().

+ Here is the call graph for this function:

◆ buildExportFileXLS()

ilQuestionpoolExport::buildExportFileXLS ( )
protected

build xml export file

Definition at line 203 of file class.ilQuestionpoolExport.php.

204 {
205 require_once 'Modules/TestQuestionPool/classes/class.ilAssExcelFormatHelper.php';
206 require_once 'Modules/TestQuestionPool/classes/class.assQuestion.php';
207
208 $worksheet = new ilAssExcelFormatHelper();
209 $worksheet->addSheet('Sheet 1');
210 $row = 1;
211 $col = 0;
212
213 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("title"));
214 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("description"));
215 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("question_type"));
216 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("author"));
217 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("create_date"));
218 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col) . $row, $this->lng->txt("last_update"));
219
220 $col = 0;
221 $row++;
222 $questions = $this->qpl_obj->getQuestionList();
223 foreach ($questions as $question) {
224 $worksheet->setCell($row, $col++, $question["title"]);
225 $worksheet->setCell($row, $col++, $question["description"]);
226 $worksheet->setCell($row, $col++, $this->lng->txt($question["type_tag"]));
227 $worksheet->setCell($row, $col++, $question["author"]);
228 $created = new ilDate($question["created"], IL_CAL_UNIX);
229 $worksheet->setCell($row, $col++, $created);
230 $updated = new ilDate($question["tstamp"], IL_CAL_UNIX);
231 $worksheet->setCell($row, $col++, $updated);
232 $col = 0;
233 $row++;
234 }
235
236 $excelfile = $this->export_dir . '/' . $this->filename;
237 $worksheet->writeToFile($excelfile);
238 ilUtil::zip($excelfile, $this->export_dir . "/" . $this->zipfilename);
239 if (@file_exists($this->export_dir . "/" . $this->filename)) {
240 @unlink($this->export_dir . "/" . $this->filename);
241 }
242 }
$filename
Definition: buildRTE.php:89
const IL_CAL_UNIX
Class ilAssExcelFormatHelper.
Class for single dates.
static zip($a_dir, $a_file, $compress_content=false)
zips given directory/file into given zip.file

References $filename, $questions, IL_CAL_UNIX, and ilUtil\zip().

Referenced by buildExportFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildExportFileXML()

ilQuestionpoolExport::buildExportFileXML ( )

build xml export file

Definition at line 112 of file class.ilQuestionpoolExport.php.

113 {
114 global $DIC;
115 $ilBench = $DIC['ilBench'];
116
117 $ilBench->start("QuestionpoolExport", "buildExportFile");
118
119 include_once("./Services/Xml/classes/class.ilXmlWriter.php");
120 $this->xml = new ilXmlWriter;
121
122 // set dtd definition
123 $this->xml->xmlSetDtdDef("<!DOCTYPE Test SYSTEM \"http://www.ilias.uni-koeln.de/download/dtd/ilias_co.dtd\">");
124
125 // set generated comment
126 $this->xml->xmlSetGenCmt("Export of ILIAS Test Questionpool " .
127 $this->qpl_obj->getId() . " of installation " . $this->inst . ".");
128
129 // set xml header
130 $this->xml->xmlHeader();
131
132 // create directories
133 include_once "./Services/Utilities/classes/class.ilUtil.php";
134 ilUtil::makeDir($this->export_dir . "/" . $this->subdir);
135 ilUtil::makeDir($this->export_dir . "/" . $this->subdir . "/objects");
136
137 // get Log File
138 $expDir = $this->qpl_obj->getExportDirectory();
139 ilUtil::makeDirParents($expDir);
140
141 include_once "./Services/Logging/classes/class.ilLog.php";
142 $expLog = new ilLog($expDir, "export.log");
143 $expLog->delete();
144 $expLog->setLogFormat("");
145 $expLog->write(date("[y-m-d H:i:s] ") . "Start Export");
146
147 // write qti file
148 $qti_file = fopen($this->export_dir . "/" . $this->subdir . "/" . $this->qti_filename, "w");
149 fwrite($qti_file, $this->qpl_obj->questionsToXML($this->questions));
150 fclose($qti_file);
151
152 // get xml content
153 $ilBench->start("QuestionpoolExport", "buildExportFile_getXML");
154 $this->qpl_obj->objectToXmlWriter(
155 $this->xml,
156 $this->inst_id,
157 $this->export_dir . "/" . $this->subdir,
158 $expLog,
159 $this->questions
160 );
161 $ilBench->stop("QuestionpoolExport", "buildExportFile_getXML");
162 $ilBench->start("QuestionpoolExport", "buildExportFile_dumpToFile");
163 $this->xml->xmlDumpFile($this->export_dir . "/" . $this->subdir . "/" . $this->filename, false);
164 $ilBench->stop("QuestionpoolExport", "buildExportFile_dumpToFile");
165
166 // add media objects which were added with tiny mce
167 $ilBench->start("QuestionpoolExport", "buildExportFile_saveAdditionalMobs");
168 $this->exportXHTMLMediaObjects($this->export_dir . "/" . $this->subdir);
169 $ilBench->stop("QuestionpoolExport", "buildExportFile_saveAdditionalMobs");
170
171 // zip the file
172 $ilBench->start("QuestionpoolExport", "buildExportFile_zipFile");
173 ilUtil::zip($this->export_dir . "/" . $this->subdir, $this->export_dir . "/" . $this->subdir . ".zip");
174 $ilBench->stop("QuestionpoolExport", "buildExportFile_zipFile");
175
176 // destroy writer object
177 $this->xml->_XmlWriter;
178 $expLog->write(date("[y-m-d H:i:s] ") . "Finished Export");
179 $ilBench->stop("QuestionpoolExport", "buildExportFile");
180
181 return $this->export_dir . "/" . $this->subdir . ".zip";
182 }
logging
Definition: class.ilLog.php:19
static makeDirParents($a_dir)
Create a new directory and all parent directories.
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
XML writer class.
xmlSetDtdDef($dtdDef)
Sets dtd definition.
global $ilBench
Definition: ilias.php:21

References $DIC, $ilBench, exportXHTMLMediaObjects(), ilUtil\makeDir(), ilUtil\makeDirParents(), ilXmlWriter\xmlSetDtdDef(), and ilUtil\zip().

Referenced by buildExportFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ exportXHTMLMediaObjects()

ilQuestionpoolExport::exportXHTMLMediaObjects (   $a_export_dir)

Definition at line 184 of file class.ilQuestionpoolExport.php.

185 {
186 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
187
188 foreach ($this->questions as $question_id) {
189 $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $question_id);
190 foreach ($mobs as $mob) {
191 if (ilObjMediaObject::_exists($mob)) {
192 $mob_obj = new ilObjMediaObject($mob);
193 $mob_obj->exportFiles($a_export_dir);
194 unset($mob_obj);
195 }
196 }
197 }
198 }
Class ilObjMediaObject.
static _getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
static _exists($a_id, $a_reference=false, $a_type=null)
checks wether a lm content object with specified id exists or not
$mobs
Definition: imgupload.php:54

References $mobs, ilObjMediaObject\_exists(), and ilObjMediaObject\_getMobsOfObject().

Referenced by buildExportFileXML().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getInstId()

ilQuestionpoolExport::getInstId ( )

Definition at line 84 of file class.ilQuestionpoolExport.php.

References $inst_id.

Field Documentation

◆ $db

ilQuestionpoolExport::$db

Definition at line 18 of file class.ilQuestionpoolExport.php.

◆ $err

ilQuestionpoolExport::$err

Definition at line 17 of file class.ilQuestionpoolExport.php.

◆ $ilias

ilQuestionpoolExport::$ilias

Definition at line 19 of file class.ilQuestionpoolExport.php.

Referenced by __construct().

◆ $inst_id

ilQuestionpoolExport::$inst_id

Definition at line 25 of file class.ilQuestionpoolExport.php.

Referenced by getInstId().

◆ $lng

ilQuestionpoolExport::$lng

Definition at line 27 of file class.ilQuestionpoolExport.php.

Referenced by __construct().

◆ $mode

ilQuestionpoolExport::$mode

Definition at line 26 of file class.ilQuestionpoolExport.php.

◆ $qpl_obj

ilQuestionpoolExport::$qpl_obj

Definition at line 23 of file class.ilQuestionpoolExport.php.

◆ $questions

ilQuestionpoolExport::$questions

Definition at line 24 of file class.ilQuestionpoolExport.php.

Referenced by buildExportFileXLS().


The documentation for this class was generated from the following file: