ILIAS  release_8 Revision v8.24
ilQuestionpoolExport Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. 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...
 

Private Attributes

string $export_dir = ''
 
string $subdir = ''
 
string $filename = ''
 
string $zipfilename = ''
 
ilXmlWriter $xml
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning 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 30 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 54 of file class.ilQuestionpoolExport.php.

55 {
56 global $DIC;
57 $ilErr = $DIC['ilErr'];
58 $ilDB = $DIC['ilDB'];
59 $ilias = $DIC['ilias'];
60 $lng = $DIC['lng'];
61
62 $this->qpl_obj = &$a_qpl_obj;
63 if (!is_array($array_questions)) {
64 $array_questions = &$a_qpl_obj->getAllQuestionIds();
65 }
66
67 $this->err = &$ilErr;
68 $this->ilias = &$ilias;
69 $this->db = &$ilDB;
70 $this->mode = $a_mode;
71 $this->lng = &$lng;
72 $settings = $this->ilias->getAllSettings();
73 $this->inst_id = IL_INST_ID;
74 $this->questions = $array_questions;
75 $date = time();
76 $this->qpl_obj->createExportDirectory();
77 switch ($this->mode) {
78 case "xml":
79 $this->export_dir = $this->qpl_obj->getExportDirectory('xml');
80 $this->subdir = $date . "__" . $this->inst_id . "__" .
81 "qpl" . "_" . $this->qpl_obj->getId();
82 $this->filename = $this->subdir . ".xml";
83 $this->qti_filename = $date . "__" . $this->inst_id . "__" .
84 "qti" . "_" . $this->qpl_obj->getId() . ".xml";
85 break;
86 case "xls":
87 $this->export_dir = $this->qpl_obj->getExportDirectory('xls');
88 $this->filename = $date . "__" . $this->inst_id . "__" .
89 "qpl" . "_" . $this->qpl_obj->getId() . ".xlsx";
90 $this->zipfilename = $date . "__" . $this->inst_id . "__" .
91 "qpl" . "_" . $this->qpl_obj->getId() . ".zip";
92 break;
93 default:
94 $this->export_dir = $this->qpl_obj->getExportDirectory('zip');
95 $this->subdir = $date . "__" . $this->inst_id . "__" .
96 "qpl" . "_" . $this->qpl_obj->getId();
97 $this->filename = $this->subdir . ".xml";
98 $this->qti_filename = $date . "__" . $this->inst_id . "__" .
99 "qti" . "_" . $this->qpl_obj->getId() . ".xml";
100 break;
101 }
102 }
const IL_INST_ID
Definition: constants.php:40
global $DIC
Definition: feed.php:28
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
header include for all ilias files.
$ilErr
Definition: raiseError.php:17

References $DIC, $ilDB, $ilErr, $ilias, $lng, ILIAS\LTI\ToolProvider\$settings, IL_INST_ID, and ILIAS\Repository\lng().

+ Here is the call graph for this function:

Member Function Documentation

◆ buildExportFile()

ilQuestionpoolExport::buildExportFile ( )

build export file (complete zip file)

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

113 : string
114 {
115 switch ($this->mode) {
116 case "xls":
117 return $this->buildExportFileXLS();
118 case "xml":
119 default:
120 return $this->buildExportFileXML();
121 }
122 }
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 217 of file class.ilQuestionpoolExport.php.

217 : string
218 {
219 require_once 'Modules/TestQuestionPool/classes/class.ilAssExcelFormatHelper.php';
220 require_once 'Modules/TestQuestionPool/classes/class.assQuestion.php';
221
222 $worksheet = new ilAssExcelFormatHelper();
223 $worksheet->addSheet('Sheet 1');
224 $row = 1;
225 $col = 0;
226
227 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("title"));
228 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("description"));
229 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("question_type"));
230 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("author"));
231 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("create_date"));
232 $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col) . $row, $this->lng->txt("last_update"));
233
234 $col = 0;
235 $row++;
236 $questions = $this->qpl_obj->getQuestionList();
237 foreach ($questions as $question) {
238 $worksheet->setCell($row, $col++, $question["title"]);
239 $worksheet->setCell($row, $col++, $question["description"]);
240 $worksheet->setCell($row, $col++, $this->lng->txt($question["type_tag"]));
241 $worksheet->setCell($row, $col++, $question["author"]);
242 $created = new ilDate($question["created"], IL_CAL_UNIX);
243 $worksheet->setCell($row, $col++, $created);
244 $updated = new ilDate($question["tstamp"], IL_CAL_UNIX);
245 $worksheet->setCell($row, $col++, $updated);
246 $col = 0;
247 $row++;
248 }
249
250 $excelfile = $this->export_dir . '/' . $this->filename;
251 $worksheet->writeToFile($excelfile);
252 ilFileUtils::zip($excelfile, $this->export_dir . "/" . $this->zipfilename);
253 if (@file_exists($this->export_dir . "/" . $this->filename)) {
254 @unlink($this->export_dir . "/" . $this->filename);
255 }
256 return $this->export_dir . "/" . $this->zipfilename;
257 }
const IL_CAL_UNIX
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class for single dates.
static zip(string $a_dir, string $a_file, bool $compress_content=false)
zips given directory/file into given zip.file
int $updated
Timestamp for when the object was last updated.
Definition: System.php:158
int $created
Timestamp for when the object was created.
Definition: System.php:151

