MDL-30865 Workshop method aggregate_grading_grades_process() accepts explicit aggregation timestamp

This commit is contained in:
David Mudrak
2012-01-04 02:20:06 +01:00
committed by Eloy Lafuente (stronk7)
parent 5d25ef18c5
commit a1373126eb
2 changed files with 16 additions and 9 deletions
+8 -3
View File
@@ -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);
}
}
+8 -6
View File
@@ -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() {