ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilSurveyImporter Class Reference

Importer class for files. More...

+ Inheritance diagram for ilSurveyImporter:
+ Collaboration diagram for ilSurveyImporter:

Public Member Functions

 __construct ()
 Constructor. More...
 
 init ()
 Init. More...
 
 setSurvey (ilObjSurvey $a_val)
 Set current survey object (being imported). More...
 
 getSurvey ()
 Get current survey object. More...
 
 importXmlRepresentation ($a_entity, $a_id, $a_xml, $a_mapping)
 Import XML. More...
 
- Public Member Functions inherited from ilXmlImporter
 __construct ()
 Constructor. More...
 
 setImport ($a_val)
 Set import. More...
 
 getImport ()
 Get import. More...
 
 init ()
 Init. More...
 
 setInstallId ($a_val)
 Set installation id. More...
 
 getInstallId ()
 Get installation id. More...
 
 setInstallUrl ($a_val)
 Set installation url. More...
 
 getInstallUrl ()
 Get installation url. More...
 
 setSchemaVersion ($a_val)
 Set schema version. More...
 
 getSchemaVersion ()
 Get schema version. More...
 
 setImportDirectory ($a_val)
 Set import directory. More...
 
 getImportDirectory ()
 Get import directory. More...
 
 setSkipEntities ($a_val)
 Set skip entities. More...
 
 getSkipEntities ()
 Get skip entities. More...
 
 exportedFromSameInstallation ()
 Is exporting and importing installation identical? More...
 
 importXmlRepresentation ($a_entity, $a_id, $a_xml, $a_mapping)
 Import xml representation. More...
 
 finalProcessing ($a_mapping)
 Final processing. More...
 
 afterContainerImportProcessing (ilImportMapping $mapping)
 Called after all container objects have been implemented. More...
 

Protected Member Functions

 parseXmlFileNames ()
 Create qti and xml file name. More...
 

Protected Attributes

 $log
 
 $svy_log
 
- Protected Attributes inherited from ilXmlImporter
 $skip_entities = array()
 
 $imp
 

Static Protected Attributes

static $survey
 

Detailed Description

Importer class for files.

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
Id

Definition at line 13 of file class.ilSurveyImporter.php.

Constructor & Destructor Documentation

◆ __construct()

ilSurveyImporter::__construct ( )

Constructor.

Reimplemented from ilXmlImporter.

Definition at line 24 of file class.ilSurveyImporter.php.

25 {
26 parent::__construct();
27 global $DIC;
28
29 $this->log = $DIC["ilLog"];
30 }
global $DIC
Definition: saml.php:7

References $DIC.

Member Function Documentation

◆ getSurvey()

ilSurveyImporter::getSurvey ( )

Get current survey object.

Returns
ilObjSurvey survey

Definition at line 76 of file class.ilSurveyImporter.php.

77 {
78 return self::$survey;
79 }

References $survey.

◆ importXmlRepresentation()

ilSurveyImporter::importXmlRepresentation (   $a_entity,
  $a_id,
  $a_xml,
  $a_mapping 
)

Import XML.

Parameters

return

Reimplemented from ilXmlImporter.

Definition at line 87 of file class.ilSurveyImporter.php.

