mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
Merged changes from MOODLE_17_STABLE for MDL-7707
This commit is contained in:
parent
bfec96420b
commit
512ce79274
@ -8,7 +8,8 @@
|
||||
**/
|
||||
|
||||
require_once("../../config.php");
|
||||
require_once("locallib.php");
|
||||
require_once($CFG->dirroot.'/mod/lesson/lib.php');
|
||||
require_once($CFG->dirroot.'/mod/lesson/locallib.php');
|
||||
|
||||
$id = required_param('id', PARAM_INT); // course
|
||||
|
||||
@ -29,8 +30,8 @@
|
||||
|
||||
/// Print the header
|
||||
|
||||
if ($course->id != SITEID) {
|
||||
$navigation = "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->";
|
||||
if ($course->category) {
|
||||
$navigation = "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> ->";
|
||||
} else {
|
||||
$navigation = '';
|
||||
}
|
||||
@ -86,19 +87,13 @@
|
||||
if (has_capability('mod/lesson:manage', $context)) {
|
||||
$grade_value = $lesson->grade;
|
||||
} else {
|
||||
// it's a student, show their mean or maximum grade
|
||||
if ($lesson->usemaxgrade) {
|
||||
$grade = get_record_sql("SELECT MAX(grade) as grade FROM {$CFG->prefix}lesson_grades
|
||||
WHERE lessonid = $lesson->id AND userid = $USER->id GROUP BY userid");
|
||||
} else {
|
||||
$grade = get_record_sql("SELECT AVG(grade) as grade FROM {$CFG->prefix}lesson_grades
|
||||
WHERE lessonid = $lesson->id AND userid = $USER->id GROUP BY userid");
|
||||
}
|
||||
if ($grade) {
|
||||
// it's a student, show their grade
|
||||
$grade_value = 0;
|
||||
if ($return = lesson_grades($lesson->id)) {
|
||||
// grades are stored as percentages
|
||||
$grade_value = number_format($grade->grade * $lesson->grade / 100, 1);
|
||||
} else {
|
||||
$grade_value = 0;
|
||||
if (isset($return->grades[$USER->id])) {
|
||||
$grade_value = $return->grades[$USER->id];
|
||||
}
|
||||
}
|
||||
}
|
||||
$table->data[] = array ($lesson->section, $link, $grade_value, $due);
|
||||
|
@ -388,14 +388,24 @@ function lesson_grades($lessonid) {
|
||||
if (!$lesson = get_record("lesson", "id", $lessonid)) {
|
||||
return NULL;
|
||||
}
|
||||
if ($lesson->usemaxgrade) {
|
||||
$grades = get_records_sql_menu("SELECT userid,MAX(grade) FROM {$CFG->prefix}lesson_grades WHERE
|
||||
lessonid = $lessonid GROUP BY userid");
|
||||
} else {
|
||||
$grades = get_records_sql_menu("SELECT userid,AVG(grade) FROM {$CFG->prefix}lesson_grades WHERE
|
||||
if ($lesson->retake) {
|
||||
if ($lesson->usemaxgrade) {
|
||||
$grades = get_records_sql_menu("SELECT userid,MAX(grade) FROM {$CFG->prefix}lesson_grades WHERE
|
||||
lessonid = $lessonid GROUP BY userid");
|
||||
} else {
|
||||
$grades = get_records_sql_menu("SELECT userid,AVG(grade) FROM {$CFG->prefix}lesson_grades WHERE
|
||||
lessonid = $lessonid GROUP BY userid");
|
||||
}
|
||||
} else {
|
||||
// Retakes is turned Off; only count first attempt
|
||||
$firstgrades = get_records_sql("SELECT userid, MIN(completed), grade FROM {$CFG->prefix}lesson_grades WHERE lessonid = $lessonid GROUP BY userid");
|
||||
$grades = array();
|
||||
if (!empty($firstgrades)) {
|
||||
foreach($firstgrades as $userid => $info) {
|
||||
$grades[$userid] = $info->grade;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// convert grades from percentages and tidy the numbers
|
||||
if (!$lesson->practice) { // dont display practice lessons
|
||||
if ($grades) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user