From: tjhunt Date: Mon, 13 Apr 2009 06:54:34 +0000 (+0000) Subject: filters: MDL-7336 rename get_active_filters -> filter_get_active_in_context and impro... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=1f8c468dbdc11b1b3374246eaa5c3ae76705c241;p=moodle.git filters: MDL-7336 rename get_active_filters -> filter_get_active_in_context and improve auto-sorting. --- diff --git a/lib/filterlib.php b/lib/filterlib.php index 19aef380a3..def5d45106 100644 --- a/lib/filterlib.php +++ b/lib/filterlib.php @@ -167,8 +167,9 @@ function filter_get_all_installed() { * @param integer $sortorder (optional) a position in the sortorder to place this filter. * If not given defaults to: * No change in order if we are updating an exsiting record, and not changing to or from TEXTFILTER_DISABLED. - * Just after the last currently active filter for a change to TEXTFILTER_ON or TEXTFILTER_OFF - * Just after the very last filter for a change to TEXTFILTER_DISABLED + * Just after the last currently active filter when adding an unknown filter + * in state TEXTFILTER_ON or TEXTFILTER_OFF, or enabling/diabling an exsisting filter. + * Just after the very last filter when adding an unknown filter in state TEXTFILTER_DISABLED */ function filter_set_global_state($filter, $state, $sortorder = false) { global $DB; @@ -203,7 +204,7 @@ function filter_set_global_state($filter, $state, $sortorder = false) { // Automatic sort order. if ($sortorder === false) { - if ($state == TEXTFILTER_DISABLED) { + if ($state == TEXTFILTER_DISABLED && $insert) { $prevmaxsortorder = $DB->get_field('filter_active', 'MAX(sortorder)', array()); } else { $prevmaxsortorder = $DB->get_field_select('filter_active', 'MAX(sortorder)', 'active <> ?', array(TEXTFILTER_DISABLED)); @@ -341,7 +342,7 @@ function filter_get_local_config($filter, $contextid) { * empty array. So, an example return value for this function might be * array('filter/tex' => array(), 'mod/glossary' => array('glossaryid', 123)) */ -function get_active_filters($context) { +function filter_get_active_in_context($context) { global $DB; $contextids = str_replace('/', ',', trim($context->path, '/')); diff --git a/lib/simpletest/testfilterconfig.php b/lib/simpletest/testfilterconfig.php index 1237fbb397..5f16665a66 100644 --- a/lib/simpletest/testfilterconfig.php +++ b/lib/simpletest/testfilterconfig.php @@ -215,7 +215,7 @@ class filter_active_global_test extends UnitTestCaseUsingDatabase { // Exercise SUT. filter_set_global_state('filter/1', TEXTFILTER_DISABLED); // Validate. - $this->assert_global_sort_order(array('filter/2', 'filter/3', 'filter/1')); + $this->assert_global_sort_order(array('filter/2', 'filter/1', 'filter/3')); } } @@ -342,7 +342,7 @@ class filter_config_test extends UnitTestCaseUsingDatabase { } } -class get_active_filters_test extends UnitTestCaseUsingDatabase { +class filter_get_active_in_context_test extends UnitTestCaseUsingDatabase { private $syscontext; private $childcontext; private $childcontext2; @@ -387,7 +387,7 @@ class get_active_filters_test extends UnitTestCaseUsingDatabase { // Setup fixture. filter_set_global_state('filter/name', TEXTFILTER_ON); // Exercise SUT. - $filters = get_active_filters($this->syscontext); + $filters = filter_get_active_in_context($this->syscontext); // Validate. $this->assert_filter_list(array('filter/name'), $filters); // Check no config returned correctly. @@ -398,7 +398,7 @@ class get_active_filters_test extends UnitTestCaseUsingDatabase { // Setup fixture. filter_set_global_state('filter/name', TEXTFILTER_OFF); // Exercise SUT. - $filters = get_active_filters($this->childcontext2); + $filters = filter_get_active_in_context($this->childcontext2); // Validate. $this->assert_filter_list(array(), $filters); } @@ -408,7 +408,7 @@ class get_active_filters_test extends UnitTestCaseUsingDatabase { filter_set_global_state('filter/name', TEXTFILTER_OFF); filter_set_local_state('filter/name', $this->childcontext->id, TEXTFILTER_ON); // Exercise SUT. - $filters = get_active_filters($this->childcontext2); + $filters = filter_get_active_in_context($this->childcontext2); // Validate. $this->assert_filter_list(array('filter/name'), $filters); } @@ -418,7 +418,7 @@ class get_active_filters_test extends UnitTestCaseUsingDatabase { filter_set_global_state('filter/name', TEXTFILTER_ON); filter_set_local_state('filter/name', $this->childcontext->id, TEXTFILTER_OFF); // Exercise SUT. - $filters = get_active_filters($this->childcontext2); + $filters = filter_get_active_in_context($this->childcontext2); // Validate. $this->assert_filter_list(array(), $filters); } @@ -428,7 +428,7 @@ class get_active_filters_test extends UnitTestCaseUsingDatabase { filter_set_global_state('filter/name', TEXTFILTER_DISABLED); filter_set_local_state('filter/name', $this->childcontext->id, TEXTFILTER_ON); // Exercise SUT. - $filters = get_active_filters($this->syscontext); + $filters = filter_get_active_in_context($this->syscontext); // Validate. $this->assert_filter_list(array(), $filters); } @@ -438,7 +438,7 @@ class get_active_filters_test extends UnitTestCaseUsingDatabase { filter_set_global_state('filter/name', TEXTFILTER_ON); filter_set_local_config('filter/name', $this->childcontext->id, 'settingname', 'A value'); // Exercise SUT. - $filters = get_active_filters($this->childcontext); + $filters = filter_get_active_in_context($this->childcontext); // Validate. $this->assertEqual(array('settingname' => 'A value'), $filters['filter/name']); } @@ -449,7 +449,7 @@ class get_active_filters_test extends UnitTestCaseUsingDatabase { filter_set_local_config('filter/name', $this->childcontext->id, 'settingname', 'A value'); filter_set_local_config('filter/name', $this->childcontext->id, 'anothersettingname', 'Another value'); // Exercise SUT. - $filters = get_active_filters($this->childcontext); + $filters = filter_get_active_in_context($this->childcontext); // Validate. $this->assertEqual(array('settingname' => 'A value', 'anothersettingname' => 'Another value'), $filters['filter/name']); } @@ -460,7 +460,7 @@ class get_active_filters_test extends UnitTestCaseUsingDatabase { filter_set_local_config('filter/name', $this->childcontext->id, 'settingname', 'A value'); filter_set_local_config('filter/name', $this->childcontext2->id, 'anothersettingname', 'Another value'); // Exercise SUT. - $filters = get_active_filters($this->childcontext2); + $filters = filter_get_active_in_context($this->childcontext2); // Validate. $this->assertEqual(array('anothersettingname' => 'Another value'), $filters['filter/name']); } @@ -471,7 +471,7 @@ class get_active_filters_test extends UnitTestCaseUsingDatabase { filter_set_local_config('filter/name', $this->childcontext->id, 'settingname', 'A value'); filter_set_local_config('filter/other', $this->childcontext->id, 'anothersettingname', 'Another value'); // Exercise SUT. - $filters = get_active_filters($this->childcontext); + $filters = filter_get_active_in_context($this->childcontext); // Validate. $this->assertEqual(array('settingname' => 'A value'), $filters['filter/name']); }