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/** 25* Export class for survey questionpools 26* 27* @author Helmut Schottmüller <helmut.schottmueller@mac.com> 28* @version $Id$ 29* @ingroup ModulesSurveyQuestionPool 30*/ 31class ilSurveyQuestionpoolExport 32{ 33 public $db; // database object 34 public $spl_obj; // survey questionpool object 35 public $inst_id; // installation id 36 public $mode; 37 38 /** 39 * Constructor 40 * @access public 41 */ 42 public function __construct($a_spl_obj, $a_mode = "xml") 43 { 44 global $DIC; 45 46 $ilDB = $DIC->database(); 47 48 $this->spl_obj = $a_spl_obj; 49 50 $this->db = $ilDB; 51 $this->mode = $a_mode; 52 53 $this->inst_id = IL_INST_ID; 54 55 $date = time(); 56 switch ($this->mode) { 57 default: 58 $this->export_dir = $this->spl_obj->getExportDirectory(); 59 $this->subdir = $date . "__" . $this->inst_id . "__" . 60 "spl" . "_" . $this->spl_obj->getId(); 61 $this->filename = $this->subdir . ".xml"; 62 break; 63 } 64 } 65 66 public function getInstId() 67 { 68 return $this->inst_id; 69 } 70 71 72 /** 73 * build export file (complete zip file) 74 * 75 * @access public 76 * @return 77 */ 78 public function buildExportFile($questions = null) 79 { 80 switch ($this->mode) { 81 default: 82 return $this->buildExportFileXML($questions); 83 break; 84 } 85 } 86 87 /** 88 * build xml export file 89 */ 90 public function buildExportFileXML($questions = null) 91 { 92 // create directories 93 $this->spl_obj->createExportDirectory(); 94 ilUtil::makeDir($this->export_dir . "/" . $this->subdir); 95 96 // get Log File 97 include_once "./Services/Logging/classes/class.ilLog.php"; 98 $expLog = new ilLog($this->spl_obj->getExportDirectory(), "export.log"); 99 $expLog->delete(); 100 $expLog->setLogFormat(""); 101 $expLog->write(date("[y-m-d H:i:s] ") . "Start Export"); 102 // write qti file 103 $qti_file = fopen($this->export_dir . "/" . $this->subdir . "/" . $this->filename, "w"); 104 fwrite($qti_file, $this->spl_obj->toXML($questions)); 105 fclose($qti_file); 106 // destroy writer object 107 $this->xml->_XmlWriter; 108 109 ilUtil::zip( 110 $this->export_dir . "/" . $this->subdir, 111 $this->export_dir . "/" . $this->subdir . ".zip" 112 ); 113 114 $expLog->write(date("[y-m-d H:i:s] ") . "Finished Export"); 115 116 return $this->export_dir . "/" . $this->subdir . ".zip"; 117 } 118} 119