]> git.mjollnir.org Git - moodle.git/commitdiff
"MDL-20125, added configurable setting to section_links block, credits to Jason Hardi...
authorDongsheng Cai <unoter@gmail.com>
Fri, 4 Dec 2009 09:01:50 +0000 (09:01 +0000)
committerDongsheng Cai <unoter@gmail.com>
Fri, 4 Dec 2009 09:01:50 +0000 (09:01 +0000)
blocks/section_links/block_section_links.php
blocks/section_links/config_instance.html [new file with mode: 0755]
blocks/section_links/settings.php [new file with mode: 0755]
lang/en_utf8/block_section_links.php

index 391091392be4a74e4365b115c55268b9d520556f..4ce0aeabba2633d368d539479cb5d884a57654a1 100644 (file)
@@ -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 (executable)
index 0000000..069e22e
--- /dev/null
@@ -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>
diff --git a/blocks/section_links/settings.php b/blocks/section_links/settings.php
new file mode 100755 (executable)
index 0000000..9b0d1da
--- /dev/null
@@ -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);
+}
+
+?>
index 575348789fe852d29478414e386ab2222566f00f..3770d2c83719ddb5f80bb3bba1a738ac55fa172c 100644 (file)
@@ -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';