ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilSurveyImporter.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once("./Services/Export/classes/class.ilXmlImporter.php");
5
14{
18 protected $log;
19
20
24 public function __construct()
25 {
26 parent::__construct();
27 global $DIC;
28
29 $this->log = $DIC["ilLog"];
30 }
31
35 protected static $survey;
36
40 protected $svy_log;
41
48 public function init()
49 {
50 include_once("./Modules/Survey/classes/class.ilSurveyDataSet.php");
51 $this->ds = new ilSurveyDataSet();
52 $this->ds->setDSPrefix("ds");
53 $this->ds->setImport($this);
54
55 $this->svy_log = ilLoggerFactory::getLogger("svy");
56 }
57
58
66 public function setSurvey(ilObjSurvey $a_val)
67 {
68 self::$survey = $a_val;
69 }
70
76 public function getSurvey()
77 {
78 return self::$survey;
79 }
80
93 public function importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
94 {
95 if ($a_entity == "svy") {
96 // Container import => test object already created
97 if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_id)) {
98 $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
99 #$newObj->setImportDirectory(dirname(rtrim($this->getImportDirectory(),'/')));
100 } else { // case ii, non container
101 $new_id = $a_mapping->getMapping("Modules/Survey", "svy", 0);
102 $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
103 }
104 $this->setSurvey($newObj);
105
106 include_once "./Services/Survey/classes/class.SurveyImportParser.php";
107
108 list($xml_file) = $this->parseXmlFileNames();
109
110 if (!@file_exists($xml_file)) {
111 $GLOBALS['ilLog']->write(__METHOD__ . ': Cannot find xml definition: ' . $xml_file);
112 return false;
113 }
114 $GLOBALS['ilLog']->write("getQuestionPoolID = " . $this->getImport()->getConfig("Modules/Survey")->getQuestionPoolID());
115
116 $import = new SurveyImportParser($this->getImport()->getConfig("Modules/Survey")->getQuestionPoolID(), $xml_file, true, $a_mapping);
117
118 $import->setSurveyObject($newObj);
119 $import->startParsing();
120
121 $this->svy_log->debug("is array import_mob_xml: -" . is_array($_SESSION["import_mob_xhtml"]) . "-");
122
123 // this is "written" by Services/Survey/classes/class.ilSurveyImportParser
124 if (is_array($_SESSION["import_mob_xhtml"])) {
125 include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
126 include_once "./Services/RTE/classes/class.ilRTE.php";
127 include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
128 foreach ($_SESSION["import_mob_xhtml"] as $mob) {
129 $this->svy_log->debug("import mob xhtml, type: " . $mob["type"] . ", id: " . $mob["mob"]);
130
131 if (!$mob["type"]) {
132 $mob["type"] = "svy:html";
133 }
134
135 $importfile = dirname($xml_file) . "/" . $mob["uri"];
136 $this->svy_log->debug("import file: " . $importfile);
137
138 if (file_exists($importfile)) {
139 $media_object = ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false);
140
141 // survey mob
142 if ($mob["type"] == "svy:html") {
143 ilObjMediaObject::_saveUsage($media_object->getId(), "svy:html", $newObj->getId());
144 $this->svy_log->debug("old introduction: " . $newObj->getIntroduction());
145 $newObj->setIntroduction(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $newObj->getIntroduction()));
146 $newObj->setOutro(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $newObj->getOutro()));
147
148 $this->svy_log->debug("new introduction: " . $newObj->getIntroduction());
149 } elseif ($import->questions[$mob["id"]]) {
150 $new_qid = $import->questions[$mob["id"]];
151 ilObjMediaObject::_saveUsage($media_object->getId(), $mob["type"], $new_qid);
152 $new_question = SurveyQuestion::_instanciateQuestion($new_qid);
153 $qtext = $new_question->getQuestiontext();
154
155 $this->svy_log->debug("old question text: " . $qtext);
156
157 $qtext = ilRTE::_replaceMediaObjectImageSrc($qtext, 0);
158 $qtext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $qtext);
159 $qtext = ilRTE::_replaceMediaObjectImageSrc($qtext, 1);
160 $new_question->setQuestiontext($qtext);
161 $new_question->saveToDb();
162
163 $this->svy_log->debug("new question text: " . $qtext);
164
165 // also fix existing original in pool
166 if ($new_question->getOriginalId()) {
167 $pool_question = SurveyQuestion::_instanciateQuestion($new_question->getOriginalId());
168 $pool_question->setQuestiontext($qtext);
169 $pool_question->saveToDb();
170 }
171 }
172 } else {
173 $this->svy_log->error("Error: Could not open XHTML mob file for test introduction during test import. File $importfile does not exist!");
174 }
175 }
176 $newObj->setIntroduction(ilRTE::_replaceMediaObjectImageSrc($newObj->getIntroduction(), 1));
177 $newObj->setOutro(ilRTE::_replaceMediaObjectImageSrc($newObj->getOutro(), 1));
178 $newObj->saveToDb();
179 }
180 $a_mapping->addMapping("Modules/Survey", "svy", (int) $a_id, (int) $newObj->getId());
181 return $newObj->getId();
182 } else {
183 include_once("./Services/DataSet/classes/class.ilDataSetImportParser.php");
185 $a_entity,
186 $this->getSchemaVersion(),
187 $a_xml,
188 $this->ds,
189 $a_mapping
190 );
191 }
192
193 return true;
194 }
195
196
201 protected function parseXmlFileNames()
202 {
203 $GLOBALS['ilLog']->write(__METHOD__ . ': ' . $this->getImportDirectory());
204
205 $basename = basename($this->getImportDirectory());
206 $xml = $this->getImportDirectory() . '/' . $basename . '.xml';
207
208 return array($xml);
209 }
210}
$parser
Definition: BPMN2Parser.php:23
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
Survey Question Import Parser.
static _instanciateQuestion($question_id)
Creates an instance of a question with a given question id.
Manifest parser for ILIAS standard export files.
static getLogger($a_component_id)
Get component logger.
static _saveUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Save usage of mob within another container (e.g.
static _saveTempFileAsMediaObject($name, $tmp_name, $upload=true)
Create new media object and update page in db and return new media object.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static _replaceMediaObjectImageSrc($a_text, $a_direction=0, $nic=IL_INST_ID)
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
Survey Data set class.
Importer class for files.
parseXmlFileNames()
Create qti and xml file name.
getSurvey()
Get current survey object.
importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
Import XML.
setSurvey(ilObjSurvey $a_val)
Set current survey object (being imported).
Xml importer class.
getSchemaVersion()
Get schema version.
getImport()
Get import.
getImportDirectory()
Get import directory.
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
getConfig()
Get the Config.
global $DIC
Definition: saml.php:7