ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilTestQuestionPoolImporter Class Reference

Importer class for question pools. More...

+ Inheritance diagram for ilTestQuestionPoolImporter:
+ Collaboration diagram for ilTestQuestionPoolImporter:

Public Member Functions

 importXmlRepresentation ($a_entity, $a_id, $a_xml, $a_mapping)
 Import XML. More...
 
 finalProcessing ($a_mapping)
 Final processing. More...
 
- Public Member Functions inherited from ilXmlImporter
 __construct ()
 Constructor. More...
 
 setImport ($a_val)
 Set import. More...
 
 getImport ()
 Get import. More...
 
 init ()
 Init. More...
 
 setInstallId ($a_val)
 Set installation id. More...
 
 getInstallId ()
 Get installation id. More...
 
 setInstallUrl ($a_val)
 Set installation url. More...
 
 getInstallUrl ()
 Get installation url. More...
 
 setSchemaVersion ($a_val)
 Set schema version. More...
 
 getSchemaVersion ()
 Get schema version. More...
 
 setImportDirectory ($a_val)
 Set import directory. More...
 
 getImportDirectory ()
 Get import directory. More...
 
 setSkipEntities ($a_val)
 Set skip entities. More...
 
 getSkipEntities ()
 Get skip entities. More...
 
 exportedFromSameInstallation ()
 Is exporting and importing installation identical? More...
 
 importXmlRepresentation ($a_entity, $a_id, $a_xml, $a_mapping)
 Import xml representation. More...
 
 finalProcessing ($a_mapping)
 Final processing. More...
 
 afterContainerImportProcessing (ilImportMapping $mapping)
 Called after all container objects have been implemented. More...
 

Protected Member Functions

 parseXmlFileNames ()
 Create qti and xml file name. More...
 
 importQuestionSkillAssignments ($xmlFile, ilImportMapping $mappingRegistry, $targetParentObjId)
 

Private Member Functions

 getImportDirectoryContainer ()
 
 getImportPackageName ()
 

Private Attributes

 $poolOBJ
 

Additional Inherited Members

- Protected Attributes inherited from ilXmlImporter
 $skip_entities = array()
 
 $imp
 

Detailed Description

Importer class for question pools.

Author
Helmut Schottmüller ilias.nosp@m.@aur.nosp@m.ealis.nosp@m..de
Version
$Id$

Definition at line 14 of file class.ilTestQuestionPoolImporter.php.

Member Function Documentation

◆ finalProcessing()

ilTestQuestionPoolImporter::finalProcessing (   $a_mapping)

Final processing.

Parameters
ilImportMapping$a_mapping
Returns

Reimplemented from ilXmlImporter.

Definition at line 145 of file class.ilTestQuestionPoolImporter.php.

146 {
147 //echo "<pre>".print_r($a_mapping, true)."</pre>"; exit;
148 // get all glossaries of the import
149 include_once("./Services/Taxonomy/classes/class.ilObjTaxonomy.php");
150 $maps = $a_mapping->getMappingsOfEntity("Modules/TestQuestionPool", "qpl");
151 foreach ($maps as $old => $new) {
152 if ($old != "new_id" && (int) $old > 0) {
153 // get all new taxonomys of this object
154 $new_tax_ids = $a_mapping->getMapping("Services/Taxonomy", "tax_usage_of_obj", $old);
155 if ($new_tax_ids !== false) {
156 $tax_ids = explode(":", $new_tax_ids);
157 foreach ($tax_ids as $tid) {
158 ilObjTaxonomy::saveUsage($tid, $new);
159 }
160 }
161
162 $taxMappings = $a_mapping->getMappingsOfEntity('Services/Taxonomy', 'tax');
163 foreach ($taxMappings as $oldTaxId => $newTaxId) {
164 if ($oldTaxId == $this->poolOBJ->getNavTaxonomyId()) {
165 $this->poolOBJ->setNavTaxonomyId($newTaxId);
166 $this->poolOBJ->saveToDb();
167 break;
168 }
169 }
170 }
171 }
172 }
static saveUsage($a_tax_id, $a_obj_id)
Save Usage.

References ilObjTaxonomy\saveUsage().

+ Here is the call graph for this function:

◆ getImportDirectoryContainer()

ilTestQuestionPoolImporter::getImportDirectoryContainer ( )
private

