ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilQuestionpoolExport.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 include_once "./Modules/Test/classes/inc.AssessmentConstants.php";
25 
36 {
37  var $err; // error object
38  var $db; // database object
39  var $ilias; // ilias object
40  var $qpl_obj; // questionpool object
41  var $questions; // array with question ids to export
42  var $inst_id; // installation id
43  var $mode;
44  var $lng;
45 
50  function ilQuestionpoolExport(&$a_qpl_obj, $a_mode = "xml", $array_questions = null)
51  {
52  global $ilErr, $ilDB, $ilias, $lng;
53 
54  $this->qpl_obj =& $a_qpl_obj;
55  if (!is_array($array_questions))
56  {
57  $array_questions =& $a_qpl_obj->getAllQuestionIds();
58  }
59 
60  $this->err =& $ilErr;
61  $this->ilias =& $ilias;
62  $this->db =& $ilDB;
63  $this->mode = $a_mode;
64  $this->lng =& $lng;
65 
66  $settings = $this->ilias->getAllSettings();
67  $this->inst_id = IL_INST_ID;
68  $this->questions = $array_questions;
69  $date = time();
70  $this->qpl_obj->createExportDirectory();
71  switch($this->mode)
72  {
73  case "xls":
74  $this->export_dir = $this->qpl_obj->getExportDirectory('xls');
75  $this->filename = $date."__".$this->inst_id."__".
76  "qpl"."_".$this->qpl_obj->getId() . ".xls";
77  $this->zipfilename = $date."__".$this->inst_id."__".
78  "qpl"."_".$this->qpl_obj->getId() . ".zip";
79  break;
80  case "xml":
81  default:
82  $this->export_dir = $this->qpl_obj->getExportDirectory('zip');
83  $this->subdir = $date."__".$this->inst_id."__".
84  "qpl"."_".$this->qpl_obj->getId();
85  $this->filename = $this->subdir.".xml";
86  $this->qti_filename = $date."__".$this->inst_id."__".
87  "qti"."_".$this->qpl_obj->getId().".xml";
88  break;
89  }
90  }
91 
92  function getInstId()
93  {
94  return $this->inst_id;
95  }
96 
97 
104  function buildExportFile()
105  {
106  switch ($this->mode)
107  {
108  case "xls":
109  return $this->buildExportFileXLS();
110  break;
111  case "xml":
112  default:
113  return $this->buildExportFileXML();
114  break;
115  }
116  }
117 
122  {
123  global $ilBench;
124 
125  $ilBench->start("QuestionpoolExport", "buildExportFile");
126 
127  include_once("./Services/Xml/classes/class.ilXmlWriter.php");
128  $this->xml = new ilXmlWriter;
129 
130  // set dtd definition
131  $this->xml->xmlSetDtdDef("<!DOCTYPE Test SYSTEM \"http://www.ilias.uni-koeln.de/download/dtd/ilias_co.dtd\">");
132 
133  // set generated comment
134  $this->xml->xmlSetGenCmt("Export of ILIAS Test Questionpool ".
135  $this->qpl_obj->getId()." of installation ".$this->inst.".");
136 
137  // set xml header
138  $this->xml->xmlHeader();
139 
140  // create directories
141  include_once "./Services/Utilities/classes/class.ilUtil.php";
142  ilUtil::makeDir($this->export_dir."/".$this->subdir);
143  ilUtil::makeDir($this->export_dir."/".$this->subdir."/objects");
144 
145  // get Log File
146  $expDir = $this->qpl_obj->getExportDirectory();
147  ilUtil::makeDirParents($expDir);
148 
149  include_once "./Services/Logging/classes/class.ilLog.php";
150  $expLog = new ilLog($expDir, "export.log");
151  $expLog->delete();
152  $expLog->setLogFormat("");
153  $expLog->write(date("[y-m-d H:i:s] ")."Start Export");
154 
155  // write qti file
156  $qti_file = fopen($this->export_dir."/".$this->subdir."/".$this->qti_filename, "w");
157  fwrite($qti_file, $this->qpl_obj->toXML($this->questions));
158  fclose($qti_file);
159 
160  // get xml content
161  $ilBench->start("QuestionpoolExport", "buildExportFile_getXML");
162  $this->qpl_obj->exportPagesXML($this->xml, $this->inst_id,
163  $this->export_dir."/".$this->subdir, $expLog, $this->questions);
164  $ilBench->stop("QuestionpoolExport", "buildExportFile_getXML");
165 
166  // dump xml document to screen (only for debugging reasons)
167  /*
168  echo "<PRE>";
169  echo htmlentities($this->xml->xmlDumpMem($format));
170  echo "</PRE>";
171  */
172 
173  // dump xml document to file
174  $ilBench->start("QuestionpoolExport", "buildExportFile_dumpToFile");
175  $this->xml->xmlDumpFile($this->export_dir."/".$this->subdir."/".$this->filename
176  , false);
177  $ilBench->stop("QuestionpoolExport", "buildExportFile_dumpToFile");
178 
179  // add media objects which were added with tiny mce
180  $ilBench->start("QuestionpoolExport", "buildExportFile_saveAdditionalMobs");
181  $this->exportXHTMLMediaObjects($this->export_dir."/".$this->subdir);
182  $ilBench->stop("QuestionpoolExport", "buildExportFile_saveAdditionalMobs");
183 
184  // zip the file
185  $ilBench->start("QuestionpoolExport", "buildExportFile_zipFile");
186  ilUtil::zip($this->export_dir."/".$this->subdir, $this->export_dir."/".$this->subdir.".zip");
187  if (@is_dir($this->export_dir."/".$this->subdir))
188  {
189  // Do not delete this dir, since it is required for container exports
190  #ilUtil::delDir($this->export_dir."/".$this->subdir);
191  }
192 
193  $ilBench->stop("QuestionpoolExport", "buildExportFile_zipFile");
194 
195  // destroy writer object
196  $this->xml->_XmlWriter;
197 
198  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export");
199  $ilBench->stop("QuestionpoolExport", "buildExportFile");
200 
201  return $this->export_dir."/".$this->subdir.".zip";
202  }
203 
204  function exportXHTMLMediaObjects($a_export_dir)
205  {
206  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
207 
208  foreach ($this->questions as $question_id)
209  {
210  $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $question_id);
211  foreach ($mobs as $mob)
212  {
213  if (ilObjMediaObject::_exists($mob))
214  {
215  $mob_obj =& new ilObjMediaObject($mob);
216  $mob_obj->exportFiles($a_export_dir);
217  unset($mob_obj);
218  }
219  }
220  }
221  }
222 
227  {
228  global $ilBench;
229 
230  $ilBench->start("QuestionpoolExport", "buildExportFile");
231  include_once "./Services/Excel/classes/class.ilExcelWriterAdapter.php";
232  $adapter = new ilExcelWriterAdapter($this->export_dir . "/" . $this->filename, FALSE);
233  $workbook = $adapter->getWorkbook();
234  $workbook->setVersion(8); // Use Excel97/2000 Format
235  $format_bold =& $workbook->addFormat();
236  $format_bold->setBold();
237  $format_percent =& $workbook->addFormat();
238  $format_percent->setNumFormat("0.00%");
239  $format_datetime =& $workbook->addFormat();
240  $format_datetime->setNumFormat("DD/MM/YYYY hh:mm:ss");
241  $format_title =& $workbook->addFormat();
242  $format_title->setBold();
243  $format_title->setColor('black');
244  $format_title->setPattern(1);
245  $format_title->setFgColor('silver');
246  $worksheet =& $workbook->addWorksheet();
247  $row = 0;
248  $col = 0;
249  // title row
250  include_once "./Services/Excel/classes/class.ilExcelUtils.php";
251  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
252  $worksheet->write($row, $col, ilExcelUtils::_convert_text($this->lng->txt("title"), "latin1"), $format_title);
253  $col++;
254  $worksheet->write($row, $col, ilExcelUtils::_convert_text($this->lng->txt("description"), "latin1"), $format_title);
255  $col++;
256  $worksheet->write($row, $col, ilExcelUtils::_convert_text($this->lng->txt("question_type"), "latin1"), $format_title);
257  $col++;
258  $worksheet->write($row, $col, ilExcelUtils::_convert_text($this->lng->txt("author"), "latin1"), $format_title);
259  $col++;
260  $worksheet->write($row, $col, ilExcelUtils::_convert_text($this->lng->txt("create_date"), "latin1"), $format_title);
261  $col++;
262  $worksheet->write($row, $col, ilExcelUtils::_convert_text($this->lng->txt("last_update"), "latin1"), $format_title);
263  $col = 0;
264  $row++;
265  $questions = $this->qpl_obj->getQuestionList();
266  foreach ($questions as $question)
267  {
268  $worksheet->write($row, $col, ilExcelUtils::_convert_text($question["title"], "latin1"));
269  $col++;
270  $worksheet->write($row, $col, ilExcelUtils::_convert_text($question["description"], "latin1"));
271  $col++;
272  $worksheet->write($row, $col, ilExcelUtils::_convert_text($this->lng->txt($question["type_tag"]), "latin1"));
273  $col++;
274  $worksheet->write($row, $col, ilExcelUtils::_convert_text($question["author"], "latin1"));
275  $col++;
276 
277 // ilDatePresentation::formatDate(new ilDateTime($question["created"],IL_CAL_UNIX))
278  $worksheet->write($row, $col, ilExcelUtils::_convert_text(ilFormat::formatDate(date('Y-m-d', $question["created"]), "date", false, false), "latin1"));
279  $col++;
280  $worksheet->write($row, $col, ilExcelUtils::_convert_text(ilFormat::formatDate(date('Y-m-d', $question["tstamp"]), "date", false, false), "latin1"));
281  $col = 0;
282  $row++;
283  }
284  $workbook->close();
285  ilUtil::zip($this->export_dir . "/" . $this->filename, $this->export_dir . "/" . $this->zipfilename);
286  if (@file_exists($this->export_dir . "/" . $this->filename)) @unlink($this->export_dir . "/" . $this->filename);
287  }
288 }
289 
290 ?>