ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $ilErr, $ilDB, $ilias, $lng;
36
37 $this->qpl_obj =&$a_qpl_obj;
38 if (!is_array($array_questions)) {
39 $array_questions =&$a_qpl_obj->getAllQuestionIds();
40 }
41
42 $this->err =&$ilErr;
43 $this->ilias =&$ilias;
44 $this->db =&$ilDB;
45 $this->mode = $a_mode;
46 $this->lng =&$lng;
47
48 $settings = $this->ilias->getAllSettings();
49 $this->inst_id = IL_INST_ID;
50 $this->questions = $array_questions;
51 $date = time();
52 $this->qpl_obj->createExportDirectory();
53 switch ($this->mode) {
54 case "xml":
55 $this->export_dir = $this->qpl_obj->getExportDirectory('xml');
56 $this->subdir = $date . "__" . $this->inst_id . "__" .
57 "qpl" . "_" . $this->qpl_obj->getId();
58 $this->filename = $this->subdir . ".xml";
59 $this->qti_filename = $date . "__" . $this->inst_id . "__" .
60 "qti" . "_" . $this->qpl_obj->getId() . ".xml";
61 break;
62 case "xls":
63 $this->export_dir = $this->qpl_obj->getExportDirectory('xls');
64 $this->filename = $date . "__" . $this->inst_id . "__" .
65 "qpl" . "_" . $this->qpl_obj->getId() . ".xlsx";
66 $this->zipfilename = $date . "__" . $this->inst_id . "__" .
67 "qpl" . "_" . $this->qpl_obj->getId() . ".zip";
68 break;
69 default:
70 $this->export_dir = $this->qpl_obj->getExportDirectory('zip');
71 $this->subdir = $date . "__" . $this->inst_id . "__" .
72 "qpl" . "_" . $this->qpl_obj->getId();
73 $this->filename = $this->subdir . ".xml";
74 $this->qti_filename = $date . "__" . $this->inst_id . "__" .
75 "qti" . "_" . $this->qpl_obj->getId() . ".xml";
76 break;
77 }
78 }
redirection script todo: (a better solution should control the processing via a xml file)
global $ilErr
Definition: raiseError.php:16
global $ilDB

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

Member Function Documentation

◆ buildExportFile()

ilQuestionpoolExport::buildExportFile ( )

build export file (complete zip file)

@access public

Returns

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

93 {
94 switch ($this->mode) {
95 case "xls":
96 return $this->buildExportFileXLS();
97 break;
98 case "xml":
99 default:
100 return $this->buildExportFileXML();
101 break;
102 }
103 }
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 213 of file class.ilQuestionpoolExport.php.

214 {
215 require_once 'Modules/TestQuestionPool/classes/class.ilAssExcelFormatHelper.php';
216 require_once 'Modules/TestQuestionPool/classes/class.assQuestion.php';
217
219 $worksheet->addSheet('Sheet 1');
220 $row = 1;
221 $col = 0;
222
223 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("title"));
224 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("description"));
225 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("question_type"));
226 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("author"));
227 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("create_date"));
228 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col) . $row, $this->lng->txt("last_update"));
229
230 $col = 0;
231 $row++;
232 $questions = $this->qpl_obj->getQuestionList();
233 foreach ($questions as $question) {
234 $worksheet->setCell($row, $col++, $question["title"]);
235 $worksheet->setCell($row, $col++, $question["description"]);
236 $worksheet->setCell($row, $col++, $this->lng->txt($question["type_tag"]));
237 $worksheet->setCell($row, $col++, $question["author"]);
238 $created = new ilDate($question["created"], IL_CAL_UNIX);
239 $worksheet->setCell($row, $col++, $created);
240 $updated = new ilDate($question["tstamp"], IL_CAL_UNIX);
241 $worksheet->setCell($row, $col++, $updated);
242 $col = 0;
243 $row++;
244 }
245
246 $excelfile = $this->export_dir . '/' . $this->filename;
247 $worksheet->writeToFile($excelfile);
248 ilUtil::zip($excelfile, $this->export_dir . "/" . $this->zipfilename);
249 if (@file_exists($this->export_dir . "/" . $this->filename)) {
250 @unlink($this->export_dir . "/" . $this->filename);
251 }
252 }
$worksheet
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, $row, $worksheet, 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 108 of file class.ilQuestionpoolExport.php.

