ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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 (protected ilObjQuestionPool $qpl_obj, protected string $mode="xml", protected ?array $questions=null)
 Constructor public. More...
 
 getInstId ()
 
 buildExportFile ()
 build export file (complete zip file) More...
 
 buildExportFileXML ()
 build xml export file More...
 
 exportXHTMLMediaObjects ($a_export_dir)
 

Data Fields

ilErrorHandling $err
 
ilDBInterface $db
 
ILIAS $ilias
 
string $inst_id
 
ilLanguage $lng
 

Protected Member Functions

 buildExportFileXLSX ()
 build xml export file More...
 

Private Attributes

string $export_dir = ''
 
string $subdir = ''
 
string $filename = ''
 
string $zipfilename = ''
 
string $qti_filename = ''
 
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 ( protected ilObjQuestionPool  $qpl_obj,
protected string  $mode = "xml",
protected ?array  $questions = null 
)

Constructor public.

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

References $DIC, IL_INST_ID, and ILIAS\Repository\lng().

53  {
54  global $DIC;
55  $this->err = $DIC['ilErr'];
56  $this->db = $DIC['ilDB'];
57  $this->ilias = $DIC['ilias'];
58  $this->lng = $DIC['lng'];
59 
60  if (!is_array($this->questions)) {
61  $this->questions = $this->qpl_obj->getAllQuestionIds();
62  }
63 
64  $this->inst_id = IL_INST_ID;
65  $date = time();
66 
67  $this->qpl_obj->createExportDirectory();
68  switch ($this->mode) {
69  case "xml":
70  $this->export_dir = $this->qpl_obj->getExportDirectory('xml');
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  case "xlsx":
78  $this->export_dir = $this->qpl_obj->getExportDirectory('xlsx');
79  $this->filename = $date . "__" . $this->inst_id . "__" .
80  "qpl" . "_" . $this->qpl_obj->getId() . ".xlsx";
81  $this->zipfilename = $date . "__" . $this->inst_id . "__" .
82  "qpl" . "_" . $this->qpl_obj->getId() . ".zip";
83  break;
84  default:
85  $this->export_dir = $this->qpl_obj->getExportDirectory('zip');
86  $this->subdir = $date . "__" . $this->inst_id . "__" .
87  "qpl" . "_" . $this->qpl_obj->getId();
88  $this->filename = $this->subdir . ".xml";
89  $this->qti_filename = $date . "__" . $this->inst_id . "__" .
90  "qti" . "_" . $this->qpl_obj->getId() . ".xml";
91  break;
92  }
93  }
const IL_INST_ID
Definition: constants.php:40
global $DIC
Definition: feed.php:28
header include for all ilias files.
+ Here is the call graph for this function:

Member Function Documentation

◆ buildExportFile()

ilQuestionpoolExport::buildExportFile ( )

build export file (complete zip file)

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

References buildExportFileXLSX(), and buildExportFileXML().

104  : string
105  {
106  switch ($this->mode) {
107  case "xlsx":
108  return $this->buildExportFileXLSX();
109  case "xml":
110  default:
111  return $this->buildExportFileXML();
112  }
113  }
buildExportFileXML()
build xml export file
buildExportFileXLSX()
build xml export file
+ Here is the call graph for this function:

◆ buildExportFileXLSX()

ilQuestionpoolExport::buildExportFileXLSX ( )
protected

build xml export file

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

References ILIAS\LTI\ToolProvider\$created, $filename, ILIAS\LTI\ToolProvider\$updated, IL_CAL_UNIX, and ILIAS\Repository\lng().

Referenced by buildExportFile().

192  : string
193  {
194  $worksheet = new ilAssExcelFormatHelper();
195  $worksheet->addSheet('Sheet 1');
196  $row = 1;
197  $col = 0;
198 
199  $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("title"));
200  $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("description"));
201  $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("question_type"));
202  $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("author"));
203  $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("create_date"));
204  $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col) . $row, $this->lng->txt("last_update"));
205 
206  $col = 0;
207  $row++;
208  $questions = $this->qpl_obj->getQuestionList();
209  foreach ($questions as $question) {
210  $worksheet->setCell($row, $col++, $question["title"]);
211  $worksheet->setCell($row, $col++, $question["description"]);
212  $worksheet->setCell($row, $col++, $this->lng->txt($question["type_tag"]));
213  $worksheet->setCell($row, $col++, $question["author"]);
214  $created = new ilDate($question["created"], IL_CAL_UNIX);
215  $worksheet->setCell($row, $col++, $created);
216  $updated = new ilDate($question["tstamp"], IL_CAL_UNIX);
217  $worksheet->setCell($row, $col++, $updated);
218  $col = 0;
219  $row++;
220  }
221 
222  $excelfile = $this->export_dir . '/' . $this->filename;
223  $worksheet->writeToFile($excelfile);
224  return $excelfile;
225  }
const IL_CAL_UNIX
int $updated
Timestamp for when the object was last updated.
Definition: System.php:158
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
int $created
Timestamp for when the object was created.
Definition: System.php:151
+ 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 118 of file class.ilQuestionpoolExport.php.

