ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
class.ilTestQuestionPoolImporter.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_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 $_SESSION['qpl_import_subdir'] = $this->getImportPackageName();
33 }
34 else // case ii, non container
35 {
36 // Shouldn't happen
37 $GLOBALS['ilLog']->write(__METHOD__.': Called in non container mode');
38 return false;
39 }
40
41 list($xml_file,$qti_file) = $this->parseXmlFileNames();
42
43 if(!@file_exists($xml_file))
44 {
45 $GLOBALS['ilLog']->write(__METHOD__.': Cannot find xml definition: '. $xml_file);
46 return false;
47 }
48 if(!@file_exists($qti_file))
49 {
50 $GLOBALS['ilLog']->write(__METHOD__.': Cannot find xml definition: '. $qti_file);
51 return false;
52 }
53
54 // FIXME: Copied from ilObjQuestionPoolGUI::importVerifiedFileObject
55 // TODO: move all logic to ilObjQuestionPoolGUI::importVerifiedFile and call
56 // this method from ilObjQuestionPoolGUI and ilTestImporter
57
58 $GLOBALS['ilLog']->write(__METHOD__.': xml file: '. $xml_file . ", qti file:" . $qti_file);
59
60 $newObj->setOnline(true);
61 $newObj->saveToDb();
62
63 // start parsing of QTI files
64 include_once "./Services/QTI/classes/class.ilQTIParser.php";
65 $qtiParser = new ilQTIParser($qti_file, IL_MO_PARSE_QTI, $newObj->getId(), null);
66 $result = $qtiParser->startParsing();
67
68 // import page data
69 if (strlen($xml_file))
70 {
71 include_once ("./Modules/LearningModule/classes/class.ilContObjParser.php");
72 $contParser = new ilContObjParser($newObj, $xml_file, basename($this->getImportDirectory()));
73 $contParser->setQuestionMapping($qtiParser->getImportMapping());
74 $contParser->startParsing();
75 }
76
77 $a_mapping->addMapping("Modules/TestQuestionPool", "qpl", $a_id, $newObj->getId());
79 }
80
81
86 protected function parseXmlFileNames()
87 {
88 $GLOBALS['ilLog']->write(__METHOD__.': '.$this->getImportDirectory());
89
90 $basename = basename($this->getImportDirectory());
91
92 $xml = $this->getImportDirectory().'/'.$basename.'.xml';
93 $qti = $this->getImportDirectory().'/'.preg_replace('/qpl/', 'qti', $basename).'.xml';
94
95 return array($xml,$qti);
96 }
97
98 private function getImportDirectoryContainer()
99 {
100 $dir = $this->getImportDirectory();
101 $dir = dirname($dir);
102 return $dir;
103 }
104
105 private function getImportPackageName()
106 {
107 $dir = $this->getImportDirectory();
108 $name = basename($dir);
109 return $name;
110 }
111}
112
113?>
$result
const IL_MO_PARSE_QTI
Content Object Parser.
_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
Importer class for question pools.
parseXmlFileNames()
Create qti and xml file name.
importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
Import XML.
Xml importer class.
getImportDirectory()
Get import directory.
$GLOBALS['ct_recipient']
< 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']