ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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

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

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

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

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

Referenced by finalProcessing().

171  {
172  require_once 'Services/Taxonomy/classes/class.ilObjTaxonomy.php';
173 
174  // get all new taxonomies of this object and store usage for test object
175 
176  $new_tax_ids = $mapping->getMapping(
177  'Services/Taxonomy',
178  'tax_usage_of_obj',
179  $oldTstObjId
180  );
181 
182  if ($new_tax_ids !== false) {
183  $tax_ids = explode(":", $new_tax_ids);
184 
185  foreach ($tax_ids as $tid) {
186  ilObjTaxonomy::saveUsage($tid, $newTstObjId);
187  }
188  }
189 
190  // update all source pool definition's tax/taxNode ids with new mapped id
191  global $DIC; /* @var ILIAS\DI\Container $DIC */
192  $ilDB = $DIC['ilDB'];
193 
194  require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetSourcePoolDefinitionFactory.php';
196  $ilDB,
197  $testOBJ
198  );
199 
200  require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetSourcePoolDefinitionList.php';
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  }
getMapping($a_comp, $a_entity, $a_old_id)
Get a mapping.
global $DIC
Definition: saml.php:7
getNewMappedTaxonomyFilter(ilImportMapping $mapping, array $mappedFilter)
static saveUsage($a_tax_id, $a_obj_id)
Save Usage.
global $ilDB
+ 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().

283  {
284  $dir = $this->getImportDirectory();
285  $dir = dirname($dir);
286  return $dir;
287  }
getImportDirectory()
Get import directory.
+ 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().

290  {
291  $dir = $this->getImportDirectory();
292  $name = basename($dir);
293  return $name;
294  }
getImportDirectory()
Get import directory.
+ 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().

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($a_comp, $a_entity, $a_old_id)
Get a mapping.
+ 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 $parser, ilObject\getId(), ilXmlImporter\getInstallId(), ilAssQuestionSkillAssignmentImportFails\registerFailedImports(), and ilObjTest\setOnline().

Referenced by importXmlRepresentation().

312  {
313  require_once 'Modules/TestQuestionPool/classes/questions/class.ilAssQuestionSkillAssignmentXmlParser.php';
315  $parser->startParsing();
316 
317  require_once 'Modules/TestQuestionPool/classes/questions/class.ilAssQuestionSkillAssignmentImporter.php';
318  $importer = new ilAssQuestionSkillAssignmentImporter();
319  $importer->setTargetParentObjId($testOBJ->getId());
320  $importer->setImportInstallationId($this->getInstallId());
321  $importer->setImportMappingRegistry($mapping);
322  $importer->setImportMappingComponent('Modules/Test');
323  $importer->setImportAssignmentList($parser->getAssignmentList());
324 
325  $importer->import();
326 
327  if ($importer->getFailedImportAssignmentList()->assignmentsExist()) {
328  require_once 'Modules/TestQuestionPool/classes/questions/class.ilAssQuestionSkillAssignmentImportFails.php';
329  $qsaImportFails = new ilAssQuestionSkillAssignmentImportFails($testOBJ->getId());
330  $qsaImportFails->registerFailedImports($importer->getFailedImportAssignmentList());
331 
332  $testOBJ->setOnline(false);
333  }
334 
335  return $importer->getSuccessImportAssignmentList();
336  }
setOnline($a_online=true)
getId()
get object id public
$parser
Definition: BPMN2Parser.php:23
getInstallId()
Get installation id.
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 
)
protected

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

References $parser.

Referenced by importXmlRepresentation().

297  {
298  require_once 'Modules/Test/classes/class.ilObjTestXMLParser.php';
299  $parser = new ilObjTestXMLParser($xmlFile);
300  $parser->setTestOBJ($testOBJ);
301  $parser->setImportMapping($a_mapping);
302  $parser->startParsing();
303  }
$parser
Definition: BPMN2Parser.php:23
+ 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 344 of file class.ilTestImporter.php.

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

Referenced by importXmlRepresentation().

345  {
346  require_once 'Modules/Test/classes/class.ilTestSkillLevelThresholdXmlParser.php';
348  $parser->startParsing();
349 
350  require_once 'Modules/Test/classes/class.ilTestSkillLevelThresholdImporter.php';
351  $importer = new ilTestSkillLevelThresholdImporter();
352  $importer->setTargetTestId($testOBJ->getTestId());
353  $importer->setImportInstallationId($this->getInstallId());
354  $importer->setImportMappingRegistry($mapping);
355  $importer->setImportedQuestionSkillAssignmentList($assignmentList);
356  $importer->setImportThresholdList($parser->getSkillLevelThresholdImportList());
357  $importer->import();
358 
359  if ($importer->getFailedThresholdImportSkillList()->skillsExist()) {
360  require_once 'Modules/Test/classes/class.ilTestSkillLevelThresholdImportFails.php';
361  $sltImportFails = new ilTestSkillLevelThresholdImportFails($testOBJ->getId());
362  $sltImportFails->registerFailedImports($importer->getFailedThresholdImportSkillList());
363 
364  $testOBJ->setOfflineStatus(true);
365  }
366  }
registerFailedImports(ilAssQuestionAssignedSkillList $skillList)
getTestId()
Gets the database id of the additional test data.
getId()
get object id public
$parser
Definition: BPMN2Parser.php:23
setOfflineStatus($a_status)
Set offline status.
getInstallId()
Get installation id.
+ 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

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

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

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

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: saml.php:7
getImportDirectory()
Get import directory.
+ 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: