From 3bd217aaa4099f157e14032065be2060431d9e2f Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Fri, 14 Oct 2011 13:55:54 +0200 Subject: [PATCH] Grading manager's set_active_method() returns bool now --- grade/grading/lib.php | 7 +++++++ grade/grading/simpletest/testlib.php | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/grade/grading/lib.php b/grade/grading/lib.php index aed7f8530d7..58a2f6f86b8 100644 --- a/grade/grading/lib.php +++ b/grade/grading/lib.php @@ -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; } /** diff --git a/grade/grading/simpletest/testlib.php b/grade/grading/simpletest/testlib.php index 379599f4620..1bb2a067dbf 100644 --- a/grade/grading/simpletest/testlib.php +++ b/grade/grading/simpletest/testlib.php @@ -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());