Definition at line 191 of file class.ilTestQuestionPoolImporter.php.

192 {
193 $dir = $this->getImportDirectory();
194 $dir = dirname($dir);
195 return $dir;
196 }
getImportDirectory()
Get import directory.

References ilXmlImporter\getImportDirectory().

Referenced by importXmlRepresentation().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getImportPackageName()

ilTestQuestionPoolImporter::getImportPackageName ( )
private

Definition at line 198 of file class.ilTestQuestionPoolImporter.php.

199 {
200 $dir = $this->getImportDirectory();
201 $name = basename($dir);
202 return $name;
203 }

References $name, and ilXmlImporter\getImportDirectory().

Referenced by importXmlRepresentation().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ importQuestionSkillAssignments()

ilTestQuestionPoolImporter::importQuestionSkillAssignments (   $xmlFile,
ilImportMapping  $mappingRegistry,
  $targetParentObjId 
)
protected

Definition at line 205 of file class.ilTestQuestionPoolImporter.php.

206 {
207 require_once 'Modules/TestQuestionPool/classes/questions/class.ilAssQuestionSkillAssignmentXmlParser.php';
209 $parser->startParsing();
210
211 require_once 'Modules/TestQuestionPool/classes/questions/class.ilAssQuestionSkillAssignmentImporter.php';
212 $importer = new ilAssQuestionSkillAssignmentImporter();
213 $importer->setTargetParentObjId($targetParentObjId);
214 $importer->setImportInstallationId($this->getInstallId());
215 $importer->setImportMappingRegistry($mappingRegistry);
216 $importer->setImportMappingComponent('Modules/TestQuestionPool');
217 $importer->setImportAssignmentList($parser->getAssignmentList());
218
219 $importer->import();
220
221 if ($importer->getFailedImportAssignmentList()->assignmentsExist()) {
222 require_once 'Modules/TestQuestionPool/classes/questions/class.ilAssQuestionSkillAssignmentImportFails.php';
223 $qsaImportFails = new ilAssQuestionSkillAssignmentImportFails($targetParentObjId);
224 $qsaImportFails->registerFailedImports($importer->getFailedImportAssignmentList());
225
226 $this->poolOBJ->setOnline(false);
227 }
228 }
$parser
Definition: BPMN2Parser.php:23
getInstallId()
Get installation id.

References $parser, and ilXmlImporter\getInstallId().

Referenced by importXmlRepresentation().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ importXmlRepresentation()

ilTestQuestionPoolImporter::importXmlRepresentation (   $a_entity,
  $a_id,
  $a_xml,
  $a_mapping 
)

Import XML.

Parameters

return

Reimplemented from ilXmlImporter.

Definition at line 27 of file class.ilTestQuestionPoolImporter.php.

