/** * 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->addGeneralMetadata($item); $this->object->setTitle($item->getTitle()); $this->object->setNrOfTries($item->getMaxattempts()); $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->setOrderText($item->getMetadataEntry("ordertext")); $this->object->setTextSize($item->getMetadataEntry("textsize")); $this->object->setSeparator($item->getMetadataEntry("separator")); // 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) { $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"]; } else { $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"]; } $GLOBALS['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile); $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)); $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, null, null, null, $tst_id); $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); } }
/** * Import XML * * @param * @return */ function importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping) { // Container import => test object already created if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_id)) { $newObj = ilObjectFactory::getInstanceByObjId($new_id, false); #$newObj->setImportDirectory(dirname(rtrim($this->getImportDirectory(),'/'))); } else { // Shouldn't happen $GLOBALS['ilLog']->write(__METHOD__ . ': Called in non container mode'); return false; } include_once "./Services/Survey/classes/class.SurveyImportParser.php"; list($xml_file) = $this->parseXmlFileNames(); if (!@file_exists($xml_file)) { $GLOBALS['ilLog']->write(__METHOD__ . ': Cannot find xml definition: ' . $xml_file); return false; } $import = new SurveyImportParser(-1, $xml_file, TRUE); $import->setSurveyObject($newObj); $import->startParsing(); 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 = dirname($xml_file) . "/" . $mob["uri"]; if (file_exists($importfile)) { $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE); ilObjMediaObject::_saveUsage($media_object->getId(), "svy:html", $newObj->getId()); $newObj->setIntroduction(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $newObj->getIntroduction())); $newObj->setOutro(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $newObj->getOutro())); } else { global $ilLog; $ilLog->write("Error: Could not open XHTML mob file for test introduction during test import. File {$importfile} does not exist!"); } } $newObj->setIntroduction(ilRTE::_replaceMediaObjectImageSrc($newObj->getIntroduction(), 1)); $newObj->setOutro(ilRTE::_replaceMediaObjectImageSrc($newObj->getOutro(), 1)); $newObj->saveToDb(); } $a_mapping->addMapping("Modules/Survey", "svy", $a_id, $newObj->getId()); return true; }
/** * Save all usages of media objects (media aliases, media objects, internal links) * * @param string $a_xml xml data of page */ static function saveMobUsage($a_page, $a_domdoc, $a_old_nr = 0) { $usages = array(); // media aliases $xpath = new DOMXPath($a_domdoc); $nodes = $xpath->query('//MediaAlias'); foreach ($nodes as $node) { $id_arr = explode("_", $node->getAttribute("OriginId")); $mob_id = $id_arr[count($id_arr) - 1]; if ($mob_id > 0 && $id_arr[1] == "") { $usages[$mob_id] = true; } } // media objects $xpath = new DOMXPath($a_domdoc); $nodes = $xpath->query('//MediaObject/MetaData/General/Identifier'); foreach ($nodes as $node) { $mob_entry = $node->getAttribute("Entry"); $mob_arr = explode("_", $mob_entry); $mob_id = $mob_arr[count($mob_arr) - 1]; if ($mob_id > 0 && $mob_arr[1] == "") { $usages[$mob_id] = true; } } // internal links $xpath = new DOMXPath($a_domdoc); $nodes = $xpath->query("//IntLink[@Type='MediaObject']"); foreach ($nodes as $node) { $mob_target = $node->getAttribute("Target"); $mob_arr = explode("_", $mob_target); //echo "<br>3<br>"; //echo $mob_target."<br>"; //var_dump($mob_arr); $mob_id = $mob_arr[count($mob_arr) - 1]; if ($mob_id > 0 && $mob_arr[1] == "") { $usages[$mob_id] = true; } } include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php"; ilObjMediaObject::_deleteAllUsages($a_page->getParentType() . ":pg", $a_page->getId(), $a_old_nr, $a_page->getLanguage()); foreach ($usages as $mob_id => $val) { ilObjMediaObject::_saveUsage($mob_id, $a_page->getParentType() . ":pg", $a_page->getId(), $a_old_nr, $a_page->getLanguage()); } return $usages; }
/** * 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); } }
/** * 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; $points = 0; $upperlimit = 0; $lowerlimit = 0; $feedbacksgeneric = array(); $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; } } foreach ($item->resprocessing as $resprocessing) { foreach ($resprocessing->respcondition as $respcondition) { $conditionvar = $respcondition->getConditionvar(); foreach ($conditionvar->order as $order) { switch ($order["field"]) { case "varlte": $upperlimit = $conditionvar->varlte[$order["index"]]->getContent(); break; case "vargte": $lowerlimit = $conditionvar->vargte[$order["index"]]->getContent(); break; } } foreach ($respcondition->setvar as $setvar) { $points = $setvar->getContent(); } if (count($respcondition->displayfeedback)) { 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->setNrOfTries($item->getMaxattempts()); $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->setMaxChars($maxchars); $this->object->setPoints($points); $this->object->setLowerLimit($lowerlimit); $this->object->setUpperLimit($upperlimit); $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) { $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"]; } else { $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"]; } $GLOBALS['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile); $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, null, null, null, $tst_id); $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); } }
public function saveStatutoryRegulationsObject() { require_once 'Services/RTE/classes/class.ilRTE.php'; if (isset($_POST['statutory_regulations']) && $_POST['statutory_regulations'] != NULL) { $this->genSetData->set('statutory_regulations', ilRTE::_replaceMediaObjectImageSrc($_POST['statutory_regulations'], 0), 'regulations'); // copy temporary media objects (frm~) include_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php'; $mediaObjects = ilRTE::_getMediaObjects($_POST['statutory_regulations'], 0); $myMediaObjects = ilObjMediaObject::_getMobsOfObject('pays~:html', ilObject::_lookupObjId($this->ref_id)); foreach ($mediaObjects as $mob) { foreach ($myMediaObjects as $myMob) { if ($mob == $myMob) { // change usage ilObjMediaObject::_removeUsage($mob, 'pays~:html', ilObject::_lookupObjId($this->ref_id)); break; } } ilObjMediaObject::_saveUsage($mob, 'pays~:html', ilObject::_lookupObjId($this->ref_id)); } } else { $this->genSetData->set('statutory_regulations', NULL, 'regulations'); } // remove usage of deleted media objects include_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php'; $oldMediaObjects = ilObjMediaObject::_getMobsOfObject('pays~:html', ilObject::_lookupObjId($this->ref_id)); $curMediaObjects = ilRTE::_getMediaObjects($_POST['statutory_regulations'], 0); foreach ($oldMediaObjects as $oldMob) { $found = false; foreach ($curMediaObjects as $curMob) { if ($oldMob == $curMob) { $found = true; break; } } if (!$found) { if (ilObjMediaObject::_exists($oldMob)) { ilObjMediaObject::_removeUsage($oldMob, 'pays~:html', ilObject::_lookupObjId($this->ref_id)); $mob_obj = new ilObjMediaObject($oldMob); $mob_obj->delete(); } } } $this->genSetData->set('show_sr_shoppingcart', isset($_POST['show_sr_shoppingcart']) ? 1 : 0, 'regulations'); $this->genSetData->set('attach_sr_invoice', isset($_POST['attach_sr_invoice']) ? 1 : 0, 'regulations'); $this->StatutoryRegulationsObject(); ilUtil::sendSuccess($this->lng->txt('pays_updated_general_settings')); return true; }
/** * 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->setNrOfTries($item->getMaxattempts()); $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->setWidth($item->getMetadataEntry("width")); $this->object->setHeight($item->getMetadataEntry("height")); $this->object->setApplet($item->getMetadataEntry("applet")); $this->object->setParameters(unserialize($item->getMetadataEntry("params"))); $this->object->setPoints($item->getMetadataEntry("points")); $this->object->saveToDb(); $flashapplet =& base64_decode($item->getMetadataEntry("swf")); if (!file_exists($this->object->getFlashPath())) { include_once "./Services/Utilities/classes/class.ilUtil.php"; ilUtil::makeDirParents($this->object->getFlashPath()); } $filename = $this->object->getFlashPath() . $this->object->getApplet(); $fh = fopen($filename, "wb"); if ($fh == false) { // global $ilErr; // $ilErr->raiseError($this->object->lng->txt("error_save_image_file") . ": $php_errormsg", $ilErr->MESSAGE); // return; } else { fwrite($fh, $flashapplet); fclose($fh); } $feedbacksgeneric = $this->getFeedbackGeneric($item); // 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) { $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"]; } else { $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"]; } $GLOBALS['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile); $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 (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, null, null, null, $tst_id); $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(); $applet = NULL; $maxpoints = 0; $javacode = ""; $javacodebase = ""; $javaarchive = ""; $params = array(); $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']); $answers = array(); foreach ($presentation->order as $entry) { switch ($entry["type"]) { case "material": $material = $presentation->material[$entry["index"]]; for ($i = 0; $i < $material->getMaterialCount(); $i++) { $mat = $material->getMaterial($i); if (strcmp($mat["type"], "mattext") == 0) { $mattext = $mat["material"]; if (strlen($mattext->getLabel()) == 0 && strlen($this->object->QTIMaterialToString($item->getQuestiontext())) == 0) { $item->setQuestiontext($mattext->getContent()); } if (strcmp($mattext->getLabel(), "points") == 0) { $maxpoints = $mattext->getContent(); } else { if (strcmp($mattext->getLabel(), "java_code") == 0) { $javacode = $mattext->getContent(); } else { if (strcmp($mattext->getLabel(), "java_codebase") == 0) { $javacodebase = $mattext->getContent(); } else { if (strcmp($mattext->getLabel(), "java_archive") == 0) { $javaarchive = $mattext->getContent(); } else { if (strlen($mattext->getLabel()) > 0) { array_push($params, array("key" => $mattext->getLabel(), "value" => $mattext->getContent())); } } } } } } elseif (strcmp($mat["type"], "matapplet") == 0) { $applet = $mat["material"]; } } break; } } $feedbacksgeneric = array(); foreach ($item->resprocessing as $resprocessing) { 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->setNrOfTries($item->getMaxattempts()); $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->setJavaAppletFilename($applet->getUri()); $this->object->setJavaWidth($applet->getWidth()); $this->object->setJavaHeight($applet->getHeight()); $this->object->setJavaCode($javacode); $this->object->setJavaCodebase($javacodebase); $this->object->setJavaArchive($javaarchive); $this->object->setPoints($maxpoints); foreach ($params as $pair) { $this->object->addParameter($pair["key"], $pair["value"]); } $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(); } $javaapplet =& base64_decode($applet->getContent()); $javapath = $this->object->getJavaPath(); if (!file_exists($javapath)) { include_once "./Services/Utilities/classes/class.ilUtil.php"; ilUtil::makeDirParents($javapath); } $javapath .= $this->object->getJavaAppletFilename(); $fh = fopen($javapath, "wb"); if ($fh == false) { // global $ilErr; // $ilErr->raiseError($this->object->lng->txt("error_save_image_file") . ": $php_errormsg", $ilErr->MESSAGE); // return; } else { $javafile = fwrite($fh, $javaapplet); fclose($fh); } // handle the import of media objects in XHTML code foreach ($feedbacksgeneric as $correctness => $material) { $m = $this->object->QTIMaterialToString($material); $feedbacksgeneric[$correctness] = $m; } $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) { $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"]; } else { $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"]; } $GLOBALS['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile); $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, null, null, null, $tst_id); $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); } }
/** * synchronises appearances of media objects in $a_text with media * object usage table * * @param string $a_text text, including media object tags * @param string $a_usage_type type of context of usage, e.g. cat:html * @param int $a_usage_id if of context of usage, e.g. category id */ function _cleanupMediaObjectUsage($a_text, $a_usage_type, $a_usage_id) { // get current stored mobs include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php"; $mobs = ilObjMediaObject::_getMobsOfObject($a_usage_type, $a_usage_id); while (eregi("data\\/" . CLIENT_ID . "\\/mobs\\/mm_([0-9]+)", $a_text, $found)) { $a_text = str_replace($found[0], "", $a_text); if (!in_array($found[1], $mobs)) { // save usage if missing ilObjMediaObject::_saveUsage($found[1], $a_usage_type, $a_usage_id); } else { // if already saved everything ok -> take mob out of mobs array unset($mobs[$found[1]]); } } // remaining usages are not in text anymore -> delete them // and media objects (note: delete method of ilObjMediaObject // checks whether object is used in another context; if yes, // the object is not deleted!) foreach ($mobs as $mob) { ilObjMediaObject::_removeUsage($mob, $a_usage_type, $a_usage_id); $mob_obj =& new ilObjMediaObject($mob); $mob_obj->delete(); } }
/** * save all usages of media objects (media aliases, media objects, internal links) * * @param string $a_xml xml data of page */ function saveMobUsage($a_xml, $a_old_nr = 0) { $doc = domxml_open_mem($a_xml); // media aliases $xpc = xpath_new_context($doc); $path = "//MediaAlias"; $res =& xpath_eval($xpc, $path); $usages = array(); for ($i = 0; $i < count($res->nodeset); $i++) { $id_arr = explode("_", $res->nodeset[$i]->get_attribute("OriginId")); $mob_id = $id_arr[count($id_arr) - 1]; if ($mob_id > 0) { $usages[$mob_id] = true; } } // media objects $xpc = xpath_new_context($doc); $path = "//MediaObject/MetaData/General/Identifier"; $res =& xpath_eval($xpc, $path); for ($i = 0; $i < count($res->nodeset); $i++) { $mob_entry = $res->nodeset[$i]->get_attribute("Entry"); $mob_arr = explode("_", $mob_entry); $mob_id = $mob_arr[count($mob_arr) - 1]; if ($mob_id > 0) { $usages[$mob_id] = true; } } // internal links $xpc = xpath_new_context($doc); $path = "//IntLink[@Type='MediaObject']"; $res =& xpath_eval($xpc, $path); for ($i = 0; $i < count($res->nodeset); $i++) { $mob_target = $res->nodeset[$i]->get_attribute("Target"); $mob_arr = explode("_", $mob_target); $mob_id = $mob_arr[count($mob_arr) - 1]; if ($mob_id > 0) { $usages[$mob_id] = true; } } include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php"; ilObjMediaObject::_deleteAllUsages($this->getParentType() . ":pg", $this->getId(), $a_old_nr); foreach ($usages as $mob_id => $val) { ilObjMediaObject::_saveUsage($mob_id, $this->getParentType() . ":pg", $this->getId(), $a_old_nr); } return $usages; }
/** * 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(); $questionimage = array(); $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']); $answers = array(); foreach ($presentation->order as $entry) { switch ($entry["type"]) { case "response": $response = $presentation->response[$entry["index"]]; $rendertype = $response->getRenderType(); switch (strtolower(get_class($rendertype))) { case "ilqtirenderhotspot": foreach ($rendertype->material as $mat) { for ($i = 0; $i < $mat->getMaterialCount(); $i++) { $m = $mat->getMaterial($i); if (strcmp($m["type"], "matimage") == 0) { $questionimage = array("imagetype" => $m["material"]->getImageType(), "label" => $m["material"]->getLabel(), "content" => $m["material"]->getContent()); } } } foreach ($rendertype->response_labels as $response_label) { $ident = $response_label->getIdent(); $answerhint = ""; foreach ($response_label->material as $mat) { $answerhint .= $this->object->QTIMaterialToString($mat); } $answers[$ident] = array("answerhint" => $answerhint, "areatype" => $response_label->getRarea(), "coordinates" => $response_label->getContent(), "points" => 0, "answerorder" => $response_label->getIdent(), "correctness" => "1", "action" => ""); } break; } break; } } $responses = array(); $feedbacks = array(); $feedbacksgeneric = array(); foreach ($item->resprocessing as $resprocessing) { foreach ($resprocessing->respcondition as $respcondition) { $coordinates = ""; $conditionvar = $respcondition->getConditionvar(); foreach ($conditionvar->order as $order) { switch ($order["field"]) { case "varinside": $coordinates = $conditionvar->varinside[$order["index"]]->getContent(); break; } } foreach ($respcondition->setvar as $setvar) { foreach ($answers as $ident => $answer) { if (strcmp($answer["coordinates"], $coordinates) == 0) { $answers[$ident]["action"] = $setvar->getAction(); $answers[$ident]["points"] = $setvar->getContent(); if (count($respcondition->displayfeedback)) { 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; } } } } } } if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0) { // found a feedback for the identifier if (count($ifb->material)) { foreach ($ifb->material as $material) { $feedbacks[$ident] = $material; } } if (count($ifb->flow_mat) > 0) { foreach ($ifb->flow_mat as $fmat) { if (count($fmat->material)) { foreach ($fmat->material as $material) { $feedbacks[$ident] = $material; } } } } } } } } } } } } } } $this->object->setTitle($item->getTitle()); $this->object->setNrOfTries($item->getMaxattempts()); $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"]); $areas = array("2" => "rect", "1" => "circle", "3" => "poly"); $this->object->setImageFilename($questionimage["label"]); foreach ($answers as $answer) { $this->object->addAnswer($answer["answerhint"], $answer["points"], $answer["answerorder"], $answer["coordinates"], $areas[$answer["areatype"]]); } $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(); } $image =& base64_decode($questionimage["content"]); $imagepath = $this->object->getImagePath(); if (!file_exists($imagepath)) { include_once "./Services/Utilities/classes/class.ilUtil.php"; ilUtil::makeDirParents($imagepath); } $imagepath .= $questionimage["label"]; $fh = fopen($imagepath, "wb"); if ($fh == false) { // global $ilErr; // $ilErr->raiseError($this->object->lng->txt("error_save_image_file") . ": $php_errormsg", $ilErr->MESSAGE); // return; } else { $imagefile = fwrite($fh, $image); fclose($fh); } // handle the import of media objects in XHTML code foreach ($feedbacks as $ident => $material) { $m = $this->object->QTIMaterialToString($material); $feedbacks[$ident] = $m; } foreach ($feedbacksgeneric as $correctness => $material) { $m = $this->object->QTIMaterialToString($material); $feedbacksgeneric[$correctness] = $m; } $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) { $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"]; } else { $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"]; } $GLOBALS['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile); $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 ($feedbacks as $ident => $material) { $feedbacks[$ident] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material); } 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 ($feedbacks as $ident => $material) { $this->object->saveFeedbackSingleAnswer($ident, ilRTE::_replaceMediaObjectImageSrc($material, 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, null, null, null, $tst_id); $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(); $shuffle = 0; $now = getdate(); $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']); $definitions = array(); $terms = array(); $foundimage = FALSE; foreach ($presentation->order as $entry) { switch ($entry["type"]) { case "response": $response = $presentation->response[$entry["index"]]; $rendertype = $response->getRenderType(); switch (strtolower(get_class($rendertype))) { case "ilqtirenderchoice": $shuffle = $rendertype->getShuffle(); $answerorder = 0; foreach ($rendertype->response_labels as $response_label) { $ident = $response_label->getIdent(); $answertext = ""; $answerimage = array(); foreach ($response_label->material as $mat) { for ($m = 0; $m < $mat->getMaterialCount(); $m++) { $foundmat = $mat->getMaterial($m); if (strcmp($foundmat["type"], "mattext") == 0) { $answertext .= $foundmat["material"]->getContent(); } if (strcmp($foundmat["type"], "matimage") == 0) { $foundimage = TRUE; $answerimage = array("imagetype" => $foundmat["material"]->getImageType(), "label" => $foundmat["material"]->getLabel(), "content" => $foundmat["material"]->getContent()); } } } if ($response_label->getMatchMax() == 1 && strlen($response_label->getMatchGroup())) { $definitions[$ident] = array("answertext" => $answertext, "answerimage" => $answerimage, "points" => 0, "answerorder" => $ident, "action" => ""); } else { $terms[$ident] = array("term" => $answertext, "answerimage" => $answerimage, "points" => 0, "ident" => $ident, "action" => ""); } } break; } break; } } $responses = array(); $feedbacksgeneric = array(); foreach ($item->resprocessing as $resprocessing) { foreach ($resprocessing->respcondition as $respcondition) { $subset = array(); $correctness = 1; $conditionvar = $respcondition->getConditionvar(); foreach ($conditionvar->order as $order) { switch ($order["field"]) { case "varsubset": $subset = split(",", $conditionvar->varsubset[$order["index"]]->getContent()); break; } } foreach ($respcondition->setvar as $setvar) { array_push($responses, array("subset" => $subset, "action" => $setvar->getAction(), "points" => $setvar->getContent())); } if (count($respcondition->displayfeedback)) { 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; } } } } } } } } } } } } include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingTerm.php"; include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingDefinition.php"; include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingPair.php"; $this->object->createNewQuestion(); $this->addGeneralMetadata($item); $this->object->setTitle($item->getTitle()); $this->object->setNrOfTries($item->getMaxattempts()); $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"]); $extended_shuffle = $item->getMetadataEntry("shuffle"); $this->object->setThumbGeometry($item->getMetadataEntry("thumb_geometry")); $this->object->setElementHeight($item->getMetadataEntry("element_height")); // save images foreach ($terms as $term) { if (count($term['answerimage'])) { $this->saveImage($term['answerimage']['content'], $term['answerimage']['label']); } } foreach ($definitions as $definition) { if (count($definition['answerimage'])) { $this->saveImage($definition['answerimage']['content'], $definition['answerimage']['label']); } } foreach ($terms as $termindex => $term) { $this->object->addTerm(new assAnswerMatchingTerm($term["term"], $term['answerimage']['label'], $term["ident"])); } foreach ($definitions as $definitionindex => $definition) { $this->object->addDefinition(new assAnswerMatchingDefinition($definition["answertext"], $definition['answerimage']['label'], $definition["answerorder"])); } if (strlen($extended_shuffle) > 0) { $shuffle = $extended_shuffle; } $this->object->setShuffle($shuffle); foreach ($responses as $response) { $subset = $response["subset"]; foreach ($subset as $ident) { if (array_key_exists($ident, $definitions)) { $definition = $definitions[$ident]; } if (array_key_exists($ident, $terms)) { $term = $terms[$ident]; } } $this->object->addMatchingPair(new assAnswerMatchingTerm('', '', $term["ident"]), new assAnswerMatchingDefinition('', '', $definition["answerorder"]), $response['points']); } // 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(); } foreach ($responses as $response) { $subset = $response["subset"]; foreach ($subset as $ident) { if (array_key_exists($ident, $definitions)) { $definition = $definitions[$ident]; } if (array_key_exists($ident, $terms)) { $term = $terms[$ident]; } } } 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) { $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"]; } else { $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"]; } $GLOBALS['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile); $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->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, null, null, null, $tst_id); $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"]); 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); } }
/** * Called before finishing import. Fix references inside DataCollections * * @param ilImportMapping $a_mapping */ public function beforeFinishImport(ilImportMapping $a_mapping) { foreach ($this->import_temp_new_mob_ids as $new_mob_id) { ilObjMediaObject::_saveUsage($new_mob_id, "dcl:html", $a_mapping->getTargetId()); } foreach ($this->import_temp_refs as $record_field_id => $old_record_id) { $new_record_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_record', $old_record_id); $value = $new_record_id ? (int) $new_record_id : NULL; /** @var ilDataCollectionRecordField $record_field */ $record_field = $this->import_record_field_cache[$record_field_id]; $record_field->setValue($value, true); $record_field->doUpdate(); } foreach ($this->import_temp_refs_props as $field_prop_id => $old_field_id) { $new_field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_field', $old_field_id); $value = $new_field_id ? (int) $new_field_id : NULL; $field_prop = new ilDataCollectionFieldProp($field_prop_id); $field_prop->setValue($value); $field_prop->doUpdate(); } }
/** * 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, $ilLog; // 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']); // get the generic feedbach $feedbacksgeneric = array(); if (isset($item->itemfeedback)) { 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; } } } } } } } } // set question properties $this->addGeneralMetadata($item); $this->object->setTitle($item->getTitle()); $this->object->setNrOfTries($item->getMaxattempts()); $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->setAccountsXML(base64_decode($item->getMetadataEntry('accounts_content'))); $this->object->setPoints($item->getMetadataEntry("points")); // additional content editing mode information $this->object->setAdditionalContentEditingMode($this->fetchAdditionalContentEditingModeInformation($item)); // first save the question without its parts (to get a new question id) $this->object->saveToDb('', false); // then create the parts $parts = unserialize($item->getMetadataEntry('booking_parts')); if (is_array($parts)) { for ($i = 0; $i < count($parts); $i++) { $part = $parts[$i]; // since plugin version 1.1.7 the text of the questions parts is added as material to the presentation // this enables images in the parts text // the material index 0 is used for the question text if (isset($item->presentation->material[$i + 1])) { $part['text'] = $this->object->QTIMaterialToString($item->presentation->material[$i + 1]); } // create and add a new part $part_obj = $this->object->getPart(); $part_obj->setPosition($part['position']); $part_obj->setText($part['text']); $part_obj->setMaxPoints($part['max_points']); $part_obj->setMaxLines($part['max_lines']); $part_obj->setBookingXML(base64_decode($part['booking_def'])); $part_obj->write(); } } // convert the generic feedback 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) { $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"]; } else { $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"]; } global $ilLog; $ilLog->write($importfile); $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE); ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId()); // images in question text $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext); // images in question parts foreach ($this->object->getParts() as $part_obj) { $part_obj->setText(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $part_obj->getText())); } // images in feedback 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 ($this->object->getParts() as $part_obj) { $part_obj->setText(ilRTE::_replaceMediaObjectImageSrc($part_obj->getText(), 1)); $part_obj->write(); } foreach ($feedbacksgeneric as $correctness => $material) { $this->object->feedbackOBJ->importGenericFeedback($this->object->getId(), $correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1)); } if (count($item->suggested_solutions)) { foreach ($item->suggested_solutions as $suggested_solution) { $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true); } } // Now save the question again // (this also recalculates the maximum points) $this->object->saveToDb('', true); // import mapping for tests if ($tst_id > 0) { $q_1_id = $this->object->getId(); $question_id = $this->object->duplicate(true, null, null, null, $tst_id); $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); } }
/** * Function to parse incoming data from form input value $value. returns the strin/number/etc. to store in the database. * @param $value * @param ilDataCollectionRecordField $record_field * @return int|string */ public function parseValue($value, ilDataCollectionRecordField $record_field) { $return = false; if ($this->id == ilDataCollectionDatatype::INPUTFORMAT_FILE) { $file = $value; if ($file['tmp_name']) { $file_obj = new ilObjFile(); $file_obj->setType("file"); $file_obj->setTitle($file["name"]); $file_obj->setFileName($file["name"]); $file_obj->setFileType(ilMimeTypeUtil::getMimeType("", $file["name"], $file["type"])); $file_obj->setFileSize($file["size"]); $file_obj->setMode("object"); $file_obj->create(); $file_obj->getUploadFile($file["tmp_name"], $file["name"]); $file_id = $file_obj->getId(); $return = $file_id; } else { $return = $record_field->getValue(); } } elseif ($this->id == ilDataCollectionDatatype::INPUTFORMAT_MOB) { if ($value == -1) { //marked for deletion. return 0; } $media = $value; if ($media['tmp_name']) { $mob = new ilObjMediaObject(); $mob->setTitle($media['name']); $mob->create(); $mob_dir = ilObjMediaObject::_getDirectory($mob->getId()); if (!is_dir($mob_dir)) { $mob->createDirectory(); } $media_item = new ilMediaItem(); $mob->addMediaItem($media_item); $media_item->setPurpose("Standard"); $file_name = ilUtil::getASCIIFilename($media['name']); $file_name = str_replace(" ", "_", $file_name); $file = $mob_dir . "/" . $file_name; $title = $file_name; ilUtil::moveUploadedFile($media['tmp_name'], $file_name, $file); ilUtil::renameExecutables($mob_dir); list($width, $height, $type, $attr) = getimagesize($file); $arr_properties = $record_field->getField()->getProperties(); $new_width = $arr_properties[ilDataCollectionField::PROPERTYID_WIDTH]; $new_height = $arr_properties[ilDataCollectionField::PROPERTYID_HEIGHT]; if ($new_width || $new_height) { //only resize if it is bigger, not if it is smaller if ($new_height < $height && $new_width < $width) { //resize proportional if (!$new_height || !$new_width) { $format = ilObjMediaObject::getMimeType($file); $wh = ilObjMediaObject::_determineWidthHeight("", "", $format, "File", $file, "", true, false, $arr_properties[ilDataCollectionField::PROPERTYID_WIDTH], (int) $arr_properties[ilDataCollectionField::PROPERTYID_HEIGHT]); } else { $wh['width'] = (int) $arr_properties[ilDataCollectionField::PROPERTYID_WIDTH]; $wh['height'] = (int) $arr_properties[ilDataCollectionField::PROPERTYID_HEIGHT]; } } $location = ilObjMediaObject::_resizeImage($file, $wh['width'], $wh['height'], false); } else { $location = $title; } ilObjMediaObject::_saveUsage($mob->getId(), "dcl:html", $record_field->getRecord()->getTable()->getCollectionObject()->getId()); $format = ilObjMediaObject::getMimeType($file); $media_item->setFormat($format); $media_item->setLocation($location); $media_item->setLocationType("LocalFile"); $mob->update(); $return = $mob->getId(); } else { $return = $record_field->getValue(); } } elseif ($this->id == ilDataCollectionDatatype::INPUTFORMAT_DATETIME) { return $value["date"] . " " . $value["time"]; } elseif ($this->id == ilDataCollectionDatatype::INPUTFORMAT_BOOLEAN) { $return = $value ? 1 : 0; } elseif ($this->id == ilDataCollectionDatatype::INPUTFORMAT_TEXT) { $arr_properties = $record_field->getField()->getProperties(); if ($arr_properties[ilDataCollectionField::PROPERTYID_TEXTAREA]) { $return = nl2br($value); } else { $return = $value; } } else { if ($this->id == ilDataCollectionDatatype::INPUTFORMAT_NUMBER) { $return = $value == '' ? null : $value; //SW, Ilias Mantis #0011799: Return null otherwise '' is casted to 0 in DB } else { $return = $value; } } return $return; }
/** * handler for end of element * * @param resource $a_xml_parser xml parser * @param string $a_name element name */ public function handlerEndTag($a_xml_parser, $a_name) { global $ilDB, $ilUser; $this->cdata = trim($this->cdata); $arrayname = strtolower($this->entity) . 'Array'; $x =& $this->{$arrayname}; switch ($a_name) { case 'Forum': $query_num_posts = "SELECT COUNT(pos_pk) cnt\n\t\t\t\t\t\t\t\t\t\tFROM frm_posts\n\t\t\t\t\t\t\t\t\tWHERE pos_top_fk = " . $ilDB->quote($this->lastHandledForumId, 'integer'); $res_pos = $ilDB->query($query_num_posts); $data_pos = $ilDB->fetchAssoc($res_pos); $num_posts = $data_pos['cnt']; $query_num_threads = "SELECT COUNT(thr_pk) cnt\n\t\t\t\t\t\t\t\t\t\tFROM frm_threads\n\t\t\t\t\t\t\t\t\t WHERE thr_top_fk = " . $ilDB->quote($this->lastHandledForumId, 'integer'); $res_thr = $ilDB->query($query_num_threads); $data_thr = $ilDB->fetchAssoc($res_thr); $num_threads = $data_thr['cnt']; $update_str = "{$this->lastHandledForumId}#{$this->lastHandledThreadId}#{$this->lastHandledPostId}"; $ilDB->manipulateF("UPDATE frm_data \n\t\t\t\t\t\tSET top_last_post = %s,\n\t\t\t\t\t\t\ttop_num_posts = %s,\n\t\t\t\t\t\t\ttop_num_threads = %s\n\t\t\t\t\tWHERE top_frm_fk = %s", array('text', 'integer', 'integer', 'integer'), array($update_str, $num_posts, $num_threads, $this->forum_obj_id)); break; case 'Id': $x['Id'] = $this->cdata; break; case 'ObjId': $x['ObjId'] = $this->cdata; break; case 'Title': $x['Title'] = $this->cdata; break; case 'Description': $x['Description'] = $this->cdata; break; case 'DefaultView': $x['DefaultView'] = $this->cdata; break; case 'Pseudonyms': $x['Pseudonyms'] = $this->cdata; break; case 'Statistics': $x['Statistics'] = $this->cdata; break; case 'PostingActivation': $x['PostingActivation'] = $this->cdata; break; case 'PresetSubject': $x['PresetSubject'] = $this->cdata; break; case 'PresetRe': $x['PresetRe'] = $this->cdata; break; case 'NotificationType': $x['NotificationType'] = $this->cdata; break; case 'ForceNotification': $x['ForceNotification'] = $this->cdata; break; case 'ToggleNotification': $x['ToggleNotification'] = $this->cdata; break; case 'LastPost': $x['LastPost'] = $this->cdata; break; case 'Moderator': $x['Moderator'] = $this->cdata; break; case 'CreateDate': $x['CreateDate'] = $this->cdata; break; case 'UpdateDate': $x['UpdateDate'] = $this->cdata; break; case 'UpdateUserId': $x['UpdateUserId'] = $this->cdata; break; case 'UserId': $x['UserId'] = $this->cdata; if ($this->entity == 'forum' && $this->forumArray) { //// @todo: Maybe problems if the forum xml is imported as content of a course // createSettings accesses superglobal $_GET array, which can cause problems // with public_notifications of block settings $this->forum->createSettings(); $forum_array = $this->getUserIdAndAlias($this->forumArray['UserId'], ''); // Store old user id $oldUsrId = $ilUser->getId(); // Manipulate user object $ilUser->setId($forum_array['usr_id']); // create frm_data $this->forum->saveData(array()); // Restore old user id $ilUser->setId($oldUsrId); $update_forum_array = $this->getUserIdAndAlias($this->forumArray['UpdateUserId'], ''); // Store old user id $oldUsrId = $_SESSION["AccountId"]; // Manipulate user object $_SESSION["AccountId"] = $update_forum_array['usr_id']; $this->forum->setTitle($this->forumArray["Title"]); $this->forum->setDescription($this->forumArray["Description"]); $this->forum->update(); // Restore old user id $_SESSION["AccountId"] = $oldUsrId; // create frm_settings $newObjProp = ilForumProperties::getInstance($this->forum->getId()); $newObjProp->setDefaultView((int) $this->forumArray['DefaultView']); $newObjProp->setAnonymisation((int) $this->forumArray['Pseudonyms']); $newObjProp->setStatisticsStatus((int) $this->forumArray['Statistics']); $newObjProp->setPostActivation((int) $this->forumArray['PostingActivation']); $newObjProp->setPresetSubject((int) $this->forumArray['PresetSubject']); $newObjProp->setAddReSubject((int) $this->forumArray['PresetRe']); $newObjProp->setNotificationType($this->forumArray['NotificationType'] ? $this->forumArray['NotificationType'] : 'all_users'); $newObjProp->setAdminForceNoti((int) $this->forumArray['ForceNotification']); $newObjProp->setUserToggleNoti((int) $this->forumArray['ToggleNotification']); $newObjProp->insert(); $id = $this->getNewForumPk(); $this->forum_obj_id = $newObjProp->getObjId(); $this->mapping['frm'][$this->forumArray['Id']] = $id; $this->lastHandledForumId = $id; unset($this->forumArray); } break; case 'Thread': $update_str = "{$this->lastHandledForumId}#{$this->lastHandledThreadId}#{$this->lastHandledPostId}"; $ilDB->manipulateF("UPDATE frm_threads\n\t\t\t\t\t\tSET thr_last_post = %s\n\t\t\t\t\tWHERE thr_pk = %s", array('text', 'integer'), array($update_str, $this->lastHandledThreadId)); break; case 'Subject': $x['Subject'] = $this->cdata; break; case 'Alias': $x['Alias'] = $this->cdata; break; case 'Sticky': $x['Sticky'] = $this->cdata; break; case 'Closed': $x['Closed'] = $this->cdata; if ($this->entity == 'thread' && $this->threadArray) { require_once 'Modules/Forum/classes/class.ilForumTopic.php'; $this->forumThread = new ilForumTopic(); $this->forumThread->setId($this->threadArray['Id']); $this->forumThread->setForumId($this->lastHandledForumId); $this->forumThread->setSubject($this->threadArray['Subject']); $this->forumThread->setSticky($this->threadArray['Sticky']); $this->forumThread->setClosed($this->threadArray['Closed']); $this->forumThread->setCreateDate($this->threadArray['CreateDate']); $this->forumThread->setChangeDate($this->threadArray['UpdateDate']); $this->forumThread->setImportName($this->threadArray['ImportName']); $usr_data = $this->getUserIdAndAlias($this->threadArray['UserId'], $this->threadArray['Alias']); $this->forumThread->setUserId($usr_data['usr_id']); $this->forumThread->setUserAlias($usr_data['usr_alias']); $this->forumThread->insert(); $this->mapping['thr'][$this->threadArray['Id']] = $this->forumThread->getId(); $this->lastHandledThreadId = $this->forumThread->getId(); unset($this->threadArray); } break; case 'Post': break; case 'Censorship': $x['Censorship'] = $this->cdata; break; case 'CensorshipMessage': $x['CensorshipMessage'] = $this->cdata; break; case 'Notification': $x['Notification'] = $this->cdata; break; case 'ImportName': $x['ImportName'] = $this->cdata; break; case 'Status': $x['Status'] = $this->cdata; break; case 'Message': $x['Message'] = $this->cdata; break; case 'Lft': $x['Lft'] = $this->cdata; break; case 'Rgt': $x['Rgt'] = $this->cdata; break; case 'Depth': $x['Depth'] = $this->cdata; break; case 'ParentId': $x['ParentId'] = $this->cdata; if ($this->entity == 'post' && $this->postArray) { require_once 'Modules/Forum/classes/class.ilForumPost.php'; $this->forumPost = new ilForumPost(); $this->forumPost->setId($this->postArray['Id']); $this->forumPost->setCensorship($this->postArray['Censorship']); $this->forumPost->setCensorshipComment($this->postArray['CensorshipMessage']); $this->forumPost->setNotification($this->postArray['Notification']); $this->forumPost->setImportName($this->postArray['ImportName']); $this->forumPost->setStatus($this->postArray['Status']); $this->forumPost->setMessage($this->postArray['Message']); $this->forumPost->setSubject($this->postArray['Subject']); $this->forumPost->setLft($this->postArray['Lft']); $this->forumPost->setRgt($this->postArray['Rgt']); $this->forumPost->setDepth($this->postArray['Depth']); $this->forumPost->setParentId($this->postArray['ParentId']); $this->forumPost->setThread($this->forumThread); $this->forumPost->setThreadId($this->lastHandledThreadId); $this->forumPost->setForumId($this->lastHandledForumId); $this->forumPost->setCreateDate($this->postArray['CreateDate']); $this->forumPost->setChangeDate($this->postArray['UpdateDate']); $usr_data = $this->getUserIdAndAlias($this->postArray['UserId'], $this->postArray['Alias']); $update_usr_data = $this->getUserIdAndAlias($this->postArray['UpdateUserId']); $this->forumPost->setUserId($usr_data['usr_id']); $this->forumPost->setUserAlias($usr_data['usr_alias']); $this->forumPost->setUpdateUserId($update_usr_data['usr_id']); $this->forumPost->insert(); if ($this->mapping['pos'][$this->postArray['ParentId']]) { $parentId = $this->mapping['pos'][$this->postArray['ParentId']]; } else { $parentId = 0; } $postTreeNodeId = $ilDB->nextId('frm_posts_tree'); $ilDB->insert('frm_posts_tree', array('fpt_pk' => array('integer', $postTreeNodeId), 'thr_fk' => array('integer', $this->lastHandledThreadId), 'pos_fk' => array('integer', $this->forumPost->getId()), 'parent_pos' => array('integer', $parentId), 'lft' => array('integer', $this->postArray['Lft']), 'rgt' => array('integer', $this->postArray['Rgt']), 'depth' => array('integer', $this->postArray['Depth']), 'fpt_date' => array('timestamp', date('Y-m-d H:i:s')))); $this->mapping['pos'][$this->postArray['Id']] = $this->forumPost->getId(); $this->lastHandledPostId = $this->forumPost->getId(); $media_objects_found = false; foreach ($this->mediaObjects as $mob_attr) { $importfile = $this->getImportDirectory() . '/' . $mob_attr['uri']; if (file_exists($importfile)) { $mob = ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false); ilObjMediaObject::_saveUsage($mob->getId(), "frm:html", $this->forumPost->getId()); $this->forumPost->setMessage(str_replace(array("src=\"" . $mob_attr["label"] . "\"", "src=\"" . preg_replace("/(il)_[\\d]+_(mob)_([\\d]+)/", "\$1_0_\$2_\$3", $mob_attr["label"]) . "\""), "src=\"" . "il_" . IL_INST_ID . "_mob_" . $mob->getId() . "\"", $this->forumPost->getMessage())); $media_objects_found = true; } } if ($media_objects_found) { $this->forumPost->update(); } unset($this->postArray); } break; case 'Content': $x['content'] = $this->cdata; break; case 'Attachment': $filedata = new ilFileDataForum($this->forum->getId(), $this->lastHandledPostId); $importPath = $this->contentArray['content']; if (strlen($importPath)) { $importPath = $this->getImportDirectory() . '/' . $importPath; $newFilename = preg_replace("/^\\d+_\\d+(_.*)/ims", $this->forum->getId() . "_" . $this->lastHandledPostId . "\$1", basename($importPath)); $path = $filedata->getForumPath(); $newPath = $path . '/' . $newFilename; @copy($importPath, $newPath); } break; } $this->cdata = ''; return; }
public function fromXML(&$item, &$questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping) { global $ilUser; unset($_SESSION["import_mob_xhtml"]); $duration = $item->getDuration(); $shuffle = 0; $answers = array(); $presentation = $item->getPresentation(); foreach ($presentation->order as $entry) { switch ($entry["type"]) { case "response": $response = $presentation->response[$entry["index"]]; $rendertype = $response->getRenderType(); switch (strtolower(get_class($response->getRenderType()))) { case "ilqtirenderchoice": $shuffle = $rendertype->getShuffle(); $answerorder = 0; $foundimage = FALSE; foreach ($rendertype->response_labels as $response_label) { $ident = $response_label->getIdent(); $answertext = ""; $answerimage = array(); foreach ($response_label->material as $mat) { $embedded = false; for ($m = 0; $m < $mat->getMaterialCount(); $m++) { $foundmat = $mat->getMaterial($m); if (strcmp($foundmat["type"], "mattext") == 0) { } if (strcmp($foundmat["type"], "matimage") == 0) { if (strlen($foundmat["material"]->getEmbedded())) { $embedded = true; } } } if ($embedded) { for ($m = 0; $m < $mat->getMaterialCount(); $m++) { $foundmat = $mat->getMaterial($m); if (strcmp($foundmat["type"], "mattext") == 0) { $answertext .= $foundmat["material"]->getContent(); } if (strcmp($foundmat["type"], "matimage") == 0) { $foundimage = TRUE; $answerimage = array("imagetype" => $foundmat["material"]->getImageType(), "label" => $foundmat["material"]->getLabel(), "content" => $foundmat["material"]->getContent()); } } } else { $answertext = $this->object->QTIMaterialToString($mat); } } $answers[$ident] = array("answertext" => $answertext, "imagefile" => $answerimage, "answerorder" => $ident); } break; } break; } } $feedbacks = array(); $feedbacksgeneric = array(); foreach ($item->resprocessing as $resprocessing) { foreach ($resprocessing->outcomes->decvar as $decvar) { if ($decvar->getVarname() == 'SCORE') { $this->object->setPoints($decvar->getMaxvalue()); if ($decvar->getMinvalue() > 0) { $this->object->setScorePartialSolutionEnabled(true); } } } foreach ($resprocessing->respcondition as $respcondition) { if (!count($respcondition->setvar)) { foreach ($respcondition->getConditionvar()->varequal as $varequal) { $ident = $varequal->respident; $answers[$ident]['correctness'] = (bool) $varequal->getContent(); break; } foreach ($respcondition->displayfeedback as $feedbackpointer) { if (strlen($feedbackpointer->getLinkrefid())) { foreach ($item->itemfeedback as $ifb) { if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0) { // found a feedback for the identifier if (count($ifb->material)) { foreach ($ifb->material as $material) { $feedbacks[$ident] = $material; } } if (count($ifb->flow_mat) > 0) { foreach ($ifb->flow_mat as $fmat) { if (count($fmat->material)) { foreach ($fmat->material as $material) { $feedbacks[$ident] = $material; } } } } } } } } } else { foreach ($respcondition->displayfeedback as $feedbackpointer) { if (strlen($feedbackpointer->getLinkrefid())) { foreach ($item->itemfeedback as $ifb) { if ($ifb->getIdent() == "response_allcorrect") { // 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 ($ifb->getIdent() == "response_onenotcorrect") { // 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->addGeneralMetadata($item); $this->object->setTitle($item->getTitle()); $this->object->setNrOfTries($item->getMaxattempts()); $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->setShuffleAnswersEnabled($shuffle); $this->object->setAnswerType($item->getMetadataEntry("answer_type")); $this->object->setOptionLabel($item->getMetadataEntry("option_label_setting")); $this->object->setCustomTrueOptionLabel($item->getMetadataEntry("custom_true_option_label")); $this->object->setCustomFalseOptionLabel($item->getMetadataEntry("custom_false_option_label")); $this->object->setThumbSize($item->getMetadataEntry("thumb_size")); $this->object->saveToDb(); foreach ($answers as $answerData) { $answer = new ilAssKprimChoiceAnswer(); $answer->setImageFsDir($this->object->getImagePath()); $answer->setImageWebDir($this->object->getImagePathWeb()); $answer->setPosition($answerData['answerorder']); $answer->setAnswertext($answerData['answertext']); $answer->setCorrectness($answerData['correctness']); if (isset($answerData['imagefile']['label'])) { $answer->setImageFile($answerData['imagefile']['label']); } $this->object->addAnswer($answer); } // additional content editing mode information $this->object->setAdditionalContentEditingMode($this->fetchAdditionalContentEditingModeInformation($item)); $this->object->saveToDb(); foreach ($answers as $answer) { if (is_array($answer["imagefile"]) && count($answer["imagefile"]) > 0) { $image =& base64_decode($answer["imagefile"]["content"]); $imagepath = $this->object->getImagePath(); include_once "./Services/Utilities/classes/class.ilUtil.php"; if (!file_exists($imagepath)) { ilUtil::makeDirParents($imagepath); } $imagepath .= $answer["imagefile"]["label"]; if ($fh = fopen($imagepath, "wb")) { $imagefile = fwrite($fh, $image); fclose($fh); } } } $feedbackSetting = $item->getMetadataEntry('feedback_setting'); if (!is_null($feedbackSetting)) { $this->object->feedbackOBJ->saveSpecificFeedbackSetting($this->object->getId(), $feedbackSetting); } // handle the import of media objects in XHTML code foreach ($feedbacks as $ident => $material) { $m = $this->object->QTIMaterialToString($material); $feedbacks[$ident] = $m; } foreach ($feedbacksgeneric as $correctness => $material) { $m = $this->object->QTIMaterialToString($material); $feedbacksgeneric[$correctness] = $m; } $questiontext = $this->object->getQuestion(); $answers =& $this->object->getAnswers(); 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) { $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"]; } else { $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"]; } $GLOBALS['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile); $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 ($answers as $key => $value) { $answer_obj =& $answers[$key]; $answer_obj->setAnswertext(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $answer_obj->getAnswertext())); } foreach ($feedbacks as $ident => $material) { $feedbacks[$ident] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material); } 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 ($answers as $key => $value) { $answer_obj =& $answers[$key]; $answer_obj->setAnswertext(ilRTE::_replaceMediaObjectImageSrc($answer_obj->getAnswertext(), 1)); } foreach ($feedbacks as $ident => $material) { $this->object->feedbackOBJ->importSpecificAnswerFeedback($this->object->getId(), $ident, ilRTE::_replaceMediaObjectImageSrc($material, 1)); } foreach ($feedbacksgeneric as $correctness => $material) { $this->object->feedbackOBJ->importGenericFeedback($this->object->getId(), $correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1)); } $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, null, null, null, $tst_id); $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); } //$ilLog->write(strftime("%D %T") . ": finished import multiple choice question (single response)"); }
/** * 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(); } }
/** * Imports a survey from XML into the ILIAS database * * @return boolean True, if the import succeeds, false otherwise * @access public */ function importObject($file_info, $svy_qpl_id) { if ($svy_qpl_id < 1) { $svy_qpl_id = -1; } // check if file was uploaded $source = $file_info["tmp_name"]; $error = ""; if ($source == 'none' || !$source || $file_info["error"] > UPLOAD_ERR_OK) { $error = $this->lng->txt("import_no_file_selected"); } // check correct file type $isXml = FALSE; $isZip = FALSE; if (strcmp($file_info["type"], "text/xml") == 0 || strcmp($file_info["type"], "application/xml") == 0) { $isXml = TRUE; } // too many different mime-types, so we use the suffix $suffix = pathinfo($file_info["name"]); if (strcmp(strtolower($suffix["extension"]), "zip") == 0) { $isZip = TRUE; } if (!$isXml && !$isZip) { $error = $this->lng->txt("import_wrong_file_type"); global $ilLog; $ilLog->write("Survey: Import error. Filetype was \"" . $file_info["type"] . "\""); } if (strlen($error) == 0) { // import file as a survey $import_dir = $this->getImportDirectory(); $import_subdir = ""; $importfile = ""; include_once "./Services/Utilities/classes/class.ilUtil.php"; if ($isZip) { $importfile = $import_dir . "/" . $file_info["name"]; ilUtil::moveUploadedFile($source, $file_info["name"], $importfile); ilUtil::unzip($importfile); $found = $this->locateImportFiles($import_dir); if (!(strlen($found["dir"]) > 0 && strlen($found["xml"]) > 0)) { $error = $this->lng->txt("wrong_import_file_structure"); return $error; } $importfile = $found["xml"]; $import_subdir = $found["dir"]; } else { $importfile = tempnam($import_dir, "survey_import"); ilUtil::moveUploadedFile($source, $file_info["name"], $importfile); } $fh = fopen($importfile, "r"); if (!$fh) { $error = $this->lng->txt("import_error_opening_file"); return $error; } $xml = fread($fh, filesize($importfile)); $result = fclose($fh); if (!$result) { $error = $this->lng->txt("import_error_closing_file"); return $error; } unset($_SESSION["import_mob_xhtml"]); if (strpos($xml, "questestinterop")) { include_once "./Services/Survey/classes/class.SurveyImportParserPre38.php"; $import = new SurveyImportParserPre38($svy_qpl_id, "", TRUE); $import->setSurveyObject($this); $import->setXMLContent($xml); $import->startParsing(); } else { include_once "./Services/Survey/classes/class.SurveyImportParser.php"; $import = new SurveyImportParser($svy_qpl_id, "", TRUE); $import->setSurveyObject($this); $import->setXMLContent($xml); $import->startParsing(); } 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 = $import_subdir . "/" . $mob["uri"]; if (file_exists($importfile)) { $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE); ilObjMediaObject::_saveUsage($media_object->getId(), "svy:html", $this->getId()); $this->setIntroduction(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $this->getIntroduction())); $this->setOutro(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $this->getOutro())); } else { global $ilLog; $ilLog->write("Error: Could not open XHTML mob file for test introduction during test import. File {$importfile} does not exist!"); } } $this->setIntroduction(ilRTE::_replaceMediaObjectImageSrc($this->getIntroduction(), 1)); $this->setOutro(ilRTE::_replaceMediaObjectImageSrc($this->getOutro(), 1)); $this->saveToDb(); } // delete import directory ilUtil::delDir($this->getImportDirectory()); } return $error; }
public function addThreadObject($a_prevent_redirect = false) { /** * @var $ilUser ilObjUser * @var $ilAccess ilAccessHandler * @var $lng ilLanguage */ global $ilUser, $ilAccess, $lng; $frm = $this->object->Forum; $frm->setForumId($this->object->getId()); $frm->setForumRefId($this->object->getRefId()); if (!$ilAccess->checkAccess('add_thread', '', $this->object->getRefId())) { $this->ilias->raiseError($lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE); } $frm->setMDB2WhereCondition('top_frm_fk = %s ', array('integer'), array($frm->getForumId())); $topicData = $frm->getOneTopic(); $this->initTopicCreateForm(); if ($this->create_topic_form_gui->checkInput()) { require_once 'Services/Captcha/classes/class.ilCaptchaUtil.php'; if ($ilUser->isAnonymous() && !$ilUser->isCaptchaVerified() && ilCaptchaUtil::isActiveForForum()) { $ilUser->setCaptchaVerified(true); } if ($this->objProperties->isAnonymized()) { if (!strlen($this->create_topic_form_gui->getInput('alias'))) { $user_alias = $this->lng->txt('forums_anonymous'); } else { $user_alias = $this->create_topic_form_gui->getInput('alias'); } } else { $user_alias = $ilUser->getLogin(); } $status = 1; if ($this->objProperties->isPostActivationEnabled() && !$this->is_moderator || $this->objCurrentPost->isAnyParentDeactivated()) { $status = 0; } // build new thread $newPost = $frm->generateThread($topicData['top_pk'], $ilUser->getId(), $this->objProperties->isAnonymized() ? 0 : $ilUser->getId(), $this->handleFormInput($this->create_topic_form_gui->getInput('subject'), false), ilRTE::_replaceMediaObjectImageSrc($this->create_topic_form_gui->getInput('message'), 0), $this->create_topic_form_gui->getItemByPostVar('notify') ? (int) $this->create_topic_form_gui->getInput('notify') : 0, $this->create_topic_form_gui->getItemByPostVar('notify_posts') ? (int) $this->create_topic_form_gui->getInput('notify_posts') : 0, $user_alias, '', $status); $file = $_FILES['userfile']; // file upload if (is_array($file) && !empty($file)) { $tmp_file_obj = new ilFileDataForum($this->object->getId(), $newPost); $tmp_file_obj->storeUploadedFile($file); } // Visit-Counter $frm->setDbTable('frm_data'); $frm->setMDB2WhereCondition('top_pk = %s ', array('integer'), array($topicData['top_pk'])); $frm->updateVisits($topicData['top_pk']); $frm->setMDB2WhereCondition('thr_top_fk = %s AND thr_subject = %s AND thr_num_posts = 1 ', array('integer', 'text'), array($topicData['top_pk'], $this->create_topic_form_gui->getInput('subject'))); // copy temporary media objects (frm~) include_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php'; $mediaObjects = ilRTE::_getMediaObjects($this->create_topic_form_gui->getInput('message'), 0); foreach ($mediaObjects as $mob) { if (ilObjMediaObject::_exists($mob)) { ilObjMediaObject::_removeUsage($mob, 'frm~:html', $ilUser->getId()); ilObjMediaObject::_saveUsage($mob, 'frm:html', $newPost); } } if ($this->ilias->getSetting('forum_notification') == 1) { // send notification about new topic $objPost = new ilForumPost((int) $newPost, $this->is_moderator); $post_data = array(); $post_data = $objPost->getDataAsArray(); $titles = $this->getTitlesByRefId(array($this->object->getRefId())); $post_data["top_name"] = $titles[0]; $post_data["ref_id"] = $this->object->getRefId(); $frm->sendForumNotifications($post_data); } if (!$a_prevent_redirect) { ilUtil::sendSuccess($this->lng->txt('forums_thread_new_entry'), true); $this->ctrl->redirect($this); } else { return $newPost; } } else { $this->create_topic_form_gui->setValuesByPost(); if (!$this->objProperties->isAnonymized()) { $this->create_topic_form_gui->getItemByPostVar('alias')->setValue($ilUser->getLogin()); } return $this->tpl->setContent($this->create_topic_form_gui->getHTML()); } }
/** * 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(); } }
/** * 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(); $shuffle = 0; $now = getdate(); $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']); $answers = array(); foreach ($presentation->order as $entry) { switch ($entry["type"]) { case "response": $response = $presentation->response[$entry["index"]]; $rendertype = $response->getRenderType(); switch (strtolower(get_class($response->getRenderType()))) { case "ilqtirenderchoice": $shuffle = $rendertype->getShuffle(); $answerorder = 0; $foundimage = FALSE; foreach ($rendertype->response_labels as $response_label) { $ident = $response_label->getIdent(); $answertext = ""; $answerimage = array(); foreach ($response_label->material as $mat) { $embedded = false; for ($m = 0; $m < $mat->getMaterialCount(); $m++) { $foundmat = $mat->getMaterial($m); if (strcmp($foundmat["type"], "mattext") == 0) { } if (strcmp($foundmat["type"], "matimage") == 0) { if (strlen($foundmat["material"]->getEmbedded())) { $embedded = true; } } } if ($embedded) { for ($m = 0; $m < $mat->getMaterialCount(); $m++) { $foundmat = $mat->getMaterial($m); if (strcmp($foundmat["type"], "mattext") == 0) { $answertext .= $foundmat["material"]->getContent(); } if (strcmp($foundmat["type"], "matimage") == 0) { $foundimage = TRUE; $answerimage = array("imagetype" => $foundmat["material"]->getImageType(), "label" => $foundmat["material"]->getLabel(), "content" => $foundmat["material"]->getContent()); } } } else { $answertext = $this->object->QTIMaterialToString($mat); } } $answers[$ident] = array("answertext" => $answertext, "imagefile" => $answerimage, "points" => 0, "answerorder" => $answerorder++, "points_unchecked" => 0, "action" => ""); } break; } break; } } $responses = array(); $feedbacks = array(); $feedbacksgeneric = array(); foreach ($item->resprocessing as $resprocessing) { foreach ($resprocessing->respcondition as $respcondition) { $ident = ""; $correctness = 1; $conditionvar = $respcondition->getConditionvar(); foreach ($conditionvar->order as $order) { switch ($order["field"]) { case "arr_not": $correctness = 0; break; case "varequal": $ident = $conditionvar->varequal[$order["index"]]->getContent(); break; } } foreach ($respcondition->setvar as $setvar) { if (strcmp($ident, "") != 0) { if ($correctness) { $answers[$ident]["action"] = $setvar->getAction(); $answers[$ident]["points"] = $setvar->getContent(); if (count($respcondition->displayfeedback)) { 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; } } } } } } if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0) { // found a feedback for the identifier if (count($ifb->material)) { foreach ($ifb->material as $material) { $feedbacks[$ident] = $material; } } if (count($ifb->flow_mat) > 0) { foreach ($ifb->flow_mat as $fmat) { if (count($fmat->material)) { foreach ($fmat->material as $material) { $feedbacks[$ident] = $material; } } } } } } } } } } else { $answers[$ident]["action"] = $setvar->getAction(); $answers[$ident]["points_unchecked"] = $setvar->getContent(); } } } } } $this->addGeneralMetadata($item); $this->object->setTitle($item->getTitle()); $this->object->setNrOfTries($item->getMaxattempts()); $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->setShuffle($shuffle); $this->object->setThumbSize($item->getMetadataEntry("thumb_size")); foreach ($answers as $answer) { if (is_array($answer["imagefile"]) && count($answer["imagefile"]) > 0) { $this->object->isSingleline = true; } $this->object->addAnswer($answer["answertext"], $answer["points"], $answer["answerorder"], $answer["imagefile"]["label"]); } // additional content editing mode information $this->object->setAdditionalContentEditingMode($this->fetchAdditionalContentEditingModeInformation($item)); $this->object->saveToDb(); foreach ($answers as $answer) { if (is_array($answer["imagefile"]) && count($answer["imagefile"]) > 0) { $image =& base64_decode($answer["imagefile"]["content"]); $imagepath = $this->object->getImagePath(); include_once "./Services/Utilities/classes/class.ilUtil.php"; if (!file_exists($imagepath)) { ilUtil::makeDirParents($imagepath); } $imagepath .= $answer["imagefile"]["label"]; $fh = fopen($imagepath, "wb"); if ($fh == false) { } else { $imagefile = fwrite($fh, $image); fclose($fh); } } } foreach ($feedbacks as $ident => $material) { $m = $this->object->QTIMaterialToString($material); $feedbacks[$ident] = $m; } 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(); $answers =& $this->object->getAnswers(); 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) { $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"]; } else { $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"]; } $GLOBALS['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile); $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 ($answers as $key => $value) { $answer_obj = $answers[$key]; $answer_obj->setAnswertext(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $answer_obj->getAnswertext())); } foreach ($feedbacks as $ident => $material) { $feedbacks[$ident] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material); } 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 ($answers as $key => $value) { $answer_obj =& $answers[$key]; $answer_obj->setAnswertext(ilRTE::_replaceMediaObjectImageSrc($answer_obj->getAnswertext(), 1)); } foreach ($feedbacks as $ident => $material) { $this->object->feedbackOBJ->importSpecificAnswerFeedback($this->object->getId(), $ident, ilRTE::_replaceMediaObjectImageSrc($material, 1)); } foreach ($feedbacksgeneric as $correctness => $material) { $this->object->feedbackOBJ->importGenericFeedback($this->object->getId(), $correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1)); } $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, null, null, null, $tst_id); $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(); $shuffle = 0; $idents = array(); $now = getdate(); $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']); $gaps = array(); foreach ($presentation->order as $entry) { switch ($entry["type"]) { case "response": $response = $presentation->response[$entry["index"]]; if ($response->getResponseType() == RT_RESPONSE_STR) { array_push($idents, $response->getIdent()); } break; } } $responses = array(); $feedbacksgeneric = array(); foreach ($item->resprocessing as $resprocessing) { foreach ($resprocessing->respcondition as $respcondition) { $ident = ""; $correctness = 1; $conditionvar = $respcondition->getConditionvar(); foreach ($conditionvar->order as $order) { switch ($order["field"]) { case "varsubset": $respident = $conditionvar->varsubset[$order["index"]]->getRespident(); $content = $conditionvar->varsubset[$order["index"]]->getContent(); if (!is_array($responses[$respident])) { $responses[$respident] = array(); } $vars = split(",", $content); foreach ($vars as $var) { array_push($responses[$respident], array("solution" => $var, "points" => "")); } break; } } foreach ($respcondition->setvar as $setvar) { if (strcmp($setvar->getVarname(), "matches") == 0 && $setvar->getAction() == ACTION_ADD) { foreach ($responses[$respident] as $idx => $solutionarray) { if (strlen($solutionarray["points"] == 0)) { $responses[$respident][$idx]["points"] = $setvar->getContent(); } } } } 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->setNrOfTries($item->getMaxattempts()); $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"]); $textrating = $item->getMetadataEntry("textrating"); if (strlen($textrating) == 0) { $textrating = "ci"; } $this->object->setTextRating($textgap_rating); $this->object->setCorrectAnswers($item->getMetadataEntry("correctanswers")); $response = current($responses); $counter = 0; if (is_array($response)) { foreach ($response as $answer) { $this->object->addAnswer($answer["solution"], $answer["points"], $counter); $counter++; } } $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) { $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"]; } else { $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"]; } $GLOBALS['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile); $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, null, null, null, $tst_id); $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); } }
/** * Increases the media object usage counter when a question is duplicated * * @param integer $a_q_id The question id of the original question * @access public */ function copyXHTMLMediaObjectsOfQuestion($a_q_id) { include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php"; $mobs = ilObjMediaObject::_getMobsOfObject("spl:html", $a_q_id); foreach ($mobs as $mob) { ilObjMediaObject::_saveUsage($mob, "spl:html", $this->getId()); } }
function updateAssignmentTextObject($a_return = false) { global $ilCtrl, $ilUser; $times_up = $this->ass->getDeadline() && $this->ass->getDeadline() - time() < 0; if (!$this->ass || $this->ass->getType() != ilExAssignment::TYPE_TEXT || $times_up) { if ($times_up) { ilUtil::sendFailure($this->lng->txt("exercise_time_over"), true); } $ilCtrl->redirect($this, "showOverview"); } $this->checkPermission("read"); $form = $this->initAssignmentTextForm($this->ass); // we are not using a purifier, so we have to set the valid RTE tags // :TODO: include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php"; $rte = $form->getItemByPostVar("atxt"); $rte->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("exc_ass")); if ($form->checkInput()) { $text = trim($form->getInput("atxt")); $existing = (bool) ilExAssignment::getDeliveredFiles($this->ass->getExerciseId(), $this->ass->getId(), $ilUser->getId()); $returned_id = $this->object->updateTextSubmission($this->ass->getExerciseId(), $this->ass->getId(), $ilUser->getId(), ilRTE::_replaceMediaObjectImageSrc($text, 0)); // no empty text if ($returned_id) { if (!$existing) { // #14332 - new text $this->sendNotifications($this->ass->getId()); $this->object->handleSubmission($this->ass->getId()); } // mob usage include_once "Services/MediaObjects/classes/class.ilObjMediaObject.php"; $mobs = ilRTE::_getMediaObjects($text, 0); foreach ($mobs as $mob) { if (ilObjMediaObject::_exists($mob)) { ilObjMediaObject::_removeUsage($mob, 'exca~:html', $ilUser->getId()); ilObjMediaObject::_saveUsage($mob, 'exca:html', $returned_id); } } } ilUtil::sendSuccess($this->lng->txt("settings_saved"), true); if ($a_return) { $ilCtrl->redirect($this, "showOverview"); } else { $ilCtrl->redirect($this, "editAssignmentText"); } } $form->setValuesByPost(); $this->editAssignmentTextObject($form); }
/** * 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->addGeneralMetadata($item); $this->object->setTitle($item->getTitle()); $this->object->setNrOfTries($item->getMaxattempts()); $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); } $this->object->matchcondition = strlen($item->getMetadataEntry('matchcondition')) ? $item->getMetadataEntry('matchcondition') : 0; require_once './Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php'; $termscoring = unserialize(base64_decode($item->getMetadataEntry('termscoring'))); $termscoring = is_array($termscoring) ? $termscoring : array(); for ($i = 0; $i < count($termscoring); $i++) { $this->object->addAnswer($termscoring[$i]->getAnswertext(), $termscoring[$i]->getPoints()); } $this->object->setKeywordRelation($item->getMetadataEntry('termrelation')); $keywords = $item->getMetadataEntry("keywords"); if (strlen($keywords)) { #$this->object->setKeywords($keywords); $answers = explode(' ', $keywords); foreach ($answers as $answer) { $this->object->addAnswer($answer, $maxpoints / count($answers)); } $this->object->setKeywordRelation('one'); } // 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(); } 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) { $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"]; } else { $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"]; } $GLOBALS['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile); $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->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, null, null, null, $tst_id); $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); } }