ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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 
84  // container import
85  if ($new_id = $a_mapping->getMapping('components/ILIAS/Container', 'objs', $a_id)) {
86  $newObj = ilObjectFactory::getInstanceByObjId((int) $new_id, false);
87  } else {
88  $newObj = new ilObjSurvey(); // direct survey import
89  $newObj->setType('svy');
90  $newObj->setTitle("dummy");
91  $newObj->create(true);
92  }
93  $a_mapping->addMapping('components/ILIAS/Survey', 'svy', $a_id, (string) $newObj->getId());
94  $this->setSurvey($newObj);
95 
96 
97  [$xml_file] = $this->parseXmlFileNames();
98 
99  if (!file_exists($xml_file)) {
100  $GLOBALS['ilLog']->write(__METHOD__ . ': Cannot find xml definition: ' . $xml_file);
101  return;
102  }
103  $GLOBALS['ilLog']->write("getQuestionPoolID = " . $this->getImport()->getConfig("components/ILIAS/Survey")->getQuestionPoolID());
104 
105  $import = new SurveyImportParser(
106  $this->getImport()->getConfig("components/ILIAS/Survey")->getQuestionPoolID(),
107  $xml_file,
108  true,
109  $a_mapping
110  );
111 
112  $import->setSurveyObject($newObj);
113  $import->startParsing();
114 
115  $a_mapping->addMapping("components/ILIAS/Survey", "svy", (int) $a_id, $newObj->getId());
116  $a_mapping->addMapping(
117  "components/ILIAS/MetaData",
118  "md",
119  $a_id . ":0:svy",
120  $newObj->getId() . ":0:svy"
121  );
122  } else {
123  $parser = new ilDataSetImportParser(
124  $a_entity,
125  $this->getSchemaVersion(),
126  $a_xml,
127  $this->ds,
128  $a_mapping
129  );
130  }
131  }
132 
133 
137  protected function parseXmlFileNames(): array
138  {
139  $GLOBALS['ilLog']->write(__METHOD__ . ': ' . $this->getImportDirectory());
140 
141  $basename = basename($this->getImportDirectory());
142  $xml = $this->getImportDirectory() . '/' . $basename . '.xml';
143 
144  return array($xml);
145  }
146 }
static getLogger(string $a_component_id)
Get component logger.
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:26
importXmlRepresentation(string $a_entity, string $a_id, string $a_xml, ilImportMapping $a_mapping)
Import XML.
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.