28 {
29 /* @var ilObjQuestionPool $newObj */
30
31 include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
33
34 // Container import => pool object already created
35 if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_id)) {
36 $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
37 $newObj->setOnline(true);
38
39 $_SESSION['qpl_import_subdir'] = $this->getImportPackageName();
40
41 $newObj->setOnline(true);
42 } elseif ($new_id = $a_mapping->getMapping('Modules/TestQuestionPool', 'qpl', "new_id")) {
43 $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
44 } else {
45 // Shouldn't happen
46 global $DIC; /* @var ILIAS\DI\Container $DIC */
47 $DIC['ilLog']->write(__METHOD__ . ': non container and no tax mapping, perhaps old qpl export');
48 return false;
49 }
50
51
52
53 list($xml_file, $qti_file) = $this->parseXmlFileNames();
54
55 global $DIC; /* @var ILIAS\DI\Container $DIC */
56 if (!@file_exists($xml_file)) {
57 $DIC['ilLog']->write(__METHOD__ . ': Cannot find xml definition: ' . $xml_file);
58 return false;
59 }
60 if (!@file_exists($qti_file)) {
61 $DIC['ilLog']->write(__METHOD__ . ': Cannot find qti definition: ' . $qti_file);
62 return false;
63 }
64
65 $this->poolOBJ = $newObj;
66
67 $newObj->fromXML($xml_file);
68
69 // set another question pool name (if possible)
70 if (isset($_POST["qpl_new"]) && strlen($_POST["qpl_new"])) {
71 $newObj->setTitle($_POST["qpl_new"]);
72 }
73
74 $newObj->update();
75 $newObj->saveToDb();
76
77 // FIXME: Copied from ilObjQuestionPoolGUI::importVerifiedFileObject
78 // TODO: move all logic to ilObjQuestionPoolGUI::importVerifiedFile and call
79 // this method from ilObjQuestionPoolGUI and ilTestImporter
80
81 global $DIC; /* @var ILIAS\DI\Container $DIC */
82 $DIC['ilLog']->write(__METHOD__ . ': xml file: ' . $xml_file . ", qti file:" . $qti_file);
83
84 if (isset($_SESSION["qpl_import_idents"])) {
85 $idents = $_SESSION["qpl_import_idents"];
86 unset($_SESSION["qpl_import_idents"]);
87 } else {
88 $idents = null;
89 }
90
91 // start parsing of QTI files
92 include_once "./Services/QTI/classes/class.ilQTIParser.php";
93 $qtiParser = new ilQTIParser($qti_file, IL_MO_PARSE_QTI, $newObj->getId(), $idents);
94 $result = $qtiParser->startParsing();
95
96 // import page data
97 if (strlen($xml_file)) {
98 include_once("./Modules/LearningModule/classes/class.ilContObjParser.php");
99 $contParser = new ilContObjParser($newObj, $xml_file, basename($this->getImportDirectory()));
100 $contParser->setQuestionMapping($qtiParser->getImportMapping());
101 $contParser->startParsing();
102
103 foreach ($qtiParser->getImportMapping() as $k => $v) {
104 $oldQuestionId = substr($k, strpos($k, 'qst_') + strlen('qst_'));
105 $newQuestionId = $v['pool']; // yes, this is the new question id ^^
106
107 $a_mapping->addMapping(
108 "Services/Taxonomy",
109 "tax_item",
110 "qpl:quest:$oldQuestionId",
111 $newQuestionId
112 );
113
114 $a_mapping->addMapping(
115 "Services/Taxonomy",
116 "tax_item_obj_id",
117 "qpl:quest:$oldQuestionId",
118 $newObj->getId()
119 );
120
121 $a_mapping->addMapping(
122 "Modules/TestQuestionPool",
123 "quest",
124 $oldQuestionId,
125 $newQuestionId
126 );
127 }
128 }
129
130 $this->importQuestionSkillAssignments($xml_file, $a_mapping, $newObj->getId());
131
132 $a_mapping->addMapping("Modules/TestQuestionPool", "qpl", $a_id, $newObj->getId());
133
135
136 $newObj->saveToDb();
137 }
$result
$_POST["username"]
$_SESSION["AccountId"]
const IL_MO_PARSE_QTI
Content Object Parser.
static _setImportDirectory($a_import_dir=null)
set import directory
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
parseXmlFileNames()
Create qti and xml file name.
importQuestionSkillAssignments($xmlFile, ilImportMapping $mappingRegistry, $targetParentObjId)
global $DIC
Definition: saml.php:7

References $_POST, $_SESSION, $DIC, $result, ilObjQuestionPool\_setImportDirectory(), ilXmlImporter\getImportDirectory(), getImportDirectoryContainer(), getImportPackageName(), ilObjectFactory\getInstanceByObjId(), IL_MO_PARSE_QTI, importQuestionSkillAssignments(), and parseXmlFileNames().

+ Here is the call graph for this function:

◆ parseXmlFileNames()

ilTestQuestionPoolImporter::parseXmlFileNames ( )
protected

Create qti and xml file name.

Returns
array

Definition at line 178 of file class.ilTestQuestionPoolImporter.php.

179 {
180 global $DIC; /* @var ILIAS\DI\Container $DIC */
181 $DIC['ilLog']->write(__METHOD__ . ': ' . $this->getImportDirectory());
182
183 $basename = basename($this->getImportDirectory());
184
185 $xml = $this->getImportDirectory() . '/' . $basename . '.xml';
186 $qti = $this->getImportDirectory() . '/' . preg_replace('/qpl/', 'qti', $basename) . '.xml';
187
188 return array($xml,$qti);
189 }

References $DIC, $xml, and ilXmlImporter\getImportDirectory().

Referenced by importXmlRepresentation().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $poolOBJ

ilTestQuestionPoolImporter::$poolOBJ
private

Definition at line 19 of file class.ilTestQuestionPoolImporter.php.


The documentation for this class was generated from the following file: