ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTestImporter.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/Export/classes/class.ilXmlImporter.php");
5 
14 {
21  function importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
22  {
23  // Container import => test object already created
24  include_once "./Modules/Test/classes/class.ilObjTest.php";
26 
27  if($new_id = $a_mapping->getMapping('Services/Container','objs',$a_id))
28  {
29  $newObj = ilObjectFactory::getInstanceByObjId($new_id,false);
30  }
31  else // case ii, non container
32  {
33  // Shouldn't happen
34  $GLOBALS['ilLog']->write(__METHOD__.': Called in non container mode');
35  return false;
36  }
37 
38  list($xml_file,$qti_file) = $this->parseXmlFileNames();
39 
40  if(!@file_exists($xml_file))
41  {
42  $GLOBALS['ilLog']->write(__METHOD__.': Cannot find xml definition: '. $xml_file);
43  return false;
44  }
45  if(!@file_exists($qti_file))
46  {
47  $GLOBALS['ilLog']->write(__METHOD__.': Cannot find xml definition: '. $qti_file);
48  return false;
49  }
50 
51  // FIXME: Copied from ilObjTestGUI::importVerifiedFileObject
52  // TODO: move all logic to ilObjTest::importVerifiedFile and call
53  // this method from ilObjTestGUI and ilTestImporter
54  $newObj->mark_schema->flush();
55 
56  // Important: The container question pool is the test object implicitly. If we do not pass a valid object id here, there will be problems concerning
57  // filesystem path determinations
58  $qpl_id = $newObj->getId();
59 
60  // start parsing of QTI files
61  include_once "./Services/QTI/classes/class.ilQTIParser.php";
62  $qtiParser = new ilQTIParser($qti_file, IL_MO_PARSE_QTI, $qpl_id , array());
63  $qtiParser->setTestObject($newObj);
64  $result = $qtiParser->startParsing();
65  $newObj->saveToDb();
66 
67  // import page data
68  include_once ("./Modules/LearningModule/classes/class.ilContObjParser.php");
69  $contParser = new ilContObjParser($newObj, $xml_file, basename($this->getImportDirectory()));
70  $contParser->setQuestionMapping($qtiParser->getImportMapping());
71  $contParser->startParsing();
72 
73  $a_mapping->addMapping("Modules/Test", "tst", $a_id, $newObj->getId());
74 
76  }
77 
78 
83  protected function parseXmlFileNames()
84  {
85  $GLOBALS['ilLog']->write(__METHOD__.': '.$this->getImportDirectory());
86 
87  $basename = basename($this->getImportDirectory());
88 
89  $xml = $this->getImportDirectory().'/'.$basename.'.xml';
90  $qti = $this->getImportDirectory().'/'.preg_replace('/test|tst/', 'qti', $basename).'.xml';
91 
92  return array($xml,$qti);
93  }
94 }
95 
96 ?>