Exemplo n.º 1
0
 /**
  * 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();
     }
 }
 /**
  * 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();
     }
 }