/** * returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir) */ protected function getTstImportArchivDirectory() { include_once "./Modules/Test/classes/class.ilObjTest.php"; return ilObjTest::_getImportDirectory() . '/' . $_SESSION["tst_import_subdir"]; }
/** * Receives parameters from a QTI parser and creates a valid ILIAS test object * @param ilQTIAssessment $assessment */ public function fromXML(ilQTIAssessment $assessment) { unset($_SESSION["import_mob_xhtml"]); $this->setDescription($assessment->getComment()); $this->setTitle($assessment->getTitle()); $this->setIntroductionEnabled(false); foreach ($assessment->objectives as $objectives) { foreach ($objectives->materials as $material) { $intro = $this->QTIMaterialToString($material); $this->setIntroduction($intro); $this->setIntroductionEnabled(strlen($intro) > 0); } } if ($assessment->getPresentationMaterial() && $assessment->getPresentationMaterial()->getFlowMat(0) && $assessment->getPresentationMaterial()->getFlowMat(0)->getMaterial(0)) { $this->setFinalStatement($this->QTIMaterialToString($assessment->getPresentationMaterial()->getFlowMat(0)->getMaterial(0))); } foreach ($assessment->assessmentcontrol as $assessmentcontrol) { switch ($assessmentcontrol->getSolutionswitch()) { case "Yes": $this->setInstantFeedbackSolution(1); break; default: $this->setInstantFeedbackSolution(0); break; } } $this->setStartingTimeEnabled(false); $this->setEndingTimeEnabled(false); $this->setPasswordEnabled(false); $this->setLimitUsersEnabled(false); foreach ($assessment->qtimetadata as $metadata) { switch ($metadata["label"]) { case "test_type": // for old tests with a test type $type = $metadata["entry"]; switch ($type) { case 1: // assessment $this->setAnonymity(1); break; case 2: // self assessment break; case 4: // online exam $this->setFixedParticipants(1); $this->setListOfQuestionsSettings(7); $this->setShowSolutionPrintview(1); break; case 5: // varying random test break; } break; case "sequence_settings": $this->setSequenceSettings($metadata["entry"]); break; case "author": $this->setAuthor($metadata["entry"]); break; case "nr_of_tries": $this->setNrOfTries($metadata["entry"]); break; case "kiosk": $this->setKiosk($metadata["entry"]); break; case "showfinalstatement": $this->setShowFinalStatement($metadata["entry"]); break; case "showinfo": $this->setShowInfo($metadata["entry"]); break; case "forcejs": $this->setForceJS($metadata["entry"]); break; case "customstyle": $this->setCustomStyle($metadata["entry"]); break; case "highscore_enabled": $this->setHighscoreEnabled($metadata["entry"]); break; case "highscore_anon": $this->setHighscoreAnon($metadata["entry"]); break; case "highscore_achieved_ts": $this->setHighscoreAchievedTS($metadata["entry"]); break; case "highscore_score": $this->setHighscoreScore($metadata["entry"]); break; case "highscore_percentage": $this->setHighscorePercentage($metadata["entry"]); break; case "highscore_hints": $this->setHighscoreHints($metadata["entry"]); break; case "highscore_wtime": $this->setHighscoreWTime($metadata["entry"]); break; case "highscore_own_table": $this->setHighscoreOwnTable($metadata["entry"]); break; case "highscore_top_table": $this->setHighscoreTopTable($metadata["entry"]); break; case "highscore_top_num": $this->setHighscoreTopNum($metadata["entry"]); break; case "hide_previous_results": if ($metadata["entry"] == 0) { $this->setUsePreviousAnswers(1); } else { $this->setUsePreviousAnswers(0); } break; case "use_previous_answers": $this->setUsePreviousAnswers($metadata["entry"]); break; case "answer_feedback": $this->setAnswerFeedback($metadata["entry"]); break; case "hide_title_points": $this->setTitleOutput($metadata["entry"]); break; case "title_output": $this->setTitleOutput($metadata["entry"]); break; case "question_set_type": $this->setQuestionSetType($metadata["entry"]); break; case "random_test": if ($metadata["entry"]) { $this->setQuestionSetType(self::QUESTION_SET_TYPE_RANDOM); } else { $this->setQuestionSetType(self::QUESTION_SET_TYPE_FIXED); } break; case "results_presentation": $this->setResultsPresentation($metadata["entry"]); break; case "reset_processing_time": $this->setResetProcessingTime($metadata["entry"]); break; case "instant_verification": $this->setInstantFeedbackSolution($metadata["entry"]); break; case "answer_feedback_points": $this->setAnswerFeedbackPoints($metadata["entry"]); break; case "anonymity": $this->setAnonymity($metadata["entry"]); break; case "show_cancel": $this->setShowCancel($metadata["entry"]); break; case "show_marker": $this->setShowMarker($metadata["entry"]); break; case "fixed_participants": $this->setFixedParticipants($metadata["entry"]); break; case "score_reporting": $this->setScoreReporting($metadata["entry"]); break; case "shuffle_questions": $this->setShuffleQuestions($metadata["entry"]); break; case "count_system": $this->setCountSystem($metadata["entry"]); break; case "mc_scoring": $this->setMCScoring($metadata["entry"]); break; case "mailnotification": $this->setMailNotification($metadata["entry"]); break; case "mailnottype": $this->setMailNotificationType($metadata["entry"]); break; case "exportsettings": $this->setExportSettings($metadata['exportsettings']); break; case "score_cutting": $this->setScoreCutting($metadata["entry"]); break; case "password": $this->setPassword($metadata["entry"]); $this->setPasswordEnabled(strlen($metadata["entry"]) > 0); break; case "allowedUsers": $this->setAllowedUsers($metadata["entry"]); $this->setLimitUsersEnabled(strlen($metadata["entry"]) > 0); break; case "allowedUsersTimeGap": $this->setAllowedUsersTimeGap($metadata["entry"]); break; case "pass_scoring": $this->setPassScoring($metadata["entry"]); break; case "show_summary": $this->setListOfQuestionsSettings($metadata["entry"]); break; case "reporting_date": $iso8601period = $metadata["entry"]; if (preg_match("/P(\\d+)Y(\\d+)M(\\d+)DT(\\d+)H(\\d+)M(\\d+)S/", $iso8601period, $matches)) { $this->setReportingDate(sprintf("%02d%02d%02d%02d%02d%02d", $matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6])); } break; case "processing_time": $this->setProcessingTime($metadata['entry']); break; case "starting_time": $iso8601period = $metadata["entry"]; if (preg_match("/P(\\d+)Y(\\d+)M(\\d+)DT(\\d+)H(\\d+)M(\\d+)S/", $iso8601period, $matches)) { $this->setStartingTime(sprintf("%02d%02d%02d%02d%02d%02d", $matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6])); $this->setStartingTimeEnabled(true); } break; case "ending_time": $iso8601period = $metadata["entry"]; if (preg_match("/P(\\d+)Y(\\d+)M(\\d+)DT(\\d+)H(\\d+)M(\\d+)S/", $iso8601period, $matches)) { $this->setEndingTime(sprintf("%02d%02d%02d%02d%02d%02d", $matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6])); $this->setEndingTimeEnabled(true); } break; case "enable_examview": $this->setEnableExamview($metadata["entry"]); break; case 'show_examview_html': $this->setShowExamviewHtml($metadata['entry']); break; case 'show_examview_pdf': $this->setShowExamviewPdf($metadata['entry']); break; case 'redirection_mode': $this->setRedirectionMode($metadata['entry']); break; case 'redirection_url': $this->setRedirectionUrl($metadata['entry']); break; case 'examid_in_kiosk': case 'examid_in_test_pass': $this->setShowExamIdInTestPassEnabled($metadata['entry']); break; case 'show_exam_id': case 'examid_in_test_res': $this->setShowExamIdInTestResultsEnabled($metadata['entry']); break; case 'enable_archiving': $this->setEnableArchiving($metadata['entry']); break; case 'sign_submission': $this->setSignSubmission($metadata['entry']); break; case 'char_selector_availability': $this->setCharSelectorAvailability($metadata['entry']); break; case 'char_selector_definition': $this->setCharSelectorDefinition($metadata['entry']); break; case 'skill_service': $this->setSkillServiceEnabled((bool) $metadata['entry']); break; case 'result_tax_filters': $this->setResultFilterTaxIds(strlen($metadata['entry']) ? unserialize($metadata['entry']) : array()); break; case 'show_grading_status': $this->setShowGradingStatusEnabled((bool) $metadata['entry']); break; case 'show_grading_mark': $this->setShowGradingMarkEnabled((bool) $metadata['entry']); break; } if (preg_match("/mark_step_\\d+/", $metadata["label"])) { $xmlmark = $metadata["entry"]; preg_match("/<short>(.*?)<\\/short>/", $xmlmark, $matches); $mark_short = $matches[1]; preg_match("/<official>(.*?)<\\/official>/", $xmlmark, $matches); $mark_official = $matches[1]; preg_match("/<percentage>(.*?)<\\/percentage>/", $xmlmark, $matches); $mark_percentage = $matches[1]; preg_match("/<passed>(.*?)<\\/passed>/", $xmlmark, $matches); $mark_passed = $matches[1]; $this->mark_schema->addMarkStep($mark_short, $mark_official, $mark_percentage, $mark_passed); } } // handle the import of media objects in XHTML code if (is_array($_SESSION["import_mob_xhtml"])) { include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php"; include_once "./Services/RTE/classes/class.ilRTE.php"; include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php"; foreach ($_SESSION["import_mob_xhtml"] as $mob) { $importfile = ilObjTest::_getImportDirectory() . '/' . $mob["uri"]; if (file_exists($importfile)) { $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE); ilObjMediaObject::_saveUsage($media_object->getId(), "tst:html", $this->getId()); $this->setIntroduction(ilRTE::_replaceMediaObjectImageSrc(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $this->getIntroduction()), 1)); $this->setFinalStatement(ilRTE::_replaceMediaObjectImageSrc(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $this->getFinalStatement()), 1)); } else { global $ilLog; $ilLog->write("Error: Could not open XHTML mob file for test introduction during test import. File {$importfile} does not exist!"); } } $this->saveToDb(); } }
/** * imports question(s) into the questionpool (after verification) */ function importVerifiedFileObject() { include_once "./Modules/Test/classes/class.ilObjTest.php"; // create new questionpool object $newObj = new ilObjTest(0, true); // set type of questionpool object $newObj->setType($_GET["new_type"]); // set title of questionpool object to "dummy" $newObj->setTitle("dummy"); // set description of questionpool object $newObj->setDescription("test import"); // create the questionpool class in the ILIAS database (object_data table) $newObj->create(true); // create a reference for the questionpool object in the ILIAS database (object_reference table) $newObj->createReference(); // put the questionpool object in the administration tree $newObj->putInTree($_GET["ref_id"]); // get default permissions and set the permissions for the questionpool object $newObj->setPermissions($_GET["ref_id"]); // notify the questionpool object and all its parent objects that a "new" object was created $newObj->notify("new", $_GET["ref_id"], $_GET["parent_non_rbac_id"], $_GET["ref_id"], $newObj->getRefId()); // empty mark schema $newObj->mark_schema->flush(); // start parsing of QTI files include_once "./Services/QTI/classes/class.ilQTIParser.php"; // Handle selection of "no questionpool" as qpl_id = -1 -> use test object id instead. // TODO: chek if empty strings in $_POST["qpl_id"] relates to a bug or not if ($_POST["qpl_id"] == "-1") { $qpl_id = $newObj->id; } else { $qpl_id = $_POST["qpl_id"]; } $qtiParser = new ilQTIParser($_SESSION["tst_import_qti_file"], IL_MO_PARSE_QTI, $qpl_id, $_POST["ident"]); $qtiParser->setTestObject($newObj); $result = $qtiParser->startParsing(); $newObj->saveToDb(); // import page data include_once "./Modules/LearningModule/classes/class.ilContObjParser.php"; $contParser = new ilContObjParser($newObj, $_SESSION["tst_import_xml_file"], $_SESSION["tst_import_subdir"]); $contParser->setQuestionMapping($qtiParser->getImportMapping()); $contParser->startParsing(); // import test results if (@file_exists($_SESSION["tst_import_results_file"])) { include_once "./Modules/Test/classes/class.ilTestResultsImportParser.php"; $results = new ilTestResultsImportParser($_SESSION["tst_import_results_file"], $newObj); $results->startParsing(); } // delete import directory ilUtil::delDir(ilObjTest::_getImportDirectory()); ilUtil::sendSuccess($this->lng->txt("object_imported"), true); $newObj->updateMetaData(); ilUtil::redirect("ilias.php?ref_id=" . $newObj->getRefId() . "&baseClass=ilObjTestGUI"); }
/** * Creates a question from a QTI file * * Receives parameters from a QTI parser and creates a valid ILIAS question object * * @param object $item The QTI item object * @param integer $questionpool_id The id of the parent questionpool * @param integer $tst_id The id of the parent test if the question is part of a test * @param object $tst_object A reference to the parent test object * @param integer $question_counter A reference to a question counter to count the questions of an imported question pool * @param array $import_mapping An array containing references to included ILIAS objects * @access public */ function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping) { global $ilUser; // empty session variable for imported xhtml mobs unset($_SESSION["import_mob_xhtml"]); $presentation = $item->getPresentation(); $duration = $item->getDuration(); $now = getdate(); $maxchars = 0; $maxpoints = 0; $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']); foreach ($presentation->order as $entry) { switch ($entry["type"]) { case "response": $response = $presentation->response[$entry["index"]]; $rendertype = $response->getRenderType(); switch (strtolower(get_class($rendertype))) { case "ilqtirenderfib": $maxchars = $rendertype->getMaxchars(); break; } break; } } $feedbacksgeneric = array(); foreach ($item->resprocessing as $resprocessing) { $outcomes = $resprocessing->getOutcomes(); foreach ($outcomes->decvar as $decvar) { $maxpoints = $decvar->getMaxvalue(); } foreach ($resprocessing->respcondition as $respcondition) { foreach ($respcondition->displayfeedback as $feedbackpointer) { if (strlen($feedbackpointer->getLinkrefid())) { foreach ($item->itemfeedback as $ifb) { if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) { // found a feedback for the identifier if (count($ifb->material)) { foreach ($ifb->material as $material) { $feedbacksgeneric[1] = $material; } } if (count($ifb->flow_mat) > 0) { foreach ($ifb->flow_mat as $fmat) { if (count($fmat->material)) { foreach ($fmat->material as $material) { $feedbacksgeneric[1] = $material; } } } } } else { if (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) { // found a feedback for the identifier if (count($ifb->material)) { foreach ($ifb->material as $material) { $feedbacksgeneric[0] = $material; } } if (count($ifb->flow_mat) > 0) { foreach ($ifb->flow_mat as $fmat) { if (count($fmat->material)) { foreach ($fmat->material as $material) { $feedbacksgeneric[0] = $material; } } } } } } } } } } } $this->object->setTitle($item->getTitle()); $this->object->setComment($item->getComment()); $this->object->setAuthor($item->getAuthor()); $this->object->setOwner($ilUser->getId()); $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext())); $this->object->setObjId($questionpool_id); $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]); $this->object->setPoints($maxpoints); $this->object->setMaxNumOfChars($maxchars); $textrating = $item->getMetadataEntry("textrating"); if (strlen($textrating)) { $this->object->setTextRating($textrating); } $keywords = $item->getMetadataEntry("keywords"); if (strlen($keywords)) { $this->object->setKeywords($keywords); } $this->object->saveToDb(); if (count($item->suggested_solutions)) { foreach ($item->suggested_solutions as $suggested_solution) { $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true); } $this->object->saveToDb(); } foreach ($feedbacksgeneric as $correctness => $material) { $m = $this->object->QTIMaterialToString($material); $feedbacksgeneric[$correctness] = $m; } // handle the import of media objects in XHTML code $questiontext = $this->object->getQuestion(); if (is_array($_SESSION["import_mob_xhtml"])) { include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php"; include_once "./Services/RTE/classes/class.ilRTE.php"; foreach ($_SESSION["import_mob_xhtml"] as $mob) { if ($tst_id > 0) { include_once "./Modules/Test/classes/class.ilObjTest.php"; $importfile = ilObjTest::_getImportDirectory() . "/" . $_SESSION["tst_import_subdir"] . "/" . $mob["uri"]; } else { include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php"; $importfile = ilObjQuestionPool::_getImportDirectory() . "/" . $_SESSION["qpl_import_subdir"] . "/" . $mob["uri"]; } $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE); ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId()); $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext); foreach ($feedbacksgeneric as $correctness => $material) { $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material); } } } $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1)); foreach ($feedbacksgeneric as $correctness => $material) { $this->object->saveFeedbackGeneric($correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1)); } $this->object->saveToDb(); if ($tst_id > 0) { $q_1_id = $this->object->getId(); $question_id = $this->object->duplicate(true); $tst_object->questions[$question_counter++] = $question_id; $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id); } else { $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0); } }
/** * Receives parameters from a QTI parser and creates a valid ILIAS test object * * @param object $assessment The QTI assessment object * @access public */ function fromXML(&$assessment) { unset($_SESSION["import_mob_xhtml"]); $this->setDescription($assessment->getComment()); $this->setTitle($assessment->getTitle()); foreach ($assessment->objectives as $objectives) { foreach ($objectives->materials as $material) { $this->setIntroduction($this->QTIMaterialToString($material)); } } if ($assessment->getPresentationMaterial()) { $this->setFinalStatement($this->QTIMaterialToString($assessment->getPresentationMaterial()->getMaterial(0))); } foreach ($assessment->assessmentcontrol as $assessmentcontrol) { switch ($assessmentcontrol->getSolutionswitch()) { case "Yes": $this->setInstantFeedbackSolution(1); break; default: $this->setInstantFeedbackSolution(0); break; } } foreach ($assessment->qtimetadata as $metadata) { switch ($metadata["label"]) { case "test_type": // for old tests with a test type $type = $metadata["entry"]; switch ($type) { case 1: // assessment $this->setAnonymity(1); break; case 2: // self assessment break; case 4: // online exam $this->setFixedParticipants(1); $this->setListOfQuestionsSettings(7); $this->setShowSolutionPrintview(1); break; case 5: // varying random test break; } break; case "sequence_settings": $this->setSequenceSettings($metadata["entry"]); break; case "author": $this->setAuthor($metadata["entry"]); break; case "nr_of_tries": $this->setNrOfTries($metadata["entry"]); break; case "kiosk": $this->setKiosk($metadata["entry"]); break; case "showfinalstatement": $this->setShowFinalStatement($metadata["entry"]); break; case "showinfo": $this->setShowInfo($metadata["entry"]); break; case "forcejs": $this->setForceJS($metadata["entry"]); break; case "customstyle": $this->setCustomStyle($metadata["entry"]); break; case "hide_previous_results": if ($metadata["entry"] == 0) { $this->setUsePreviousAnswers(1); } else { $this->setUsePreviousAnswers(0); } break; case "use_previous_answers": $this->setUsePreviousAnswers($metadata["entry"]); break; case "answer_feedback": $this->setAnswerFeedback($metadata["entry"]); break; case "hide_title_points": $this->setTitleOutput($metadata["entry"]); break; case "title_output": $this->setTitleOutput($metadata["entry"]); break; case "random_test": $this->setRandomTest($metadata["entry"]); break; case "random_question_count": $this->setRandomQuestionCount($metadata["entry"]); break; case "results_presentation": $this->setResultsPresentation($metadata["entry"]); break; case "reset_processing_time": $this->setResetProcessingTime($metadata["entry"]); break; case "instant_verification": $this->setInstantFeedbackSolution($metadata["entry"]); break; case "answer_feedback_points": $this->setAnswerFeedbackPoints($metadata["entry"]); break; case "anonymity": $this->setAnonymity($metadata["entry"]); break; case "show_cancel": $this->setShowCancel($metadata["entry"]); break; case "show_marker": $this->setShowMarker($metadata["entry"]); break; case "fixed_participants": $this->setFixedParticipants($metadata["entry"]); break; case "score_reporting": $this->setScoreReporting($metadata["entry"]); break; case "shuffle_questions": $this->setShuffleQuestions($metadata["entry"]); break; case "count_system": $this->setCountSystem($metadata["entry"]); break; case "mc_scoring": $this->setMCScoring($metadata["entry"]); break; case "mailnotification": $this->setMailNotification($metadata["entry"]); break; case "mailnottype": $this->setMailNotificationType($metadata["entry"]); break; case "exportsettings": $this->setExportSettings($metadata['exportsettings']); break; case "score_cutting": $this->setScoreCutting($metadata["entry"]); break; case "password": $this->setPassword($metadata["entry"]); break; case "allowedUsers": $this->setAllowedUsers($metadata["entry"]); break; case "allowedUsersTimeGap": $this->setAllowedUsersTimeGap($metadata["entry"]); break; case "pass_scoring": $this->setPassScoring($metadata["entry"]); break; case "show_summary": $this->setListOfQuestionsSettings($metadata["entry"]); break; case "reporting_date": $iso8601period = $metadata["entry"]; if (preg_match("/P(\\d+)Y(\\d+)M(\\d+)DT(\\d+)H(\\d+)M(\\d+)S/", $iso8601period, $matches)) { $this->setReportingDate(sprintf("%02d%02d%02d%02d%02d%02d", $matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6])); } break; case "processing_time": $this->setProcessingTime($metadata['entry']); break; case "starting_time": $iso8601period = $metadata["entry"]; if (preg_match("/P(\\d+)Y(\\d+)M(\\d+)DT(\\d+)H(\\d+)M(\\d+)S/", $iso8601period, $matches)) { $this->setStartingTime(sprintf("%02d%02d%02d%02d%02d%02d", $matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6])); } break; case "ending_time": $iso8601period = $metadata["entry"]; if (preg_match("/P(\\d+)Y(\\d+)M(\\d+)DT(\\d+)H(\\d+)M(\\d+)S/", $iso8601period, $matches)) { $this->setEndingTime(sprintf("%02d%02d%02d%02d%02d%02d", $matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6])); } break; } if (preg_match("/mark_step_\\d+/", $metadata["label"])) { $xmlmark = $metadata["entry"]; preg_match("/<short>(.*?)<\\/short>/", $xmlmark, $matches); $mark_short = $matches[1]; preg_match("/<official>(.*?)<\\/official>/", $xmlmark, $matches); $mark_official = $matches[1]; preg_match("/<percentage>(.*?)<\\/percentage>/", $xmlmark, $matches); $mark_percentage = $matches[1]; preg_match("/<passed>(.*?)<\\/passed>/", $xmlmark, $matches); $mark_passed = $matches[1]; $this->mark_schema->addMarkStep($mark_short, $mark_official, $mark_percentage, $mark_passed); } } // handle the import of media objects in XHTML code if (is_array($_SESSION["import_mob_xhtml"])) { include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php"; include_once "./Services/RTE/classes/class.ilRTE.php"; include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php"; foreach ($_SESSION["import_mob_xhtml"] as $mob) { $importfile = ilObjTest::_getImportDirectory() . '/' . $mob["uri"]; if (file_exists($importfile)) { $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE); ilObjMediaObject::_saveUsage($media_object->getId(), "tst:html", $this->getId()); $this->setIntroduction(ilRTE::_replaceMediaObjectImageSrc(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $this->getIntroduction()), 1)); $this->setFinalStatement(ilRTE::_replaceMediaObjectImageSrc(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $this->getFinalStatement()), 1)); } else { global $ilLog; $ilLog->write("Error: Could not open XHTML mob file for test introduction during test import. File {$importfile} does not exist!"); } } $this->saveToDb(); } }
/** * Creates a question from a QTI file * * Receives parameters from a QTI parser and creates a valid ILIAS question object * * @param object $item The QTI item object * @param integer $questionpool_id The id of the parent questionpool * @param integer $tst_id The id of the parent test if the question is part of a test * @param object $tst_object A reference to the parent test object * @param integer $question_counter A reference to a question counter to count the questions of an imported question pool * @param array $import_mapping An array containing references to included ILIAS objects * @access public */ function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping) { global $ilUser; // empty session variable for imported xhtml mobs unset($_SESSION["import_mob_xhtml"]); $presentation = $item->getPresentation(); $duration = $item->getDuration(); $now = getdate(); $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']); $feedbacksgeneric = array(); $this->object->setTitle($item->getTitle()); $this->object->setComment($item->getComment()); $this->object->setAuthor($item->getAuthor()); $this->object->setOwner($ilUser->getId()); $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext())); $this->object->setObjId($questionpool_id); $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]); if (preg_match_all("/(\\\$v\\d+)/ims", $this->object->getQuestion(), $matches)) { foreach ($matches[1] as $variable) { $data = unserialize($item->getMetadataEntry($variable)); $unit = $this->object->getUnitRepository()->getUnit($data["unitvalue"]); require_once 'Modules/TestQuestionPool/classes/class.assFormulaQuestionVariable.php'; $varObj = new assFormulaQuestionVariable($variable, $data["rangemin"], $data["rangemax"], $unit, $data["precision"], $data["intprecision"]); $this->object->addVariable($varObj); } } if (preg_match_all("/(\\\$r\\d+)/ims", $this->object->getQuestion(), $rmatches)) { foreach ($rmatches[1] as $result) { $data = unserialize($item->getMetadataEntry($result)); $unit = $this->object->getUnitRepository()->getUnit($data["unitvalue"]); require_once 'Modules/TestQuestionPool/classes/class.assFormulaQuestionResult.php'; if (!is_array($data["rating"])) { $resObj = new assFormulaQuestionResult($result, $data["rangemin"], $data["rangemax"], $data["tolerance"], $unit, $data["formula"], $data["points"], $data["precision"], TRUE); } else { $resObj = new assFormulaQuestionResult($result, $data["rangemin"], $data["rangemax"], $data["tolerance"], $unit, $data["formula"], $data["points"], $data["precision"], FALSE, $data["rating"]["sign"], $data["rating"]["value"], $data["rating"]["unit"]); } $this->object->addResult($resObj); if (is_array($data["resultunits"])) { foreach ($data["resultunits"] as $resu) { $ru = $this->object->getUnitRepository()->getUnit($resu["unitvalue"]); if (is_object($ru)) { $this->object->addResultUnit($resObj, $ru); } } } } } $this->object->setPoints($item->getMetadataEntry("points")); $this->addGeneralMetadata($item); // additional content editing mode information $this->object->setAdditionalContentEditingMode($this->fetchAdditionalContentEditingModeInformation($item)); $this->object->saveToDb(); // handle the import of media objects in XHTML code $questiontext = $this->object->getQuestion(); if (is_array($_SESSION["import_mob_xhtml"])) { include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php"; include_once "./Services/RTE/classes/class.ilRTE.php"; foreach ($_SESSION["import_mob_xhtml"] as $mob) { if ($tst_id > 0) { include_once "./Modules/Test/classes/class.ilObjTest.php"; $importfile = ilObjTest::_getImportDirectory() . "/" . $_SESSION["tst_import_subdir"] . "/" . $mob["uri"]; } else { include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php"; $importfile = ilObjQuestionPool::_getImportDirectory() . "/" . $_SESSION["qpl_import_subdir"] . "/" . $mob["uri"]; } $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE); ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId()); $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext); } } $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1)); // additional content editing mode information $this->object->setAdditionalContentEditingMode($this->fetchAdditionalContentEditingModeInformation($item)); $this->object->saveToDb(); if (count($item->suggested_solutions)) { foreach ($item->suggested_solutions as $suggested_solution) { $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true); } $this->object->saveToDb(); } if ($tst_id > 0) { $q_1_id = $this->object->getId(); $question_id = $this->object->duplicate(true); $tst_object->questions[$question_counter++] = $question_id; $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id); } else { $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0); } }
/** * Creates a question from a QTI file * * Receives parameters from a QTI parser and creates a valid ILIAS question object * * @param object $item The QTI item object * @param integer $questionpool_id The id of the parent questionpool * @param integer $tst_id The id of the parent test if the question is part of a test * @param object $tst_object A reference to the parent test object * @param integer $question_counter A reference to a question counter to count the questions of an imported question pool * @param array $import_mapping An array containing references to included ILIAS objects * @access public */ function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping) { global $ilUser; // empty session variable for imported xhtml mobs unset($_SESSION["import_mob_xhtml"]); $presentation = $item->getPresentation(); $duration = $item->getDuration(); $now = getdate(); $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']); $feedbacksgeneric = array(); $this->object->setTitle($item->getTitle()); $this->object->setComment($item->getComment()); $this->object->setAuthor($item->getAuthor()); $this->object->setOwner($ilUser->getId()); $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext())); $this->object->setObjId($questionpool_id); $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]); $this->object->setPoints($item->getMetadataEntry("points")); $this->object->setOptionString($item->getMetadataEntry("option_string")); $this->object->setSampleSolution($item->getMetadataEntry("sample_solution")); $this->object->saveToDb('', false); // handle the import of media objects in XHTML code $questiontext = $this->object->getQuestion(); if (is_array($_SESSION["import_mob_xhtml"])) { include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php"; include_once "./Services/RTE/classes/class.ilRTE.php"; foreach ($_SESSION["import_mob_xhtml"] as $mob) { if ($tst_id > 0) { include_once "./Modules/Test/classes/class.ilObjTest.php"; $importfile = ilObjTest::_getImportDirectory() . '/' . $mob["uri"]; } else { include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php"; $importfile = ilObjQuestionPool::_getImportDirectory() . '/' . $mob["uri"]; } $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE); ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId()); $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext); } } $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1)); // feedback $feedbacksgeneric = array(); foreach ($item->itemfeedback as $ifb) { if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) { // found a feedback for the identifier if (count($ifb->material)) { foreach ($ifb->material as $material) { $feedbacksgeneric[1] = $material; } } if (count($ifb->flow_mat) > 0) { foreach ($ifb->flow_mat as $fmat) { if (count($fmat->material)) { foreach ($fmat->material as $material) { $feedbacksgeneric[1] = $material; } } } } } else { if (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) { // found a feedback for the identifier if (count($ifb->material)) { foreach ($ifb->material as $material) { $feedbacksgeneric[0] = $material; } } if (count($ifb->flow_mat) > 0) { foreach ($ifb->flow_mat as $fmat) { if (count($fmat->material)) { foreach ($fmat->material as $material) { $feedbacksgeneric[0] = $material; } } } } } } } // genericFeedback foreach ($feedbacksgeneric as $correctness => $material) { $m = $this->object->QTIMaterialToString($material); $feedbacksgeneric[$correctness] = $m; } foreach ($feedbacksgeneric as $correctness => $material) { //$this->object->saveFeedbackGeneric($correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1)); $this->object->feedbackOBJ->importGenericFeedback($this->object->getId(), $correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1)); } $this->object->saveToDb(); if ($tst_id > 0) { $q_1_id = $this->object->getId(); $question_id = $this->object->duplicate(true); $tst_object->questions[$question_counter++] = $question_id; $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id); } else { $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0); } }