Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

"MDL-20125, added configurable setting to section_links block, credit…

…s to Jason Hardin"
  • Loading branch information...
commit 0cd77e569fa340460e73afd6bf4dbf37b831a7ad 1 parent 44d34e8
@dcai dcai authored
View
35 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) {
@@ -29,6 +29,11 @@ function get_content() {
global $CFG, $USER, $COURSE;
$highlight = 0;
+ if(isset($this->config)){
+ $config = $this->config;
+ } else{
+ $config = get_config('blocks/section_links');
+ }
if ($this->content !== NULL) {
return $this->content;
@@ -60,11 +65,21 @@ function get_content() {
$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)) {
@@ -112,6 +127,16 @@ function get_content() {
$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');
+ }
}
?>
View
73 blocks/section_links/config_instance.html
@@ -0,0 +1,73 @@
+<?php
+$numberofsections = array();
+for ($i = 1; $i < 53; $i++){
+ $numberofsections[$i] = $i;
+}
+
+$increments = array();
+
+for ($i = 1; $i < 11; $i++){
+ $increments[$i] = $i;
+}
+
+if(isset($this->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);
+}
+
+?>
+<table cellpadding="9" cellspacing="0">
+<?php
+for($i = 1; $i < 3; $i++){
+?>
+ <tr valign="top">
+ <td align="right">
+ <?php print_string('numsections'.$i, 'block_section_links'); ?>:
+ </td>
+ <td>
+ <?php choose_from_menu($numberofsections, 'numsections'.$i, $selected[$i][0]); ?>
+ </td>
+ <td>
+ <?php print_string('numsectionsdesc'.$i, 'block_section_links'); ?>
+ </td>
+ </tr>
+ <tr valign="top">
+ <td align="right">
+ <?php print_string('incby'.$i, 'block_section_links'); ?>:
+ </td>
+ <td>
+ <?php choose_from_menu($increments, 'incby'.$i, $selected[$i][1]); ?>
+ </td>
+ <td>
+ <?php print_string('incbydesc'.$i, 'block_section_links'); ?>
+ </td>
+ </tr>
+<?php }
+?>
+<tr>
+ <td colspan="3" align="center">
+ <input type="hidden" name="sesskey" value="<?php echo sesskey();?>">
+ <input type="submit" value="<?php print_string('savechanges') ?>" />
+ </td>
+</tr>
+</table>
View
33 blocks/section_links/settings.php
@@ -0,0 +1,33 @@
+<?php
+$configs = array();
+
+$numberofsections = array();
+
+for ($i = 1; $i < 53; $i++){
+ $numberofsections[$i] = $i;
+}
+$increments = array();
+
+for ($i = 1; $i < 11; $i++){
+ $increments[$i] = $i;
+}
+
+$selected = array(1 => 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);
+}
+
+?>
View
8 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';
Please sign in to comment.
Something went wrong with that request. Please try again.