ILIAS  eassessment Revision 61809
 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  if($new_id = $a_mapping->getMapping('Services/Container','objs',$a_id))
25  {
26  $newObj = ilObjectFactory::getInstanceByObjId($new_id,false);
27  $newObj->setImportDirectory(dirname(rtrim($this->getImportDirectory(),'/')));
28  }
29  else // case ii, non container
30  {
31  // Shouldn't happen
32  $GLOBALS['ilLog']->write(__METHOD__.': Called in non container mode');
33  return false;
34  }
35 
36  list($xml_file,$qti_file) = $this->parseXmlFileNames();
37 
38  if(!@file_exists($xml_file))
39  {
40  $GLOBALS['ilLog']->write(__METHOD__.': Cannot find xml definition: '. $xml_file);
41  return false;
42  }
43  if(!@file_exists($qti_file))
44  {
45  $GLOBALS['ilLog']->write(__METHOD__.': Cannot find xml definition: '. $qti_file);
46  return false;
47  }
48 
49  // FIXME: Copied from ilObjTestGUI::importVerifiedFileObject
50  // TODO: move all logic to ilObjTest::importVerifiedFile and call
51  // this method from ilObjTestGUI and ilTestImporter
52  $newObj->mark_schema->flush();
53 
54  // start parsing of QTI files
55  include_once "./Services/QTI/classes/class.ilQTIParser.php";
56  $qtiParser = new ilQTIParser($qti_file, IL_MO_PARSE_QTI, -1 , array());
57  $qtiParser->setTestObject($newObj);
58  $result = $qtiParser->startParsing();
59  $newObj->saveToDb();
60 
61  // import page data
62  include_once ("./Modules/LearningModule/classes/class.ilContObjParser.php");
63  $contParser = new ilContObjParser($newObj, $xml_file, basename($this->getImportDirectory()));
64  $contParser->setQuestionMapping($qtiParser->getImportMapping());
65  $contParser->startParsing();
66 
67  $a_mapping->addMapping("Modules/Test", "tst", $a_id, $newObj->getId());
68  }
69 
70 
75  protected function parseXmlFileNames()
76  {
77  $GLOBALS['ilLog']->write(__METHOD__.': '.$this->getImportDirectory());
78 
79  $basename = basename($this->getImportDirectory());
80 
81  $xml = $this->getImportDirectory().'/'.$basename.'.xml';
82  $qti = $this->getImportDirectory().'/'.str_replace('test', 'qti', $basename).'.xml';
83 
84  return array($xml,$qti);
85  }
86 }
87 
88 ?>