MDL-84291 format_weeks: max initial sections setting

This commit is contained in:
ferran
2025-06-03 12:58:52 +02:00
parent b3cb1eb18a
commit c960a9c5b8
7 changed files with 109 additions and 2 deletions
@@ -0,0 +1,8 @@
issueNumber: MDL-84291
notes:
format_weeks:
- message: >-
The weekly sections format now has a system setting called Maximum
initial number of weeks that replaced the old "Max sections" when
creating a new course
type: improved
+14
View File
@@ -46,5 +46,19 @@ function xmldb_format_weeks_upgrade($oldversion) {
// Automatically generated Moodle v5.0.0 release upgrade line.
// Put any upgrade step following this.
if ($oldversion < 2025052600) {
$config = get_config('format_weeks');
// Crerate the default maxinitialsections setting if is not set.
if (!isset($config->maxinitialsections)) {
// The system may have some maxsections defined. We will keep the same value.
$courseconfig = get_config('moodlecourse');
$max = (int) $courseconfig->maxsections;
$config->maxinitialsections = $max ?: 52;
set_config('maxinitialsections', $config->maxinitialsections, 'format_weeks');
}
upgrade_plugin_savepoint(true, 2025052600, 'format', 'weeks');
}
return true;
}
@@ -27,6 +27,8 @@ $string['automaticenddate'] = 'Calculate the end date from the number of section
$string['automaticenddate_help'] = 'If enabled, the end date for the course will be automatically calculated from the number of sections and the course start date.';
$string['currentsection'] = 'Current week';
$string['hidefromothers'] = 'Hide';
$string['maxinitialsections'] = 'Maximum number of weeks at course creation';
$string['maxinitialsections_help'] = 'Sets the maximum number of weeks that can be assigned to a course at the time of creation. This limit helps prevent accidental creation of overly long courses. It does not restrict teachers from adding more weeks later during course editing.';
$string['page-course-view-weeks'] = 'Any course main page in weekly sections format';
$string['page-course-view-weeks-x'] = 'Any course page in weekly sections format';
$string['pluginname'] = 'Weekly sections';
+2 -1
View File
@@ -319,7 +319,8 @@ class format_weeks extends core_courseformat\base {
// The "Number of sections" option is no longer available when editing course, instead teachers should
// delete and add sections when needed.
$courseconfig = get_config('moodlecourse');
$max = (int)$courseconfig->maxsections;
$weeksconfig = get_config('format_weeks');
$max = (int)$weeksconfig->maxinitialsections;
$element = $mform->addElement('select', 'numsections', get_string('numberweeks'), range(0, $max ?: 52));
$mform->setType('numsections', PARAM_INT);
if (is_null($mform->getElementValue('numsections'))) {
+8
View File
@@ -33,4 +33,12 @@ if ($ADMIN->fulltree) {
new lang_string('indentation_help', 'format_weeks').'<br />'.$link,
1
));
$settings->add(new admin_setting_configtext(
name: 'format_weeks/maxinitialsections',
visiblename: new lang_string('maxinitialsections', 'format_weeks'),
description: new lang_string('maxinitialsections_help', 'format_weeks'),
defaultsetting: 52,
paramtype: PARAM_INT,
));
}
@@ -0,0 +1,74 @@
@format @format_weeks
Feature: Weeks format courses are created with the system default number of sections
In order to create courses
As a course creator
I need my week courses to be created as the system default number of sections
@javascript
Scenario: Weeks formats cannot be created with more sections than the format max
Given the following config values are set as admin:
| maxinitialsections | 5 | format_weeks |
| numsections | 40 | moodlecourse |
When I log in as "admin"
And I navigate to "Courses > Manage courses and categories" in site administration
And I click on "Create new course" "link"
And I expand all fieldsets
And I set the field "Course full name" to "Course 1"
And I set the field "Course short name" to "C1"
And I set the field "Format" to "Weekly sections"
Then the "Number of sections" select box should contain "5"
And the "Number of sections" select box should not contain "6"
And I expand all fieldsets
And I set the field "Number of sections" to "5"
And I click on "Save and display" "button"
And "[data-for='section'][data-number='1']" "css_element" should exist
And "[data-for='section'][data-number='2']" "css_element" should exist
And "[data-for='section'][data-number='3']" "css_element" should exist
And "[data-for='section'][data-number='4']" "css_element" should exist
And "[data-for='section'][data-number='5']" "css_element" should exist
And "[data-for='section'][data-number='6']" "css_element" should not exist
@javascript
Scenario: Weeks formats will be created with the system default
Given the following config values are set as admin:
| numsections | 5 | moodlecourse |
When I log in as "admin"
And I navigate to "Courses > Manage courses and categories" in site administration
And I click on "Create new course" "link"
And I expand all fieldsets
And I set the field "Course full name" to "Course 1"
And I set the field "Course short name" to "C1"
And I set the field "Format" to "Weekly sections"
Then the "Number of sections" select box should contain "52"
And the "Number of sections" select box should not contain "53"
And I click on "Save and display" "button"
And "[data-for='section'][data-number='1']" "css_element" should exist
And "[data-for='section'][data-number='2']" "css_element" should exist
And "[data-for='section'][data-number='3']" "css_element" should exist
And "[data-for='section'][data-number='4']" "css_element" should exist
And "[data-for='section'][data-number='5']" "css_element" should exist
And "[data-for='section'][data-number='6']" "css_element" should not exist
@javascript
Scenario: Weeks formats can be created with a specific number of sections
Given the following config values are set as admin:
| numsections | 4 | moodlecourse |
| maxinitialsections | 10 | format_weeks |
When I log in as "admin"
And I navigate to "Courses > Manage courses and categories" in site administration
And I click on "Create new course" "link"
And I expand all fieldsets
And I set the field "Course full name" to "Course 1"
And I set the field "Course short name" to "C1"
And I set the field "Format" to "Weekly sections"
Then the "Number of sections" select box should contain "10"
And the "Number of sections" select box should not contain "11"
And I expand all fieldsets
And I set the field "Number of sections" to "5"
And I click on "Save and display" "button"
And "[data-for='section'][data-number='1']" "css_element" should exist
And "[data-for='section'][data-number='2']" "css_element" should exist
And "[data-for='section'][data-number='3']" "css_element" should exist
And "[data-for='section'][data-number='4']" "css_element" should exist
And "[data-for='section'][data-number='5']" "css_element" should exist
And "[data-for='section'][data-number='6']" "css_element" should not exist
+1 -1
View File
@@ -25,6 +25,6 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2025041400; // The current plugin version (Date: YYYYMMDDXX).
$plugin->version = 2025052600; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2025040800; // Requires this Moodle version.
$plugin->component = 'format_weeks'; // Full name of the plugin (used for diagnostics).