MDL-47893 gradebook: Progress bar and continues for grade saving.

When you save a grade you are notified of how many grades have
been updated and any warnings.
This commit is contained in:
Zachary Durber 2014-10-31 15:39:34 +08:00
parent 1d9155872f
commit 50e30bd4e3
6 changed files with 50 additions and 16 deletions

View file

@ -333,6 +333,9 @@ class grade extends tablelike implements selectable_items, filterable_items {
} }
foreach ($data as $varname => $value) { foreach ($data as $varname => $value) {
if (preg_match('/override_(\d+)_(\d+)/', $varname, $matches)) {
$data->$matches[0] = '1';
}
if (!preg_match('/^finalgrade_(\d+)_/', $varname, $matches)) { if (!preg_match('/^finalgrade_(\d+)_/', $varname, $matches)) {
continue; continue;
} }

View file

@ -255,7 +255,17 @@ abstract class screen {
$fields = $this->definition(); $fields = $this->definition();
// Avoiding execution timeouts when updating
// a large amount of grades.
$progress = 0;
$progressbar = new \core\progress\display_if_slow();
$progressbar->start_html();
$progressbar->start_progress(get_string('savegrades', 'gradereport_singleview'), count((array) $data) - 1);
$changecount = array();
foreach ($data as $varname => $throw) { foreach ($data as $varname => $throw) {
$progressbar->progress($progress);
$progress++;
if (preg_match("/(\w+)_(\d+)_(\d+)/", $varname, $matches)) { if (preg_match("/(\w+)_(\d+)_(\d+)/", $varname, $matches)) {
$itemid = $matches[2]; $itemid = $matches[2];
$userid = $matches[3]; $userid = $matches[3];
@ -270,6 +280,9 @@ abstract class screen {
if (preg_match('/^old[oe]{1}/', $varname)) { if (preg_match('/^old[oe]{1}/', $varname)) {
$elementname = preg_replace('/^old/', '', $varname); $elementname = preg_replace('/^old/', '', $varname);
if (!isset($data->$elementname)) { if (!isset($data->$elementname)) {
// Decrease the progress because we've increased the
// size of the array we are iterating through.
$progress--;
$data->$elementname = false; $data->$elementname = false;
} }
} }
@ -309,6 +322,9 @@ abstract class screen {
if (!empty($msg)) { if (!empty($msg)) {
$warnings[] = $msg; $warnings[] = $msg;
} }
if (preg_match('/_(\d+)_(\d+)/', $varname, $matchelement)) {
$changecount[$matchelement[0]] = 1;
}
} }
// Some post-processing. // Some post-processing.
@ -316,8 +332,11 @@ abstract class screen {
$eventdata->warnings = $warnings; $eventdata->warnings = $warnings;
$eventdata->post_data = $data; $eventdata->post_data = $data;
$eventdata->instance = $this; $eventdata->instance = $this;
$eventdata->changecount = $changecount;
return $eventdata->warnings; $progressbar->end_html();
return $eventdata;
} }
/** /**

View file

@ -337,7 +337,6 @@ class user extends tablelike implements selectable_items {
if ($bulk->is_applied($data)) { if ($bulk->is_applied($data)) {
$filter = $bulk->get_type($data); $filter = $bulk->get_type($data);
$insertvalue = $bulk->get_insert_value($data); $insertvalue = $bulk->get_insert_value($data);
// Appropriately massage data that may not exist.
$userid = $this->item->id; $userid = $this->item->id;
foreach ($this->items as $gradeitemid => $gradeitem) { foreach ($this->items as $gradeitemid => $gradeitem) {
@ -357,6 +356,9 @@ class user extends tablelike implements selectable_items {
} }
foreach ($data as $varname => $value) { foreach ($data as $varname => $value) {
if (preg_match('/override_(\d+)_(\d+)/', $varname, $matches)) {
$data->$matches[0] = '1';
}
if (!preg_match('/^finalgrade_(\d+)_/', $varname, $matches)) { if (!preg_match('/^finalgrade_(\d+)_/', $varname, $matches)) {
continue; continue;
} }
@ -376,7 +378,6 @@ class user extends tablelike implements selectable_items {
} }
} }
} }
return parent::process($data); return parent::process($data);
} }
} }

View file

@ -48,7 +48,6 @@ if (!$course = $DB->get_record('course', $courseparams)) {
} }
require_login($course); require_login($course);
$PAGE->set_pagelayout('report');
if (!in_array($itemtype, gradereport_singleview::valid_screens())) { if (!in_array($itemtype, gradereport_singleview::valid_screens())) {
print_error('notvalid', 'gradereport_singleview', '', $itemtype); print_error('notvalid', 'gradereport_singleview', '', $itemtype);
@ -99,15 +98,25 @@ $pageparams = array(
$currentpage = new moodle_url('/grade/report/singleview/index.php', $pageparams); $currentpage = new moodle_url('/grade/report/singleview/index.php', $pageparams);
if ($data = data_submitted()) { if ($data = data_submitted()) {
require_sesskey(); // Must have a sesskey for all actions. $PAGE->set_pagelayout('redirect');
$warnings = $report->process_data($data); $PAGE->set_title(get_string('savegrades', 'gradereport_singleview'));
echo $OUTPUT->header();
if (empty($warnings)) { require_sesskey(); // Must have a sesskey for all actions.
redirect($currentpage); $result = $report->process_data($data);
die();
if (!empty($result->warnings)) {
foreach ($result->warnings as $warning) {
echo $OUTPUT->notification($warning);
}
} }
echo $OUTPUT->notification(get_string('savegradessuccess', 'gradereport_singleview', count ((array)$result->changecount)));
echo $OUTPUT->continue_button($currentpage);
echo $OUTPUT->footer();
die();
} }
$PAGE->set_pagelayout('report');
print_grade_page_head($course->id, 'report', 'singleview', $reportname); print_grade_page_head($course->id, 'report', 'singleview', $reportname);
$graderrightnav = $graderleftnav = null; $graderrightnav = $graderleftnav = null;
@ -157,12 +166,6 @@ if ($report->screen->display_group_selector()) {
echo $report->group_selector; echo $report->group_selector;
} }
if (!empty($warnings)) {
foreach ($warnings as $warning) {
echo $OUTPUT->notification($warning);
}
}
echo $report->output(); echo $report->output();
if ($report->screen->supports_paging()) { if ($report->screen->supports_paging()) {

View file

@ -45,6 +45,8 @@ $string['overrideall'] = 'Override all grades';
$string['overridefor'] = 'Override for {$a}'; $string['overridefor'] = 'Override for {$a}';
$string['overridenone'] = 'Override no grades'; $string['overridenone'] = 'Override no grades';
$string['pluginname'] = 'Single view'; $string['pluginname'] = 'Single view';
$string['savegrades'] = 'Saving grades';
$string['savegradessuccess'] = 'Grades were set for {$a} items';
$string['singleview:view'] = 'View report'; $string['singleview:view'] = 'View report';
$string['summarygrade'] = 'A table of users, with columns for range, grade, feedback, and whether to override or exclude a particular grade.'; $string['summarygrade'] = 'A table of users, with columns for range, grade, feedback, and whether to override or exclude a particular grade.';
$string['summaryuser'] = 'A table of grade items, with columns for grade category, range, grade, feedback, and whether to override or exclude a particular grade.'; $string['summaryuser'] = 'A table of grade items, with columns for grade category, range, grade, feedback, and whether to override or exclude a particular grade.';

View file

@ -58,7 +58,9 @@ Feature: We can use Single view
| Feedback for Test assignment one | test data | | Feedback for Test assignment one | test data |
And I click on "Exclude for Test assignment four" "checkbox" And I click on "Exclude for Test assignment four" "checkbox"
And I press "Update" And I press "Update"
Then the following should exist in the "generaltable" table: Then I should see "Grades were set for 2 items"
And I press "Continue"
And the following should exist in the "generaltable" table:
| Test assignment four | | Test assignment four |
| excluded | | excluded |
And the following should exist in the "generaltable" table: And the following should exist in the "generaltable" table:
@ -71,6 +73,8 @@ Feature: We can use Single view
| Feedback for james (Student) 1 | test data2 | | Feedback for james (Student) 1 | test data2 |
And I click on "Exclude for holly (Student) 2" "checkbox" And I click on "Exclude for holly (Student) 2" "checkbox"
And I press "Update" And I press "Update"
Then I should see "Grades were set for 2 items"
And I press "Continue"
And the following should exist in the "generaltable" table: And the following should exist in the "generaltable" table:
| Test assignment three | | Test assignment three |
| 12.05 | | 12.05 |
@ -79,6 +83,8 @@ Feature: We can use Single view
And I click on "new grade item 1" "option" And I click on "new grade item 1" "option"
And I click on "Very good" "option" And I click on "Very good" "option"
And I press "Update" And I press "Update"
Then I should see "Grades were set for 1 items"
And I press "Continue"
And the following should exist in the "generaltable" table: And the following should exist in the "generaltable" table:
| Grade for james (Student) 1 | "Very good" | | Grade for james (Student) 1 | "Very good" |