19 declare(strict_types=1);
46 $this->
logger = TestDIC::dic()[
'logging.logger'];
47 $this->db = $DIC[
'ilDB'];
58 $results_file_path =
null;
59 if ($new_id = (
int) $a_mapping->
getMapping(
'components/ILIAS/Container',
'objs', $a_id)) {
68 $selected_questions = [];
71 $new_id = (
int) $a_mapping->
getMapping(
'components/ILIAS/Test',
'tst',
'new_id');
74 $selected_questions =
ilSession::get(
'tst_import_selected_questions') ?? [];
82 $new_obj->loadFromDb();
84 if (!file_exists($xmlfile)) {
85 $this->
logger->error(__METHOD__ .
': Cannot find xml definition: ' . $xmlfile);
88 if (!file_exists($qtifile)) {
89 $this->
logger->error(__METHOD__ .
': Cannot find xml definition: ' . $qtifile);
103 $qti_parser->startParsing();
104 $new_obj = $qti_parser->getTestObject();
112 $question_page_parser->setQuestionMapping($qti_parser->getImportMapping());
113 $question_page_parser->startParsing();
117 if ($new_obj->isRandomTest()) {
121 if ($results_file_path !==
null && file_exists($results_file_path)) {
128 $new_obj->saveToDb();
135 $a_mapping->
addMapping(
"components/ILIAS/Test",
"tst", (
string) $a_id, (
string) $new_obj->getId());
137 "components/ILIAS/MetaData",
140 $new_obj->getId() .
":0:tst" 145 array $question_id_mapping,
149 foreach ($question_id_mapping as $old_question_id => $new_question_id) {
151 'components/ILIAS/Taxonomy',
153 "tst:quest:{$old_question_id}",
154 (
string) $new_question_id
158 'components/ILIAS/Taxonomy',
160 "tst:quest:{$old_question_id}",
165 'components/ILIAS/Test',
167 (
string) $old_question_id,
168 (
string) $new_question_id
179 foreach ($maps as $old => $new) {
180 if ($old ==
"new_id" || (
int) $old <= 0) {
184 if (isset(self::$finallyProcessedTestsRegistry[$new])) {
189 if ($test_obj->isRandomTest()) {
193 self::$finallyProcessedTestsRegistry[$new] =
true;
199 string $old_tst_obj_id,
200 string $new_tst_obj_id,
204 'components/ILIAS/Taxonomy',
209 if ($new_tax_ids !==
null) {
210 foreach (explode(
':', $new_tax_ids) as $tax_id) {
224 $src_pool_def_list->loadDefinitions();
226 foreach ($src_pool_def_list as $definition) {
227 $mapped_taxonomy_filter = $definition->getMappedTaxonomyFilter();
228 if ($mapped_taxonomy_filter === []) {
232 $definition->setMappedTaxonomyFilter(
235 $mapped_taxonomy_filter
238 $definition->saveToDb();
246 $new_mapped_filter = [];
247 foreach ($mapped_filter as $tax_id => $tax_nodes) {
249 'components/ILIAS/Taxonomy',
254 if ($new_tax_id ===
null) {
258 $new_mapped_filter[$new_tax_id] = [];
260 foreach ($tax_nodes as $tax_node_id) {
262 'components/ILIAS/Taxonomy',
264 (
string) $tax_node_id
267 if ($new_tax_node_id ===
null) {
271 $new_mapped_filter[$new_tax_id][] = $new_tax_node_id;
275 return $new_mapped_filter;
283 $test_obj->questions = [];
285 $parser->setTestOBJ($test_obj);
286 $parser->setImportMapping($a_mapping);
287 $parser->startParsing();
296 $parser->startParsing();
299 $importer->setTargetParentObjId($test_obj->
getId());
300 $importer->setImportInstallationId((
int) $this->
getInstallId());
301 $importer->setImportMappingRegistry($mapping);
302 $importer->setImportMappingComponent(
'components/ILIAS/Test');
303 $importer->setImportAssignmentList($parser->getAssignmentList());
307 if ($importer->getFailedImportAssignmentList()->assignmentsExist()) {
316 return $importer->getSuccessImportAssignmentList();
326 $parser->initSkillLevelThresholdImportList();
327 $parser->startParsing();
330 $importer->setTargetTestId($test_obj->
getTestId());
331 $importer->setImportInstallationId((
int) $this->
getInstallId());
332 $importer->setImportMappingRegistry($mapping);
333 $importer->setImportedQuestionSkillAssignmentList($assignment_list);
334 $importer->setImportThresholdList($parser->getSkillLevelThresholdImportList());
337 if ($importer->getFailedThresholdImportSkillList()->skillsExist()) {
static get(string $a_var)
importXmlRepresentation(string $a_entity, string $a_id, string $a_xml, ilImportMapping $a_mapping)
getNewMappedTaxonomyFilter(ilImportMapping $mapping, array $mapped_filter)
registerFailedImports(ilAssQuestionAssignedSkillList $skillList)
getTestId()
Gets the database id of the additional test data.
trait TestQuestionsImportTrait
importRandomQuestionSetConfig(ilObjTest $test_obj, ?string $xml_file, \ilImportMapping $a_mapping)
addMapping(string $a_comp, string $a_entity, string $a_old_id, string $a_new_id)
buildImportDirectoriesFromContainerImport(string $importdir)
buildResultsFilePath(string $importdir, string $subdir)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
finalRandomTestTaxonomyProcessing(ilImportMapping $mapping, string $old_tst_obj_id, string $new_tst_obj_id, ilObjTest $test_obj)
Importer class for files.
getMapping(string $a_comp, string $a_entity, string $a_old_id)
getMappingsOfEntity(string $a_comp, string $a_entity)
importQuestionSkillAssignments(ilImportMapping $mapping, ilObjTest $test_obj, ?string $xml_file)
readonly TestLogger $logger
Legacy Content Object Parser.
readonly ilDBInterface $db
setOfflineStatus(bool $status)
addTaxonomyAndQuestionsMapping(array $question_id_mapping, int $new_obj_id, ilImportMapping $mapping)
setTestObject(ilObjTest $tst_object)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static saveUsage(int $a_tax_id, int $a_obj_id)
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
importSkillLevelThresholds(ilImportMapping $mapping, ilAssQuestionSkillAssignmentList $assignment_list, ilObjTest $test_obj, ?string $xml_file)
__construct(Container $dic, ilPlugin $plugin)
finalProcessing(ilImportMapping $a_mapping)
array buildImportDirectoriesFromImportFile(string $file_to_import)
static $finallyProcessedTestsRegistry
static clear(string $a_var)
registerFailedImports(ilAssQuestionSkillAssignmentImportList $assignmentList)
static set(string $a_var, $a_val)
Set a value.