MDL-12517 reverting the moving of data processign, returning array of warnings instead from function

This commit is contained in:
skodak
2007-12-18 13:52:15 +00:00
parent 44e65ebf62
commit 7293bdf4cb
2 changed files with 20 additions and 13 deletions
+13 -4
View File
@@ -121,13 +121,22 @@ if (!empty($target) && !empty($action) && confirm_sesskey()) {
// 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();
@@ -146,9 +155,9 @@ echo $report->group_selector;
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');
+7 -9
View File
@@ -146,14 +146,12 @@ class grade_report_grader extends grade_report {
/**
* 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();
@@ -209,11 +207,11 @@ class grade_report_grader extends grade_report {
$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') {
@@ -229,7 +227,7 @@ class grade_report_grader extends grade_report {
$grade_item->update_final_grade($userid, $finalgrade, 'gradebook', $feedback, FORMAT_MOODLE);
}
return true;
return $warnings;
}