示例#1
0
/**
 * Update the sumgrades field of the quiz. This needs to be called whenever
 * the grading structure of the quiz is changed. For example if a question is
 * added or removed, or a question weight is changed.
 *
 * You should call {@link quiz_delete_previews()} before you call this function.
 *
 * @param object $quiz a quiz.
 */
function quiz_update_sumgrades($quiz) {
    global $DB;

    $sql = 'UPDATE {quiz}
            SET sumgrades = COALESCE((
                SELECT SUM(grade)
                FROM {quiz_question_instances}
                WHERE quiz = {quiz}.id
            ), 0)
            WHERE id = ?';
    $DB->execute($sql, array($quiz->id));
    $quiz->sumgrades = $DB->get_field('quiz', 'sumgrades', array('id' => $quiz->id));

    if ($quiz->sumgrades < 0.000005 && quiz_has_attempts($quiz->id)) {
        // If the quiz has been attempted, and the sumgrades has been
        // set to 0, then we must also set the maximum possible grade to 0, or
        // we will get a divide by zero error.
        quiz_set_grade(0, $quiz);
    }
}
示例#2
0
        for ($i = $moveselectedonpage; $i > $numpages; $i--) {
            $questions[] = 0;
            $pagebreakpositions[] = count($questions) - 1;
        }
        $moveselectedpos = $pagebreakpositions[$moveselectedonpage - 1];
        // Do the move.
        array_splice($questions, $moveselectedpos, 0, $selectedquestionids);
        $quiz->questions = implode(',', $questions);
        // Update the database.
        $DB->set_field('quiz', 'questions', $quiz->questions, array('id' => $quiz->id));
        $deletepreviews = true;
    }
    // If rescaling is required save the new maximum.
    $maxgrade = unformat_float(optional_param('maxgrade', -1, PARAM_RAW));
    if ($maxgrade >= 0) {
        quiz_set_grade($maxgrade, $quiz);
    }
    if ($deletepreviews) {
        quiz_delete_previews($quiz);
    }
    if ($recomputesummarks) {
        quiz_update_sumgrades($quiz);
        quiz_update_all_attempt_sumgrades($quiz);
        quiz_update_all_final_grades($quiz);
        quiz_update_grades($quiz, 0, true);
    }
    redirect($afteractionurl);
}
$questionbank->process_actions($thispageurl, $cm);
// End of process commands =====================================================
$PAGE->requires->yui2_lib('container');
示例#3
0
/**
 * Update the sumgrades field of the quiz. This needs to be called whenever
 * the grading structure of the quiz is changed. For example if a question is
 * added or removed, or a question weight is changed.
 *
 * @param object $quiz a quiz.
 */
