diff --git a/grade/report/grade_breakdown/index.php b/grade/report/grade_breakdown/index.php index 635887232e331..6a141ba0136e2 100755 --- a/grade/report/grade_breakdown/index.php +++ b/grade/report/grade_breakdown/index.php @@ -31,10 +31,6 @@ $gradeid = optional_param('grade', null, PARAM_INT); $groupid = optional_param('group', null, PARAM_INT); -$PAGE->set_url(new moodle_url('/grade/report/grade_breakdown/index.php', array( - 'id' => $courseid, 'grade' => $gradeid, 'group' => $groupid -))); - if (!$course = $DB->get_record('course', array('id' => $courseid))) { print_error('nocourseid'); } @@ -46,12 +42,12 @@ require_capability('gradereport/grade_breakdown:view', $context); // Are they a teacher? -$is_teacher = has_capability('moodle/grade:viewall', $context); +$isteacher = has_capability('moodle/grade:viewall', $context); // Graded roles $gradedroles = explode(',', $CFG->gradebookroles); -$has_access = false; +$hasaccess = false; // If the user is a "student" (graded role), and the teacher allowed them // to view the report @@ -61,19 +57,19 @@ $CFG->grade_report_grade_breakdown_allowstudents ); -if (!$is_teacher && $allowstudents) { - $user_roles = get_user_roles($context, $USER->id); +if (!$isteacher && $allowstudents) { + $userroles = get_user_roles($context, $USER->id); - foreach ($user_roles as $role) { + foreach ($userroles as $role) { if (in_array($role->roleid, $gradedroles)) { - $has_access = true; + $hasaccess = true; break; } } } // End permission -$_s = function($key, $a = null) { +$s = function($key, $a = null) { return get_string($key, 'gradereport_grade_breakdown'); }; @@ -81,22 +77,38 @@ 'type' => 'report', 'plugin' => 'grade_breakdown', 'courseid' => $courseid )); +$reportname = $s('pluginname'); + +$PAGE->set_context($context); +$url = new moodle_url('/grade/report/grade_breakdown/index.php', ['id' => $courseid]); +$PAGE->set_url($url); + if (!isset($USER->grade_last_report)) { $USER->grade_last_report = array(); } $USER->grade_last_report[$course->id] = 'grade_breakdown'; -grade_regrade_final_grades($courseid); - -$reportname = $_s('pluginname'); - -$PAGE->set_context($context); +grade_regrade_final_grades($course->id); + +print_grade_page_head( + $course->id, + 'report', + $active_plugin = 'grade_breakdown', + $heading = $reportname, + $return = false, + $buttons = false, + $shownavigation = true, + $headerhelpidentifier = null, + $headerhelpcomponent = null, + $user = null, + $actionbar = null, + $showtitle = true +); -print_grade_page_head($course->id, 'report', 'grade_breakdown', $reportname, false); // The current user does not have access to view this report -if (!$has_access && !$is_teacher) { - echo $OUTPUT->heading($_s('teacher_disabled')); +if (!$hasaccess && !$isteacher) { + echo $OUTPUT->heading($s('teacher_disabled')); echo $OUTPUT->footer(); exit; } @@ -118,13 +130,12 @@ 'u.id', 'u.lastname, u.firstname', null, $groupid ); } - -$num_users = count($users); +$numusers = count($users); // The student has access, but they still are unable to view it // if there is 10 or less student enrollments in the class -if (!$is_teacher && $num_users <= 10) { - echo $OUTPUT->heading($_s('size_disabled')); +if (!$isteacher && $numusers <= 10) { + echo $OUTPUT->heading($s('size_disabled')); echo $OUTPUT->footer(); exit; } @@ -137,7 +148,7 @@ $report->setup_groups(); echo '
- '. ($is_teacher ? $report->group_selector : '') . $report->grade_selector . ' + '. ($isteacher ? $report->group_selector : '') . $report->grade_selector . '
'; $report->print_table(); diff --git a/grade/report/grade_breakdown/letter_report.php b/grade/report/grade_breakdown/letter_report.php index 9119059b5f760..d86485e195c53 100755 --- a/grade/report/grade_breakdown/letter_report.php +++ b/grade/report/grade_breakdown/letter_report.php @@ -33,6 +33,14 @@ $bound = required_param('bound', PARAM_RAW); $gradeid = required_param('grade', PARAM_INT); $groupid = optional_param('group', 0, PARAM_INT); +$groupid = isset($groupid) ? $groupid : 0; + +$parms = array( + 'id' => $courseid, + 'bound' => $bound, + 'grade' => $gradeid, + 'group' => $groupid +); if (!$course = $DB->get_record('course', array('id' => $courseid))) { print_error('nocourseid'); @@ -50,18 +58,28 @@ $strgrades = get_string('grades'); $reportname = get_string('pluginname', 'gradereport_grade_breakdown'); -$PAGE->set_url(new moodle_url('/grade/report/grade_breakdown/letter_report.php', - array( - 'id' => $courseid, - 'bound' => $bound, - 'grade' => $gradeid, - 'group' => $groupid - ) -)); +//$url = new moodle_url('/grade/report/grade_breakdown/letter_report.php', $parms); +$url = new moodle_url('/grade/report/grade_breakdown/index.php', ['id' => $courseid]); $PAGE->set_context($context); - -print_grade_page_head($course->id, 'report', 'grade_breakdown', $reportname, false); +$PAGE->set_url($url); + +$abar = new \core_grades\output\general_action_bar($PAGE->context, $PAGE->url, 'report', 'grade_breakdown'); + +print_grade_page_head( + $course->id, + 'report', + $active_plugin = 'grade_breakdown', + $heading = $reportname, + $return = false, + $buttons = false, + $shownavigation = true, + $headerhelpidentifier = null, + $headerhelpcomponent = null, + $user = null, + $actionbar = $abar, + $showtitle = true +); // This grade report has the functionality to print the right // group selector @@ -123,15 +141,19 @@ 'courseid' => $courseid )); +$decimals = $grade_item->decimals; + $letters = grade_get_letters($context); -$high = 100; +$high = $CFG->unlimitedgrades = 1 ? 10000 : 100; + foreach($letters as $boundary => $letter) { // Found it! if ($boundary == $bound) { break; } - $high = $boundary - (1 / (pow(10, $decimals))); + $val = (1 / (pow(10, $decimals))); + $high = $boundary - $val; } // In the event that we're looking at the max, students actually have the @@ -143,7 +165,7 @@ $query_params = array( 'courseid' => $courseid, - 'gradeid' => $gradeid, + 'gradeid' => $grade_item->id, 'real_high' => $real_high, 'real_low' => $real_low ); @@ -163,9 +185,13 @@ // Get all the grades for the users within the range specified with $real_high and $real_low -$mainuserfields = user_picture::fields('u', array('id'), 'userid'); +$userfields = \core_user\fields::for_name()->get_required_fields(); + +$mainuserfields = implode(',u.', $userfields); -$sql = "SELECT u.id, $mainuserfields, g.id AS gradeid, g.finalgrade +$highselect = $real_high >= 100 ? "" : "AND g.finalgrade <= $real_high"; + +$sql = "SELECT u.id, $mainuserfields, g.id AS gradesid, g.finalgrade $group_name FROM {grade_grades} g, {user} u @@ -174,7 +200,7 @@ $group_where AND g.itemid = :gradeid AND g.userid IN ({$userids}) - AND g.finalgrade <= :real_high + $highselect AND g.finalgrade >= :real_low ORDER BY g.finalgrade DESC"; @@ -189,9 +215,9 @@ // Get the Moodle version of this grade item $item_params = array('id' => $gradeid); -$grade_item = grade_item::fetch($item_params); +$gradeitem = grade_item::fetch($item_params); -$name = $grade_item->get_name(); +$name = $gradeitem->get_name(); $g_params = array('id' => $groupid); $groupname = ($groupid) ? ' in ' . $DB->get_field('groups', 'name', $g_params) : ''; @@ -199,7 +225,6 @@ echo $OUTPUT->heading(get_string('user_grades', 'gradereport_grade_breakdown') . $letters[$bound] . ' for ' . $name . $groupname); - $numusers = count($graded_users); // Build the data @@ -214,15 +239,15 @@ $line[] = html_writer::link($url, fullname($gr)); - $line[] = grade_format_gradevalue($gr->finalgrade, $grade_item, true, + $line[] = grade_format_gradevalue($gr->finalgrade, $gradeitem, true, GRADE_DISPLAY_TYPE_REAL); - $line[] = grade_format_gradevalue($gr->finalgrade, $grade_item, true, + $line[] = grade_format_gradevalue($gr->finalgrade, $gradeitem, true, GRADE_DISPLAY_TYPE_PERCENTAGE); - $line[] = find_rank($context, $grade_item, $gr, $groupid) . '/' . $numusers; + $line[] = find_rank($context, $gradeitem, $gr, $groupid) . '/' . $numusers; - $line[] = print_edit_link($courseid, $grade_item, $gr->gradeid); + $line[] = print_edit_link($courseid, $gradeitem, $gr->gradesid); $data[] = $line; }