// Initialise the grader report object
$report = new grade_report_grader($courseid, $gpr, $context, $page, $sortitemid);
+
+/// processing posted grades & feedback here
+if ($data = data_submitted() and confirm_sesskey() and has_capability('moodle/grade:edit', $context)) {
+ $warnings = $report->process_data($data);
+} else {
+ $warings = array();
+}
+
+
// Override perpage if set in URL
if ($perpageurl) {
$report->user_prefs['studentsperpage'] = $perpageurl;
}
+// final grades MUST be loaded after the processing
$report->load_users();
-
$numusers = $report->get_numusers();
$report->load_final_grades();
echo '<div class="clearer"></div>';
echo $report->get_toggles_html();
-/// processing posted grades & feedback here
-if ($data = data_submitted() and confirm_sesskey()) {
- $report->process_data($data);
+//show warnings if any
+foreach($warnings as $warning) {
+ notify($warning);
}
$studentsperpage = $report->get_pref('studentsperpage');
/**
* Processes the data sent by the form (grades and feedbacks).
- * @var array $data
- * @return bool Success or Failure (array of errors).
+ * Caller is reposible for all access control checks
+ * @param array $data form submission (with magic quotes)
+ * @return array empty array if success, array of warnings if something fails.
*/
function process_data($data) {
-
- if (!has_capability('moodle/grade:edit', $this->context)) {
- return false;
- }
+ $warnings = array();
// always initialize all arrays
$queue = array();
$errorstr = 'morethanmax';
}
if ($errorstr) {
- $user = get_record('user', 'id', $userid,'','','','','id, firstname, lastname');
+ $user = get_record('user', 'id', $userid, '', '', '', '', 'id, firstname, lastname');
$gradestr = new object();
$gradestr->username = fullname($user);
$gradestr->itemname = $grade_item->get_name();
- notify(get_string($errorstr, 'grades', $gradestr));
+ $warnings[] = get_string($errorstr, 'grades', $gradestr);
}
} else if ($data_type == 'feedback') {
$grade_item->update_final_grade($userid, $finalgrade, 'gradebook', $feedback, FORMAT_MOODLE);
}
- return true;
+ return $warnings;
}