ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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 27 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 145 of file class.ilTestQuestionPoolImporter.php.

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

145  : void
146  {
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 !== null) {
153  $tax_ids = explode(":", $new_tax_ids);
154  foreach ($tax_ids as $tid) {
155  ilObjTaxonomy::saveUsage((int) $tid, $new);
156  }
157  }
158  }
159  }
160  }
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 179 of file class.ilTestQuestionPoolImporter.php.

References ilXmlImporter\getImportDirectory().

Referenced by importXmlRepresentation().

179  : string
180  {
181  $dir = $this->getImportDirectory();
182  $dir = dirname($dir);
183  return $dir;
184  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getImportPackageName()

ilTestQuestionPoolImporter::getImportPackageName ( )
private

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

References ilXmlImporter\getImportDirectory().

Referenced by importXmlRepresentation().

186  : string
187  {
188  $dir = $this->getImportDirectory();
189  $name = basename($dir);
190  return $name;
191  }
+ 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 193 of file class.ilTestQuestionPoolImporter.php.

References ilXmlImporter\getInstallId().

Referenced by importXmlRepresentation().

193  : void
194  {
195  $parser = new ilAssQuestionSkillAssignmentXmlParser($xmlFile);
196  $parser->startParsing();
197 
198  $importer = new ilAssQuestionSkillAssignmentImporter();
199  $importer->setTargetParentObjId($targetParentObjId);
200  $importer->setImportInstallationId($this->getInstallId());
201  $importer->setImportMappingRegistry($mappingRegistry);
202  $importer->setImportMappingComponent('Modules/TestQuestionPool');
203  $importer->setImportAssignmentList($parser->getAssignmentList());
204 
205  $importer->import();
206 
207  if ($importer->getFailedImportAssignmentList()->assignmentsExist()) {
208  $qsaImportFails = new ilAssQuestionSkillAssignmentImportFails($targetParentObjId);
209  $qsaImportFails->registerFailedImports($importer->getFailedImportAssignmentList());
210 
211  $this->poolOBJ->getObjectProperties()->storePropertyIsOnline($this->poolOBJ->getObjectProperties()->getPropertyIsOnline()->withOffline());
212  }
213  }
+ 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 39 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().

39  : void
40  {
42 
43  // Container import => pool object already created
44  if (($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_id)) !== null) {
45  $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
46  $newObj->getObjectProperties()->storePropertyIsOnline($newObj->getObjectProperties()->getPropertyIsOnline()->withOffline()); // sets Question pools to always online
47 
48  ilSession::set('qpl_import_subdir', $this->getImportPackageName());
49  } elseif (($new_id = $a_mapping->getMapping('Modules/TestQuestionPool', 'qpl', "new_id")) !== null) {
50  $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
51  } else {
52  // Shouldn't happen
53  global $DIC; /* @var ILIAS\DI\Container $DIC */
54  $DIC['ilLog']->write(__METHOD__ . ': non container and no tax mapping, perhaps old qpl export');
55  return;
56  }
57 
58  list($xml_file, $qti_file) = $this->parseXmlFileNames();
59 
60  global $DIC; /* @var ILIAS\DI\Container $DIC */
61  if (!@file_exists($xml_file)) {
62  $DIC['ilLog']->write(__METHOD__ . ': Cannot find xml definition: ' . $xml_file);
63  return;
64  }
65  if (!@file_exists($qti_file)) {
66  $DIC['ilLog']->write(__METHOD__ . ': Cannot find qti definition: ' . $qti_file);
67  return;
68  }
69 
70  $this->poolOBJ = $newObj;
71 
72  $newObj->fromXML($xml_file);
73 
74  // set another question pool name (if possible)
75  if (isset($_POST["qpl_new"]) && strlen($_POST["qpl_new"])) {
76  $newObj->setTitle($_POST["qpl_new"]);
77  }
78 
79  $newObj->update();
80  $newObj->saveToDb();
81 
82  // FIXME: Copied from ilObjQuestionPoolGUI::importVerifiedFileObject
83  // TODO: move all logic to ilObjQuestionPoolGUI::importVerifiedFile and call
84  // this method from ilObjQuestionPoolGUI and ilTestImporter
85 
86  global $DIC; /* @var ILIAS\DI\Container $DIC */
87  $DIC['ilLog']->write(__METHOD__ . ': xml file: ' . $xml_file . ", qti file:" . $qti_file);
88 
89  if (ilSession::get("qpl_import_idents") !== null) {
90  $idents = ilSession::get("qpl_import_idents");
91  ilSession::clear("qpl_import_idents");
92  } else {
93  $idents = null;
94  }
95 
96  $qtiParser = new ilQTIParser($qti_file, ilQTIParser::IL_MO_PARSE_QTI, $newObj->getId(), $idents);
97  $qtiParser->startParsing();
98 
99  if (strlen($xml_file)) {
100  $questionPageParser = new ilQuestionPageParser($newObj, $xml_file, basename($this->getImportDirectory()));
101  $questionPageParser->setQuestionMapping($qtiParser->getImportMapping());
102  $questionPageParser->startParsing();
103 
104  foreach ($qtiParser->getImportMapping() as $k => $v) {
105  $oldQuestionId = substr($k, strpos($k, 'qst_') + strlen('qst_'));
106  $newQuestionId = $v['pool']; // yes, this is the new question id ^^
107 
108  $a_mapping->addMapping(
109  "Services/Taxonomy",
110  "tax_item",
111  "qpl:quest:$oldQuestionId",
112  $newQuestionId
113  );
114 
115  $a_mapping->addMapping(
116  "Services/Taxonomy",
117  "tax_item_obj_id",
118  "qpl:quest:$oldQuestionId",
119  $newObj->getId()
120  );
121 
122  $a_mapping->addMapping(
123  "Modules/TestQuestionPool",
124  "quest",
125  $oldQuestionId,
126  $newQuestionId
127  );
128  }
129  }
130 
131  $this->importQuestionSkillAssignments($xml_file, $a_mapping, $newObj->getId());
132 
133  $a_mapping->addMapping("Modules/TestQuestionPool", "qpl", $a_id, $newObj->getId());
134 
136 
137  $newObj->saveToDb();
138  }
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)
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 166 of file class.ilTestQuestionPoolImporter.php.

References $DIC, and ilXmlImporter\getImportDirectory().

Referenced by importXmlRepresentation().

166  : array
167  {
168  global $DIC; /* @var ILIAS\DI\Container $DIC */
169  $DIC['ilLog']->write(__METHOD__ . ': ' . $this->getImportDirectory());
170 
171  $basename = basename($this->getImportDirectory());
172 
173  $xml = $this->getImportDirectory() . '/' . $basename . '.xml';
174  $qti = $this->getImportDirectory() . '/' . preg_replace('/qpl/', 'qti', $basename) . '.xml';
175 
176  return array($xml,$qti);
177  }
global $DIC
Definition: feed.php:28
+ 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 32 of file class.ilTestQuestionPoolImporter.php.


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