Permalink
Browse files

MDL-26257 grade: fixed the grader report edit mode ajax and fixed a s…

…pot in the grader report that should be using get_students_per_page()
  • Loading branch information...
1 parent 8233747 commit a740a0ad9862d1551bc7cc7f918ce8af3b5dd152 @andyjdavis andyjdavis committed Mar 27, 2012
Showing with 140 additions and 50 deletions.
  1. +2 −2 grade/report/grader/index.php
  2. +32 −12 grade/report/grader/lib.php
  3. +105 −35 grade/report/grader/module.js
  4. +1 −1 lang/en/grades.php
@@ -147,7 +147,7 @@
echo $OUTPUT->notification($warning);
}
-$studentsperpage = $report->get_pref('studentsperpage');
+$studentsperpage = $report->get_students_per_page();
// Don't use paging if studentsperpage is empty or 0 at course AND site levels
if (!empty($studentsperpage)) {
echo $OUTPUT->paging_bar($numusers, $report->page, $studentsperpage, $report->pbarurl);
@@ -164,7 +164,7 @@
echo '<input type="hidden" value="grader" name="report"/>';
echo '<input type="hidden" value="'.$page.'" name="page"/>';
echo $reporthtml;
- echo '<div class="submit"><input type="submit" value="'.s(get_string('update')).'" /></div>';
+ echo '<div class="submit"><input type="submit" id="gradersubmit" value="'.s(get_string('update')).'" /></div>';
echo '</div></form>';
} else {
echo $reporthtml;
@@ -177,6 +177,10 @@ public function process_data($data) {
$queue = array();
$this->load_users();
$this->load_final_grades();
+
+ // Were any changes made?
+ $changedgrades = false;
+
foreach ($data as $varname => $postedvalue) {
$needsupdate = false;
@@ -204,6 +208,7 @@ public function process_data($data) {
// -1 means no grade
continue;
}
+ $changedgrades = true;
} else if ($datatype == 'feedback') {
if ($oldvalue->feedback == $postedvalue) {
continue;
@@ -278,14 +283,17 @@ public function process_data($data) {
$gradeitem->update_final_grade($userid, $finalgrade, 'gradebook', $feedback, FORMAT_MOODLE);
- // Update the array of loaded grades
- if ($datatype == 'grade') {
- $this->grades[$userid][$itemid]->finalgrade = $finalgrade;
- } else if ($datatype == 'feedback') {
+ // We can update feedback without reloading the grade item as it doesn't affect grade calculations
+ if ($datatype == 'feedback') {
$this->grades[$userid][$itemid]->feedback = $feedback;
}
}
+ if ($changedgrades) {
+ // If a final grade was overriden reload grades so dependent grades like course total will be correct
+ $this->grades = null;
+ }
+
return $warnings;
}
@@ -892,6 +900,15 @@ public function get_right_rows() {
} else {
$gradeval = $grade->finalgrade;
}
+ if (!empty($grade->finalgrade)) {
+ $gradevalforJS = null;
+ if ($item->scaleid && !empty($scalesarray[$item->scaleid])) {
+ $gradevalforJS = (int)$gradeval;
+ } else {
+ $gradevalforJS = format_float($gradeval, $decimalpoints);
+ }
+ $jsarguments['grades'][] = array('user'=>$userid, 'item'=>$itemid, 'grade'=>$gradevalforJS);
+ }
// MDL-11274
// Hide grades in the grader report if the current grader doesn't have 'moodle/grade:viewhidden'
@@ -1056,8 +1073,7 @@ public function get_right_rows() {
}
$jsarguments['cfg']['feedbacktrunclength'] = $this->feedback_trunc_length;
- //feedbacks are now being stored in $jsarguments['feedback'] in get_right_rows()
- //$jsarguments['cfg']['feedback'] = $this->feedbacks;
+ // Student grades and feedback are already at $jsarguments['feedback'] and $jsarguments['grades']
}
$jsarguments['cfg']['isediting'] = (bool)$USER->gradeediting[$this->courseid];
$jsarguments['cfg']['courseid'] = $this->courseid;
@@ -1673,21 +1689,21 @@ public function get_sort_arrows(array $extrafields = array()) {
}
/**
- * Returns the number of students to be displayed on each page
+ * Returns the maximum number of students to be displayed on each page
*
* Takes into account the 'studentsperpage' user preference and the 'max_input_vars'
* PHP setting. Too many fields is only a problem when submitting grades but
* we respect 'max_input_vars' even when viewing grades to prevent students disappearing
* when toggling editing on and off.
*
- * @return int The number of students to display per page
+ * @return int The maximum number of students to display per page
*/
- private function get_students_per_page() {
+ public function get_students_per_page() {
global $USER;
static $studentsperpage = null;
if ($studentsperpage === null) {
- $studentsperpage = $this->get_pref('studentsperpage');
+ $originalstudentsperpage = $studentsperpage = $this->get_pref('studentsperpage');
// Will this number of students result in more fields that we are allowed?
$maxinputvars = ini_get('max_input_vars');
@@ -1705,7 +1721,6 @@ private function get_students_per_page() {
$fieldsperstudent = $fieldspergradeitem * count($this->gtree->get_items());
$fieldsrequired = $studentsperpage * $fieldsperstudent;
-
if ($fieldsrequired > $maxinputvars) {
$studentsperpage = floor($maxinputvars / $fieldsperstudent);
if ($studentsperpage<1) {
@@ -1714,7 +1729,12 @@ private function get_students_per_page() {
// if there are >500 grade items and quickgrading and showquickfeedback are on
$studentsperpage = 1;
}
- debugging(get_string('studentsperpagereduced', 'grades'));
+
+ $a = new stdClass();
+ $a->originalstudentsperpage = $originalstudentsperpage;
+ $a->studentsperpage = $studentsperpage;
+ $a->maxinputvars = $maxinputvars;
+ debugging(get_string('studentsperpagereduced', 'grades', $a));
}
}
}
Oops, something went wrong.

0 comments on commit a740a0a

Please sign in to comment.