ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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{
21 function importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
22 {
23 // Container import => test object already created
24 if($new_id = $a_mapping->getMapping('Services/Container','objs',$a_id))
25 {
26 $newObj = ilObjectFactory::getInstanceByObjId($new_id,false);
27 #$newObj->setImportDirectory(dirname(rtrim($this->getImportDirectory(),'/')));
28 }
29 else // case ii, non container
30 {
31 // Shouldn't happen
32 $GLOBALS['ilLog']->write(__METHOD__.': Called in non container mode');
33 return false;
34 }
35
36
37 include_once "./Services/Survey/classes/class.SurveyImportParser.php";
38
39 list($xml_file) = $this->parseXmlFileNames();
40
41 if(!@file_exists($xml_file))
42 {
43 $GLOBALS['ilLog']->write(__METHOD__.': Cannot find xml definition: '. $xml_file);
44 return false;
45 }
46
47 $import = new SurveyImportParser(-1, $xml_file, TRUE);
48 $import->setSurveyObject($newObj);
49 $import->startParsing();
50
51 if (is_array($_SESSION["import_mob_xhtml"]))
52 {
53 include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
54 include_once "./Services/RTE/classes/class.ilRTE.php";
55 include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
56 foreach ($_SESSION["import_mob_xhtml"] as $mob)
57 {
58 $importfile = dirname($xml_file) . "/" . $mob["uri"];
59 if (file_exists($importfile))
60 {
61 $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
62 ilObjMediaObject::_saveUsage($media_object->getId(), "svy:html", $newObj->getId());
63 $newObj->setIntroduction(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $newObj->getIntroduction()));
64 $newObj->setOutro(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $newObj->getOutro()));
65 }
66 else
67 {
68 global $ilLog;
69 $ilLog->write("Error: Could not open XHTML mob file for test introduction during test import. File $importfile does not exist!");
70 }
71 }
72 $newObj->setIntroduction(ilRTE::_replaceMediaObjectImageSrc($newObj->getIntroduction(), 1));
73 $newObj->setOutro(ilRTE::_replaceMediaObjectImageSrc($newObj->getOutro(), 1));
74 $newObj->saveToDb();
75 }
76
77 $a_mapping->addMapping("Modules/Survey", "svy", $a_id, $newObj->getId());
78
79 return true;
80
81 }
82
83
88 protected function parseXmlFileNames()
89 {
90 $GLOBALS['ilLog']->write(__METHOD__.': '.$this->getImportDirectory());
91
92 $basename = basename($this->getImportDirectory());
93 $xml = $this->getImportDirectory().'/'.$basename.'.xml';
94
95 return array($xml);
96 }
97}
98
99?>
$_SESSION["AccountId"]
Survey Question Import Parser.
_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.
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...
Importer class for files.
parseXmlFileNames()
Create qti and xml file name.
importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
Import XML.
Xml importer class.
getImportDirectory()
Get import directory.
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276