88 {
89 if ($a_entity == "svy") {
90 // Container import => test object already created
91 if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_id)) {
92 $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
93 #$newObj->setImportDirectory(dirname(rtrim($this->getImportDirectory(),'/')));
94 } else { // case ii, non container
95 $new_id = $a_mapping->getMapping("Modules/Survey", "svy", 0);
96 $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
97 }
98 $this->setSurvey($newObj);
99
100 include_once "./Services/Survey/classes/class.SurveyImportParser.php";
101
102 list($xml_file) = $this->parseXmlFileNames();
103
104 if (!@file_exists($xml_file)) {
105 $GLOBALS['ilLog']->write(__METHOD__ . ': Cannot find xml definition: ' . $xml_file);
106 return false;
107 }
108 $GLOBALS['ilLog']->write("getQuestionPoolID = " . $this->getImport()->getConfig("Modules/Survey")->getQuestionPoolID());
109
110 $import = new SurveyImportParser($this->getImport()->getConfig("Modules/Survey")->getQuestionPoolID(), $xml_file, true, $a_mapping);
111
112 $import->setSurveyObject($newObj);
113 $import->startParsing();
114
115 $this->svy_log->debug("is array import_mob_xml: -" . is_array($_SESSION["import_mob_xhtml"]) . "-");
116
117 // this is "written" by Services/Survey/classes/class.ilSurveyImportParser
118 if (is_array($_SESSION["import_mob_xhtml"])) {
119 include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
120 include_once "./Services/RTE/classes/class.ilRTE.php";
121 include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
122 foreach ($_SESSION["import_mob_xhtml"] as $mob) {
123 $this->svy_log->debug("import mob xhtml, type: " . $mob["type"] . ", id: " . $mob["mob"]);
124
125 if (!$mob["type"]) {
126 $mob["type"] = "svy:html";
127 }
128
129 $importfile = dirname($xml_file) . "/" . $mob["uri"];
130 $this->svy_log->debug("import file: " . $importfile);
131
132 if (file_exists($importfile)) {
133 $media_object = ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false);
134
135 // survey mob
136 if ($mob["type"] == "svy:html") {
137 ilObjMediaObject::_saveUsage($media_object->getId(), "svy:html", $newObj->getId());
138 $this->svy_log->debug("old introduction: " . $newObj->getIntroduction());
139 $newObj->setIntroduction(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $newObj->getIntroduction()));
140 $newObj->setOutro(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $newObj->getOutro()));
141
142 $this->svy_log->debug("new introduction: " . $newObj->getIntroduction());
143 } elseif ($import->questions[$mob["id"]]) {
144 $new_qid = $import->questions[$mob["id"]];
145 ilObjMediaObject::_saveUsage($media_object->getId(), $mob["type"], $new_qid);
146 $new_question = SurveyQuestion::_instanciateQuestion($new_qid);
147 $qtext = $new_question->getQuestiontext();
148
149 $this->svy_log->debug("old question text: " . $qtext);
150
151 $qtext = ilRTE::_replaceMediaObjectImageSrc($qtext, 0);
152 $qtext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $qtext);
153 $qtext = ilRTE::_replaceMediaObjectImageSrc($qtext, 1);
154 $new_question->setQuestiontext($qtext);
155 $new_question->saveToDb();
156
157 $this->svy_log->debug("new question text: " . $qtext);
158
159 // also fix existing original in pool
160 if ($new_question->getOriginalId()) {
161 $pool_question = SurveyQuestion::_instanciateQuestion($new_question->getOriginalId());
162 $pool_question->setQuestiontext($qtext);
163 $pool_question->saveToDb();
164 }
165 }
166 } else {
167 $this->svy_log->error("Error: Could not open XHTML mob file for test introduction during test import. File $importfile does not exist!");
168 }
169 }
170 $newObj->setIntroduction(ilRTE::_replaceMediaObjectImageSrc($newObj->getIntroduction(), 1));
171 $newObj->setOutro(ilRTE::_replaceMediaObjectImageSrc($newObj->getOutro(), 1));
172 $newObj->saveToDb();
173 }
174
175 $a_mapping->addMapping("Modules/Survey", "svy", $a_id, $newObj->getId());
176 } else {
177 include_once("./Services/DataSet/classes/class.ilDataSetImportParser.php");
179 $a_entity,
180 $this->getSchemaVersion(),
181 $a_xml,
182 $this->ds,
183 $a_mapping
184 );
185 }
186
187 return true;
188 }
$parser
Definition: BPMN2Parser.php:23
$_SESSION["AccountId"]
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 _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...
parseXmlFileNames()
Create qti and xml file name.
setSurvey(ilObjSurvey $a_val)
Set current survey object (being imported).
getSchemaVersion()
Get schema version.
getImport()
Get import.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
getConfig()
Get the Config.

References $_SESSION, $GLOBALS, $parser, SurveyQuestion\_instanciateQuestion(), ilRTE\_replaceMediaObjectImageSrc(), ilObjMediaObject\_saveTempFileAsMediaObject(), ilObjMediaObject\_saveUsage(), League\Flysystem\getConfig(), ilXmlImporter\getImport(), ilObjectFactory\getInstanceByObjId(), ilXmlImporter\getSchemaVersion(), parseXmlFileNames(), and setSurvey().

+ Here is the call graph for this function:

◆ init()

ilSurveyImporter::init ( )

Init.

Parameters

return

Reimplemented from ilXmlImporter.

Definition at line 48 of file class.ilSurveyImporter.php.

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 }
static getLogger($a_component_id)
Get component logger.
Survey Data set class.

References ilLoggerFactory\getLogger().

+ Here is the call graph for this function:

◆ parseXmlFileNames()

ilSurveyImporter::parseXmlFileNames ( )
protected

Create qti and xml file name.

Returns
array

Definition at line 195 of file class.ilSurveyImporter.php.

196 {
197 $GLOBALS['ilLog']->write(__METHOD__ . ': ' . $this->getImportDirectory());
198
199 $basename = basename($this->getImportDirectory());
200 $xml = $this->getImportDirectory() . '/' . $basename . '.xml';
201
202 return array($xml);
203 }
getImportDirectory()
Get import directory.
$xml
Definition: metadata.php:240

References $GLOBALS, $xml, and ilXmlImporter\getImportDirectory().

Referenced by importXmlRepresentation().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setSurvey()

ilSurveyImporter::setSurvey ( ilObjSurvey  $a_val)

Set current survey object (being imported).

This is done statically, since the survey import uses multiple input files being processed for every survey and all of these need the current survey object (ilSurveyImporter is intantiated multiple times)

Parameters
ilObjSurvey$a_valsurvey

Definition at line 66 of file class.ilSurveyImporter.php.

67 {
68 self::$survey = $a_val;
69 }

Referenced by importXmlRepresentation().

+ Here is the caller graph for this function:

Field Documentation

◆ $log

ilSurveyImporter::$log
protected

Definition at line 18 of file class.ilSurveyImporter.php.

◆ $survey

ilSurveyImporter::$survey
staticprotected

Definition at line 35 of file class.ilSurveyImporter.php.

Referenced by getSurvey().

◆ $svy_log

ilSurveyImporter::$svy_log
protected

Definition at line 40 of file class.ilSurveyImporter.php.


The documentation for this class was generated from the following file: