From 6c33f53253b6544d5453bc5f01e2c3b647f1e816 Mon Sep 17 00:00:00 2001 From: Dongsheng Cai Date: Fri, 4 Dec 2009 09:01:50 +0000 Subject: [PATCH] "MDL-20125, added configurable setting to section_links block, credits to Jason Hardin, merged from 1.9" --- blocks/section_links/block_section_links.php | 35 ++++++++-- blocks/section_links/config_instance.html | 73 ++++++++++++++++++++ blocks/section_links/settings.php | 33 +++++++++ lang/en_utf8/block_section_links.php | 8 +++ 4 files changed, 144 insertions(+), 5 deletions(-) create mode 100755 blocks/section_links/config_instance.html create mode 100755 blocks/section_links/settings.php diff --git a/blocks/section_links/block_section_links.php b/blocks/section_links/block_section_links.php index 391091392b..4ce0aeabba 100644 --- a/blocks/section_links/block_section_links.php +++ b/blocks/section_links/block_section_links.php @@ -4,7 +4,7 @@ class block_section_links extends block_base { function init() { $this->title = get_string('blockname', 'block_section_links'); - $this->version = 2007101509; + $this->version = 2007101511; } function instance_config($instance) { @@ -31,6 +31,11 @@ class block_section_links extends block_base { global $CFG, $USER, $DB; $highlight = 0; + if(isset($this->config)){ + $config = $this->config; + } else{ + $config = get_config('blocks/section_links'); + } if ($this->content !== NULL) { return $this->content; @@ -58,11 +63,21 @@ class block_section_links extends block_base { $sectionname = 'topic'; } $inc = 1; - if ($course->numsections > 22) { - $inc = 2; + + if(!empty($config->numsections1) and ($course->numsections > $config->numsections1)) { + $inc = $config->incby1; + } else { + if ($course->numsections > 22) { + $inc = 2; + } } - if ($course->numsections > 40) { - $inc = 5; + + if(!empty($config->numsections2) and ($course->numsections > $config->numsections2)) { + $inc = $config->incby1; + } else { + if ($course->numsections > 40) { + $inc = 5; + } } if (!empty($USER->id)) { @@ -110,6 +125,16 @@ class block_section_links extends block_base { $this->content->text = $text; return $this->content; } + /** + * Has instance config + * @return boolean + **/ + function instance_allow_config() { + return true; + } + function before_delete() { + delete_records('config_plugins', 'plugin', 'blocks/section_links'); + } } diff --git a/blocks/section_links/config_instance.html b/blocks/section_links/config_instance.html new file mode 100755 index 0000000000..069e22ee90 --- /dev/null +++ b/blocks/section_links/config_instance.html @@ -0,0 +1,73 @@ +config)){ + $config = $this->config; +} else{ + $config = get_config('blocks/section_links'); +} + +$selected = array(); +if (!empty($config->numsections1)) { + if (!empty($config->incby1)) { + $config->incby1 = 2; + } + $selected[1] = array($config->numsections1, $config->incby1); +} else { + $selected[1] = array(22, 2); +} + +if (!empty($config->numsections2)) { + if (!empty($config->incby1)) { + $config->incby1 = 5; + } + $selected[2] = array($config->numsections2, $config->incby2); +} else { + $selected[2] = array(40, 5); +} + +?> + + + + + + + + + + + + + + + + +
+ : + + + + +
+ : + + + + +
+ + +
diff --git a/blocks/section_links/settings.php b/blocks/section_links/settings.php new file mode 100755 index 0000000000..9b0d1dad26 --- /dev/null +++ b/blocks/section_links/settings.php @@ -0,0 +1,33 @@ + array(22,2), + 2 => array(40,5)); + +for($i = 1; $i < 3; $i++){ + $configs[] = new admin_setting_configselect('numsections'.$i, get_string('numsections'.$i, 'block_section_links'), + get_string('numsectionsdesc'.$i, 'block_section_links'), + $selected[$i][0], $numberofsections); + + $configs[] = new admin_setting_configselect('incby'.$i, get_string('incby'.$i, 'block_section_links'), + get_string('incbydesc'.$i, 'block_section_links'), + $selected[$i][1], $increments); +} + +foreach ($configs as $config) { + $config->plugin = 'blocks/section_links'; + $settings->add($config); +} + +?> diff --git a/lang/en_utf8/block_section_links.php b/lang/en_utf8/block_section_links.php index 575348789f..3770d2c837 100644 --- a/lang/en_utf8/block_section_links.php +++ b/lang/en_utf8/block_section_links.php @@ -3,8 +3,16 @@ $string['blockname'] = 'Section Links'; +$string['incby1'] = 'Increase by '; +$string['incbydesc1'] = 'This is the value the section is incremented each time a section link is displayed starting at 1.'; +$string['incby2'] = 'Alternative Increase by '; +$string['incbydesc2'] = 'This is the value the section is incremented each time a section link is displayed starting at 1.'; $string['jumptocurrenttopic'] = 'Jump to current topic'; $string['jumptocurrentweek'] = 'Jump to current week'; +$string['numsections1'] = 'Number of Sections'; +$string['numsectionsdesc1'] = 'Once the number of sections in the course reaches this number then the increment by value is used.'; +$string['numsections2'] = 'Alternative Number of Sections'; +$string['numsectionsdesc2'] = 'Once the number of sections in the course reaches this number then the Alternative increment by value is used.'; $string['topics'] = 'Topics'; $string['weeks'] = 'Weeks'; -- 2.39.5