Skip to content

Commit

Permalink
Merge branch 'MDL-47893-master' of git://github.com/zbdd/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
danpoltawski committed Nov 4, 2014
2 parents f820acf + 50e30bd commit f616195
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 15 deletions.
3 changes: 3 additions & 0 deletions grade/report/singleview/classes/local/screen/grade.php
Expand Up @@ -333,6 +333,9 @@ public function process($data) {
}

foreach ($data as $varname => $value) {
if (preg_match('/override_(\d+)_(\d+)/', $varname, $matches)) {
$data->$matches[0] = '1';
}
if (!preg_match('/^finalgrade_(\d+)_/', $varname, $matches)) {
continue;
}
Expand Down
21 changes: 20 additions & 1 deletion grade/report/singleview/classes/local/screen/screen.php
Expand Up @@ -255,7 +255,17 @@ public function process($data) {

$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) {
$progressbar->progress($progress);
$progress++;
if (preg_match("/(\w+)_(\d+)_(\d+)/", $varname, $matches)) {
$itemid = $matches[2];
$userid = $matches[3];
Expand All @@ -270,6 +280,9 @@ public function process($data) {
if (preg_match('/^old[oe]{1}/', $varname)) {
$elementname = preg_replace('/^old/', '', $varname);
if (!isset($data->$elementname)) {
// Decrease the progress because we've increased the
// size of the array we are iterating through.
$progress--;
$data->$elementname = false;
}
}
Expand Down Expand Up @@ -309,15 +322,21 @@ public function process($data) {
if (!empty($msg)) {
$warnings[] = $msg;
}
if (preg_match('/_(\d+)_(\d+)/', $varname, $matchelement)) {
$changecount[$matchelement[0]] = 1;
}
}

// Some post-processing.
$eventdata = new stdClass;
$eventdata->warnings = $warnings;
$eventdata->post_data = $data;
$eventdata->instance = $this;
$eventdata->changecount = $changecount;

$progressbar->end_html();

return $eventdata->warnings;
return $eventdata;
}

/**
Expand Down
5 changes: 3 additions & 2 deletions grade/report/singleview/classes/local/screen/user.php
Expand Up @@ -337,7 +337,6 @@ public function process($data) {
if ($bulk->is_applied($data)) {
$filter = $bulk->get_type($data);
$insertvalue = $bulk->get_insert_value($data);
// Appropriately massage data that may not exist.

$userid = $this->item->id;
foreach ($this->items as $gradeitemid => $gradeitem) {
Expand All @@ -357,6 +356,9 @@ public function process($data) {
}

foreach ($data as $varname => $value) {
if (preg_match('/override_(\d+)_(\d+)/', $varname, $matches)) {
$data->$matches[0] = '1';
}
if (!preg_match('/^finalgrade_(\d+)_/', $varname, $matches)) {
continue;
}
Expand All @@ -376,7 +378,6 @@ public function process($data) {
}
}
}

return parent::process($data);
}
}
25 changes: 14 additions & 11 deletions grade/report/singleview/index.php
Expand Up @@ -48,7 +48,6 @@
}

require_login($course);
$PAGE->set_pagelayout('report');

if (!in_array($itemtype, gradereport_singleview::valid_screens())) {
print_error('notvalid', 'gradereport_singleview', '', $itemtype);
Expand Down Expand Up @@ -99,15 +98,25 @@
$currentpage = new moodle_url('/grade/report/singleview/index.php', $pageparams);

if ($data = data_submitted()) {
$PAGE->set_pagelayout('redirect');
$PAGE->set_title(get_string('savegrades', 'gradereport_singleview'));
echo $OUTPUT->header();

require_sesskey(); // Must have a sesskey for all actions.
$warnings = $report->process_data($data);
$result = $report->process_data($data);

if (empty($warnings)) {
redirect($currentpage);
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);

$graderrightnav = $graderleftnav = null;
Expand Down Expand Up @@ -157,12 +166,6 @@
echo $report->group_selector;
}

if (!empty($warnings)) {
foreach ($warnings as $warning) {
echo $OUTPUT->notification($warning);
}
}

echo $report->output();

if ($report->screen->supports_paging()) {
Expand Down
2 changes: 2 additions & 0 deletions grade/report/singleview/lang/en/gradereport_singleview.php
Expand Up @@ -45,6 +45,8 @@
$string['overridefor'] = 'Override for {$a}';
$string['overridenone'] = 'Override no grades';
$string['pluginname'] = 'Single view';
$string['savegrades'] = 'Saving grades';
$string['savegradessuccess'] = 'Grades were set for {$a} items';
$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['summaryuser'] = 'A table of grade items, with columns for grade category, range, grade, feedback, and whether to override or exclude a particular grade.';
8 changes: 7 additions & 1 deletion grade/report/singleview/tests/behat/singleview.feature
Expand Up @@ -58,7 +58,9 @@ Feature: We can use Single view
| Feedback for Test assignment one | test data |
And I click on "Exclude for Test assignment four" "checkbox"
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 |
| excluded |
And the following should exist in the "generaltable" table:
Expand All @@ -71,6 +73,8 @@ Feature: We can use Single view
| Feedback for james (Student) 1 | test data2 |
And I click on "Exclude for holly (Student) 2" "checkbox"
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:
| Test assignment three |
| 12.05 |
Expand All @@ -79,6 +83,8 @@ Feature: We can use Single view
And I click on "new grade item 1" "option"
And I click on "Very good" "option"
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:
| Grade for james (Student) 1 | "Very good" |

Expand Down

0 comments on commit f616195

Please sign in to comment.