当前位置: 首页>>代码示例>>PHP>>正文


PHP quiz_calculate_best_grade函数代码示例

本文整理汇总了PHP中quiz_calculate_best_grade函数的典型用法代码示例。如果您正苦于以下问题:PHP quiz_calculate_best_grade函数的具体用法?PHP quiz_calculate_best_grade怎么用?PHP quiz_calculate_best_grade使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了quiz_calculate_best_grade函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: prevent_new_attempt

 public function prevent_new_attempt($numattempts, $lastattempt)
 {
     global $DB;
     if ($numattempts == 0) {
         return false;
     }
     // Check if preventonpass is set, and whether the student has passed the minimum passing grade.
     $previousattempts = $DB->get_records_select('quiz_attempts', "quiz = :quizid AND userid = :userid AND timefinish > 0 and preview != 1", array('quizid' => $this->quiz->id, 'userid' => $lastattempt->userid));
     if (quiz_rescale_grade(quiz_calculate_best_grade($this->quiz, $previousattempts), $this->quiz, false) >= $this->quiz->reattemptchecker) {
         return get_string('accessprevented', 'quizaccess_reattemptchecker');
     }
     return false;
 }
开发者ID:jmvedrine,项目名称:moodle-quizaccess_reattemptchecker,代码行数:13,代码来源:rule.php

示例2: quiz_save_best_grade

/**
 * Save the overall grade for a user at a quiz in the quiz_grades table
 *
 * @param object $quiz The quiz for which the best grade is to be calculated and then saved.
 * @param integer $userid The userid to calculate the grade for. Defaults to the current user.
 * @return boolean Indicates success or failure.
 */
function quiz_save_best_grade($quiz, $userid = null)
{
    global $USER;
    if (empty($userid)) {
        $userid = $USER->id;
    }
    // Get all the attempts made by the user
    if (!($attempts = quiz_get_user_attempts($quiz->id, $userid))) {
        notify('Could not find any user attempts');
        return false;
    }
    // Calculate the best grade
    $bestgrade = quiz_calculate_best_grade($quiz, $attempts);
    $bestgrade = quiz_rescale_grade($bestgrade, $quiz);
    // Save the best grade in the database
    if ($grade = get_record('quiz_grades', 'quiz', $quiz->id, 'userid', $userid)) {
        $grade->grade = $bestgrade;
        $grade->timemodified = time();
        if (!update_record('quiz_grades', $grade)) {
            notify('Could not update best grade');
            return false;
        }
    } else {
        $grade->quiz = $quiz->id;
        $grade->userid = $userid;
        $grade->grade = $bestgrade;
        $grade->timemodified = time();
        if (!insert_record('quiz_grades', $grade)) {
            notify('Could not insert new best grade');
            return false;
        }
    }
    quiz_update_grades($quiz, $userid);
    return true;
}
开发者ID:kai707,项目名称:ITSA-backup,代码行数:42,代码来源:locallib.php

示例3: quiz_save_best_grade

/**
 * Save the overall grade for a user at a quiz in the quiz_grades table
 *
 * @param object $quiz The quiz for which the best grade is to be calculated and then saved.
 * @param int $userid The userid to calculate the grade for. Defaults to the current user.
 * @param array $attempts The attempts of this user. Useful if you are
 * looping through many users. Attempts can be fetched in one master query to
 * avoid repeated querying.
 * @return bool Indicates success or failure.
 */
function quiz_save_best_grade($quiz, $userid = null, $attempts = array()) {
    global $DB, $OUTPUT, $USER;

    if (empty($userid)) {
        $userid = $USER->id;
    }

    if (!$attempts) {
        // Get all the attempts made by the user.
        $attempts = quiz_get_user_attempts($quiz->id, $userid);
    }

    // Calculate the best grade.
    $bestgrade = quiz_calculate_best_grade($quiz, $attempts);
    $bestgrade = quiz_rescale_grade($bestgrade, $quiz, false);

    // Save the best grade in the database.
    if (is_null($bestgrade)) {
        $DB->delete_records('quiz_grades', array('quiz' => $quiz->id, 'userid' => $userid));

    } else if ($grade = $DB->get_record('quiz_grades',
            array('quiz' => $quiz->id, 'userid' => $userid))) {
        $grade->grade = $bestgrade;
        $grade->timemodified = time();
        $DB->update_record('quiz_grades', $grade);

    } else {
        $grade = new stdClass();
        $grade->quiz = $quiz->id;
        $grade->userid = $userid;
        $grade->grade = $bestgrade;
        $grade->timemodified = time();
        $DB->insert_record('quiz_grades', $grade);
    }

    quiz_update_grades($quiz, $userid);
}
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:47,代码来源:locallib.php

示例4: quiz_save_best_grade

/**
 * Save the overall grade for a user at a quiz in the quiz_grades table
 *
 * @param object $quiz The quiz for which the best grade is to be calculated and then saved.
 * @param integer $userid The userid to calculate the grade for. Defaults to the current user.
 * @param array $attempts The attempts of this user. Useful if you are
 * looping through many users. Attempts can be fetched in one master query to
 * avoid repeated querying.
 * @return boolean Indicates success or failure.
 */
function quiz_save_best_grade($quiz, $userid = null, $attempts = array())
{
    global $DB;
    global $USER, $OUTPUT;
    if (empty($userid)) {
        $userid = $USER->id;
    }
    if (!$attempts) {
        // Get all the attempts made by the user
        if (!($attempts = quiz_get_user_attempts($quiz->id, $userid))) {
            echo $OUTPUT->notification('Could not find any user attempts');
            return false;
        }
    }
    // Calculate the best grade
    $bestgrade = quiz_calculate_best_grade($quiz, $attempts);
    $bestgrade = quiz_rescale_grade($bestgrade, $quiz, false);
    // Save the best grade in the database
    if ($grade = $DB->get_record('quiz_grades', array('quiz' => $quiz->id, 'userid' => $userid))) {
        $grade->grade = $bestgrade;
        $grade->timemodified = time();
        $DB->update_record('quiz_grades', $grade);
    } else {
        $grade->quiz = $quiz->id;
        $grade->userid = $userid;
        $grade->grade = $bestgrade;
        $grade->timemodified = time();
        $DB->insert_record('quiz_grades', $grade);
    }
    quiz_update_grades($quiz, $userid);
    return true;
}
开发者ID:ajv,项目名称:Offline-Caching,代码行数:42,代码来源:locallib.php


注:本文中的quiz_calculate_best_grade函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。