ILIAS  eassessment Revision 61809
 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)
51  {
52  global $ilErr, $ilDB, $ilias, $lng;
53 
54  $this->qpl_obj =& $a_qpl_obj;
55 
56  $this->err =& $ilErr;
57  $this->ilias =& $ilias;
58  $this->db =& $ilDB;
59  $this->mode = $a_mode;
60  $this->lng =& $lng;
61 
62  $settings = $this->ilias->getAllSettings();
63  $this->inst_id = IL_INST_ID;
64  $this->questions = $array_questions;
65  $date = time();
66  $this->qpl_obj->createExportDirectory();
67  switch($this->mode)
68  {
69  case "xls":
70  include_once "./Services/Excel/classes/class.ilExcelUtils.php";
71  $adapter = ilExcelUtils::ExcelAdapter();
72  $this->export_dir = $this->qpl_obj->getExportDirectory();
73  $this->filename = $date."__".$this->inst_id."__".
74  "qpl"."__".$this->qpl_obj->getId() . "." . $adapter->getFileExtension();
75  break;
76  case "xml":
77  default:
78  $this->export_dir = $this->qpl_obj->getExportDirectory();
79  $this->subdir = $date."__".$this->inst_id."__".
80  "qpl"."__".$this->qpl_obj->getId();
81  $this->filename = $this->subdir.".xml";
82  $this->qti_filename = $date."__".$this->inst_id."__".
83  "qti"."__".$this->qpl_obj->getId().".xml";
84  break;
85  }
86  }
87 
88  function getInstId()
89  {
90  return $this->inst_id;
91  }
92 
93 
100  function buildExportFile()
101  {
102  switch ($this->mode)
103  {
104  case "xls":
105  return $this->buildExportFileXLS();
106  break;
107  case "xml":
108  default:
109  return $this->buildExportFileXML();
110  break;
111  }
112  }
113 
118  {
119  global $ilBench;
120 
121  $ilBench->start("QuestionpoolExport", "buildExportFile");
122 
123  include_once("./Services/Xml/classes/class.ilXmlWriter.php");
124  $this->xml = new ilXmlWriter;
125 
126  // set dtd definition
127  $this->xml->xmlSetDtdDef("<!DOCTYPE Test SYSTEM \"http://www.ilias.uni-koeln.de/download/dtd/ilias_co.dtd\">");
128 
129  // set generated comment
130  $this->xml->xmlSetGenCmt("Export of ILIAS Test Questionpool ".
131  $this->qpl_obj->getId()." of installation ".$this->inst.".");
132 
133  // set xml header
134  $this->xml->xmlHeader();
135 
136  // create directories
137  include_once "./Services/Utilities/classes/class.ilUtil.php";
138  ilUtil::makeDir($this->export_dir."/".$this->subdir);
139  ilUtil::makeDir($this->export_dir."/".$this->subdir."/objects");
140 
141  // get Log File
142  $expDir = $this->qpl_obj->getExportDirectory();
143  include_once "./Services/Logging/classes/class.ilLog.php";
144  $expLog = new ilLog($expDir, "export.log");
145  $expLog->delete();
146  $expLog->setLogFormat("");
147  $expLog->write(date("[y-m-d H:i:s] ")."Start Export");
148 
149  // write qti file
150  $qti_file = fopen($this->export_dir."/".$this->subdir."/".$this->qti_filename, "w");
151  fwrite($qti_file, $this->qpl_obj->toXML($this->questions));
152  fclose($qti_file);
153 
154  // get xml content
155  $ilBench->start("QuestionpoolExport", "buildExportFile_getXML");
156  $this->qpl_obj->exportPagesXML($this->xml, $this->inst_id,
157  $this->export_dir."/".$this->subdir, $expLog, $this->questions);
158  $ilBench->stop("QuestionpoolExport", "buildExportFile_getXML");
159 
160  // dump xml document to screen (only for debugging reasons)
161  /*
162  echo "<PRE>";
163  echo htmlentities($this->xml->xmlDumpMem($format));
164  echo "</PRE>";
165  */
166 
167  // dump xml document to file
168  $ilBench->start("QuestionpoolExport", "buildExportFile_dumpToFile");
169  $this->xml->xmlDumpFile($this->export_dir."/".$this->subdir."/".$this->filename
170  , false);
171  $ilBench->stop("QuestionpoolExport", "buildExportFile_dumpToFile");
172 
173  // add media objects which were added with tiny mce
174  $ilBench->start("QuestionpoolExport", "buildExportFile_saveAdditionalMobs");
175  $this->exportXHTMLMediaObjects($this->export_dir."/".$this->subdir);
176  $ilBench->stop("QuestionpoolExport", "buildExportFile_saveAdditionalMobs");
177 
178  // zip the file
179  $ilBench->start("QuestionpoolExport", "buildExportFile_zipFile");
180  ilUtil::zip($this->export_dir."/".$this->subdir,
181  $this->export_dir."/".$this->subdir.".zip");
182  $ilBench->stop("QuestionpoolExport", "buildExportFile_zipFile");
183 
184  // destroy writer object
185  $this->xml->_XmlWriter;
186 
187  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export");
188  $ilBench->stop("QuestionpoolExport", "buildExportFile");
189 
190  return $this->export_dir."/".$this->subdir.".zip";
191  }
192 
193  function exportXHTMLMediaObjects($a_export_dir)
194  {
195  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
196 
197  foreach ($this->questions as $question_id)
198  {
199  $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $question_id);
200  foreach ($mobs as $mob)
201  {
202  if (ilObjMediaObject::_exists($mob))
203  {
204  $mob_obj =& new ilObjMediaObject($mob);
205  $mob_obj->exportFiles($a_export_dir);
206  unset($mob_obj);
207  }
208  }
209  }
210  }
211 
216  {
217  global $ilBench;
218 
219  $ilBench->start("QuestionpoolExport", "buildExportFile");
220  include_once "./Services/Excel/classes/class.ilExcelUtils.php";
221  $adapter = ilExcelUtils::ExcelAdapter();
222  $adapter->setWorksheetTitle($this->lng->txt("tst_results_aggregated"));
223 
224  $row = 0;
225  $col = 0;
226  // title row
227  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
228  $adapter->setCellValue($row, $col, $this->lng->txt("title"), CELL_FORMAT_TITLE);
229  $col++;
230  $adapter->setCellValue($row, $col, $this->lng->txt("description"), CELL_FORMAT_TITLE);
231  $col++;
232  $adapter->setCellValue($row, $col, $this->lng->txt("question_type"), CELL_FORMAT_TITLE);
233  $col++;
234  $adapter->setCellValue($row, $col, $this->lng->txt("author"), CELL_FORMAT_TITLE);
235  $col++;
236  $adapter->setCellValue($row, $col, $this->lng->txt("create_date"), CELL_FORMAT_TITLE);
237  $col++;
238  $adapter->setCellValue($row, $col, $this->lng->txt("last_update"), CELL_FORMAT_TITLE);
239  $col = 0;
240  $row++;
241  $questions = $this->qpl_obj->getQuestionList();
242  foreach ($questions as $question)
243  {
244  $adapter->setCellValue($row, $col, $question["title"]);
245  $col++;
246  $adapter->setCellValue($row, $col, $question["description"]);
247  $col++;
248  $adapter->setCellValue($row, $col, $this->lng->txt($question["type_tag"]));
249  $col++;
250  $adapter->setCellValue($row, $col, $question["author"]);
251  $col++;
252 
253 // ilDatePresentation::formatDate(new ilDateTime($question["created"],IL_CAL_UNIX))
254  $adapter->setCellValue($row, $col, ilFormat::formatDate(ilFormat::ftimestamp2dateDB($question["created"]), "date"));
255  $col++;
256  $adapter->setCellValue($row, $col, ilFormat::formatDate(ilFormat::ftimestamp2dateDB($question["tstamp"]), "date"));
257  $col = 0;
258  $row++;
259  }
260  $file = $adapter->save();
261  @rename($file, $this->export_dir . "/" . $this->filename);
262  }
263 }
264 
265 ?>