References $DIC, $inst_id, exportXHTMLMediaObjects(), ilFileUtils\makeDir(), ilFileUtils\makeDirParents(), and ilFileUtils\zip().

Referenced by buildExportFile().

118  : string
119  {
120  global $DIC;
121  $ilBench = $DIC['ilBench'];
122 
123  $ilBench->start("QuestionpoolExport", "buildExportFile");
124 
125  $this->xml = new ilXmlWriter();
126  $this->xml->xmlSetDtdDef("<!DOCTYPE Test SYSTEM \"http://www.ilias.uni-koeln.de/download/dtd/ilias_co.dtd\">");
127  $this->xml->xmlSetGenCmt("Export of ILIAS Test Questionpool " .
128  $this->qpl_obj->getId() . " of installation " . $this->inst_id);
129  $this->xml->xmlHeader();
130 
131  ilFileUtils::makeDir($this->export_dir . "/" . $this->subdir);
132  ilFileUtils::makeDir($this->export_dir . "/" . $this->subdir . "/objects");
133 
134  $expDir = $this->qpl_obj->getExportDirectory();
136 
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  $qti_file = fopen($this->export_dir . "/" . $this->subdir . "/" . $this->qti_filename, "w");
143  fwrite($qti_file, $this->qpl_obj->questionsToXML($this->questions));
144  fclose($qti_file);
145 
146  $ilBench->start("QuestionpoolExport", "buildExportFile_getXML");
147  $this->qpl_obj->objectToXmlWriter(
148  $this->xml,
149  $this->inst_id,
150  $this->export_dir . "/" . $this->subdir,
151  $expLog,
152  $this->questions
153  );
154  $ilBench->stop("QuestionpoolExport", "buildExportFile_getXML");
155 
156  $ilBench->start("QuestionpoolExport", "buildExportFile_dumpToFile");
157  $this->xml->xmlDumpFile($this->export_dir . "/" . $this->subdir . "/" . $this->filename, false);
158  $ilBench->stop("QuestionpoolExport", "buildExportFile_dumpToFile");
159 
160  $ilBench->start("QuestionpoolExport", "buildExportFile_saveAdditionalMobs");
161  $this->exportXHTMLMediaObjects($this->export_dir . "/" . $this->subdir);
162  $ilBench->stop("QuestionpoolExport", "buildExportFile_saveAdditionalMobs");
163 
164  $ilBench->start("QuestionpoolExport", "buildExportFile_zipFile");
165  ilFileUtils::zip($this->export_dir . "/" . $this->subdir, $this->export_dir . "/" . $this->subdir . ".zip");
166 
167  $ilBench->stop("QuestionpoolExport", "buildExportFile_zipFile");
168 
169  $expLog->write(date("[y-m-d H:i:s] ") . "Finished Export");
170  $ilBench->stop("QuestionpoolExport", "buildExportFile");
171 
172  return $this->export_dir . "/" . $this->subdir . ".zip";
173  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: class.ilLog.php:30
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
global $DIC
Definition: feed.php:28
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 ...
+ 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 175 of file class.ilQuestionpoolExport.php.

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

Referenced by buildExportFileXML().

175  : void
176  {
177  foreach ($this->questions as $question_id) {
178  $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $question_id);
179  foreach ($mobs as $mob) {
180  if (ilObjMediaObject::_exists($mob)) {
181  $mob_obj = new ilObjMediaObject($mob);
182  $mob_obj->exportFiles($a_export_dir);
183  unset($mob_obj);
184  }
185  }
186  }
187  }
static _exists(int $id, bool $reference=false, ?string $type=null)
static _getMobsOfObject(string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getInstId()

ilQuestionpoolExport::getInstId ( )

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

References $inst_id.

96  {
97  return $this->inst_id;
98  }

Field Documentation

◆ $db

ilDBInterface ilQuestionpoolExport::$db

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

◆ $err

ilErrorHandling ilQuestionpoolExport::$err

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

◆ $export_dir

string ilQuestionpoolExport::$export_dir = ''
private

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

◆ $filename

string ilQuestionpoolExport::$filename = ''
private

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

Referenced by buildExportFileXLSX().

◆ $ilias

ILIAS ilQuestionpoolExport::$ilias

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

◆ $inst_id

string ilQuestionpoolExport::$inst_id

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

Referenced by buildExportFileXML(), and getInstId().

◆ $lng

ilLanguage ilQuestionpoolExport::$lng

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

◆ $qti_filename

string ilQuestionpoolExport::$qti_filename = ''
private

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

◆ $subdir

string ilQuestionpoolExport::$subdir = ''
private

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

◆ $xml

ilXmlWriter ilQuestionpoolExport::$xml
private

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

◆ $zipfilename

string ilQuestionpoolExport::$zipfilename = ''
private

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


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