ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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

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

References $new, $old, and ilObjTaxonomy\saveUsage().

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

◆ getImportDirectoryContainer()

ilTestQuestionPoolImporter::getImportDirectoryContainer ( )
private

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

References ilXmlImporter\getImportDirectory().

Referenced by importXmlRepresentation().

188  {
189  $dir = $this->getImportDirectory();
190  $dir = dirname($dir);
191  return $dir;
192  }
getImportDirectory()
Get import directory.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getImportPackageName()

ilTestQuestionPoolImporter::getImportPackageName ( )
private

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

References $name, and ilXmlImporter\getImportDirectory().

Referenced by importXmlRepresentation().

195  {
196  $dir = $this->getImportDirectory();
197  $name = basename($dir);
198  return $name;
199  }
getImportDirectory()
Get import directory.
if($format !==null) $name
Definition: metadata.php:146
+ 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 201 of file class.ilTestQuestionPoolImporter.php.

References $parser, and ilXmlImporter\getInstallId().

Referenced by importXmlRepresentation().

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

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

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

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  $GLOBALS['ilLog']->write(__METHOD__ . ': non container and no tax mapping, perhaps old qpl export');
47  return false;
48  }
49 
50 
51 
52  list($xml_file, $qti_file) = $this->parseXmlFileNames();
53 
54  if (!@file_exists($xml_file)) {
55  $GLOBALS['ilLog']->write(__METHOD__ . ': Cannot find xml definition: ' . $xml_file);
56  return false;
57  }
58  if (!@file_exists($qti_file)) {
59  $GLOBALS['ilLog']->write(__METHOD__ . ': Cannot find qti definition: ' . $qti_file);
60  return false;
61  }
62 
63  $this->poolOBJ = $newObj;
64 
65  $newObj->fromXML($xml_file);
66 
67  // set another question pool name (if possible)
68  if (isset($_POST["qpl_new"]) && strlen($_POST["qpl_new"])) {
69  $newObj->setTitle($_POST["qpl_new"]);
70  }
71 
72  $newObj->update();
73  $newObj->saveToDb();
74 
75  // FIXME: Copied from ilObjQuestionPoolGUI::importVerifiedFileObject
76  // TODO: move all logic to ilObjQuestionPoolGUI::importVerifiedFile and call
77  // this method from ilObjQuestionPoolGUI and ilTestImporter
78 
79  $GLOBALS['ilLog']->write(__METHOD__ . ': xml file: ' . $xml_file . ", qti file:" . $qti_file);
80 
81  if (isset($_SESSION["qpl_import_idents"])) {
82  $idents = $_SESSION["qpl_import_idents"];
83  unset($_SESSION["qpl_import_idents"]);
84  } else {
85  $idents = null;
86  }
87 
88  // start parsing of QTI files
89  include_once "./Services/QTI/classes/class.ilQTIParser.php";
90  $qtiParser = new ilQTIParser($qti_file, IL_MO_PARSE_QTI, $newObj->getId(), $idents);
91  $result = $qtiParser->startParsing();
92 
93  // import page data
94  if (strlen($xml_file)) {
95  include_once("./Modules/LearningModule/classes/class.ilContObjParser.php");
96  $contParser = new ilContObjParser($newObj, $xml_file, basename($this->getImportDirectory()));
97  $contParser->setQuestionMapping($qtiParser->getImportMapping());
98  $contParser->startParsing();
99 
100  foreach ($qtiParser->getImportMapping() as $k => $v) {
101  $oldQuestionId = substr($k, strpos($k, 'qst_')+strlen('qst_'));
102  $newQuestionId = $v['pool']; // yes, this is the new question id ^^
103 
104  $a_mapping->addMapping(
105  "Services/Taxonomy",
106  "tax_item",
107  "qpl:quest:$oldQuestionId",
108  $newQuestionId
109  );
110 
111  $a_mapping->addMapping(
112  "Services/Taxonomy",
113  "tax_item_obj_id",
114  "qpl:quest:$oldQuestionId",
115  $newObj->getId()
116  );
117 
118  $a_mapping->addMapping(
119  "Modules/TestQuestionPool",
120  "quest",
121  $oldQuestionId,
122  $newQuestionId
123  );
124  }
125  }
126 
127  $this->importQuestionSkillAssignments($xml_file, $a_mapping, $newObj->getId());
128 
129  $a_mapping->addMapping("Modules/TestQuestionPool", "qpl", $a_id, $newObj->getId());
130 
132 
133  $newObj->saveToDb();
134  }
Content Object Parser.
$_SESSION["AccountId"]
$result
getImportDirectory()
Get import directory.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
const IL_MO_PARSE_QTI
parseXmlFileNames()
Create qti and xml file name.
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
importQuestionSkillAssignments($xmlFile, ilImportMapping $mappingRegistry, $targetParentObjId)
$_POST["username"]
+ Here is the call graph for this function:

◆ parseXmlFileNames()

ilTestQuestionPoolImporter::parseXmlFileNames ( )
protected

Create qti and xml file name.

Returns
array

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

References $GLOBALS, $xml, array, and ilXmlImporter\getImportDirectory().

Referenced by importXmlRepresentation().

176  {
177  $GLOBALS['ilLog']->write(__METHOD__ . ': ' . $this->getImportDirectory());
178 
179  $basename = basename($this->getImportDirectory());
180 
181  $xml = $this->getImportDirectory() . '/' . $basename . '.xml';
182  $qti = $this->getImportDirectory() . '/' . preg_replace('/qpl/', 'qti', $basename) . '.xml';
183 
184  return array($xml,$qti);
185  }
getImportDirectory()
Get import directory.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
$xml
Definition: metadata.php:240
Create styles array
The data for the language used.
+ 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: