Exemplo n.º 1
0
licence -- see the LICENCE file for more details
------------------------------------------------------------------------------*/
if (isset($_REQUEST["itemtype"])) {
    // item type chosen
    // look for a item type class with this name
    $classname = "QTI" . ucfirst($_REQUEST["itemtype"]);
    if (!@class_exists($classname) || !is_subclass_of($classname, "QTIAssessmentItem")) {
        servererror("Item type doesn't exist or not implemented");
    }
    $ai = new $classname();
    $ai->sessionStore();
    $action = new EditAssessmentItemAction();
    redirect($action->actionURL($ai, false));
}
// choose from a list of item types
$items = item_types();
$GLOBALS["title"] = "New assessment item";
include "htmlheader.php";
?>
<h2><?php 
echo $GLOBALS["title"];
?>
</h2>
<p>The first stage is to choose an item type.</p>
<dl>
	<?php 
foreach ($items as $item) {
    ?>
		<dt>
			<a href="<?php 
    echo SITEROOT_WEB;
Exemplo n.º 2
0
function xmltoqtiobject($xml, &$errors, &$warnings, &$messages, $metadata = array(), $newidentifier = false)
{
    // make sure it's valid QTI
    if (!validateQTI($xml, $errors, $warnings, $messages)) {
        $errors[] = "The assessment item found is not valid QTI";
        return false;
    }
    // load to SimpleXML object
    $xml = simplexml_load_string($xml);
    // test against supported item types
    $items = item_types();
    $scores = array();
    $ai = null;
    foreach ($items as $item) {
        $score = $item->fromXML($xml);
        $scores[] = $score;
        if ($score == 255) {
            $ai = $item;
            break;
        }
    }
    if (is_null($ai)) {
        arsort($scores);
        $keys = array_keys($scores);
        if ($scores[$keys[0]] == 0) {
            $errors[] = "The uploaded item was not of a recognized type";
            return false;
        } else {
            $ai = $items[$keys[0]];
            $ai->addWarning("Item did not exactly match any of the implemented types. The closest match ({$ai->itemTypePrint()}, " . round($scores[$keys[0]] / 2.55) . "% match) was chosen.");
        }
    }
    // give it a new identifier if appropriate, restore manifest identifier if
    // no new identifier is wanted
    if ($newidentifier) {
        $ai->setQTIID(null);
    } else {
        if (array_key_exists("midentifier", $metadata)) {
            $ai->setMID($metadata["midentifier"]);
        }
    }
    // restore the metadata taken from the manifest
    if (array_key_exists("description", $metadata)) {
        $ai->data("description", $metadata["description"]);
    }
    if (array_key_exists("keywords", $metadata)) {
        $ai->data("keywords", implode(", ", $metadata["keywords"]));
    }
    // take the user to the main menu with the uploaded item highlighted
    return $ai;
}