ILIAS  release_8 Revision v8.23
ilTestImporter Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Inheritance diagram for ilTestImporter:
+ Collaboration diagram for ilTestImporter:

Public Member Functions

 importXmlRepresentation (string $a_entity, string $a_id, string $a_xml, ilImportMapping $a_mapping)
 Import XML. More...
 
 addTexonomyAndQuestionsMapping (array $question_id_mapping, int $new_obj_id, ilImportMapping $mapping)
 
 finalProcessing (ilImportMapping $a_mapping)
 Final processing. More...
 
 importRandomQuestionSetConfig (ilObjTest $testOBJ, $xmlFile, $a_mapping)
 
- Public Member Functions inherited from ilXmlImporter
 __construct ()
 
 setImport (ilImport $a_val)
 
 getImport ()
 
 init ()
 
 setInstallId (string $a_val)
 
 getInstallId ()
 
 setInstallUrl (string $a_val)
 
 getInstallUrl ()
 
 setSchemaVersion (string $a_val)
 
 getSchemaVersion ()
 
 setImportDirectory (string $a_val)
 
 getImportDirectory ()
 
 setSkipEntities (array $a_val)
 
 getSkipEntities ()
 
 exportedFromSameInstallation ()
 
 importXmlRepresentation (string $a_entity, string $a_id, string $a_xml, ilImportMapping $a_mapping)
 
 finalProcessing (ilImportMapping $a_mapping)
 
 afterContainerImportProcessing (ilImportMapping $mapping)
 

Static Public Attributes

static $finallyProcessedTestsRegistry = array()
 

Protected Member Functions

 finalRandomTestTaxonomyProcessing (ilImportMapping $mapping, $oldTstObjId, $newTstObjId, ilObjTest $testOBJ)
 
 getNewMappedTaxonomyFilter (ilImportMapping $mapping, array $mappedFilter)
 
 parseXmlFileNames ()
 Create qti and xml file name. More...
 
 importQuestionSkillAssignments (ilImportMapping $mapping, ilObjTest $testOBJ, $xmlFile)
 
 importSkillLevelThresholds (ilImportMapping $mapping, ilAssQuestionSkillAssignmentList $assignmentList, ilObjTest $testOBJ, $xmlFile)
 

Private Member Functions

 getImportDirectoryContainer ()
 
 getImportPackageName ()
 

Additional Inherited Members

- Protected Attributes inherited from ilXmlImporter
array $skip_entities = array()
 
ilImport $imp
 
string $install_id
 
string $install_url
 
string $schema_version
 
string $import_directory
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Importer class for files

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

Definition at line 26 of file class.ilTestImporter.php.

Member Function Documentation

◆ addTexonomyAndQuestionsMapping()

ilTestImporter::addTexonomyAndQuestionsMapping ( array  $question_id_mapping,
int  $new_obj_id,
ilImportMapping  $mapping 
)

Definition at line 120 of file class.ilTestImporter.php.

References ilImportMapping\addMapping().

Referenced by importXmlRepresentation().

121  {
122  foreach ($question_id_mapping as $oldQuestionId => $newQuestionId) {
123  $mapping->addMapping(
124  "Services/Taxonomy",
125  "tax_item",
126  "tst:quest:$oldQuestionId",
127  $newQuestionId
128  );
129 
130  $mapping->addMapping(
131  "Services/Taxonomy",
132  "tax_item_obj_id",
133  "tst:quest:$oldQuestionId",
134  $new_obj_id
135  );
136 
137  $mapping->addMapping(
138  "Modules/Test",
139  "quest",
140  $oldQuestionId,
141  $newQuestionId
142  );
143  }
144 
145  return $mapping;
146  }
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)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ finalProcessing()

ilTestImporter::finalProcessing ( ilImportMapping  $a_mapping)

Final processing.

Parameters
ilImportMapping$a_mapping
Returns
void

Definition at line 153 of file class.ilTestImporter.php.

References finalRandomTestTaxonomyProcessing(), ilObjectFactory\getInstanceByObjId(), and ilImportMapping\getMappingsOfEntity().

