本文整理汇总了PHP中quiz_get_best_grade函数的典型用法代码示例。如果您正苦于以下问题:PHP quiz_get_best_grade函数的具体用法?PHP quiz_get_best_grade怎么用?PHP quiz_get_best_grade使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了quiz_get_best_grade函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
// Initialize $PAGE, compute blocks
$PAGE->set_url('/mod/quiz/view.php', array('id' => $cm->id));
// Get this user's attempts.
$attempts = quiz_get_user_attempts($quiz->id, $USER->id, 'finished', true);
$lastfinishedattempt = end($attempts);
$unfinished = false;
if ($unfinishedattempt = quiz_get_user_attempt_unfinished($quiz->id, $USER->id)) {
$attempts[] = $unfinishedattempt;
$unfinished = true;
}
$numattempts = count($attempts);
// Work out the final grade, checking whether it was overridden in the gradebook.
if (!$canpreview) {
$mygrade = quiz_get_best_grade($quiz, $USER->id);
} else if ($lastfinishedattempt) {
// Users who can preview the quiz don't get a proper grade, so work out a
// plausible value to display instead, so the page looks right.
$mygrade = quiz_rescale_grade($lastfinishedattempt->sumgrades, $quiz, false);
} else {
$mygrade = null;
}
$mygradeoverridden = false;
$gradebookfeedback = '';
$grading_info = grade_get_grades($course->id, 'mod', 'quiz', $quiz->id, $USER->id);
if (!empty($grading_info->items)) {
$item = $grading_info->items[0];
if (isset($item->grades[$USER->id])) {
示例2: get_user_best_grade
/**
* Get the best current grade for the given user on a quiz.
*
* @param int $quizid quiz instance id
* @param int $userid user id
* @return array of warnings and the grade information
* @since Moodle 3.1
*/
public static function get_user_best_grade($quizid, $userid = 0)
{
global $DB, $USER;
$warnings = array();
$params = array('quizid' => $quizid, 'userid' => $userid);
$params = self::validate_parameters(self::get_user_best_grade_parameters(), $params);
list($quiz, $course, $cm, $context) = self::validate_quiz($params['quizid']);
// Default value for userid.
if (empty($params['userid'])) {
$params['userid'] = $USER->id;
}
$user = core_user::get_user($params['userid'], '*', MUST_EXIST);
core_user::require_active_user($user);
// Extra checks so only users with permissions can view other users attempts.
if ($USER->id != $user->id) {
require_capability('mod/quiz:viewreports', $context);
}
$result = array();
$grade = quiz_get_best_grade($quiz, $user->id);
if ($grade === null) {
$result['hasgrade'] = false;
} else {
$result['hasgrade'] = true;
$result['grade'] = $grade;
}
$result['warnings'] = $warnings;
return $result;
}
示例3: certificate_activity_completed
function certificate_activity_completed(&$activity, &$cm, $userid = 0)
{
global $CFG, $USER;
static $quizid, $questid, $assid, $lessid, $feedid, $survid, $scormid, $facetofaceid;
if (!$userid) {
$userid = $USER->id;
}
if (empty($quizid)) {
$quizid = get_field('modules', 'id', 'name', 'quiz');
$questid = get_field('modules', 'id', 'name', 'questionnaire');
$assid = get_field('modules', 'id', 'name', 'assignment');
$lessid = get_field('modules', 'id', 'name', 'lesson');
$feedid = get_field('modules', 'id', 'name', 'feedback');
$survid = get_field('modules', 'id', 'name', 'survey');
$scormid = get_field('modules', 'id', 'name', 'scorm');
$facetofaceid = get_field('modules', 'id', 'name', 'facetoface');
}
/// If the module is not visible, it can't be accessed by students (assignment module
/// will give us errors), so return true if its not visible.
if (!empty($cm)) {
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context)) {
return true;
}
if ($cm->module == $quizid) {
require_once $CFG->dirroot . '/mod/quiz/locallib.php';
$quiz = get_record('quiz', 'id', $cm->instance);
$score = quiz_get_best_grade($quiz, $userid);
$grade = (int) ((double) $score / (double) $quiz->grade * 100.0);
return $grade >= (int) $activity->linkgrade;
} else {
if ($cm->module == $assid) {
require_once $CFG->dirroot . '/mod/assignment/lib.php';
$assignment = get_record('assignment', 'id', $cm->instance);
require_once "{$CFG->dirroot}/mod/assignment/type/{$assignment->assignmenttype}/assignment.class.php";
$assignmentclass = "assignment_{$assignment->assignmenttype}";
$assignmentinstance = new $assignmentclass($cm->id, $assignment, $cm);
if (!($submission = $assignmentinstance->get_submission($userid))) {
return false;
} else {
if ($assignmentinstance->assignment->grade <= 0) {
return true;
} else {
$grade = (int) ((double) $submission->grade / (double) $assignmentinstance->assignment->grade * 100.0);
return $grade >= (int) $activity->linkgrade;
}
}
} else {
if ($cm->module == $questid) {
return get_record('questionnaire_attempts', 'qid', $cm->instance, 'userid', $userid) !== false;
} else {
if ($cm->module == $feedid) {
return get_record('feedback_completed', 'feedback', $cm->instance, 'userid', $userid) !== false;
} else {
if ($cm->module == $survid) {
return get_record('survey_answers', 'id', $cm->instance, 'userid', $userid) !== false;
} else {
if ($cm->module == $scormid) {
require_once $CFG->dirroot . '/mod/scorm/locallib.php';
$scorm = get_record('scorm', 'id', $cm->instance);
$score = scorm_grade_user($scorm, $userid);
if ($scorm->grademethod % 10 == 0) {
// GRADESCOES
if (!($scorm->maxgrade = count_records_select('scorm_scoes', "scorm='{$scorm->id}' AND launch<>'" . sql_empty() . "'"))) {
return true;
}
}
$return->maxgrade = $scorm->maxgrade;
$grade = (int) ((double) $score / (double) $scorm->maxgrade * 100.0);
return $grade >= (int) $activity->linkgrade;
} else {
if ($cm->module == $lessid) {
require_once $CFG->dirroot . '/mod/lesson/locallib.php';
if (!($lesson = get_record('lesson', 'id', $cm->instance))) {
return true;
} else {
$ntries = count_records('lesson_grades', 'lessonid', $lesson->id, 'userid', $userid) - 1;
$gradeinfo = lesson_grade($lesson, $ntries);
return $gradeinfo->grade >= (int) $activity->linkgrade;
}
} else {
if ($cm->module == $facetofaceid) {
require_once $CFG->libdir . '/gradelib.php';
$grading_info = grade_get_grades($cm->course, 'mod', 'facetoface', $cm->instance, $userid);
if (empty($grading_info)) {
return false;
}
$grade = $grading_info->items[0]->grades[$userid]->grade;
return $grade >= (int) $activity->linkgrade;
} else {
return true;
}
}
}
}
}
}
}
}
} else {
//.........这里部分代码省略.........
示例4: quiz_user_outline
function quiz_user_outline($course, $user, $mod, $quiz)
{
/// Return a small object with summary information about what a
/// user has done with a given particular instance of this module
/// Used for user activity reports.
/// $return->time = the time they did it
/// $return->info = a short text description
$grade = quiz_get_best_grade($quiz, $user->id);
if (is_null($grade)) {
return NULL;
}
$result = new stdClass();
$result->info = get_string('grade') . ': ' . $grade . '/' . $quiz->grade;
$result->time = get_field('quiz_attempts', 'MAX(timefinish)', 'userid', $user->id, 'quiz', $quiz->id);
return $result;
}
示例5: quiz_user_complete
function quiz_user_complete($course, $user, $mod, $quiz)
{
global $DB;
/// Print a detailed representation of what a user has done with
/// a given particular instance of this module, for user activity reports.
if ($attempts = $DB->get_records('quiz_attempts', array('userid' => $user->id, 'quiz' => $quiz->id), 'attempt')) {
if (quiz_has_grades($quiz) && ($grade = quiz_get_best_grade($quiz, $user->id))) {
echo get_string('grade') . ': ' . $grade . '/' . quiz_format_grade($quiz, $quiz->grade) . '<br />';
}
foreach ($attempts as $attempt) {
echo get_string('attempt', 'quiz') . ' ' . $attempt->attempt . ': ';
if ($attempt->timefinish == 0) {
print_string('unfinished');
} else {
echo quiz_format_grade($quiz, $attempt->sumgrades) . '/' . quiz_format_grade($quiz, $quiz->sumgrades);
}
echo ' - ' . userdate($attempt->timemodified) . '<br />';
}
} else {
print_string('noattempts', 'quiz');
}
return true;
}
示例6: quiz_user_complete
/**
* Print a detailed representation of what a user has done with
* a given particular instance of this module, for user activity reports.
*
* @global object
* @param object $course
* @param object $user
* @param object $mod
* @param object $quiz
* @return bool
*/
function quiz_user_complete($course, $user, $mod, $quiz)
{
global $DB;
if ($attempts = $DB->get_records('quiz_attempts', array('userid' => $user->id, 'quiz' => $quiz->id), 'attempt')) {
if (quiz_has_grades($quiz) && ($grade = quiz_get_best_grade($quiz, $user->id))) {
echo get_string('grade') . ': ' . $grade . '/' . quiz_format_grade($quiz, $quiz->grade) . '<br />';
}
foreach ($attempts as $attempt) {
echo get_string('attempt', 'quiz') . ' ' . $attempt->attempt . ': ';
if ($attempt->timefinish == 0) {
print_string('unfinished');
} else {
echo quiz_format_grade($quiz, $attempt->sumgrades) . '/' . quiz_format_grade($quiz, $quiz->sumgrades);
}
echo ' - ' . userdate($attempt->timemodified) . '<br />';
}
} else {
print_string('noattempts', 'quiz');
}
return true;
}