function quiz_update_sumgrades($quiz) {
    global $DB;
    $sql = 'UPDATE {quiz}
            SET sumgrades = COALESCE((
                SELECT SUM(grade)
                FROM {quiz_question_instances}
                WHERE quiz = {quiz}.id
            ), 0)
            WHERE id = ?';
    $DB->execute($sql, array($quiz->id));
    $quiz->sumgrades = $DB->get_field('quiz', 'sumgrades', array('id' => $quiz->id));
    if ($quiz->sumgrades < 0.000005 && quiz_clean_layout($quiz->questions, true)) {
        // If there is at least one question in the quiz, and the sumgrades has been
        // set to 0, then also set the maximum possible grade to 0.
        quiz_set_grade(0, $quiz);
    }
}
示例#4
0
        }
        $quiz->questions = implode(",", $questions);
        // Always have a page break at the end
        $quiz->questions = $quiz->questions . ',0';
        // Avoid duplicate page breaks
        while (strpos($quiz->questions, ',0,0')) {
            $quiz->questions = str_replace(',0,0', ',0', $quiz->questions);
        }
        if (!set_field('quiz', 'questions', $quiz->questions, 'id', $quiz->instance)) {
            error('Could not save question list');
        }
    }
    // If rescaling is required save the new maximum
    $maxgrade = optional_param('maxgrade', -1, PARAM_INTEGER);
    if ($maxgrade >= 0) {
        if (!quiz_set_grade($maxgrade, $quiz)) {
            error('Could not set a new maximum grade for the quiz');
        }
    }
    $significantchangemade = true;
}
/// Delete any teacher preview attempts if the quiz has been modified
if ($significantchangemade) {
    $previewattempts = get_records_select('quiz_attempts', 'quiz = ' . $quiz->id . ' AND preview = 1');
    if ($previewattempts) {
        foreach ($previewattempts as $attempt) {
            quiz_delete_attempt($attempt, $quiz);
        }
    }
}
question_showbank_actions($thispageurl, $cm);
示例#5
0
    if ($questions) {
        ksort($questions);
        $quiz->questions = implode(",", $questions);
        // Always have a page break at the end
        $quiz->questions = $quiz->questions . ',0';
        // Avoid duplicate page breaks
        while (strpos($quiz->questions, ',0,0')) {
            $quiz->questions = str_replace(',0,0', ',0', $quiz->questions);
        }
        if (!set_field('quiz', 'questions', $quiz->questions, 'id', $quiz->instance)) {
            error('Could not save question list');
        }
    }
    // If rescaling is required save the new maximum
    if (isset($_REQUEST['maxgrade'])) {
        if (!quiz_set_grade(optional_param('maxgrade', 0), $quiz)) {
            error('Could not set a new maximum grade for the quiz');
        }
    }
}
/// Delete any teacher preview attempts if the quiz has been modified
if (isset($_REQUEST['savechanges']) or isset($_REQUEST['delete']) or isset($_REQUEST['repaginate']) or isset($_REQUEST['addrandom']) or isset($_REQUEST['addquestion']) or isset($_REQUEST['up']) or isset($_REQUEST['down']) or isset($_REQUEST['add'])) {
    delete_records('quiz_attempts', 'preview', '1', 'quiz', $quiz->id);
}
question_showbank_actions($thispageurl, $cm);
/// all commands have been dealt with, now print the page
// Print basic page layout.
if (isset($quiz->instance) and record_exists_select('quiz_attempts', "quiz = '{$quiz->instance}' AND preview = '0'")) {
    // one column layout with table of questions used in this quiz
    $strupdatemodule = has_capability('moodle/course:manageactivities', $contexts->lowest()) ? update_module_button($cm->id, $course->id, get_string('modulename', 'quiz')) : "";
    $navlinks = array();
示例#6
0
    if ($questions) {
        ksort($questions);
        $modform->questions = implode(",", $questions);
        // Always have a page break at the end
        $modform->questions = $modform->questions . ',0';
        // Avoid duplicate page breaks
        while (strpos($modform->questions, ',0,0')) {
            $modform->questions = str_replace(',0,0', ',0', $modform->questions);
        }
        if (!set_field('quiz', 'questions', $modform->questions, 'id', $modform->instance)) {
            error('Could not save question list');
        }
    }
    // If rescaling is required save the new maximum
    if (isset($_REQUEST['maxgrade'])) {
        if (!quiz_set_grade(optional_param('maxgrade', 0), $modform)) {
            error('Could not set a new maximum grade for the quiz');
        }
    }
}
if (isset($_REQUEST['showbreaks'])) {
    $SESSION->quiz_showbreaks = optional_param('showbreaks', 0, PARAM_BOOL);
    $SESSION->quiz_reordertool = optional_param('reordertool', 0, PARAM_BOOL);
}
/// Delete any teacher preview attempts if the quiz has been modified
if (isset($_REQUEST['savechanges']) or isset($_REQUEST['delete']) or isset($_REQUEST['repaginate']) or isset($_REQUEST['addrandom']) or isset($_REQUEST['addquestion']) or isset($_REQUEST['up']) or isset($_REQUEST['down']) or isset($_REQUEST['add'])) {
    delete_records('quiz_attempts', 'preview', '1', 'quiz', $modform->id);
}
/// all commands have been dealt with, now print the page
if (empty($modform->category) or !record_exists('question_categories', 'id', $modform->category)) {
    $category = get_default_question_category($course->id);
/**
 * Update the sumgrades field of the quiz. This needs to be called whenever
 * the grading structure of the quiz is changed. For example if a question is
 * added or removed, or a question weight is changed.
 *
 * @param object $quiz a quiz.
 */
function quiz_update_sumgrades($quiz)
{
    global $DB;
    $sql = 'UPDATE {quiz}
            SET sumgrades = COALESCE((
                SELECT SUM(grade)
                FROM {quiz_question_instances}
                WHERE quiz = {quiz}.id
            ), 0)
            WHERE id = ?';
    $DB->execute($sql, array($quiz->id));
    $quiz->sumgrades = $DB->get_field('quiz', 'sumgrades', array('id' => $quiz->id));
    if ($quiz->sumgrades < 5.0E-6) {
        quiz_set_grade(0, $quiz);
    }
}