ILIAS  release_7 Revision v7.30-3-g800a261c036
ilTestImporter Class Reference

Importer class for files. More...

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

Public Member Functions

 importXmlRepresentation ($a_entity, $a_id, $a_xml, $a_mapping)
 Import XML. More...
 
 finalProcessing ($a_mapping)
 Final processing. 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...
 

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...
 
 importRandomQuestionSetConfig (ilObjTest $testOBJ, $xmlFile, $a_mapping)
 
 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
 $skip_entities = array()
 
 $imp
 

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.ilTestImporter.php.

Member Function Documentation

◆ finalProcessing()

ilTestImporter::finalProcessing (   $a_mapping)

Final processing.

Parameters
ilImportMapping$a_mapping
Returns

Reimplemented from ilXmlImporter.

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

145 {
146 $maps = $a_mapping->getMappingsOfEntity("Modules/Test", "tst");
147
148 foreach ($maps as $old => $new) {
149 if ($old == "new_id" || (int) $old <= 0) {
150 continue;
151 }
152
153 if (isset(self::$finallyProcessedTestsRegistry[$new])) {
154 continue;
155 }
156
157 /* @var ilObjTest $testOBJ */
158 $testOBJ = ilObjectFactory::getInstanceByObjId($new, false);
159 if ($testOBJ->isRandomTest()) {
160 $this->finalRandomTestTaxonomyProcessing($a_mapping, $old, $new, $testOBJ);
161 }
162
163 self::$finallyProcessedTestsRegistry[$new] = true;
164 }
165 }
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
finalRandomTestTaxonomyProcessing(ilImportMapping $mapping, $oldTstObjId, $newTstObjId, ilObjTest $testOBJ)

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

+ Here is the call graph for this function:

◆ finalRandomTestTaxonomyProcessing()

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

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

168 {
169 require_once 'Services/Taxonomy/classes/class.ilObjTaxonomy.php';
170
171 // get all new taxonomies of this object and store usage for test object
172
173 $new_tax_ids = $mapping->getMapping(
174 'Services/Taxonomy',
175 'tax_usage_of_obj',
176 $oldTstObjId
177 );
178
179 if ($new_tax_ids !== false) {
180 $tax_ids = explode(":", $new_tax_ids);
181
182 foreach ($tax_ids as $tid) {
183 ilObjTaxonomy::saveUsage($tid, $newTstObjId);
184 }
185 }
186
187 // update all source pool definition's tax/taxNode ids with new mapped id
188 global $DIC; /* @var ILIAS\DI\Container $DIC */
189 $ilDB = $DIC['ilDB'];
190
191 require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetSourcePoolDefinitionFactory.php';
193 $ilDB,
194 $testOBJ
195 );
196
197 require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetSourcePoolDefinitionList.php';
199 $ilDB,
200 $testOBJ,
201 $srcPoolDefFactory
202 );
203
204 $srcPoolDefList->loadDefinitions();
205
206 foreach ($srcPoolDefList as $definition) {
207 // #21330
208 if (!is_array($definition->getMappedTaxonomyFilter()) || 0 === count($definition->getMappedTaxonomyFilter())) {
209 continue;
210 }
211
212 $definition->setMappedTaxonomyFilter(
214 $mapping,
215 $definition->getMappedTaxonomyFilter()
216 )
217 );
218 $definition->saveToDb();
219 }
220 }
getMapping($a_comp, $a_entity, $a_old_id)
Get a mapping.
static saveUsage($a_tax_id, $a_obj_id)
Save Usage.
getNewMappedTaxonomyFilter(ilImportMapping $mapping, array $mappedFilter)
global $DIC
Definition: goto.php:24
global $ilDB

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

Referenced by finalProcessing().

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

◆ getImportDirectoryContainer()

ilTestImporter::getImportDirectoryContainer ( )
private

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

280 {
281 $dir = $this->getImportDirectory();
282 $dir = dirname($dir);
283 return $dir;
284 }
getImportDirectory()
Get import directory.

References ilXmlImporter\getImportDirectory().

Referenced by importXmlRepresentation().

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

◆ getImportPackageName()

ilTestImporter::getImportPackageName ( )
private

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

287 {
288 $dir = $this->getImportDirectory();
289 $name = basename($dir);
290 return $name;
291 }
if($format !==null) $name
Definition: metadata.php:230

References $name, and ilXmlImporter\getImportDirectory().

Referenced by importXmlRepresentation().

+ 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 227 of file class.ilTestImporter.php.

228 {
229 $newMappedFilter = array();
230
231 foreach ($mappedFilter as $taxId => $taxNodes) {
232 $newTaxId = $mapping->getMapping(
233 'Services/Taxonomy',
234 'tax',
235 $taxId
236 );
237
238 if (!$newTaxId) {
239 continue;
240 }
241
242 $newMappedFilter[$newTaxId] = array();
243
244 foreach ($taxNodes as $taxNodeId) {
245 $newTaxNodeId = $mapping->getMapping(
246 'Services/Taxonomy',
247 'tax_tree',
248 $taxNodeId
249 );
250
251 if (!$newTaxNodeId) {
252 continue;
253 }
254
255 $newMappedFilter[$newTaxId][] = $newTaxNodeId;
256 }
257 }
258
259 return $newMappedFilter;
260 }

References ilImportMapping\getMapping().

Referenced by finalRandomTestTaxonomyProcessing().

+ 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 308 of file class.ilTestImporter.php.

309 {
310 require_once 'Modules/TestQuestionPool/classes/questions/class.ilAssQuestionSkillAssignmentXmlParser.php';
311 $parser = new ilAssQuestionSkillAssignmentXmlParser($xmlFile);
312 $parser->startParsing();
313
314 require_once 'Modules/TestQuestionPool/classes/questions/class.ilAssQuestionSkillAssignmentImporter.php';
315 $importer = new ilAssQuestionSkillAssignmentImporter();
316 $importer->setTargetParentObjId($testOBJ->getId());
317 $importer->setImportInstallationId($this->getInstallId());
318 $importer->setImportMappingRegistry($mapping);
319 $importer->setImportMappingComponent('Modules/Test');
320 $importer->setImportAssignmentList($parser->getAssignmentList());
321
322 $importer->import();
323
324 if ($importer->getFailedImportAssignmentList()->assignmentsExist()) {
325 require_once 'Modules/TestQuestionPool/classes/questions/class.ilAssQuestionSkillAssignmentImportFails.php';
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)
getId()
get object id @access public
getInstallId()
Get installation id.

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

Referenced by importXmlRepresentation().

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

◆ importRandomQuestionSetConfig()

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

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

294 {
295 require_once 'Modules/Test/classes/class.ilObjTestXMLParser.php';
296 $parser = new ilObjTestXMLParser($xmlFile);
297 $parser->setTestOBJ($testOBJ);
298 $parser->setImportMapping($a_mapping);
299 $parser->startParsing();
300 }

Referenced by importXmlRepresentation().

+ 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.

342 {
343 require_once 'Modules/Test/classes/class.ilTestSkillLevelThresholdXmlParser.php';
344 $parser = new ilTestSkillLevelThresholdXmlParser($xmlFile);
345 $parser->startParsing();
346
347 require_once 'Modules/Test/classes/class.ilTestSkillLevelThresholdImporter.php';
348 $importer = new ilTestSkillLevelThresholdImporter();
349 $importer->setTargetTestId($testOBJ->getTestId());
350 $importer->setImportInstallationId($this->getInstallId());
351 $importer->setImportMappingRegistry($mapping);
352 $importer->setImportedQuestionSkillAssignmentList($assignmentList);
353 $importer->setImportThresholdList($parser->getSkillLevelThresholdImportList());
354 $importer->import();
355
356 if ($importer->getFailedThresholdImportSkillList()->skillsExist()) {
357 require_once 'Modules/Test/classes/class.ilTestSkillLevelThresholdImportFails.php';
358 $sltImportFails = new ilTestSkillLevelThresholdImportFails($testOBJ->getId());
359 $sltImportFails->registerFailedImports($importer->getFailedThresholdImportSkillList());
360
361 $testOBJ->setOfflineStatus(true);
362 }
363 }
getTestId()
Gets the database id of the additional test data.
setOfflineStatus($a_status)
Set offline status.

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

Referenced by importXmlRepresentation().

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

◆ importXmlRepresentation()

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

Import XML.

Parameters

return

Reimplemented from ilXmlImporter.

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

27 {
28 // Container import => test object already created
29 include_once "./Modules/Test/classes/class.ilObjTest.php";
31
32 if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_id)) {
33 // container content
34 $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
35 $_SESSION['tst_import_subdir'] = $this->getImportPackageName();
36 $newObj->saveToDb(); // this generates test id first time
37 $questionParentObjId = $newObj->getId();
38 } else {
39 // single object
40 $new_id = $a_mapping->getMapping('Modules/Test', 'tst', 'new_id');
41 $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
42
43 if (isset($_SESSION['tst_import_qst_parent'])) {
44 $questionParentObjId = $_SESSION['tst_import_qst_parent'];
45 } else {
46 $questionParentObjId = $newObj->getId();
47 }
48 }
49
50 $newObj->loadFromDb();
51
52 list($xml_file, $qti_file) = $this->parseXmlFileNames();
53
54 global $DIC; /* @var ILIAS\DI\Container $DIC */
55 if (!@file_exists($xml_file)) {
56 $DIC['ilLog']->write(__METHOD__ . ': Cannot find xml definition: ' . $xml_file);
57 return false;
58 }
59 if (!@file_exists($qti_file)) {
60 $DIC['ilLog']->write(__METHOD__ . ': Cannot find xml definition: ' . $qti_file);
61 return false;
62 }
63
64 /* @var ilObjTest $newObj */
65
66 // FIXME: Copied from ilObjTestGUI::importVerifiedFileObject
67 // TODO: move all logic to ilObjTest::importVerifiedFile and call
68 // this method from ilObjTestGUI and ilTestImporter
69 $newObj->mark_schema->flush();
70
71
72 if (isset($_SESSION['tst_import_idents'])) {
73 $idents = $_SESSION['tst_import_idents'];
74 } else {
75 $idents = null;
76 }
77
78 // start parsing of QTI files
79 include_once "./Services/QTI/classes/class.ilQTIParser.php";
80 $qtiParser = new ilQTIParser($qti_file, IL_MO_PARSE_QTI, $questionParentObjId, $idents);
81 $qtiParser->setTestObject($newObj);
82 $result = $qtiParser->startParsing();
83
84 // import page data
85 $contParser = new ilQuestionPageParser($newObj, $xml_file, basename($this->getImportDirectory()));
86 $contParser->setQuestionMapping($qtiParser->getImportMapping());
87 $contParser->startParsing();
88
89 foreach ($qtiParser->getQuestionIdMapping() as $oldQuestionId => $newQuestionId) {
90 $a_mapping->addMapping(
91 "Services/Taxonomy",
92 "tax_item",
93 "tst:quest:$oldQuestionId",
94 $newQuestionId
95 );
96
97 $a_mapping->addMapping(
98 "Services/Taxonomy",
99 "tax_item_obj_id",
100 "tst:quest:$oldQuestionId",
101 $newObj->getId()
102 );
103
104 $a_mapping->addMapping(
105 "Modules/Test",
106 "quest",
107 $oldQuestionId,
108 $newQuestionId
109 );
110 }
111
112 if ($newObj->isRandomTest()) {
113 $newObj->questions = array();
114 $this->importRandomQuestionSetConfig($newObj, $xml_file, $a_mapping);
115 }
116
117 // import test results
118 if (@file_exists($_SESSION["tst_import_results_file"])) {
119 include_once("./Modules/Test/classes/class.ilTestResultsImportParser.php");
120 $results = new ilTestResultsImportParser($_SESSION["tst_import_results_file"], $newObj);
121 $results->setQuestionIdMapping($a_mapping->getMappingsOfEntity('Modules/Test', 'quest'));
122 $results->setSrcPoolDefIdMapping($a_mapping->getMappingsOfEntity('Modules/Test', 'rnd_src_pool_def'));
123 $results->startParsing();
124 }
125
126 $newObj->saveToDb(); // this creates test_fi
127 $newObj->update(); // this saves ilObject data
128
129 // import skill assignments
130 $importedAssignmentList = $this->importQuestionSkillAssignments($a_mapping, $newObj, $xml_file);
131 $this->importSkillLevelThresholds($a_mapping, $importedAssignmentList, $newObj, $xml_file);
132
133 $a_mapping->addMapping("Modules/Test", "tst", $a_id, $newObj->getId());
134
136 }
$result
$_SESSION["AccountId"]
const IL_MO_PARSE_QTI
static _setImportDirectory($a_import_dir=null)
set import directory
Legacy Content Object Parser.
importQuestionSkillAssignments(ilImportMapping $mapping, ilObjTest $testOBJ, $xmlFile)
importRandomQuestionSetConfig(ilObjTest $testOBJ, $xmlFile, $a_mapping)
importSkillLevelThresholds(ilImportMapping $mapping, ilAssQuestionSkillAssignmentList $assignmentList, ilObjTest $testOBJ, $xmlFile)
parseXmlFileNames()
Create qti and xml file name.
$results

References $_SESSION, $DIC, $result, $results, ilObjTest\_setImportDirectory(), ilXmlImporter\getImportDirectory(), getImportDirectoryContainer(), getImportPackageName(), ilObjectFactory\getInstanceByObjId(), IL_MO_PARSE_QTI, importQuestionSkillAssignments(), importRandomQuestionSetConfig(), importSkillLevelThresholds(), and parseXmlFileNames().

+ Here is the call graph for this function:

◆ parseXmlFileNames()

ilTestImporter::parseXmlFileNames ( )
protected

Create qti and xml file name.

Returns
array

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

267 {
268 global $DIC; /* @var ILIAS\DI\Container $DIC */
269 $DIC['ilLog']->write(__METHOD__ . ': ' . $this->getImportDirectory());
270
271 $basename = basename($this->getImportDirectory());
272
273 $xml = $this->getImportDirectory() . '/' . $basename . '.xml';
274 $qti = $this->getImportDirectory() . '/' . preg_replace('/test|tst/', 'qti', $basename) . '.xml';
275
276 return array($xml,$qti);
277 }
$xml
Definition: metadata.php:332

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

Referenced by importXmlRepresentation().

+ 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 18 of file class.ilTestImporter.php.


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