References ILIAS\LTI\ToolProvider\$created, $filename, $questions, ILIAS\LTI\ToolProvider\$updated, $zipfilename, IL_CAL_UNIX, ILIAS\Repository\lng(), and ilFileUtils\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 127 of file class.ilQuestionpoolExport.php.

127 : string
128 {
129 global $DIC;
130 $ilBench = $DIC['ilBench'];
131
132 $ilBench->start("QuestionpoolExport", "buildExportFile");
133
134 include_once("./Services/Xml/classes/class.ilXmlWriter.php");
135 $this->xml = new ilXmlWriter();
136
137 // set dtd definition
138 $this->xml->xmlSetDtdDef("<!DOCTYPE Test SYSTEM \"http://www.ilias.uni-koeln.de/download/dtd/ilias_co.dtd\">");
139
140 // set generated comment
141 $this->xml->xmlSetGenCmt("Export of ILIAS Test Questionpool " .
142 $this->qpl_obj->getId() . " of installation " . $this->inst_id);
143
144 // set xml header
145 $this->xml->xmlHeader();
146
147 // create directories
148 include_once "./Services/Utilities/classes/class.ilUtil.php";
149 ilFileUtils::makeDir($this->export_dir . "/" . $this->subdir);
150 ilFileUtils::makeDir($this->export_dir . "/" . $this->subdir . "/objects");
151
152 // get Log File
153 $expDir = $this->qpl_obj->getExportDirectory();
155
156 include_once "./Services/Logging/classes/class.ilLog.php";
157 $expLog = new ilLog($expDir, "export.log");
158 $expLog->delete();
159 $expLog->setLogFormat("");
160 $expLog->write(date("[y-m-d H:i:s] ") . "Start Export");
161
162 // write qti file
163 $qti_file = fopen($this->export_dir . "/" . $this->subdir . "/" . $this->qti_filename, "w");
164 fwrite($qti_file, $this->qpl_obj->questionsToXML($this->questions));
165 fclose($qti_file);
166
167 // get xml content
168 $ilBench->start("QuestionpoolExport", "buildExportFile_getXML");
169 $this->qpl_obj->objectToXmlWriter(
170 $this->xml,
171 $this->inst_id,
172 $this->export_dir . "/" . $this->subdir,
173 $expLog,
174 $this->questions
175 );
176 $ilBench->stop("QuestionpoolExport", "buildExportFile_getXML");
177 $ilBench->start("QuestionpoolExport", "buildExportFile_dumpToFile");
178 $this->xml->xmlDumpFile($this->export_dir . "/" . $this->subdir . "/" . $this->filename, false);
179 $ilBench->stop("QuestionpoolExport", "buildExportFile_dumpToFile");
180
181 // add media objects which were added with tiny mce
182 $ilBench->start("QuestionpoolExport", "buildExportFile_saveAdditionalMobs");
183 $this->exportXHTMLMediaObjects($this->export_dir . "/" . $this->subdir);
184 $ilBench->stop("QuestionpoolExport", "buildExportFile_saveAdditionalMobs");
185
186 // zip the file
187 $ilBench->start("QuestionpoolExport", "buildExportFile_zipFile");
188 ilFileUtils::zip($this->export_dir . "/" . $this->subdir, $this->export_dir . "/" . $this->subdir . ".zip");
189
190 $ilBench->stop("QuestionpoolExport", "buildExportFile_zipFile");
191
192 $expLog->write(date("[y-m-d H:i:s] ") . "Finished Export");
193 $ilBench->stop("QuestionpoolExport", "buildExportFile");
194
195 return $this->export_dir . "/" . $this->subdir . ".zip";
196 }
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
static makeDir(string $a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: class.ilLog.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

References $DIC, exportXHTMLMediaObjects(), ilFileUtils\makeDir(), ilFileUtils\makeDirParents(), and ilFileUtils\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 198 of file class.ilQuestionpoolExport.php.

198 : void
199 {
200 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
201
202 foreach ($this->questions as $question_id) {
203 $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $question_id);
204 foreach ($mobs as $mob) {
205 if (ilObjMediaObject::_exists($mob)) {
206 $mob_obj = new ilObjMediaObject($mob);
207 $mob_obj->exportFiles($a_export_dir);
208 unset($mob_obj);
209 }
210 }
211 }
212 }
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
static _getMobsOfObject(string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
$mobs
Definition: imgupload.php:70

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 104 of file class.ilQuestionpoolExport.php.

References $inst_id.

Field Documentation

◆ $db

ilQuestionpoolExport::$db

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

◆ $err

ilQuestionpoolExport::$err

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

◆ $export_dir

string ilQuestionpoolExport::$export_dir = ''
private

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

◆ $filename

string ilQuestionpoolExport::$filename = ''
private

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

Referenced by buildExportFileXLS().

◆ $ilias

ilQuestionpoolExport::$ilias

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

Referenced by __construct().

◆ $inst_id

ilQuestionpoolExport::$inst_id

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

Referenced by getInstId().

◆ $lng

ilQuestionpoolExport::$lng

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

Referenced by __construct().

◆ $mode

ilQuestionpoolExport::$mode

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

◆ $qpl_obj

ilQuestionpoolExport::$qpl_obj

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

◆ $questions

ilQuestionpoolExport::$questions

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

Referenced by buildExportFileXLS().

◆ $subdir

string ilQuestionpoolExport::$subdir = ''
private

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

◆ $xml

ilXmlWriter ilQuestionpoolExport::$xml
private

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

◆ $zipfilename

string ilQuestionpoolExport::$zipfilename = ''
private

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

Referenced by buildExportFileXLS().


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