ILIAS  trunk Revision v11.0_alpha-1731-gff9cd7e2bd3
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilSurveyImporter.php
Go to the documentation of this file.
1 <?php
2 
24 {
25  protected ilSurveyDataSet $ds;
26  protected ilLogger $log;
27  protected static ilObjSurvey $survey;
28  protected ilLogger $svy_log;
29  protected \ILIAS\SurveyQuestionPool\Export\ImportManager $spl_import_manager;
30 
31  public function __construct()
32  {
34  global $DIC;
35 
36  $this->log = $DIC["ilLog"];
37 
38  $this->spl_import_manager = $DIC->surveyQuestionPool()
39  ->internal()
40  ->domain()
41  ->import();
42  }
43 
44 
45  public function init(): void
46  {
47  $this->ds = new ilSurveyDataSet();
48  $this->ds->setDSPrefix("ds");
49  $this->ds->setImport($this);
50 
51  $this->svy_log = ilLoggerFactory::getLogger("svy");
52  }
53 
54 
60  public function setSurvey(ilObjSurvey $a_val): void
61  {
62  self::$survey = $a_val;
63  }
64 
65  public function getSurvey(): ilObjSurvey
66  {
67  return self::$survey;
68  }
69 
76  public function importXmlRepresentation(
77  string $a_entity,
78  string $a_id,
79  string $a_xml,
80  ilImportMapping $a_mapping
81  ): void {
82  if ($a_entity === "svy") {
83  // Container import => test object already created
84  if (!($new_id = $a_mapping->getMapping('components/ILIAS/Container', 'objs', $a_id))) { // case ii, non container
85  $new_id = $a_mapping->getMapping("components/ILIAS/Survey", "svy", 0);
86  }
88  $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
89  $this->setSurvey($newObj);
90 
91 
92  [$xml_file] = $this->parseXmlFileNames();
93 
94  if (!file_exists($xml_file)) {
95  $GLOBALS['ilLog']->write(__METHOD__ . ': Cannot find xml definition: ' . $xml_file);
96  return;
97  }
98  $GLOBALS['ilLog']->write("getQuestionPoolID = " . $this->getImport()->getConfig("components/ILIAS/Survey")->getQuestionPoolID());
99 
100  $import = new SurveyImportParser(
101  $this->getImport()->getConfig("components/ILIAS/Survey")->getQuestionPoolID(),
102  $xml_file,
103  true,
104  $a_mapping
105  );
106 
107  $import->setSurveyObject($newObj);
108  $import->startParsing();
109 
110  $a_mapping->addMapping("components/ILIAS/Survey", "svy", (int) $a_id, $newObj->getId());
111  $a_mapping->addMapping(
112  "components/ILIAS/MetaData",
113  "md",
114  $a_id . ":0:svy",
115  $newObj->getId() . ":0:svy"
116  );
117  } else {
118  $parser = new ilDataSetImportParser(
119  $a_entity,
120  $this->getSchemaVersion(),
121  $a_xml,
122  $this->ds,
123  $a_mapping
124  );
125  }
126  }
127 
128 
132  protected function parseXmlFileNames(): array
133  {
134  $GLOBALS['ilLog']->write(__METHOD__ . ': ' . $this->getImportDirectory());
135 
136  $basename = basename($this->getImportDirectory());
137  $xml = $this->getImportDirectory() . '/' . $basename . '.xml';
138 
139  return array($xml);
140  }
141 }
static getLogger(string $a_component_id)
Get component logger.
importXmlRepresentation(string $a_entity, string $a_id, string $a_xml, ilImportMapping $a_mapping)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addMapping(string $a_comp, string $a_entity, string $a_old_id, string $a_new_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setSurvey(ilObjSurvey $a_val)
Set current survey object (being imported).
getMapping(string $a_comp, string $a_entity, string $a_old_id)
$GLOBALS["DIC"]
Definition: wac.php:53
static ilObjSurvey $survey
parseXmlFileNames()
Create qti and xml file name.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:22
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
__construct(Container $dic, ilPlugin $plugin)
ILIAS SurveyQuestionPool Export ImportManager $spl_import_manager
Xml importer class.