ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTestQuestionPoolImporter.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 
15 {
22  function importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
23  {
24  include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
26 
27  // Container import => test object already created
28  if($new_id = $a_mapping->getMapping('Services/Container','objs',$a_id))
29  {
30  $newObj = ilObjectFactory::getInstanceByObjId($new_id,false);
31  }
32  else // case ii, non container
33  {
34  // Shouldn't happen
35  $GLOBALS['ilLog']->write(__METHOD__.': Called in non container mode');
36  return false;
37  }
38 
39  list($xml_file,$qti_file) = $this->parseXmlFileNames();
40 
41  if(!@file_exists($xml_file))
42  {
43  $GLOBALS['ilLog']->write(__METHOD__.': Cannot find xml definition: '. $xml_file);
44  return false;
45  }
46  if(!@file_exists($qti_file))
47  {
48  $GLOBALS['ilLog']->write(__METHOD__.': Cannot find xml definition: '. $qti_file);
49  return false;
50  }
51 
52  include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
54 
55  // FIXME: Copied from ilObjQuestionPoolGUI::importVerifiedFileObject
56  // TODO: move all logic to ilObjQuestionPoolGUI::importVerifiedFile and call
57  // this method from ilObjQuestionPoolGUI and ilTestImporter
58 
59  $GLOBALS['ilLog']->write(__METHOD__.': xml file: '. $xml_file . ", qti file:" . $qti_file);
60 
61  $newObj->setOnline(true);
62  $newObj->saveToDb();
63 
64  // start parsing of QTI files
65  include_once "./Services/QTI/classes/class.ilQTIParser.php";
66  $qtiParser = new ilQTIParser($qti_file, IL_MO_PARSE_QTI, $newObj->getId(), null);
67  $result = $qtiParser->startParsing();
68 
69  // import page data
70  if (strlen($xml_file))
71  {
72  include_once ("./Modules/LearningModule/classes/class.ilContObjParser.php");
73  $contParser = new ilContObjParser($newObj, $xml_file, basename($this->getImportDirectory()));
74  $contParser->setQuestionMapping($qtiParser->getImportMapping());
75  $contParser->startParsing();
76  }
77 
78  $a_mapping->addMapping("Modules/TestQuestionPool", "qpl", $a_id, $newObj->getId());
80  }
81 
82 
87  protected function parseXmlFileNames()
88  {
89  $GLOBALS['ilLog']->write(__METHOD__.': '.$this->getImportDirectory());
90 
91  $basename = basename($this->getImportDirectory());
92 
93  $xml = $this->getImportDirectory().'/'.$basename.'.xml';
94  $qti = $this->getImportDirectory().'/'.preg_replace('/qpl/', 'qti', $basename).'.xml';
95 
96  return array($xml,$qti);
97  }
98 }
99 
100 ?>