ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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)
 
 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 151 of file class.ilTestImporter.php.

References $new, $old, finalRandomTestTaxonomyProcessing(), and ilObjectFactory\getInstanceByObjId().

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

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

Referenced by finalProcessing().

179  {
180  require_once 'Services/Taxonomy/classes/class.ilObjTaxonomy.php';
181 
182  // get all new taxonomies of this object and store usage for test object
183 
184  $new_tax_ids = $mapping->getMapping(
185  'Services/Taxonomy', 'tax_usage_of_obj', $oldTstObjId
186  );
187 
188  if($new_tax_ids !== false)
189  {
190  $tax_ids = explode(":", $new_tax_ids);
191 
192  foreach($tax_ids as $tid)
193  {
194  ilObjTaxonomy::saveUsage($tid, $newTstObjId);
195  }
196  }
197 
198  // update all source pool definition's tax/taxNode ids with new mapped id
199 
200  $ilDB = isset($GLOBALS['DIC']) ? $GLOBALS['DIC']['ilDB'] : $GLOBALS['ilDB'];
201 
202  require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetSourcePoolDefinitionFactory.php';
204  $ilDB, $testOBJ
205  );
206 
207  require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetSourcePoolDefinitionList.php';
209  $ilDB, $testOBJ, $srcPoolDefFactory
210  );
211 
212  $srcPoolDefList->loadDefinitions();
213 
214  foreach($srcPoolDefList as $definition)
215  {
216  if( !$definition->getMappedFilterTaxId() && !$definition->getMappedFilterTaxNodeId() )
217  {
218  continue;
219  }
220 
221  $newTaxId = $mapping->getMapping(
222  'Services/Taxonomy', 'tax', $definition->getMappedFilterTaxId()
223  );
224 
225  $definition->setMappedFilterTaxId($newTaxId ? $newTaxId : null);
226 
227  $newTaxNodeId = $mapping->getMapping(
228  'Services/Taxonomy', 'tax_tree', $definition->getMappedFilterTaxNodeId()
229  );
230 
231  $definition->setMappedFilterTaxNodeId($newTaxNodeId ? $newTaxNodeId : null);
232 
233  $definition->saveToDb();
234  }
235  }
getMapping($a_comp, $a_entity, $a_old_id)
Get a mapping.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
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 253 of file class.ilTestImporter.php.

References ilXmlImporter\getImportDirectory().

Referenced by importXmlRepresentation().

254  {
255  $dir = $this->getImportDirectory();
256  $dir = dirname($dir);
257  return $dir;
258  }
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 260 of file class.ilTestImporter.php.

References ilXmlImporter\getImportDirectory().

Referenced by importXmlRepresentation().

261  {
262  $dir = $this->getImportDirectory();
263  $name = basename($dir);
264  return $name;
265  }
getImportDirectory()
Get import directory.
+ 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 282 of file class.ilTestImporter.php.

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

Referenced by importXmlRepresentation().

283  {
284  require_once 'Modules/TestQuestionPool/classes/questions/class.ilAssQuestionSkillAssignmentXmlParser.php';
286  $parser->startParsing();
287 
288  require_once 'Modules/TestQuestionPool/classes/questions/class.ilAssQuestionSkillAssignmentImporter.php';
289  $importer = new ilAssQuestionSkillAssignmentImporter();
290  $importer->setTargetParentObjId($testOBJ->getId());
291  $importer->setImportInstallationId($this->getInstallId());
292  $importer->setImportMappingRegistry($mapping);
293  $importer->setImportMappingComponent('Modules/Test');
294  $importer->setImportAssignmentList($parser->getAssignmentList());
295 
296  $importer->import();
297 
298  if( $importer->getFailedImportAssignmentList()->assignmentsExist() )
299  {
300  require_once 'Modules/TestQuestionPool/classes/questions/class.ilAssQuestionSkillAssignmentImportFails.php';
301  $qsaImportFails = new ilAssQuestionSkillAssignmentImportFails($testOBJ->getId());
302  $qsaImportFails->registerFailedImports($importer->getFailedImportAssignmentList());
303 
304  $testOBJ->setOnline(false);
305  }
306 
307  return $importer->getSuccessImportAssignmentList();
308  }
setOnline($a_online=true)
getId()
get object id public
$parser
Definition: BPMN2Parser.php:24
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 267 of file class.ilTestImporter.php.

References $parser.

Referenced by importXmlRepresentation().

268  {
269  require_once 'Modules/Test/classes/class.ilObjTestXMLParser.php';
270  $parser = new ilObjTestXMLParser($xmlFile);
271  $parser->setTestOBJ($testOBJ);
272  $parser->setImportMapping($a_mapping);
273  $parser->startParsing();
274  }
$parser
Definition: BPMN2Parser.php:24
+ 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 316 of file class.ilTestImporter.php.

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

Referenced by importXmlRepresentation().

317  {
318  require_once 'Modules/Test/classes/class.ilTestSkillLevelThresholdXmlParser.php';
320  $parser->startParsing();
321 
322  require_once 'Modules/Test/classes/class.ilTestSkillLevelThresholdImporter.php';
323  $importer = new ilTestSkillLevelThresholdImporter();
324  $importer->setTargetTestId($testOBJ->getTestId());
325  $importer->setImportInstallationId($this->getInstallId());
326  $importer->setImportMappingRegistry($mapping);
327  $importer->setImportedQuestionSkillAssignmentList($assignmentList);
328  $importer->setImportThresholdList($parser->getSkillLevelThresholdImportList());
329  $importer->import();
330 
331  if( $importer->getFailedThresholdImportSkillList()->skillsExist() )
332  {
333  require_once 'Modules/Test/classes/class.ilTestSkillLevelThresholdImportFails.php';
334  $sltImportFails = new ilTestSkillLevelThresholdImportFails($testOBJ->getId());
335  $sltImportFails->registerFailedImports($importer->getFailedThresholdImportSkillList());
336 
337  $testOBJ->setOnline(false);
338  }
339  }
setOnline($a_online=true)
registerFailedImports(ilAssQuestionAssignedSkillList $skillList)
getTestId()
Gets the database id of the additional test data.
getId()
get object id public
$parser
Definition: BPMN2Parser.php:24
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, $GLOBALS, $result, $results, ilObjTest\_setImportDirectory(), array, 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  {
34  // container content
35  $newObj = ilObjectFactory::getInstanceByObjId($new_id,false);
36  $_SESSION['tst_import_subdir'] = $this->getImportPackageName();
37  $newObj->saveToDb(); // this generates test id first time
38  $questionParentObjId = $newObj->getId();
39  $newObj->setOnline(true);
40  $questionParentObjId = $newObj->getId();
41  }
42  else
43  {
44  // single object
45  $new_id = $a_mapping->getMapping('Modules/Test', 'tst', 'new_id');
46  $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
47 
48  if( isset($_SESSION['tst_import_qst_parent']) )
49  {
50  $questionParentObjId = $_SESSION['tst_import_qst_parent'];
51  }
52  else
53  {
54  $questionParentObjId = $newObj->getId();
55  }
56  }
57 
58  $newObj->loadFromDb();
59 
60  list($xml_file,$qti_file) = $this->parseXmlFileNames();
61 
62  if(!@file_exists($xml_file))
63  {
64  $GLOBALS['ilLog']->write(__METHOD__.': Cannot find xml definition: '. $xml_file);
65  return false;
66  }
67  if(!@file_exists($qti_file))
68  {
69  $GLOBALS['ilLog']->write(__METHOD__.': Cannot find xml definition: '. $qti_file);
70  return false;
71  }
72 
73  /* @var ilObjTest $newObj */
74 
75  // FIXME: Copied from ilObjTestGUI::importVerifiedFileObject
76  // TODO: move all logic to ilObjTest::importVerifiedFile and call
77  // this method from ilObjTestGUI and ilTestImporter
78  $newObj->mark_schema->flush();
79 
80 
81  if( isset($_SESSION['tst_import_idents']) )
82  {
83  $idents = $_SESSION['tst_import_idents'];
84  }
85  else
86  {
87  $idents = null;
88  }
89 
90  // start parsing of QTI files
91  include_once "./Services/QTI/classes/class.ilQTIParser.php";
92  $qtiParser = new ilQTIParser($qti_file, IL_MO_PARSE_QTI, $questionParentObjId, $idents);
93  $qtiParser->setTestObject($newObj);
94  $result = $qtiParser->startParsing();
95 
96  // import page data
97  include_once ("./Modules/LearningModule/classes/class.ilContObjParser.php");
98  $contParser = new ilContObjParser($newObj, $xml_file, basename($this->getImportDirectory()));
99  $contParser->setQuestionMapping($qtiParser->getImportMapping());
100  $contParser->startParsing();
101 
102  foreach($qtiParser->getQuestionIdMapping() as $oldQuestionId => $newQuestionId)
103  {
104  $a_mapping->addMapping(
105  "Services/Taxonomy", "tax_item", "tst:quest:$oldQuestionId", $newQuestionId
106  );
107 
108  $a_mapping->addMapping(
109  "Services/Taxonomy", "tax_item_obj_id", "tst:quest:$oldQuestionId", $newObj->getId()
110  );
111 
112  $a_mapping->addMapping(
113  "Modules/Test", "quest", $oldQuestionId, $newQuestionId
114  );
115  }
116 
117  if( $newObj->isRandomTest() )
118  {
119  $newObj->questions = array();
120  $this->importRandomQuestionSetConfig($newObj, $xml_file, $a_mapping);
121  }
122 
123  // import test results
124  if(@file_exists($_SESSION["tst_import_results_file"]))
125  {
126  include_once("./Modules/Test/classes/class.ilTestResultsImportParser.php");
127  $results = new ilTestResultsImportParser($_SESSION["tst_import_results_file"], $newObj);
128  $results->setQuestionIdMapping($a_mapping->getMappingsOfEntity('Modules/Test', 'quest'));
129  $results->setSrcPoolDefIdMapping($a_mapping->getMappingsOfEntity('Modules/Test', 'rnd_src_pool_def'));
130  $results->startParsing();
131  }
132 
133  $newObj->saveToDb(); // this creates test_fi
134  $newObj->update(); // this saves ilObject data
135 
136  // import skill assignments
137  $importedAssignmentList = $this->importQuestionSkillAssignments($a_mapping, $newObj, $xml_file);
138  $this->importSkillLevelThresholds($a_mapping, $importedAssignmentList, $newObj, $xml_file);
139 
140  $a_mapping->addMapping("Modules/Test", "tst", $a_id, $newObj->getId());
141 
143  }
Content Object Parser.
$_SESSION["AccountId"]
$result
getImportDirectory()
Get import directory.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
parseXmlFileNames()
Create qti and xml file name.
importQuestionSkillAssignments(ilImportMapping $mapping, ilObjTest $testOBJ, $xmlFile)
const IL_MO_PARSE_QTI
importRandomQuestionSetConfig(ilObjTest $testOBJ, $xmlFile, $a_mapping)
$results
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
Create styles array
The data for the language used.
importSkillLevelThresholds(ilImportMapping $mapping, ilAssQuestionSkillAssignmentList $assignmentList, ilObjTest $testOBJ, $xmlFile)
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 241 of file class.ilTestImporter.php.

References $GLOBALS, array, and ilXmlImporter\getImportDirectory().

Referenced by importXmlRepresentation().

242  {
243  $GLOBALS['ilLog']->write(__METHOD__.': '.$this->getImportDirectory());
244 
245  $basename = basename($this->getImportDirectory());
246 
247  $xml = $this->getImportDirectory().'/'.$basename.'.xml';
248  $qti = $this->getImportDirectory().'/'.preg_replace('/test|tst/', 'qti', $basename).'.xml';
249 
250  return array($xml,$qti);
251  }
getImportDirectory()
Get import directory.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
Create styles array
The data for the language used.
+ 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: