ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 146 of file class.ilTestImporter.php.

147 {
148 $maps = $a_mapping->getMappingsOfEntity("Modules/Test", "tst");
149
150 foreach ($maps as $old => $new) {
151 if ($old == "new_id" || (int) $old <= 0) {
152 continue;
153 }
154
155 if (isset(self::$finallyProcessedTestsRegistry[$new])) {
156 continue;
157 }
158
159 /* @var ilObjTest $testOBJ */
160 $testOBJ = ilObjectFactory::getInstanceByObjId($new, false);
161 if ($testOBJ->isRandomTest()) {
162 $this->finalRandomTestTaxonomyProcessing($a_mapping, $old, $new, $testOBJ);
163 }
164
165 self::$finallyProcessedTestsRegistry[$new] = true;
166 }
167 }
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)
$old

References $new, $old, 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 169 of file class.ilTestImporter.php.

170 {
171 require_once 'Services/Taxonomy/classes/class.ilObjTaxonomy.php';
172
173 // get all new taxonomies of this object and store usage for test object
174
175 $new_tax_ids = $mapping->getMapping(
176 'Services/Taxonomy',
177 'tax_usage_of_obj',
178 $oldTstObjId
179 );
180
181 if ($new_tax_ids !== false) {
182 $tax_ids = explode(":", $new_tax_ids);
183
184 foreach ($tax_ids as $tid) {
185 ilObjTaxonomy::saveUsage($tid, $newTstObjId);
186 }
187 }
188
189 // update all source pool definition's tax/taxNode ids with new mapped id
190
191 $ilDB = isset($GLOBALS['DIC']) ? $GLOBALS['DIC']['ilDB'] : $GLOBALS['ilDB'];
192
193 require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetSourcePoolDefinitionFactory.php';
195 $ilDB,
196 $testOBJ
197 );
198
199 require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetSourcePoolDefinitionList.php';
201 $ilDB,
202 $testOBJ,
203 $srcPoolDefFactory
204 );
205
206 $srcPoolDefList->loadDefinitions();
207
208 foreach ($srcPoolDefList as $definition) {
209 // #21330
210 if (!is_array($definition->getMappedTaxonomyFilter()) || 0 === count($definition->getMappedTaxonomyFilter())) {
211 continue;
212 }
213
214 $definition->setMappedTaxonomyFilter(
216 $mapping,
217 $definition->getMappedTaxonomyFilter()
218 )
219 );
220 $definition->saveToDb();
221 }
222 }
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)
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
global $ilDB

References $GLOBALS, $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 280 of file class.ilTestImporter.php.

281 {
282 $dir = $this->getImportDirectory();
283 $dir = dirname($dir);
284 return $dir;
285 }
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 287 of file class.ilTestImporter.php.

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

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

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

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

310 {
311 require_once 'Modules/TestQuestionPool/classes/questions/class.ilAssQuestionSkillAssignmentXmlParser.php';
313 $parser->startParsing();
314
315 require_once 'Modules/TestQuestionPool/classes/questions/class.ilAssQuestionSkillAssignmentImporter.php';
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 require_once 'Modules/TestQuestionPool/classes/questions/class.ilAssQuestionSkillAssignmentImportFails.php';
327 $qsaImportFails = new ilAssQuestionSkillAssignmentImportFails($testOBJ->getId());
328 $qsaImportFails->registerFailedImports($importer->getFailedImportAssignmentList());
329
330 $testOBJ->setOnline(false);
331 }
332
333 return $importer->getSuccessImportAssignmentList();
334 }
$parser
Definition: BPMN2Parser.php:23
setOnline($a_online=true)
getId()
get object id @access public
getInstallId()
Get installation id.

References $parser, 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 294 of file class.ilTestImporter.php.

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

References $parser.

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

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

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

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

References $_SESSION, $GLOBALS, $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 268 of file class.ilTestImporter.php.

269 {
270 $GLOBALS['ilLog']->write(__METHOD__ . ': ' . $this->getImportDirectory());
271
272 $basename = basename($this->getImportDirectory());
273
274 $xml = $this->getImportDirectory() . '/' . $basename . '.xml';
275 $qti = $this->getImportDirectory() . '/' . preg_replace('/test|tst/', 'qti', $basename) . '.xml';
276
277 return array($xml,$qti);
278 }
$xml
Definition: metadata.php:240

References $GLOBALS, $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: