예제 #1
0
$oldgrade = $RESULT->grade;
if (count($_POST) > 0) {
    if ($questions == false) {
        $_SESSION['error'] = 'Internal error: No questions';
        header('Location: ' . addSession('index.php'));
        return;
    }
    if ($USER->instructor || $ok) {
        // No problem
    } else {
        // No error message in session because status is always displayed
        header('Location: ' . addSession('index.php'));
        return;
    }
    $_SESSION['gift_submit'] = $_POST;
    $quiz = make_quiz($_POST, $questions, $errors);
    $gradetosend = $quiz['score'] * 1.0;
    $scorestr = "Your score of " . percent($gradetosend) . " has been saved.";
    if ($dueDate->penalty > 0) {
        $gradetosend = $gradetosend * (1.0 - $dueDate->penalty);
        $scorestr = "Effective Score = {$gradetosend} after " . percent($dueDate->penalty) . " late penalty";
    }
    if ($oldgrade > $gradetosend) {
        $scorestr = "New score of " . percent($gradetosend) . " is < than previous grade of " . percent($oldgrade) . ", previous grade kept";
        $gradetosend = $oldgrade;
    }
    $result = array("when" => time(), "tries" => $tries + 1, "submit" => $_POST);
    $RESULT->setJson(json_encode($result));
    // Use LTIX to send the grade back to the LMS.
    $debug_log = array();
    $retval = LTIX::gradeSend($gradetosend, false, $debug_log);
예제 #2
0
<?php

require_once "../../config.php";
require_once $CFG->dirroot . "/pdo.php";
require_once $CFG->dirroot . "/lib/lms_lib.php";
require_once "parse.php";
use Tsugi\Core\LTIX;
$LTI = LTIX::requireData();
$gift = $LINK->getJson();
$OUTPUT->headerJson();
// Check if we got any GIFT
if ($gift === false || strlen($gift) < 1) {
    echo json_encode(array("status" => "failure", "message" => "This quiz has not yet been configured"));
    return;
}
// parse the GIFT questions
$questions = array();
$errors = array();
parse_gift($gift, $questions, $errors);
// Both reduce the visible bits and score the quiz if a submission is present
$submit = isset($_SESSION['gift_submit']) ? $_SESSION['gift_submit'] : array();
$retval = make_quiz($submit, $questions, $errors);
echo json_encode($retval);