Grading manager's set_active_method() returns bool now
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user