109 {
110 global $ilBench;
111
112 $ilBench->start("QuestionpoolExport", "buildExportFile");
113
114 include_once("./Services/Xml/classes/class.ilXmlWriter.php");
115 $this->xml = new ilXmlWriter;
116
117 // set dtd definition
118 $this->xml->xmlSetDtdDef("<!DOCTYPE Test SYSTEM \"http://www.ilias.uni-koeln.de/download/dtd/ilias_co.dtd\">");
119
120 // set generated comment
121 $this->xml->xmlSetGenCmt("Export of ILIAS Test Questionpool " .
122 $this->qpl_obj->getId() . " of installation " . $this->inst . ".");
123
124 // set xml header
125 $this->xml->xmlHeader();
126
127 // create directories
128 include_once "./Services/Utilities/classes/class.ilUtil.php";
129 ilUtil::makeDir($this->export_dir . "/" . $this->subdir);
130 ilUtil::makeDir($this->export_dir . "/" . $this->subdir . "/objects");
131
132 // get Log File
133 $expDir = $this->qpl_obj->getExportDirectory();
134 ilUtil::makeDirParents($expDir);
135
136 include_once "./Services/Logging/classes/class.ilLog.php";
137 $expLog = new ilLog($expDir, "export.log");
138 $expLog->delete();
139 $expLog->setLogFormat("");
140 $expLog->write(date("[y-m-d H:i:s] ") . "Start Export");
141
142 // write qti file
143 $qti_file = fopen($this->export_dir . "/" . $this->subdir . "/" . $this->qti_filename, "w");
144 fwrite($qti_file, $this->qpl_obj->questionsToXML($this->questions));
145 fclose($qti_file);
146
147 // get xml content
148 $ilBench->start("QuestionpoolExport", "buildExportFile_getXML");
149 $this->qpl_obj->objectToXmlWriter(
150 $this->xml,
151 $this->inst_id,
152 $this->export_dir . "/" . $this->subdir,
153 $expLog,
154 $this->questions
155 );
156 $ilBench->stop("QuestionpoolExport", "buildExportFile_getXML");
157
158 // dump xml document to screen (only for debugging reasons)
159 /*
160 echo "<PRE>";
161 echo htmlentities($this->xml->xmlDumpMem($format));
162 echo "</PRE>";
163 */
164
165 // dump xml document to file
166 $ilBench->start("QuestionpoolExport", "buildExportFile_dumpToFile");
167 $this->xml->xmlDumpFile($this->export_dir . "/" . $this->subdir . "/" . $this->filename, false);
168 $ilBench->stop("QuestionpoolExport", "buildExportFile_dumpToFile");
169
170 // add media objects which were added with tiny mce
171 $ilBench->start("QuestionpoolExport", "buildExportFile_saveAdditionalMobs");
172 $this->exportXHTMLMediaObjects($this->export_dir . "/" . $this->subdir);
173 $ilBench->stop("QuestionpoolExport", "buildExportFile_saveAdditionalMobs");
174
175 // zip the file
176 $ilBench->start("QuestionpoolExport", "buildExportFile_zipFile");
177 ilUtil::zip($this->export_dir . "/" . $this->subdir, $this->export_dir . "/" . $this->subdir . ".zip");
178 if (@is_dir($this->export_dir . "/" . $this->subdir)) {
179 // Do not delete this dir, since it is required for container exports
180 #ilUtil::delDir($this->export_dir."/".$this->subdir);
181 }
182
183 $ilBench->stop("QuestionpoolExport", "buildExportFile_zipFile");
184
185 // destroy writer object
186 $this->xml->_XmlWriter;
187
188 $expLog->write(date("[y-m-d H:i:s] ") . "Finished Export");
189 $ilBench->stop("QuestionpoolExport", "buildExportFile");
190
191 return $this->export_dir . "/" . $this->subdir . ".zip";
192 }
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
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:18

References $ilBench, date, 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 194 of file class.ilQuestionpoolExport.php.

195 {
196 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
197
198 foreach ($this->questions as $question_id) {
199 $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $question_id);
200 foreach ($mobs as $mob) {
201 if (ilObjMediaObject::_exists($mob)) {
202 $mob_obj = new ilObjMediaObject($mob);
203 $mob_obj->exportFiles($a_export_dir);
204 unset($mob_obj);
205 }
206 }
207 }
208 }
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

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 80 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: