"MDL-20125, added configurable setting to section_links block, credits to Jason Hardin"
This commit is contained in:
@@ -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 @@ class block_section_links extends block_base {
|
||||
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 @@ 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)) {
|
||||
@@ -112,6 +127,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');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Executable
+73
@@ -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>
|
||||
Executable
+33
@@ -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);
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -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';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user