From a1373126eb3dc8332d371dbef3b89b37038e2723 Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Wed, 21 Dec 2011 20:41:37 +0100 Subject: [PATCH] MDL-30865 Workshop method aggregate_grading_grades_process() accepts explicit aggregation timestamp --- mod/workshop/locallib.php | 11 ++++++++--- mod/workshop/simpletest/testlocallib.php | 14 ++++++++------ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/mod/workshop/locallib.php b/mod/workshop/locallib.php index 923b83ca7f0..91e11d8ce9d 100644 --- a/mod/workshop/locallib.php +++ b/mod/workshop/locallib.php @@ -2018,9 +2018,10 @@ class workshop { * was overridden by a teacher, the gradinggradeover value is returned and the rest of grades are ignored. * * @param array $assessments of stdclass(->reviewerid ->gradinggrade ->gradinggradeover ->aggregationid ->aggregatedgrade) + * @param null|int $timegraded explicit timestamp of the aggregation, defaults to the current time * @return void */ - protected function aggregate_grading_grades_process(array $assessments) { + protected function aggregate_grading_grades_process(array $assessments, $timegraded = null) { global $DB; $reviewerid = null; // the id of the reviewer being processed @@ -2030,6 +2031,10 @@ class workshop { $sumgrades = 0; $count = 0; + if (is_null($timegraded)) { + $timegraded = time(); + } + foreach ($assessments as $assessment) { if (is_null($reviewerid)) { // the id is the same in all records, fetch it during the first loop cycle @@ -2066,13 +2071,13 @@ class workshop { $record->workshopid = $this->id; $record->userid = $reviewerid; $record->gradinggrade = $finalgrade; - $record->timegraded = time(); + $record->timegraded = $timegraded; $DB->insert_record('workshop_aggregations', $record); } else { $record = new stdclass(); $record->id = $agid; $record->gradinggrade = $finalgrade; - $record->timegraded = time(); + $record->timegraded = $timegraded; $DB->update_record('workshop_aggregations', $record); } } diff --git a/mod/workshop/simpletest/testlocallib.php b/mod/workshop/simpletest/testlocallib.php index 057422fed7a..4aa27667502 100644 --- a/mod/workshop/simpletest/testlocallib.php +++ b/mod/workshop/simpletest/testlocallib.php @@ -47,8 +47,8 @@ class testable_workshop extends workshop { parent::aggregate_submission_grades_process($assessments); } - public function aggregate_grading_grades_process(array $assessments) { - parent::aggregate_grading_grades_process($assessments); + public function aggregate_grading_grades_process(array $assessments, $timegraded = null) { + parent::aggregate_grading_grades_process($assessments, $timegraded); } } @@ -214,14 +214,15 @@ class workshop_internal_api_test extends UnitTestCase { $batch = array(); $batch[] = (object)array('reviewerid'=>3, 'gradinggrade'=>82.87670, 'gradinggradeover'=>null, 'aggregationid'=>null, 'aggregatedgrade'=>null); // expectation + $now = time(); $expected = new stdclass(); $expected->workshopid = $this->workshop->id; $expected->userid = 3; $expected->gradinggrade = 82.87670; - $expected->timegraded = time(); // warning - this is a weak point as the time may actually change + $expected->timegraded = $now; $DB->expectOnce('insert_record', array('workshop_aggregations', $expected)); // excersise SUT - $this->workshop->aggregate_grading_grades_process($batch); + $this->workshop->aggregate_grading_grades_process($batch, $now); } public function test_aggregate_grading_grades_process_single_grade_update() { @@ -265,14 +266,15 @@ class workshop_internal_api_test extends UnitTestCase { $batch[] = (object)array('reviewerid'=>5, 'gradinggrade'=>87.34311, 'gradinggradeover'=>null, 'aggregationid'=>null, 'aggregatedgrade'=>null); $batch[] = (object)array('reviewerid'=>5, 'gradinggrade'=>51.12000, 'gradinggradeover'=>null, 'aggregationid'=>null, 'aggregatedgrade'=>null); // expectation + $now = time(); $expected = new stdclass(); $expected->workshopid = $this->workshop->id; $expected->userid = 5; $expected->gradinggrade = 79.3066; - $expected->timegraded = time(); // warning - this is a weak point as the time may actually change + $expected->timegraded = $now; $DB->expectOnce('insert_record', array('workshop_aggregations', $expected)); // excersise SUT - $this->workshop->aggregate_grading_grades_process($batch); + $this->workshop->aggregate_grading_grades_process($batch, $now); } public function test_aggregate_grading_grades_process_multiple_grades_update() {