153  : void
154  {
155  $maps = $a_mapping->getMappingsOfEntity("Modules/Test", "tst");
156 
157  foreach ($maps as $old => $new) {
158  if ($old == "new_id" || (int) $old <= 0) {
159  continue;
160  }
161 
162  if (isset(self::$finallyProcessedTestsRegistry[$new])) {
163  continue;
164  }
165 
166  /* @var ilObjTest $testOBJ */
167  $testOBJ = ilObjectFactory::getInstanceByObjId($new, false);
168  if ($testOBJ->isRandomTest()) {
169  $this->finalRandomTestTaxonomyProcessing($a_mapping, $old, $new, $testOBJ);
170  }
171 
172  self::$finallyProcessedTestsRegistry[$new] = true;
173  }
174  }
getMappingsOfEntity(string $a_comp, string $a_entity)
finalRandomTestTaxonomyProcessing(ilImportMapping $mapping, $oldTstObjId, $newTstObjId, ilObjTest $testOBJ)
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
+ Here is the call graph for this function:

◆ finalRandomTestTaxonomyProcessing()

ilTestImporter::finalRandomTestTaxonomyProcessing ( ilImportMapping  $mapping,
  $oldTstObjId,
  $newTstObjId,
ilObjTest  $testOBJ 
)
protected

Definition at line 176 of file class.ilTestImporter.php.

References $DIC, $ilDB, ilImportMapping\getMapping(), getNewMappedTaxonomyFilter(), and ilObjTaxonomy\saveUsage().

Referenced by finalProcessing().

177  {
178  $new_tax_ids = $mapping->getMapping(
179  'Services/Taxonomy',
180  'tax_usage_of_obj',
181  $oldTstObjId
182  );
183 
184  if ($new_tax_ids !== false) {
185  $tax_ids = explode(":", $new_tax_ids);
186 
187  foreach ($tax_ids as $tid) {
188  ilObjTaxonomy::saveUsage((int) $tid, (int) $newTstObjId);
189  }
190  }
191 
192  // update all source pool definition's tax/taxNode ids with new mapped id
193  global $DIC; /* @var ILIAS\DI\Container $DIC */
194  $ilDB = $DIC['ilDB'];
195 
197  $ilDB,
198  $testOBJ
199  );
200 
202  $ilDB,
203  $testOBJ,
204  $srcPoolDefFactory
205  );
206 
207  $srcPoolDefList->loadDefinitions();
208 
209  foreach ($srcPoolDefList as $definition) {
210  // #21330
211  if (!is_array($definition->getMappedTaxonomyFilter()) || 0 === count($definition->getMappedTaxonomyFilter())) {
212  continue;
213  }
214 
215  $definition->setMappedTaxonomyFilter(
217  $mapping,
218  $definition->getMappedTaxonomyFilter()
219  )
220  );
221  $definition->saveToDb();
222  }
223  }
getNewMappedTaxonomyFilter(ilImportMapping $mapping, array $mappedFilter)
global $DIC
Definition: feed.php:28
getMapping(string $a_comp, string $a_entity, string $a_old_id)
static saveUsage(int $a_tax_id, int $a_obj_id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getImportDirectoryContainer()

ilTestImporter::getImportDirectoryContainer ( )
private

Definition at line 282 of file class.ilTestImporter.php.

References ilXmlImporter\getImportDirectory().

Referenced by importXmlRepresentation().

282  : string
283  {
284  $dir = $this->getImportDirectory();
285  $dir = dirname($dir);
286  return $dir;
287  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getImportPackageName()

ilTestImporter::getImportPackageName ( )
private

Definition at line 289 of file class.ilTestImporter.php.

References $name, and ilXmlImporter\getImportDirectory().

Referenced by importXmlRepresentation().

289  : string
290  {
291  $dir = $this->getImportDirectory();
292  $name = basename($dir);
293  return $name;
294  }
if($format !==null) $name
Definition: metadata.php:247
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getNewMappedTaxonomyFilter()

ilTestImporter::getNewMappedTaxonomyFilter ( ilImportMapping  $mapping,
array  $mappedFilter 
)
protected
Parameters
ilImportMapping$mapping
array$mappedFilter
Returns
array

Definition at line 230 of file class.ilTestImporter.php.

References ilImportMapping\getMapping().

Referenced by finalRandomTestTaxonomyProcessing().

230  : array
231  {
232  $newMappedFilter = array();
233 
234  foreach ($mappedFilter as $taxId => $taxNodes) {
235  $newTaxId = $mapping->getMapping(
236  'Services/Taxonomy',
237  'tax',
238  $taxId
239  );
240 
241  if (!$newTaxId) {
242  continue;
243  }
244 
245  $newMappedFilter[$newTaxId] = array();
246 
247  foreach ($taxNodes as $taxNodeId) {
248  $newTaxNodeId = $mapping->getMapping(
249  'Services/Taxonomy',
250  'tax_tree',
251  $taxNodeId
252  );
253 
254  if (!$newTaxNodeId) {
255  continue;
256  }
257 
258  $newMappedFilter[$newTaxId][] = $newTaxNodeId;
259  }
260  }
261 
262  return $newMappedFilter;
263  }
getMapping(string $a_comp, string $a_entity, string $a_old_id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ importQuestionSkillAssignments()

ilTestImporter::importQuestionSkillAssignments ( ilImportMapping  $mapping,
ilObjTest  $testOBJ,
  $xmlFile 
)
protected
Parameters
ilImportMapping$mappingRegistry
ilObjTest$testOBJ
string$xmlfile
Returns
ilAssQuestionSkillAssignmentList

Definition at line 311 of file class.ilTestImporter.php.

References ilObject\getId(), ilXmlImporter\getInstallId(), ilAssQuestionSkillAssignmentImportFails\registerFailedImports(), and ilObjTest\setOnline().

Referenced by importXmlRepresentation().

312  {
313  $parser = new ilAssQuestionSkillAssignmentXmlParser($xmlFile);
314  $parser->startParsing();
315 
316  $importer = new ilAssQuestionSkillAssignmentImporter();
317  $importer->setTargetParentObjId($testOBJ->getId());
318  $importer->setImportInstallationId($this->getInstallId());
319  $importer->setImportMappingRegistry($mapping);
320  $importer->setImportMappingComponent('Modules/Test');
321  $importer->setImportAssignmentList($parser->getAssignmentList());
322 
323  $importer->import();
324 
325  if ($importer->getFailedImportAssignmentList()->assignmentsExist()) {
326  $qsaImportFails = new ilAssQuestionSkillAssignmentImportFails($testOBJ->getId());
327  $qsaImportFails->registerFailedImports($importer->getFailedImportAssignmentList());
328 
329  $testOBJ->setOnline(false);
330  }
331 
332  return $importer->getSuccessImportAssignmentList();
333  }
setOnline($a_online=true)
registerFailedImports(ilAssQuestionSkillAssignmentImportList $assignmentList)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ importRandomQuestionSetConfig()

ilTestImporter::importRandomQuestionSetConfig ( ilObjTest  $testOBJ,
  $xmlFile,
  $a_mapping 
)

Definition at line 296 of file class.ilTestImporter.php.

Referenced by importXmlRepresentation().

297  {
298  $testOBJ->questions = [];
299  $parser = new ilObjTestXMLParser($xmlFile);
300  $parser->setTestOBJ($testOBJ);
301  $parser->setImportMapping($a_mapping);
302  $parser->startParsing();
303  }
+ Here is the caller graph for this function:

◆ importSkillLevelThresholds()

ilTestImporter::importSkillLevelThresholds ( ilImportMapping  $mapping,
ilAssQuestionSkillAssignmentList  $assignmentList,
ilObjTest  $testOBJ,
  $xmlFile 
)
protected
Parameters
ilImportMapping$mapping
ilAssQuestionSkillAssignmentList$assignmentList
ilObjTest$testOBJ
$xmlFile

Definition at line 341 of file class.ilTestImporter.php.

References ilObject\getId(), ilXmlImporter\getInstallId(), ilObjTest\getTestId(), ilTestSkillLevelThresholdImportFails\registerFailedImports(), and ilObject\setOfflineStatus().

Referenced by importXmlRepresentation().

342  {
343  $parser = new ilTestSkillLevelThresholdXmlParser($xmlFile);
344  $parser->startParsing();
345 
346  $importer = new ilTestSkillLevelThresholdImporter();
347  $importer->setTargetTestId($testOBJ->getTestId());
348  $importer->setImportInstallationId($this->getInstallId());
349  $importer->setImportMappingRegistry($mapping);
350  $importer->setImportedQuestionSkillAssignmentList($assignmentList);
351  $importer->setImportThresholdList($parser->getSkillLevelThresholdImportList());
352  $importer->import();
353 
354  if ($importer->getFailedThresholdImportSkillList()->skillsExist()) {
355  $sltImportFails = new ilTestSkillLevelThresholdImportFails($testOBJ->getId());
356  $sltImportFails->registerFailedImports($importer->getFailedThresholdImportSkillList());
357 
358  $testOBJ->setOfflineStatus(true);
359  }
360  }
registerFailedImports(ilAssQuestionAssignedSkillList $skillList)
getTestId()
Gets the database id of the additional test data.
setOfflineStatus(bool $status)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ importXmlRepresentation()

ilTestImporter::importXmlRepresentation ( string  $a_entity,
string  $a_id,
string  $a_xml,
ilImportMapping  $a_mapping 
)

Import XML.

Parameters
string$a_entity
string$a_id
string$a_xml
ilImportMapping$a_mapping
Returns
void
Exceptions
ilDatabaseException
ilObjectNotFoundException
ilSaxParserException

Definition at line 44 of file class.ilTestImporter.php.

References $DIC, $results, ilObjTest\_setImportDirectory(), ilImportMapping\addMapping(), addTexonomyAndQuestionsMapping(), ilSession\get(), ilXmlImporter\getImportDirectory(), getImportDirectoryContainer(), getImportPackageName(), ilObjectFactory\getInstanceByObjId(), ilImportMapping\getMapping(), ilImportMapping\getMappingsOfEntity(), ilQTIParser\IL_MO_PARSE_QTI, importQuestionSkillAssignments(), importRandomQuestionSetConfig(), importSkillLevelThresholds(), parseXmlFileNames(), and ilSession\set().

44  : void
45  {
47 
48  if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_id)) {
49  // container content
50  $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
51  ilSession::set('tst_import_subdir', $this->getImportPackageName());
52  $newObj->saveToDb(); // this generates test id first time
53  $questionParentObjId = $newObj->getId();
54  } else {
55  // single object
56  $new_id = $a_mapping->getMapping('Modules/Test', 'tst', 'new_id');
57  $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
58 
59  $questionParentObjId = ilSession::get('tst_import_qst_parent') ?? $newObj->getId();
60  }
61 
62  $newObj->loadFromDb();
63 
64  list($xml_file, $qti_file) = $this->parseXmlFileNames();
65 
66  global $DIC; /* @var ILIAS\DI\Container $DIC */
67  if (!@file_exists($xml_file)) {
68  $DIC['ilLog']->write(__METHOD__ . ': Cannot find xml definition: ' . $xml_file);
69  return;
70  }
71  if (!@file_exists($qti_file)) {
72  $DIC['ilLog']->write(__METHOD__ . ': Cannot find xml definition: ' . $qti_file);
73  return;
74  }
75 
76  /* @var ilObjTest $newObj */
77 
78  // FIXME: Copied from ilObjTestGUI::importVerifiedFileObject
79  // TODO: move all logic to ilObjTest::importVerifiedFile and call
80  // this method from ilObjTestGUI and ilTestImporter
81  $newObj->mark_schema->flush();
82 
83  $idents = ilSession::get('tst_import_idents');
84 
85  // start parsing of QTI files
86  $qtiParser = new ilQTIParser($qti_file, ilQTIParser::IL_MO_PARSE_QTI, $questionParentObjId, $idents);
87  $qtiParser->setTestObject($newObj);
88  $qtiParser->startParsing();
89  $newObj = $qtiParser->getTestObject();
90 
91  // import page data
92  $questionPageParser = new ilQuestionPageParser($newObj, $xml_file, basename($this->getImportDirectory()));
93  $questionPageParser->setQuestionMapping($qtiParser->getImportMapping());
94  $questionPageParser->startParsing();
95 
96  $a_mapping = $this->addTexonomyAndQuestionsMapping($qtiParser->getQuestionIdMapping(), $newObj->getId(), $a_mapping);
97 
98  if ($newObj->isRandomTest()) {
99  $this->importRandomQuestionSetConfig($newObj, $xml_file, $a_mapping);
100  }
101 
102  // import test results
103  if (@file_exists(ilSession::get("tst_import_results_file"))) {
104  $results = new ilTestResultsImportParser(ilSession::get("tst_import_results_file"), $newObj);
105  $results->setQuestionIdMapping($a_mapping->getMappingsOfEntity('Modules/Test', 'quest'));
106  $results->setSrcPoolDefIdMapping($a_mapping->getMappingsOfEntity('Modules/Test', 'rnd_src_pool_def'));
107  $results->startParsing();
108  }
109 
110  $newObj->saveToDb(); // this creates test_fi
111  $newObj->update(); // this saves ilObject data
112 
113  // import skill assignments
114  $importedAssignmentList = $this->importQuestionSkillAssignments($a_mapping, $newObj, $xml_file);
115  $this->importSkillLevelThresholds($a_mapping, $importedAssignmentList, $newObj, $xml_file);
116 
117  $a_mapping->addMapping("Modules/Test", "tst", $a_id, $newObj->getId());
118  }
static get(string $a_var)
addMapping(string $a_comp, string $a_entity, string $a_old_id, string $a_new_id)
parseXmlFileNames()
Create qti and xml file name.
global $DIC
Definition: feed.php:28
importQuestionSkillAssignments(ilImportMapping $mapping, ilObjTest $testOBJ, $xmlFile)
getMapping(string $a_comp, string $a_entity, string $a_old_id)
getMappingsOfEntity(string $a_comp, string $a_entity)
addTexonomyAndQuestionsMapping(array $question_id_mapping, int $new_obj_id, ilImportMapping $mapping)
Legacy Content Object Parser.
importRandomQuestionSetConfig(ilObjTest $testOBJ, $xmlFile, $a_mapping)
$results
importSkillLevelThresholds(ilImportMapping $mapping, ilAssQuestionSkillAssignmentList $assignmentList, ilObjTest $testOBJ, $xmlFile)
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static set(string $a_var, $a_val)
Set a value.
static _setImportDirectory($a_import_dir=null)
+ Here is the call graph for this function:

◆ parseXmlFileNames()

ilTestImporter::parseXmlFileNames ( )
protected

Create qti and xml file name.

Returns
array

Definition at line 269 of file class.ilTestImporter.php.

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

Referenced by importXmlRepresentation().

269  : array
270  {
271  global $DIC; /* @var ILIAS\DI\Container $DIC */
272  $DIC['ilLog']->write(__METHOD__ . ': ' . $this->getImportDirectory());
273 
274  $basename = basename($this->getImportDirectory());
275 
276  $xml = $this->getImportDirectory() . '/' . $basename . '.xml';
277  $qti = $this->getImportDirectory() . '/' . preg_replace('/test|tst/', 'qti', $basename) . '.xml';
278 
279  return array($xml,$qti);
280  }
global $DIC
Definition: feed.php:28
$xml
Definition: metadata.php:351
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $finallyProcessedTestsRegistry

ilTestImporter::$finallyProcessedTestsRegistry = array()
static

Definition at line 31 of file class.ilTestImporter.php.


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