ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules Pages
ilQuestionpoolExport Class Reference

Export class for questionpools. More...

+ Collaboration diagram for ilQuestionpoolExport:

Public Member Functions

 ilQuestionpoolExport (&$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)
 
 buildExportFileXLS ()
 build xml export file More...
 

Data Fields

 $err
 
 $db
 
 $ilias
 
 $qpl_obj
 
 $questions
 
 $inst_id
 
 $mode
 
 $lng
 

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.

Member Function Documentation

◆ buildExportFile()

ilQuestionpoolExport::buildExportFile ( )

build export file (complete zip file)

public

Returns

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

References buildExportFileXLS(), and buildExportFileXML().

85  {
86  switch ($this->mode)
87  {
88  case "xls":
89  return $this->buildExportFileXLS();
90  break;
91  case "xml":
92  default:
93  return $this->buildExportFileXML();
94  break;
95  }
96  }
buildExportFileXLS()
build xml export file
buildExportFileXML()
build xml export file
+ Here is the call graph for this function:

◆ buildExportFileXLS()

ilQuestionpoolExport::buildExportFileXLS ( )

build xml export file

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

References $ilBench, $row, ilExcelUtils\_convert_text(), ilFormat\formatDate(), and ilUtil\zip().

Referenced by buildExportFile().

207  {
208  global $ilBench;
209 
210  $ilBench->start("QuestionpoolExport", "buildExportFile");
211  include_once "./Services/Excel/classes/class.ilExcelWriterAdapter.php";
212  $adapter = new ilExcelWriterAdapter($this->export_dir . "/" . $this->filename, FALSE);
213  $workbook = $adapter->getWorkbook();
214  $workbook->setVersion(8); // Use Excel97/2000 Format
215  $format_bold =& $workbook->addFormat();
216  $format_bold->setBold();
217  $format_percent =& $workbook->addFormat();
218  $format_percent->setNumFormat("0.00%");
219  $format_datetime =& $workbook->addFormat();
220  $format_datetime->setNumFormat("DD/MM/YYYY hh:mm:ss");
221  $format_title =& $workbook->addFormat();
222  $format_title->setBold();
223  $format_title->setColor('black');
224  $format_title->setPattern(1);
225  $format_title->setFgColor('silver');
226  $worksheet =& $workbook->addWorksheet();
227  $row = 0;
228  $col = 0;
229  // title row
230  include_once "./Services/Excel/classes/class.ilExcelUtils.php";
231  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
232  $worksheet->write($row, $col, ilExcelUtils::_convert_text($this->lng->txt("title"), "latin1"), $format_title);
233  $col++;
234  $worksheet->write($row, $col, ilExcelUtils::_convert_text($this->lng->txt("description"), "latin1"), $format_title);
235  $col++;
236  $worksheet->write($row, $col, ilExcelUtils::_convert_text($this->lng->txt("question_type"), "latin1"), $format_title);
237  $col++;
238  $worksheet->write($row, $col, ilExcelUtils::_convert_text($this->lng->txt("author"), "latin1"), $format_title);
239  $col++;
240  $worksheet->write($row, $col, ilExcelUtils::_convert_text($this->lng->txt("create_date"), "latin1"), $format_title);
241  $col++;
242  $worksheet->write($row, $col, ilExcelUtils::_convert_text($this->lng->txt("last_update"), "latin1"), $format_title);
243  $col = 0;
244  $row++;
245  $questions = $this->qpl_obj->getQuestionList();
246  foreach ($questions as $question)
247  {
248  $worksheet->write($row, $col, ilExcelUtils::_convert_text($question["title"], "latin1"));
249  $col++;
250  $worksheet->write($row, $col, ilExcelUtils::_convert_text($question["description"], "latin1"));
251  $col++;
252  $worksheet->write($row, $col, ilExcelUtils::_convert_text($this->lng->txt($question["type_tag"]), "latin1"));
253  $col++;
254  $worksheet->write($row, $col, ilExcelUtils::_convert_text($question["author"], "latin1"));
255  $col++;
256 
257 // ilDatePresentation::formatDate(new ilDateTime($question["created"],IL_CAL_UNIX))
258  $worksheet->write($row, $col, ilExcelUtils::_convert_text(ilFormat::formatDate(date('Y-m-d', $question["created"]), "date", false, false), "latin1"));
259  $col++;
260  $worksheet->write($row, $col, ilExcelUtils::_convert_text(ilFormat::formatDate(date('Y-m-d', $question["tstamp"]), "date", false, false), "latin1"));
261  $col = 0;
262  $row++;
263  }
264  $workbook->close();
265  ilUtil::zip($this->export_dir . "/" . $this->filename, $this->export_dir . "/" . $this->zipfilename);
266  if (@file_exists($this->export_dir . "/" . $this->filename)) @unlink($this->export_dir . "/" . $this->filename);
267  }
_convert_text($a_text, $a_target="has been removed")
Class ilExcelWriterAdapter.
static zip($a_dir, $a_file, $compress_content=false)
zips given directory/file into given zip.file
formatDate($a_date, $a_mode="datetime", $a_omit_seconds=false, $a_relative=TRUE)
format a date according to the user language shortcut for Format::fmtDateTime public ...
global $ilBench
Definition: ilias.php:18
+ 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 101 of file class.ilQuestionpoolExport.php.

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

Referenced by buildExportFile().

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

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

Referenced by buildExportFileXML().

185  {
186  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
187 
188  foreach ($this->questions as $question_id)
189  {
190  $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $question_id);
191  foreach ($mobs as $mob)
192  {
193  if (ilObjMediaObject::_exists($mob))
194  {
195  $mob_obj =& new ilObjMediaObject($mob);
196  $mob_obj->exportFiles($a_export_dir);
197  unset($mob_obj);
198  }
199  }
200  }
201  }
$mobs
static _exists($a_id)
checks wether a lm content object with specified id exists or not
Class ilObjMediaObject.
_getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getInstId()

ilQuestionpoolExport::getInstId ( )

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

References $inst_id.

◆ ilQuestionpoolExport()

ilQuestionpoolExport::ilQuestionpoolExport ( $a_qpl_obj,
  $a_mode = "xml",
  $array_questions = null 
)

Constructor public.

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

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

31  {
32  global $ilErr, $ilDB, $ilias, $lng;
33 
34  $this->qpl_obj =& $a_qpl_obj;
35  if (!is_array($array_questions))
36  {
37  $array_questions =& $a_qpl_obj->getAllQuestionIds();
38  }
39 
40  $this->err =& $ilErr;
41  $this->ilias =& $ilias;
42  $this->db =& $ilDB;
43  $this->mode = $a_mode;
44  $this->lng =& $lng;
45 
46  $settings = $this->ilias->getAllSettings();
47  $this->inst_id = IL_INST_ID;
48  $this->questions = $array_questions;
49  $date = time();
50  $this->qpl_obj->createExportDirectory();
51  switch($this->mode)
52  {
53  case "xls":
54  $this->export_dir = $this->qpl_obj->getExportDirectory('xls');
55  $this->filename = $date."__".$this->inst_id."__".
56  "qpl"."_".$this->qpl_obj->getId() . ".xls";
57  $this->zipfilename = $date."__".$this->inst_id."__".
58  "qpl"."_".$this->qpl_obj->getId() . ".zip";
59  break;
60  case "xml":
61  default:
62  $this->export_dir = $this->qpl_obj->getExportDirectory('zip');
63  $this->subdir = $date."__".$this->inst_id."__".
64  "qpl"."_".$this->qpl_obj->getId();
65  $this->filename = $this->subdir.".xml";
66  $this->qti_filename = $date."__".$this->inst_id."__".
67  "qti"."_".$this->qpl_obj->getId().".xml";
68  break;
69  }
70  }
redirection script todo: (a better solution should control the processing via a xml file) ...
global $ilDB

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 ilQuestionpoolExport().

◆ $inst_id

ilQuestionpoolExport::$inst_id

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

Referenced by getInstId().

◆ $lng

ilQuestionpoolExport::$lng

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

Referenced by ilQuestionpoolExport().

◆ $mode

ilQuestionpoolExport::$mode

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

◆ $qpl_obj

ilQuestionpoolExport::$qpl_obj

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

◆ $questions

ilQuestionpoolExport::$questions

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


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