mirror of
https://github.com/moodle/moodle.git
synced 2025-08-03 16:13:28 +02:00
MDL-62748 course: maxsections is a limit
For course formats shipped with core, maxsections should be a limit to the number of sections allowed in the course.
This commit is contained in:
parent
f468f6d02a
commit
7c05d8a3d2
6 changed files with 60 additions and 13 deletions
2
course/amd/build/actions.min.js
vendored
2
course/amd/build/actions.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -588,9 +588,10 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str'
|
|||
// Add a handler for "Add sections" link to ask for a number of sections to add.
|
||||
str.get_string('numberweeks').done(function(strNumberSections) {
|
||||
var trigger = $(SELECTOR.ADDSECTIONS),
|
||||
modalTitle = trigger.attr('data-add-sections');
|
||||
modalTitle = trigger.attr('data-add-sections'),
|
||||
newSections = trigger.attr('new-sections');
|
||||
var modalBody = $('<div><label for="add_section_numsections"></label> ' +
|
||||
'<input id="add_section_numsections" type="number" min="1" value="1"></div>');
|
||||
'<input id="add_section_numsections" type="number" min="1" max="' + newSections + '" value="1"></div>');
|
||||
modalBody.find('label').html(strNumberSections);
|
||||
ModalFactory.create({
|
||||
title: modalTitle,
|
||||
|
|
|
@ -45,6 +45,30 @@ require_login($course);
|
|||
require_capability('moodle/course:update', context_course::instance($course->id));
|
||||
require_sesskey();
|
||||
|
||||
$desirednumsections = 0;
|
||||
$courseformat = course_get_format($course);
|
||||
$lastsectionnumber = $courseformat->get_last_section_number();
|
||||
$maxsections = $courseformat->get_max_sections();
|
||||
|
||||
if (isset($courseformatoptions['numsections']) && $increase !== null) {
|
||||
$desirednumsections = $courseformatoptions['numsections'] + 1;
|
||||
} else if (course_get_format($course)->uses_sections() && $insertsection !== null) {
|
||||
// Count the sections in the course.
|
||||
$desirednumsections = $lastsectionnumber + $numsections;
|
||||
}
|
||||
|
||||
if ($desirednumsections > $maxsections) {
|
||||
// Increase in number of sections is not allowed.
|
||||
\core\notification::warning(get_string('maxsectionslimit', 'moodle', $maxsections));
|
||||
$increase = null;
|
||||
$insertsection = null;
|
||||
$numsections = 0;
|
||||
|
||||
if (!$returnurl) {
|
||||
$returnurl = course_get_url($course);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($courseformatoptions['numsections']) && $increase !== null) {
|
||||
if ($increase) {
|
||||
// Add an additional section.
|
||||
|
|
|
@ -287,6 +287,18 @@ abstract class format_base {
|
|||
return (int)max(array_keys($sections));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method used to get the maximum number of sections for this course format.
|
||||
* @return int
|
||||
*/
|
||||
public function get_max_sections() {
|
||||
$maxsections = get_config('moodlecourse', 'maxsections');
|
||||
if (!isset($maxsections) || !is_numeric($maxsections)) {
|
||||
$maxsections = 52;
|
||||
}
|
||||
return $maxsections;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the course has a front page.
|
||||
*
|
||||
|
|
|
@ -952,7 +952,10 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
|
|||
return '';
|
||||
}
|
||||
|
||||
$options = course_get_format($course)->get_format_options();
|
||||
$format = course_get_format($course);
|
||||
$options = $format->get_format_options();
|
||||
$maxsections = $format->get_max_sections();
|
||||
$lastsection = $format->get_last_section_number();
|
||||
$supportsnumsections = array_key_exists('numsections', $options);
|
||||
|
||||
if ($supportsnumsections) {
|
||||
|
@ -963,6 +966,7 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
|
|||
echo html_writer::start_tag('div', array('id' => 'changenumsections', 'class' => 'mdl-right'));
|
||||
|
||||
// Increase number of sections.
|
||||
if ($lastsection < $maxsections) {
|
||||
$straddsection = get_string('increasesections', 'moodle');
|
||||
$url = new moodle_url('/course/changenumsections.php',
|
||||
array('courseid' => $course->id,
|
||||
|
@ -970,6 +974,7 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
|
|||
'sesskey' => sesskey()));
|
||||
$icon = $this->output->pix_icon('t/switch_plus', $straddsection);
|
||||
echo html_writer::link($url, $icon.get_accesshide($straddsection), array('class' => 'increase-sections'));
|
||||
}
|
||||
|
||||
if ($course->numsections > 0) {
|
||||
// Reduce number of sections sections.
|
||||
|
@ -985,11 +990,14 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
|
|||
echo html_writer::end_tag('div');
|
||||
|
||||
} else if (course_get_format($course)->uses_sections()) {
|
||||
if ($lastsection >= $maxsections) {
|
||||
// Don't allow more sections if we already hit the limit.
|
||||
return;
|
||||
}
|
||||
// Current course format does not have 'numsections' option but it has multiple sections suppport.
|
||||
// Display the "Add section" link that will insert a section in the end.
|
||||
// Note to course format developers: inserting sections in the other positions should check both
|
||||
// capabilities 'moodle/course:update' and 'moodle/course:movesections'.
|
||||
|
||||
echo html_writer::start_tag('div', array('id' => 'changenumsections', 'class' => 'mdl-right'));
|
||||
if (get_string_manager()->string_exists('addsections', 'format_'.$course->format)) {
|
||||
$straddsections = get_string('addsections', 'format_'.$course->format);
|
||||
|
@ -1002,8 +1010,9 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
|
|||
$url->param('sectionreturn', $sectionreturn);
|
||||
}
|
||||
$icon = $this->output->pix_icon('t/add', $straddsections);
|
||||
$newsections = $maxsections - $lastsection;
|
||||
echo html_writer::link($url, $icon . $straddsections,
|
||||
array('class' => 'add-sections', 'data-add-sections' => $straddsections));
|
||||
array('class' => 'add-sections', 'data-add-sections' => $straddsections, 'new-sections' => $newsections));
|
||||
echo html_writer::end_tag('div');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1162,6 +1162,7 @@ $string['markedthistopic'] = 'This topic is highlighted as the current topic';
|
|||
$string['markthistopic'] = 'Highlight this topic as the current topic';
|
||||
$string['matchingsearchandrole'] = 'Matching \'{$a->search}\' and {$a->role}';
|
||||
$string['maxareabytesreached'] = 'The file (or the total size of several files) is larger than the space remaining in this area.';
|
||||
$string['maxsectionslimit'] = 'Cannot create new section as it would exceed the maximum number of sections allowed for this course ({$a}).';
|
||||
$string['maxfilesize'] = 'Maximum size for new files: {$a}';
|
||||
$string['maxfilesreached'] = 'You are allowed to attach a maximum of {$a} file(s) to this item';
|
||||
$string['maximumchars'] = 'Maximum of {$a} characters';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue