From 50b61a3ee67ef5f699ad2fff412f8346fa8a1160 Mon Sep 17 00:00:00 2001 From: Jayce Date: Thu, 17 Apr 2025 11:05:01 +0930 Subject: [PATCH] MDL-80053 core_grade: fixed exception message appearing - Fixing the exceptions shows an incorrectly formatted table - The filler cell is only used to take space on the left rows but when the right rows are empty, it is not needed. --- public/grade/lib.php | 1 + public/grade/report/grader/lib.php | 26 +++++++++++++++++++------- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/public/grade/lib.php b/public/grade/lib.php index 466a257b3c8..f0bebafb36c 100644 --- a/public/grade/lib.php +++ b/public/grade/lib.php @@ -2502,6 +2502,7 @@ class grade_tree extends grade_structure { $this->courseid = $courseid; $this->levels = array(); $this->context = context_course::instance($courseid); + $this->items = []; if (!empty($COURSE->id) && $COURSE->id == $this->courseid) { $course = $COURSE; diff --git a/public/grade/report/grader/lib.php b/public/grade/report/grader/lib.php index 837fa93d40b..7c9b1ab007f 100644 --- a/public/grade/report/grader/lib.php +++ b/public/grade/report/grader/lib.php @@ -551,13 +551,19 @@ class grade_report_grader extends grade_report { public function get_max_students_per_page(): int { global $CFG; + $gradeitemcount = count($this->get_allgradeitems()); + if (isset($CFG->maxgradesperpage) && clean_param($CFG->maxgradesperpage, PARAM_INT) > 0) { $maxgradesperpage = $CFG->maxgradesperpage; } else { $maxgradesperpage = self::MAX_GRADES_PER_PAGE; } - return round($maxgradesperpage / count($this->get_allgradeitems())); + if ($gradeitemcount > 0) { + return round($maxgradesperpage / $gradeitemcount); + } else { + return $maxgradesperpage; + } } /** @@ -662,7 +668,9 @@ class grade_report_grader extends grade_report { $fillercell->colspan = $colspan; $fillercell->rowspan = $levels; $row = new html_table_row(array($fillercell)); - $rows[] = $row; + if ($levels >= 1) { // Do not display the filler cell if there are no levels as there will be nothing else in the row. + $rows[] = $row; + } for ($i = 1; $i < $levels; $i++) { $row = new html_table_row(); @@ -683,7 +691,6 @@ class grade_report_grader extends grade_report { $element = ['type' => 'userfield', 'name' => 'fullname']; $studentheader->text = $arrows['studentname'] . $this->gtree->get_cell_action_menu($element, 'gradeitem', $this->gpr, $this->baseurl); - $headerrow->cells[] = $studentheader; foreach ($extrafields as $field) { @@ -1299,10 +1306,15 @@ class grade_report_grader extends grade_report { // Extract rows from each side (left and right) and collate them into one row each foreach ($leftrows as $key => $row) { - $row->cells = array_merge($row->cells, $rightrows[$key]->cells); - $fulltable->data[] = $row; - unset($leftrows[$key]); - unset($rightrows[$key]); + if (isset($rightrows[$key])) { + $row->cells = array_merge($row->cells, $rightrows[$key]->cells); + $fulltable->data[] = $row; + unset($leftrows[$key]); + unset($rightrows[$key]); + } else { // Right row is not set - this is the case of the left side. + $fulltable->data[] = $row; + unset($leftrows[$key]); + } } $html .= html_writer::table($fulltable); return $OUTPUT->container($html, 'gradeparent');