ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilTestImporter Class Reference

Importer class for files. More...

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

Public Member Functions

 __construct ()
 
 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 $test_obj, $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 = []
 

Protected Member Functions

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

Private Member Functions

 getImportDirectoryContainer ()
 
 getImportPackageName ()
 

Private Attributes

ilLogger $log
 
ilDBInterface $db
 
ResourceStorage $irss
 

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

Importer class for files.

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

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

Constructor & Destructor Documentation

◆ __construct()

ilTestImporter::__construct ( )

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

References $DIC, and ILIAS\MetaData\Repository\Validation\Data\__construct().

42  {
43  global $DIC;
44  $this->log = $DIC['ilLog'];
45  $this->db = $DIC['ilDB'];
46  $this->irss = $DIC['resource_storage'];
47 
49  }
global $DIC
Definition: feed.php:28
__construct(VocabulariesInterface $vocabularies)
+ Here is the call graph for this function:

Member Function Documentation

◆ addTexonomyAndQuestionsMapping()

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

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

References ilImportMapping\addMapping().

Referenced by importXmlRepresentation().

145  {
146  foreach ($question_id_mapping as $oldQuestionId => $newQuestionId) {
147  $mapping->addMapping(
148  "Services/Taxonomy",
149  "tax_item",
150  "tst:quest:$oldQuestionId",
151  (string) $newQuestionId
152  );
153 
154  $mapping->addMapping(
155  "Services/Taxonomy",
156  "tax_item_obj_id",
157  "tst:quest:$oldQuestionId",
158  (string) $new_obj_id
159  );
160 
161  $mapping->addMapping(
162  "Modules/Test",
163  "quest",
164  (string) $oldQuestionId,
165  (string) $newQuestionId
166  );
167  }
168 
169  return $mapping;
170  }
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 177 of file class.ilTestImporter.php.

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

177  : void
178  {
179  $maps = $a_mapping->getMappingsOfEntity("Modules/Test", "tst");
180 
181  foreach ($maps as $old => $new) {
182  if ($old == "new_id" || (int) $old <= 0) {
183  continue;
184  }
185 
186  if (isset(self::$finallyProcessedTestsRegistry[$new])) {
187  continue;
188  }
189 
190  $test_obj = ilObjectFactory::getInstanceByObjId((int) $new, false);
191  if ($test_obj->isRandomTest()) {
192  $this->finalRandomTestTaxonomyProcessing($a_mapping, (string) $old, $new, $test_obj);
193  }
194 
195  self::$finallyProcessedTestsRegistry[$new] = true;
196  }
197  }
finalRandomTestTaxonomyProcessing(ilImportMapping $mapping, string $oldTstObjId, string $newTstObjId, ilObjTest $test_obj)
getMappingsOfEntity(string $a_comp, string $a_entity)
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,
string  $oldTstObjId,
string  $newTstObjId,
ilObjTest  $test_obj 
)
protected

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

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

Referenced by finalProcessing().

204  : void {
205  $new_tax_ids = $mapping->getMapping(
206  'Services/Taxonomy',
207  'tax_usage_of_obj',
208  $oldTstObjId
209  );
210 
211  if ($new_tax_ids !== null) {
212  $tax_ids = explode(":", $new_tax_ids);
213 
214  foreach ($tax_ids as $tid) {
215  ilObjTaxonomy::saveUsage((int) $tid, (int) $newTstObjId);
216  }
217  }
218 
220  $this->db,
221  $test_obj
222  );
223 
225  $this->db,
226  $test_obj,
227  $srcPoolDefFactory
228  );
229 
230  $srcPoolDefList->loadDefinitions();
231 
232  foreach ($srcPoolDefList as $definition) {
233  // #21330
234  if (!is_array($definition->getMappedTaxonomyFilter()) || 0 === count($definition->getMappedTaxonomyFilter())) {
235  continue;
236  }
237 
238  $definition->setMappedTaxonomyFilter(
240  $mapping,
241  $definition->getMappedTaxonomyFilter()
242  )
243  );
244  $definition->saveToDb();
245  }
246  }
getNewMappedTaxonomyFilter(ilImportMapping $mapping, array $mappedFilter)
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 304 of file class.ilTestImporter.php.

References ilXmlImporter\getImportDirectory().

Referenced by importXmlRepresentation().

304  : string
305  {
306  $dir = $this->getImportDirectory();
307  $dir = dirname($dir);
308  return $dir;
309  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getImportPackageName()

ilTestImporter::getImportPackageName ( )
private

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

References ilXmlImporter\getImportDirectory().

Referenced by importXmlRepresentation().

311  : string
312  {
313  $dir = $this->getImportDirectory();
314  $name = basename($dir);
315  return $name;
316  }
+ 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 253 of file class.ilTestImporter.php.

References ilImportMapping\getMapping().

Referenced by finalRandomTestTaxonomyProcessing().

253  : array
254  {
255  $newMappedFilter = [];
256 
257  foreach ($mappedFilter as $taxId => $taxNodes) {
258  $newTaxId = $mapping->getMapping(
259  'Services/Taxonomy',
260  'tax',
261  (string) $taxId
262  );
263 
264  if (!$newTaxId) {
265  continue;
266  }
267 
268  $newMappedFilter[$newTaxId] = [];
269 
270  foreach ($taxNodes as $taxNodeId) {
271  $newTaxNodeId = $mapping->getMapping(
272  'Services/Taxonomy',
273  'tax_tree',
274  (string) $taxNodeId
275  );
276 
277  if (!$newTaxNodeId) {
278  continue;
279  }
280 
281  $newMappedFilter[$newTaxId][] = $newTaxNodeId;
282  }
283  }
284 
285  return $newMappedFilter;
286  }
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  $test_obj,
  $xmlFile 
)
protected
Parameters
ilImportMapping$mappingRegistry
ilObjTest$test_obj
string$xmlfile
Returns
ilAssQuestionSkillAssignmentList

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

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

Referenced by importXmlRepresentation().

334  {
335  $parser = new ilAssQuestionSkillAssignmentXmlParser($xmlFile);
336  $parser->startParsing();
337 
338  $importer = new ilAssQuestionSkillAssignmentImporter();
339  $importer->setTargetParentObjId($test_obj->getId());
340  $importer->setImportInstallationId((int) $this->getInstallId());
341  $importer->setImportMappingRegistry($mapping);
342  $importer->setImportMappingComponent('Modules/Test');
343  $importer->setImportAssignmentList($parser->getAssignmentList());
344 
345  $importer->import();
346 
347  if ($importer->getFailedImportAssignmentList()->assignmentsExist()) {
348  $qsaImportFails = new ilAssQuestionSkillAssignmentImportFails($test_obj->getId());
349  $qsaImportFails->registerFailedImports($importer->getFailedImportAssignmentList());
350 
351  $test_obj->getObjectProperties()->storePropertyIsOnline(
352  $test_obj->getObjectProperties()->getPropertyIsOnline()->withOffline()
353  );
354  }
355 
356  return $importer->getSuccessImportAssignmentList();
357  }
registerFailedImports(ilAssQuestionSkillAssignmentImportList $assignmentList)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ importRandomQuestionSetConfig()

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

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

Referenced by importXmlRepresentation().

319  {
320  $test_obj->questions = [];
321  $parser = new ilObjTestXMLParser($xmlFile);
322  $parser->setTestOBJ($test_obj);
323  $parser->setImportMapping($a_mapping);
324  $parser->startParsing();
325  }
+ Here is the caller graph for this function:

◆ importSkillLevelThresholds()

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

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

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

Referenced by importXmlRepresentation().

366  {
367  $parser = new ilTestSkillLevelThresholdXmlParser($xmlFile);
368  $parser->initSkillLevelThresholdImportList();
369  $parser->startParsing();
370 
371  $importer = new ilTestSkillLevelThresholdImporter($this->db);
372  $importer->setTargetTestId($test_obj->getTestId());
373  $importer->setImportInstallationId((int) $this->getInstallId());
374  $importer->setImportMappingRegistry($mapping);
375  $importer->setImportedQuestionSkillAssignmentList($assignmentList);
376  $importer->setImportThresholdList($parser->getSkillLevelThresholdImportList());
377  $importer->import();
378 
379  if ($importer->getFailedThresholdImportSkillList()->skillsExist()) {
380  $sltImportFails = new ilTestSkillLevelThresholdImportFails($test_obj->getId());
381  $sltImportFails->registerFailedImports($importer->getFailedThresholdImportSkillList());
382 
383  $test_obj->setOfflineStatus(true);
384  }
385  }
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 62 of file class.ilTestImporter.php.

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

62  : void
63  {
65 
66  if ($new_id = (int) $a_mapping->getMapping('Services/Container', 'objs', $a_id)) {
67  // container content
68  $new_obj = ilObjectFactory::getInstanceByObjId($new_id, false);
69  ilSession::set('tst_import_subdir', $this->getImportPackageName());
70  $new_obj->saveToDb(); // this generates test id first time
71  $question_parent_obj_id = $new_obj->getId();
72  } else {
73  // single object
74  $new_id = (int) $a_mapping->getMapping('Modules/Test', 'tst', 'new_id');
75  $new_obj = ilObjectFactory::getInstanceByObjId($new_id, false);
76 
77  $question_parent_obj_id = (int) (ilSession::get('tst_import_qst_parent') ?? $new_obj->getId());
78  }
79 
80  $new_obj->loadFromDb();
81 
82  list($xml_file, $qti_file) = $this->parseXmlFileNames();
83 
84  if (!@file_exists($xml_file)) {
85  $this->log->write(__METHOD__ . ': Cannot find xml definition: ' . $xml_file);
86  return;
87  }
88  if (!@file_exists($qti_file)) {
89  $this->log->write(__METHOD__ . ': Cannot find xml definition: ' . $qti_file);
90  return;
91  }
92 
93  /* @var ilObjTest $new_obj */
94 
95  // FIXME: Copied from ilObjTestGUI::importVerifiedFileObject
96  // TODO: move all logic to ilObjTest::importVerifiedFile and call
97  // this method from ilObjTestGUI and ilTestImporter
98  $new_obj->getMarkSchema()->flush();
99 
100  $idents = ilSession::get('tst_import_idents');
101 
102  // start parsing of QTI files
103  $qtiParser = new ilQTIParser(
104  $qti_file,
106  $question_parent_obj_id,
107  $idents,
108  $a_mapping->getAllMappings()
109  );
110  $qtiParser->setTestObject($new_obj);
111  $qtiParser->startParsing();
112  $new_obj = $qtiParser->getTestObject();
113 
114  // import page data
115  $questionPageParser = new ilQuestionPageParser($new_obj, $xml_file, basename($this->getImportDirectory()));
116  $questionPageParser->setQuestionMapping($qtiParser->getImportMapping());
117  $questionPageParser->startParsing();
118 
119  $a_mapping = $this->addTexonomyAndQuestionsMapping($qtiParser->getQuestionIdMapping(), $new_obj->getId(), $a_mapping);
120 
121  if ($new_obj->isRandomTest()) {
122  $this->importRandomQuestionSetConfig($new_obj, $xml_file, $a_mapping);
123  }
124 
125  $results_file_path = ilSession::get("tst_import_results_file");
126  // import test results
127  if ($results_file_path !== null && file_exists($results_file_path)) {
128  $results = new ilTestResultsImportParser($results_file_path, $new_obj, $this->db, $this->log, $this->irss);
129  $results->setQuestionIdMapping($a_mapping->getMappingsOfEntity('Modules/Test', 'quest'));
130  $results->setSrcPoolDefIdMapping($a_mapping->getMappingsOfEntity('Modules/Test', 'rnd_src_pool_def'));
131  $results->startParsing();
132  }
133 
134  $new_obj->saveToDb(); // this creates test_fi
135  $new_obj->update(); // this saves ilObject data
136 
137  // import skill assignments
138  $importedAssignmentList = $this->importQuestionSkillAssignments($a_mapping, $new_obj, $xml_file);
139  $this->importSkillLevelThresholds($a_mapping, $importedAssignmentList, $new_obj, $xml_file);
140 
141  $a_mapping->addMapping("Modules/Test", "tst", (string) $a_id, (string) $new_obj->getId());
142  }
static get(string $a_var)
importSkillLevelThresholds(ilImportMapping $mapping, ilAssQuestionSkillAssignmentList $assignmentList, ilObjTest $test_obj, $xmlFile)
importQuestionSkillAssignments(ilImportMapping $mapping, ilObjTest $test_obj, $xmlFile)
addMapping(string $a_comp, string $a_entity, string $a_old_id, string $a_new_id)
parseXmlFileNames()
Create qti and xml file name.
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.
$results
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
importRandomQuestionSetConfig(ilObjTest $test_obj, $xmlFile, $a_mapping)
static set(string $a_var, $a_val)
Set a value.
static _setImportDirectory($a_import_dir=null)
setTestObject(ilObjTest $a_tst_object)
+ Here is the call graph for this function:

◆ parseXmlFileNames()

ilTestImporter::parseXmlFileNames ( )
protected

Create qti and xml file name.

Returns
array

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

References ilXmlImporter\getImportDirectory().

Referenced by importXmlRepresentation().

292  : array
293  {
294  $this->log->write(__METHOD__ . ': ' . $this->getImportDirectory());
295 
296  $basename = basename($this->getImportDirectory());
297 
298  $xml = $this->getImportDirectory() . '/' . $basename . '.xml';
299  $qti = $this->getImportDirectory() . '/' . preg_replace('/test|tst/', 'qti', $basename) . '.xml';
300 
301  return [$xml,$qti];
302  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $db

ilDBInterface ilTestImporter::$db
private

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

◆ $finallyProcessedTestsRegistry

ilTestImporter::$finallyProcessedTestsRegistry = []
static

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

◆ $irss

ResourceStorage ilTestImporter::$irss
private

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

◆ $log

ilLogger ilTestImporter::$log
private

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


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