Commit 74200b8a authored by Eloy Lafuente (stronk7)'s avatar Eloy Lafuente (stronk7)

Merge branch 'MDL-70245-master' of https://github.com/TomoTsuyuki/moodle

parents c2a21a28 745d4c2a
......@@ -89,6 +89,7 @@ $string['cachedef_user_favourite_course_content_items'] = 'User\'s starred items
$string['cachedef_user_group_groupings'] = 'User\'s groupings and groups per course';
$string['cachedef_user_course_content_items'] = 'User\'s content items (activities, resources and their subtypes) per course';
$string['cachedef_yuimodules'] = 'YUI Module definitions';
$string['cachedef_gradesetting'] = 'Course grade setting';
$string['cachelock_file_default'] = 'Default file locking';
$string['cachestores'] = 'Cache stores';
$string['canuselocalstore'] = 'Can use local store';
......
......@@ -476,4 +476,12 @@ $definitions = array(
'simplekeys' => true,
'simpledata' => false,
],
// Cache the grade setting for faster retrieval.
'gradesetting' => [
'mode' => cache_store::MODE_REQUEST,
'simplekeys' => true,
'staticacceleration' => true,
'staticaccelerationsize' => 100
],
);
......@@ -676,16 +676,18 @@ function grade_get_grades($courseid, $itemtype, $itemmodule, $iteminstance, $use
function grade_get_setting($courseid, $name, $default=null, $resetcache=false) {
global $DB;
static $cache = array();
$cache = cache::make('core', 'gradesetting');
$gradesetting = $cache->get($courseid) ?: array();
if ($resetcache or !array_key_exists($courseid, $cache)) {
$cache[$courseid] = array();
if ($resetcache or empty($gradesetting)) {
$gradesetting = array();
$cache->set($courseid, $gradesetting);
} else if (is_null($name)) {
return null;
} else if (array_key_exists($name, $cache[$courseid])) {
return $cache[$courseid][$name];
} else if (array_key_exists($name, $gradesetting)) {
return $gradesetting[$name];
}
if (!$data = $DB->get_record('grade_settings', array('courseid'=>$courseid, 'name'=>$name))) {
......@@ -698,7 +700,8 @@ function grade_get_setting($courseid, $name, $default=null, $resetcache=false) {
$result = $default;
}
$cache[$courseid][$name] = $result;
$gradesetting[$name] = $result;
$cache->set($courseid, $gradesetting);
return $result;
}
......
......@@ -275,6 +275,55 @@ class core_upgradelib_testcase extends advanced_testcase {
$this->assertEquals(20150627, $CFG->{'gradebook_calculations_freeze_' . $course2->id});
}
/**
* Test the upgrade function for final grade after setting grade max for category and grade item.
*/
public function test_upgrade_update_category_grademax_regrade_final_grades() {
global $DB;
$this->resetAfterTest();
$generator = $this->getDataGenerator();
$user = $generator->create_user();
// Create a new course.
$course = $generator->create_course();
// Set the course aggregation to weighted mean of grades.
$unitcategory = \grade_category::fetch_course_category($course->id);
$unitcategory->aggregation = GRADE_AGGREGATE_WEIGHTED_MEAN;
$unitcategory->update();
// Set grade max for category.
$gradecategoryitem = grade_item::fetch(array('iteminstance' => $unitcategory->id));
$gradecategoryitem->grademax = 50;
$gradecategoryitem->update();
// Make new grade item.
$gradeitem = new \grade_item($generator->create_grade_item([
'itemname' => 'Grade item',
'idnumber' => 'git1',
'courseid' => $course->id,
'grademin' => 0,
'grademax' => 50,
'aggregationcoef' => 100.0,
]));
// Set final grade.
$grade = $gradeitem->get_grade($user->id, true);
$grade->finalgrade = 20;
$grade->update();
$courseitem = \grade_item::fetch(['courseid' => $course->id, 'itemtype' => 'course']);
$gradeitem->force_regrading();
// Trigger regrade because the grade items needs to be updated.
grade_regrade_final_grades($course->id);
$coursegrade = new \grade_grade($courseitem->get_final($user->id), false);
$this->assertEquals(20, $coursegrade->finalgrade);
}
function test_upgrade_calculated_grade_items_regrade() {
global $DB, $CFG;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment