Grading manager's set_active_method() returns bool now

This commit is contained in:
David Mudrak
2011-10-16 19:40:46 +02:00
parent 6b5b05dc3b
commit 3bd217aaa4
2 changed files with 11 additions and 1 deletions
+7
View File
@@ -238,6 +238,7 @@ class grading_manager {
* Sets the currently active grading method in the gradable area
*
* @param string $method the method name, eg 'rubric' (must be available)
* @return bool true if the method changed or was just set, false otherwise
*/
public function set_active_method($method) {
global $DB;
@@ -266,6 +267,8 @@ class grading_manager {
'*', IGNORE_MISSING);
}
$methodchanged = false;
if ($this->areacache === false) {
// no area record yet, create one with the active method set
$area = array(
@@ -274,15 +277,19 @@ class grading_manager {
'areaname' => $this->area,
'activemethod' => $method);
$DB->insert_record('grading_areas', $area);
$methodchanged = true;
} else {
// update the existing record if needed
if ($this->areacache->activemethod !== $method) {
$DB->set_field('grading_areas', 'activemethod', $method, array('id' => $this->areacache->id));
$methodchanged = true;
}
}
$this->areacache = null;
return $methodchanged;
}
/**
+4 -1
View File
@@ -110,9 +110,12 @@ class grading_manager_test extends UnitTestCase {
$this->assertNull($gradingman->get_active_method());
// creates area implicitly and sets active method
$gradingman->set_active_method('rubric');
$this->assertTrue($gradingman->set_active_method('rubric'));
$this->assertEqual('rubric', $gradingman->get_active_method());
// repeat setting of already set active method
$this->assertFalse($gradingman->set_active_method('rubric'));
// switch the manager to another area
$gradingman->set_area($areaname2);
$this->assertNull($gradingman->get_active_method());