mirror of
https://github.com/moodle/moodle.git
synced 2025-03-18 22:50:19 +01:00
Merge branch 'MDL-51360-404-2' of https://github.com/ilyatregubov/moodle into MOODLE_404_STABLE
This commit is contained in:
commit
691f2c8950
@ -430,10 +430,14 @@ function grade_regrade_final_grades_if_required($course, callable $callback = nu
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns grading information for given activity, optionally with user grades
|
||||
* Returns grading information for given activity, optionally with user grades.
|
||||
* Manual, course or category items can not be queried.
|
||||
*
|
||||
* @category grade
|
||||
* This function can be VERY costly - it is doing full course grades recalculation if needsupdate = 1
|
||||
* for course grade item. So be sure you really need it.
|
||||
* If you need just certain grades consider using grade_item::refresh_grades()
|
||||
* together with grade_item::get_grade() instead.
|
||||
*
|
||||
* @param int $courseid ID of course
|
||||
* @param string $itemtype Type of grade item. For example, 'mod' or 'block'
|
||||
* @param string $itemmodule More specific then $itemtype. For example, 'forum' or 'quiz'. May be NULL for some item types
|
||||
@ -441,6 +445,7 @@ function grade_regrade_final_grades_if_required($course, callable $callback = nu
|
||||
* @param mixed $userid_or_ids Either a single user ID, an array of user IDs or null. If user ID or IDs are not supplied returns information about grade_item
|
||||
* @return stdClass Object with keys {items, outcomes, errors}, where 'items' is an array of grade
|
||||
* information objects (scaleid, name, grade and locked status, etc.) indexed with itemnumbers
|
||||
* @category grade
|
||||
*/
|
||||
function grade_get_grades($courseid, $itemtype, $itemmodule, $iteminstance, $userid_or_ids=null) {
|
||||
global $CFG;
|
||||
|
@ -126,21 +126,33 @@ if (!$canpreview) {
|
||||
$mygradeoverridden = false;
|
||||
$gradebookfeedback = '';
|
||||
|
||||
$item = null;
|
||||
|
||||
$gradinginfo = grade_get_grades($course->id, 'mod', 'quiz', $quiz->id, $USER->id);
|
||||
if (!empty($gradinginfo->items)) {
|
||||
$item = $gradinginfo->items[0];
|
||||
if (isset($item->grades[$USER->id])) {
|
||||
$grade = $item->grades[$USER->id];
|
||||
$gradeitem = grade_item::fetch([
|
||||
'itemtype' => 'mod',
|
||||
'itemmodule' => 'quiz',
|
||||
'iteminstance' => $quiz->id,
|
||||
'itemnumber' => 0,
|
||||
'courseid' => $course->id,
|
||||
]);
|
||||
|
||||
if ($gradeitem) {
|
||||
if ($gradeitem->refresh_grades($USER->id)) {
|
||||
$grade = $gradeitem->get_grade($USER->id, false);
|
||||
if ($grade->overridden) {
|
||||
$mygrade = $grade->grade + 0; // Convert to number.
|
||||
if ($gradeitem->needsupdate) {
|
||||
// It is Error, but let's be consistent with the old code.
|
||||
$mygrade = 0;
|
||||
} else {
|
||||
$mygrade = $grade->finalgrade;
|
||||
}
|
||||
$mygradeoverridden = true;
|
||||
}
|
||||
if (!empty($grade->str_feedback)) {
|
||||
$gradebookfeedback = $grade->str_feedback;
|
||||
|
||||
if (!empty($grade->feedback)) {
|
||||
$gradebookfeedback = $grade->feedback;
|
||||
}
|
||||
} else {
|
||||
// It is Error, but let's be consistent with the old code.
|
||||
$mygrade = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -197,9 +209,9 @@ if ($quiz->attempts != 1) {
|
||||
}
|
||||
|
||||
// Inform user of the grade to pass if non-zero.
|
||||
if ($item && grade_floats_different($item->gradepass, 0)) {
|
||||
if ($gradeitem && grade_floats_different($gradeitem->gradepass, 0)) {
|
||||
$a = new stdClass();
|
||||
$a->grade = quiz_format_grade($quiz, $item->gradepass);
|
||||
$a->grade = quiz_format_grade($quiz, $gradeitem->gradepass);
|
||||
$a->maxgrade = quiz_format_grade($quiz, $quiz->grade);
|
||||
$viewobj->infomessages[] = get_string('gradetopassoutof', 'quiz', $a);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user