ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 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 public.

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

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

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  }
global $DIC
Definition: saml.php:7
$ilErr
Definition: raiseError.php:18
redirection script todo: (a better solution should control the processing via a xml file) ...
global $ilDB

Member Function Documentation

◆ buildExportFile()

ilQuestionpoolExport::buildExportFile ( )

build export file (complete zip file)

public

Returns

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

References buildExportFileXLS(), and buildExportFileXML().

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
+ Here is the call graph for this function:

◆ buildExportFileXLS()

ilQuestionpoolExport::buildExportFileXLS ( )
protected

build xml export file

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

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

Referenced by buildExportFile().

219  {
220  require_once 'Modules/TestQuestionPool/classes/class.ilAssExcelFormatHelper.php';
221  require_once 'Modules/TestQuestionPool/classes/class.assQuestion.php';
222 
223  $worksheet = new ilAssExcelFormatHelper();
224  $worksheet->addSheet('Sheet 1');
225  $row = 1;
226  $col = 0;
227 
228  $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("title"));
229  $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("description"));
230  $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("question_type"));
231  $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("author"));
232  $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("create_date"));
233  $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col) . $row, $this->lng->txt("last_update"));
234 
235  $col = 0;
236  $row++;
237  $questions = $this->qpl_obj->getQuestionList();
238  foreach ($questions as $question) {
239  $worksheet->setCell($row, $col++, $question["title"]);
240  $worksheet->setCell($row, $col++, $question["description"]);
241  $worksheet->setCell($row, $col++, $this->lng->txt($question["type_tag"]));
242  $worksheet->setCell($row, $col++, $question["author"]);
243  $created = new ilDate($question["created"], IL_CAL_UNIX);
244  $worksheet->setCell($row, $col++, $created);
245  $updated = new ilDate($question["tstamp"], IL_CAL_UNIX);
246  $worksheet->setCell($row, $col++, $updated);
247  $col = 0;
248  $row++;
249  }
250 
251  $excelfile = $this->export_dir . '/' . $this->filename;
252  $worksheet->writeToFile($excelfile);
253  ilUtil::zip($excelfile, $this->export_dir . "/" . $this->zipfilename);
254  if (@file_exists($this->export_dir . "/" . $this->filename)) {
255  @unlink($this->export_dir . "/" . $this->filename);
256  }
257  }
const IL_CAL_UNIX
Class for single dates.
static zip($a_dir, $a_file, $compress_content=false)
zips given directory/file into given zip.file
$filename
Definition: buildRTE.php:89
$row
Class ilAssExcelFormatHelper.
+ 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.

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

Referenced by buildExportFile().

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 
163  // dump xml document to screen (only for debugging reasons)
164  /*
165  echo "<PRE>";
166  echo htmlentities($this->xml->xmlDumpMem($format));
167  echo "</PRE>";
168  */
169 
170  // dump xml document to file
171  $ilBench->start("QuestionpoolExport", "buildExportFile_dumpToFile");
172  $this->xml->xmlDumpFile($this->export_dir . "/" . $this->subdir . "/" . $this->filename, false);
173  $ilBench->stop("QuestionpoolExport", "buildExportFile_dumpToFile");
174 
175  // add media objects which were added with tiny mce
176  $ilBench->start("QuestionpoolExport", "buildExportFile_saveAdditionalMobs");
177  $this->exportXHTMLMediaObjects($this->export_dir . "/" . $this->subdir);
178  $ilBench->stop("QuestionpoolExport", "buildExportFile_saveAdditionalMobs");
179 
180  // zip the file
181  $ilBench->start("QuestionpoolExport", "buildExportFile_zipFile");
182  ilUtil::zip($this->export_dir . "/" . $this->subdir, $this->export_dir . "/" . $this->subdir . ".zip");
183  if (@is_dir($this->export_dir . "/" . $this->subdir)) {
184  // Do not delete this dir, since it is required for container exports
185  #ilUtil::delDir($this->export_dir."/".$this->subdir);
186  }
187 
188  $ilBench->stop("QuestionpoolExport", "buildExportFile_zipFile");
189 
190  // destroy writer object
191  $this->xml->_XmlWriter;
192 
193  $expLog->write(date("[y-m-d H:i:s] ") . "Finished Export");
194  $ilBench->stop("QuestionpoolExport", "buildExportFile");
195 
196  return $this->export_dir . "/" . $this->subdir . ".zip";
197  }
static makeDirParents($a_dir)
Create a new directory and all parent directories.
xmlSetDtdDef($dtdDef)
Sets dtd definition.
global $DIC
Definition: saml.php:7
XML writer class.
logging
Definition: class.ilLog.php:18
static zip($a_dir, $a_file, $compress_content=false)
zips given directory/file into given zip.file
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
global $ilBench
Definition: ilias.php:18
+ 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 199 of file class.ilQuestionpoolExport.php.

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

Referenced by buildExportFileXML().

200  {
201  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
202 
203  foreach ($this->questions as $question_id) {
204  $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $question_id);
205  foreach ($mobs as $mob) {
206  if (ilObjMediaObject::_exists($mob)) {
207  $mob_obj = new ilObjMediaObject($mob);
208  $mob_obj->exportFiles($a_export_dir);
209  unset($mob_obj);
210  }
211  }
212  }
213  }
static _getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
$mobs
Class ilObjMediaObject.
static _exists($a_id, $a_reference=false, $a_type=null)
checks wether a lm content object with specified id exists or not
+ 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: