ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f87
class.ilTestImporter.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 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  $_SESSION['tst_import_subdir'] = $this->getImportPackageName();
32  }
33  else // case ii, non container
34  {
35  // Shouldn't happen
36  $GLOBALS['ilLog']->write(__METHOD__.': Called in non container mode');
37  return false;
38  }
39 
40  list($xml_file,$qti_file) = $this->parseXmlFileNames();
41 
42  if(!@file_exists($xml_file))
43  {
44  $GLOBALS['ilLog']->write(__METHOD__.': Cannot find xml definition: '. $xml_file);
45  return false;
46  }
47  if(!@file_exists($qti_file))
48  {
49  $GLOBALS['ilLog']->write(__METHOD__.': Cannot find xml definition: '. $qti_file);
50  return false;
51  }
52 
53  // FIXME: Copied from ilObjTestGUI::importVerifiedFileObject
54  // TODO: move all logic to ilObjTest::importVerifiedFile and call
55  // this method from ilObjTestGUI and ilTestImporter
56  $newObj->mark_schema->flush();
57 
58  // 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
59  // filesystem path determinations
60  $qpl_id = $newObj->getId();
61 
62  // start parsing of QTI files
63  include_once "./Services/QTI/classes/class.ilQTIParser.php";
64  $qtiParser = new ilQTIParser($qti_file, IL_MO_PARSE_QTI, $qpl_id , array());
65  $qtiParser->setTestObject($newObj);
66  $result = $qtiParser->startParsing();
67  $newObj->saveToDb();
68 
69  // import page data
70  include_once ("./Modules/LearningModule/classes/class.ilContObjParser.php");
71  $contParser = new ilContObjParser($newObj, $xml_file, basename($this->getImportDirectory()));
72  $contParser->setQuestionMapping($qtiParser->getImportMapping());
73  $contParser->startParsing();
74 
75  $a_mapping->addMapping("Modules/Test", "tst", $a_id, $newObj->getId());
76 
78  }
79 
84  protected function parseXmlFileNames()
85  {
86  $GLOBALS['ilLog']->write(__METHOD__.': '.$this->getImportDirectory());
87 
88  $basename = basename($this->getImportDirectory());
89 
90  $xml = $this->getImportDirectory().'/'.$basename.'.xml';
91  $qti = $this->getImportDirectory().'/'.preg_replace('/test|tst/', 'qti', $basename).'.xml';
92 
93  return array($xml,$qti);
94  }
95 
96  private function getImportDirectoryContainer()
97  {
98  $dir = $this->getImportDirectory();
99  $dir = dirname($dir);
100  return $dir;
101  }
102 
103  private function getImportPackageName()
104  {
105  $dir = $this->getImportDirectory();
106  $name = basename($dir);
107  return $name;
108  }
109 }
110 
111 ?>
< a tabindex="-1" style="border-style: none;" href="#" title="Refresh Image" onclick="document.getElementById('siimage').src = './securimage_show.php?sid=' + Math.random(); this.blur(); return false">< img src="./images/refresh.png" alt="Reload Image" height="32" width="32" onclick="this.blur()" align="bottom" border="0"/></a >< br/>< strong > Enter Code *if($_SERVER['REQUEST_METHOD']=='POST' &&@ $_POST['do']=='contact') $_SESSION['ctform']['success']
Content Object Parser.
$result
getImportDirectory()
Get import directory.
parseXmlFileNames()
Create qti and xml file name.
Importer class for files.
$GLOBALS['ct_recipient']
const IL_MO_PARSE_QTI
importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
Import XML.
_setImportDirectory($a_import_dir=null)
set import directory
getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
Xml importer class.