ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 $ilDB, $ilErr, $ilias, $lng, and time.

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

Member Function Documentation

◆ buildExportFile()

ilQuestionpoolExport::buildExportFile ( )

build export file (complete zip file)

public

Returns

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

References buildExportFileXLS(), and buildExportFileXML().

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

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

Referenced by buildExportFile().

217  {
218  require_once 'Modules/TestQuestionPool/classes/class.ilAssExcelFormatHelper.php';
219  require_once 'Modules/TestQuestionPool/classes/class.assQuestion.php';
220 
222  $worksheet->addSheet('Sheet 1');
223  $row = 1;
224  $col = 0;
225 
226  $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("title"));
227  $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("description"));
228  $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("question_type"));
229  $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("author"));
230  $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col++) . $row, $this->lng->txt("create_date"));
231  $worksheet->setFormattedExcelTitle($worksheet->getColumnCoord($col) . $row, $this->lng->txt("last_update"));
232 
233  $col = 0;
234  $row++;
235  $questions = $this->qpl_obj->getQuestionList();
236  foreach ($questions as $question)
237  {
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  ilUtil::zip($excelfile , $this->export_dir . "/" . $this->zipfilename);
253  if (@file_exists($this->export_dir . "/" . $this->filename)) @unlink($this->export_dir . "/" . $this->filename);
254  }
$worksheet
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
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 111 of file class.ilQuestionpoolExport.php.

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

Referenced by buildExportFile().

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

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

Referenced by buildExportFileXML().

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

◆ getInstId()

ilQuestionpoolExport::getInstId ( )

Definition at line 82 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.


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