19declare(strict_types=1);
43 private readonly ResourceStorage
$irss;
48 $this->
logger = TestDIC::dic()[
'logging.logger'];
49 $this->db =
$DIC[
'ilDB'];
50 $this->irss =
$DIC[
'resource_storage'];
61 $results_file_path = null;
62 if ($new_id = (
int) $a_mapping->
getMapping(
'components/ILIAS/Container',
'objs', $a_id)) {
70 $selected_questions = [];
73 $new_id = (
int) $a_mapping->
getMapping(
'components/ILIAS/Test',
'tst',
'new_id');
76 $selected_questions =
ilSession::get(
'tst_import_selected_questions') ?? [];
84 $new_obj->loadFromDb();
86 if (!file_exists($xmlfile)) {
87 $this->
logger->error(__METHOD__ .
': Cannot find xml definition: ' . $xmlfile);
90 if (!file_exists($qtifile)) {
91 $this->
logger->error(__METHOD__ .
': Cannot find xml definition: ' . $qtifile);
104 $qti_parser->setTestObject($new_obj);
105 $qti_parser->startParsing();
106 $new_obj = $qti_parser->getTestObject();
114 $question_page_parser->setQuestionMapping($qti_parser->getImportMapping());
115 $question_page_parser->startParsing();
119 if ($new_obj->isRandomTest()) {
123 if ($results_file_path !==
null && file_exists($results_file_path)) {
130 $new_obj->saveToDb();
140 $a_mapping->
addMapping(
"components/ILIAS/Test",
"tst", (
string) $a_id, (
string) $new_obj->getId());
142 "components/ILIAS/MetaData",
145 $new_obj->getId() .
":0:tst"
150 array $question_id_mapping,
154 foreach ($question_id_mapping as $old_question_id => $new_question_id) {
156 'components/ILIAS/Taxonomy',
158 "tst:quest:{$old_question_id}",
159 (
string) $new_question_id
163 'components/ILIAS/Taxonomy',
165 "tst:quest:{$old_question_id}",
170 'components/ILIAS/Test',
172 (
string) $old_question_id,
173 (
string) $new_question_id
184 foreach ($maps as $old => $new) {
185 if ($old ==
"new_id" || (
int) $old <= 0) {
189 if (isset(self::$finallyProcessedTestsRegistry[$new])) {
194 if ($test_obj->isRandomTest()) {
195 $this->finalRandomTestTaxonomyProcessing($a_mapping, (
string) $old, $new, $test_obj);
198 self::$finallyProcessedTestsRegistry[$new] =
true;
204 string $old_tst_obj_id,
205 string $new_tst_obj_id,
208 $new_tax_ids = $mapping->getMapping(
209 'components/ILIAS/Taxonomy',
214 if ($new_tax_ids !==
null) {
215 foreach (explode(
':', $new_tax_ids) as $tax_id) {
229 $src_pool_def_list->loadDefinitions();
231 foreach ($src_pool_def_list as $definition) {
232 $mapped_taxonomy_filter = $definition->getMappedTaxonomyFilter();
233 if ($mapped_taxonomy_filter === []) {
237 $definition->setMappedTaxonomyFilter(
238 $this->getNewMappedTaxonomyFilter(
240 $mapped_taxonomy_filter
243 $definition->saveToDb();
251 $new_mapped_filter = [];
252 foreach ($mapped_filter as $tax_id => $tax_nodes) {
254 'components/ILIAS/Taxonomy',
259 if ($new_tax_id ===
null) {
263 $new_mapped_filter[$new_tax_id] = [];
265 foreach ($tax_nodes as $tax_node_id) {
267 'components/ILIAS/Taxonomy',
269 (
string) $tax_node_id
272 if ($new_tax_node_id ===
null) {
276 $new_mapped_filter[$new_tax_id][] = $new_tax_node_id;
280 return $new_mapped_filter;
288 $test_obj->questions = [];
290 $parser->setTestOBJ($test_obj);
291 $parser->setImportMapping($a_mapping);
292 $parser->startParsing();
304 $importer->setTargetParentObjId($test_obj->
getId());
305 $importer->setImportInstallationId((
int) $this->getInstallId());
306 $importer->setImportMappingRegistry($mapping);
307 $importer->setImportMappingComponent(
'components/ILIAS/Test');
308 $importer->setImportAssignmentList($parser->getAssignmentList());
312 if ($importer->getFailedImportAssignmentList()->assignmentsExist()) {
314 $qsaImportFails->registerFailedImports($importer->getFailedImportAssignmentList());
321 return $importer->getSuccessImportAssignmentList();
332 $parser->startParsing();
335 $importer->setTargetTestId($test_obj->
getTestId());
336 $importer->setImportInstallationId((
int) $this->getInstallId());
337 $importer->setImportMappingRegistry($mapping);
338 $importer->setImportedQuestionSkillAssignmentList($assignment_list);
339 $importer->setImportThresholdList($parser->getSkillLevelThresholdImportList());
342 if ($importer->getFailedThresholdImportSkillList()->skillsExist()) {
344 $sltImportFails->registerFailedImports($importer->getFailedThresholdImportSkillList());
addMapping(string $a_comp, string $a_entity, string $a_old_id, string $a_new_id)
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)
getTestId()
Gets the database id of the additional test data.
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
setOfflineStatus(bool $status)
Legacy Content Object Parser.
startParsing()
stores xml data in array
static get(string $a_var)
static clear(string $a_var)
Importer class for files.
readonly ilDBInterface $db
readonly TestLogger $logger
importQuestionSkillAssignments(ilImportMapping $mapping, ilObjTest $test_obj, ?string $xml_file)
finalProcessing(ilImportMapping $a_mapping)
readonly ResourceStorage $irss
importSkillLevelThresholds(ilImportMapping $mapping, ilAssQuestionSkillAssignmentList $assignment_list, ilObjTest $test_obj, ?string $xml_file)
addTaxonomyAndQuestionsMapping(array $question_id_mapping, int $new_obj_id, ilImportMapping $mapping)
static $finallyProcessedTestsRegistry
importXmlRepresentation(string $a_entity, string $a_id, string $a_xml, ilImportMapping $a_mapping)
finalRandomTestTaxonomyProcessing(ilImportMapping $mapping, string $old_tst_obj_id, string $new_tst_obj_id, ilObjTest $test_obj)
getNewMappedTaxonomyFilter(ilImportMapping $mapping, array $mapped_filter)
importRandomQuestionSetConfig(ilObjTest $test_obj, ?string $xml_file, \ilImportMapping $a_mapping)
initSkillLevelThresholdImportList()
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
buildImportDirectoriesFromContainerImport(string $importdir)
trait TestQuestionsImportTrait
buildImportDirectoriesFromImportFile(string $file_to_import)
buildResultsFilePath(string $importdir, string $subdir)