Skip to content

Commit

Permalink
MDL-25357 Allow maximum number of sections to be set by the admin. Al…
Browse files Browse the repository at this point in the history
…so allow 0 sections at an choice.

Also fix one bad <br/> in another lang string.
  • Loading branch information
timhunt committed Jul 4, 2011
1 parent 81f8e0f commit c141b05
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
12 changes: 6 additions & 6 deletions admin/settings/courses.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
$formcourseformats[$courseformat] = get_string('pluginname', "format_$courseformat");
}
$temp->add(new admin_setting_configselect('moodlecourse/format', get_string('format'), get_string('coursehelpformat'), 'weeks',$formcourseformats));
for ($i=1; $i<=52; $i++) {
$sectionmenu[$i] = "$i";
}
$temp->add(new admin_setting_configselect('moodlecourse/numsections', get_string('numberweeks'), get_string('coursehelpnumberweeks'), 10,$sectionmenu));

$temp->add(new admin_setting_configtext('moodlecourse/maxsections', get_string('maxnumberweeks'), get_string('maxnumberweeks_desc'), 52));

$temp->add(new admin_settings_num_course_sections('moodlecourse/numsections', get_string('numberweeks'), get_string('coursehelpnumberweeks'), 10));

$choices = array();
$choices['0'] = get_string('hiddensectionscollapsed');
$choices['1'] = get_string('hiddensectionsinvisible');
Expand All @@ -33,15 +34,14 @@
$temp->add(new admin_setting_configselect('moodlecourse/newsitems', get_string('newsitemsnumber'), get_string('coursehelpnewsitemsnumber'), 5,$options));
$temp->add(new admin_setting_configselect('moodlecourse/showgrades', get_string('showgrades'), get_string('coursehelpshowgrades'), 1,array(0 => get_string('no'), 1 => get_string('yes'))));
$temp->add(new admin_setting_configselect('moodlecourse/showreports', get_string('showreports'), '', 0,array(0 => get_string('no'), 1 => get_string('yes'))));

if (isset($CFG->maxbytes)) {
$choices = get_max_upload_sizes($CFG->maxbytes);
} else {
$choices = get_max_upload_sizes();
}

$temp->add(new admin_setting_configselect('moodlecourse/maxbytes', get_string('maximumupload'), get_string('coursehelpmaximumupload'), key($choices), $choices));


if (!empty($CFG->legacyfilesinnewcourses)) {
$choices = array('0'=>get_string('no'), '2'=>get_string('yes'));
$temp->add(new admin_setting_configselect('moodlecourse/legacyfiles', get_string('courselegacyfiles'), get_string('courselegacyfiles_help'), key($choices), $choices));
Expand Down
4 changes: 2 additions & 2 deletions course/edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ function definition() {
$mform->addHelpButton('format', 'format');
$mform->setDefault('format', $courseconfig->format);

for ($i=1; $i<=52; $i++) {
$sectionmenu[$i] = "$i";
for ($i = 0; $i <= $courseconfig->maxsections; $i++) {
$sectionmenu[$i] = "$i";
}
$mform->addElement('select', 'numsections', get_string('numberweeks'), $sectionmenu);
$mform->setDefault('numsections', $courseconfig->numsections);
Expand Down
4 changes: 3 additions & 1 deletion lang/en/moodle.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@
$string['coursehelpformat'] = 'The course main page will be displayed in this format.';
$string['coursehelphiddensections'] = 'How the hidden sections in the course are displayed to students.';
$string['coursehelpmaximumupload'] = 'Define the largest size of file that can be uploaded in this course, limited by the site-wide setting.';
$string['coursehelpnewsitemsnumber'] = 'Number of recent items appearing on the course home page, in a news box down the right-hand side <br/>(0 means the news box won\'t appear).';
$string['coursehelpnewsitemsnumber'] = 'Number of recent items appearing on the course home page, in a news box down the right-hand side (0 means the news box won\'t appear).';
$string['coursehelpnumberweeks'] = 'Number of weeks/topics displayed on the course main page.';
$string['coursehelpshowgrades'] = 'Enable the display of the gradebook. It does not prevent grades from being displayed within the individual activities.';
$string['coursehidden'] = 'This course is currently unavailable to students';
Expand Down Expand Up @@ -981,6 +981,8 @@
$string['maximumshort'] = 'Max';
$string['maximumupload'] = 'Maximum upload size';
$string['maximumupload_help'] = 'This setting determines the largest size of file that can be uploaded to the course, limited by the site-wide setting set by an administrator. Activity modules also include a maximum upload size setting for further restricting the file size.';
$string['maxnumberweeks'] = 'Maximum for number of weeks/topics';
$string['maxnumberweeks_desc'] = 'This controls the maximum options that appears in the "Number of weeks/topics" setting for courses.';
$string['maxsize'] = 'Max size: {$a}';
$string['maxfilesize'] = 'Maximum size for new files: {$a}';
$string['maxnumcoursesincombo'] = 'Browse <a href="{$a->link}">{$a->numberofcourses} courses</a>.';
Expand Down
26 changes: 26 additions & 0 deletions lib/adminlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3591,6 +3591,32 @@ public function load_choices() {
}


/**
* admin_setting_configselect for the default number of sections in a course,
* simply so we can lazy-load the choices.
*
* @copyright 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_settings_num_course_sections extends admin_setting_configselect {
public function __construct($name, $visiblename, $description, $defaultsetting) {
parent::__construct($name, $visiblename, $description, $defaultsetting, array());
}

/** Lazy-load the available choices for the select box */
public function load_choices() {
$max = get_config('moodlecourse', 'maxsections');
if (empty($max)) {
$max = 52;
}
for ($i = 0; $i <= $max; $i++) {
$this->choices[$i] = "$i";
}
return true;
}
}


/**
* Course category selection
*
Expand Down

0 comments on commit c141b05

Please sign in to comment.