ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
ilTestQuestionPoolImporter Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

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

Public Member Functions

 importXmlRepresentation (string $a_entity, string $a_id, string $a_xml, ilImportMapping $a_mapping)
 Import XML. More...
 
 finalProcessing (ilImportMapping $a_mapping)
 Final processing. More...
 
- Public Member Functions inherited from ilXmlImporter
 __construct ()
 
 setImport (ilImport $a_val)
 
 getImport ()
 
 init ()
 
 setInstallId (string $a_val)
 
 getInstallId ()
 
 setInstallUrl (string $a_val)
 
 getInstallUrl ()
 
 setSchemaVersion (string $a_val)
 
 getSchemaVersion ()
 
 setImportDirectory (string $a_val)
 
 getImportDirectory ()
 
 setSkipEntities (array $a_val)
 
 getSkipEntities ()
 
 exportedFromSameInstallation ()
 
 importXmlRepresentation (string $a_entity, string $a_id, string $a_xml, ilImportMapping $a_mapping)
 
 finalProcessing (ilImportMapping $a_mapping)
 
 afterContainerImportProcessing (ilImportMapping $mapping)
 

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
array $skip_entities = array()
 
ilImport $imp
 
string $install_id
 
string $install_url
 
string $schema_version
 
string $import_directory
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Importer class for question pools

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

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

Member Function Documentation

◆ finalProcessing()

ilTestQuestionPoolImporter::finalProcessing ( ilImportMapping  $a_mapping)

Final processing.

Parameters
ilImportMapping$a_mapping
Returns
void

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

References ilImportMapping\getMapping(), ilImportMapping\getMappingsOfEntity(), and ilObjTaxonomy\saveUsage().

155  : void
156  {
157  //echo "<pre>".print_r($a_mapping, true)."</pre>"; exit;
158  // get all glossaries of the import
159  include_once("./Services/Taxonomy/classes/class.ilObjTaxonomy.php");
160  $maps = $a_mapping->getMappingsOfEntity("Modules/TestQuestionPool", "qpl");
161  foreach ($maps as $old => $new) {
162  if ($old != "new_id" && (int) $old > 0) {
163  // get all new taxonomys of this object
164  $new_tax_ids = $a_mapping->getMapping("Services/Taxonomy", "tax_usage_of_obj", $old);
165  if ($new_tax_ids !== false) {
166  $tax_ids = explode(":", $new_tax_ids);
167  foreach ($tax_ids as $tid) {
168  ilObjTaxonomy::saveUsage((int) $tid, $new);
169  }
170  }
171 
172  $taxMappings = $a_mapping->getMappingsOfEntity('Services/Taxonomy', 'tax');
173  foreach ($taxMappings as $oldTaxId => $newTaxId) {
174  if ($oldTaxId == $this->poolOBJ->getNavTaxonomyId()) {
175  $this->poolOBJ->setNavTaxonomyId($newTaxId);
176  $this->poolOBJ->saveToDb();
177  break;
178  }
179  }
180  }
181  }
182  }
getMapping(string $a_comp, string $a_entity, string $a_old_id)
getMappingsOfEntity(string $a_comp, string $a_entity)
static saveUsage(int $a_tax_id, int $a_obj_id)
+ Here is the call graph for this function:

◆ getImportDirectoryContainer()

ilTestQuestionPoolImporter::getImportDirectoryContainer ( )
private

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

References ilXmlImporter\getImportDirectory().

Referenced by importXmlRepresentation().

201  : string
202  {
203  $dir = $this->getImportDirectory();
204  $dir = dirname($dir);
205  return $dir;
206  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getImportPackageName()

ilTestQuestionPoolImporter::getImportPackageName ( )
private

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

References $name, and ilXmlImporter\getImportDirectory().

Referenced by importXmlRepresentation().

208  : string
209  {
210  $dir = $this->getImportDirectory();
211  $name = basename($dir);
212  return $name;
213  }
if($format !==null) $name
Definition: metadata.php:247
+ 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 215 of file class.ilTestQuestionPoolImporter.php.

References ilXmlImporter\getInstallId().

Referenced by importXmlRepresentation().

215  : void
216  {
217  require_once 'Modules/TestQuestionPool/classes/questions/class.ilAssQuestionSkillAssignmentXmlParser.php';
218  $parser = new ilAssQuestionSkillAssignmentXmlParser($xmlFile);
219  $parser->startParsing();
220 
221  require_once 'Modules/TestQuestionPool/classes/questions/class.ilAssQuestionSkillAssignmentImporter.php';
222  $importer = new ilAssQuestionSkillAssignmentImporter();
223  $importer->setTargetParentObjId($targetParentObjId);
224  $importer->setImportInstallationId($this->getInstallId());
225  $importer->setImportMappingRegistry($mappingRegistry);
226  $importer->setImportMappingComponent('Modules/TestQuestionPool');
227  $importer->setImportAssignmentList($parser->getAssignmentList());
228 
229  $importer->import();
230 
231  if ($importer->getFailedImportAssignmentList()->assignmentsExist()) {
232  require_once 'Modules/TestQuestionPool/classes/questions/class.ilAssQuestionSkillAssignmentImportFails.php';
233  $qsaImportFails = new ilAssQuestionSkillAssignmentImportFails($targetParentObjId);
234  $qsaImportFails->registerFailedImports($importer->getFailedImportAssignmentList());
235 
236  $this->poolOBJ->setOnline(false);
237  }
238  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ importXmlRepresentation()

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

Import XML.

Parameters

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

References $DIC, ilObjQuestionPool\_setImportDirectory(), ilImportMapping\addMapping(), ilSession\clear(), ilSession\get(), ilXmlImporter\getImportDirectory(), getImportDirectoryContainer(), getImportPackageName(), ilObjectFactory\getInstanceByObjId(), ilImportMapping\getMapping(), ilQTIParser\IL_MO_PARSE_QTI, importQuestionSkillAssignments(), parseXmlFileNames(), ilSession\set(), and ilQTIParser\startParsing().

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

◆ parseXmlFileNames()

ilTestQuestionPoolImporter::parseXmlFileNames ( )
protected

Create qti and xml file name.

Returns
array

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

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

Referenced by importXmlRepresentation().

188  : array
189  {
190  global $DIC; /* @var ILIAS\DI\Container $DIC */
191  $DIC['ilLog']->write(__METHOD__ . ': ' . $this->getImportDirectory());
192 
193  $basename = basename($this->getImportDirectory());
194 
195  $xml = $this->getImportDirectory() . '/' . $basename . '.xml';
196  $qti = $this->getImportDirectory() . '/' . preg_replace('/qpl/', 'qti', $basename) . '.xml';
197 
198  return array($xml,$qti);
199  }
global $DIC
Definition: feed.php:28
$xml
Definition: metadata.php:351
+ 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 34 of file class.ilTestQuestionPoolImporter.php.


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