Merge branch 'MDL-85284-main' of https://github.com/ferranrecio/moodle
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
issueNumber: MDL-85284
|
||||
notes:
|
||||
core_course:
|
||||
- message: >-
|
||||
The changenumsections.php script is deprecated. Please use
|
||||
course/format/update.php instead.
|
||||
type: deprecated
|
||||
core_courseformat:
|
||||
- message: >-
|
||||
The course format "numsections" option to increment and decrement the
|
||||
number of sections of the course one by one is now deprecated and will
|
||||
be removed in Moodle 6.0.
|
||||
type: deprecated
|
||||
@@ -23,6 +23,8 @@
|
||||
* @copyright 2012 Dan Poltawski
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @since Moodle 2.3
|
||||
* @todo Remove file in Moodle 6.0 (MDL-86395).
|
||||
* @deprecated since Moodle 5.1 (MDL-85284)
|
||||
*/
|
||||
|
||||
require_once(__DIR__.'/../config.php');
|
||||
@@ -45,6 +47,11 @@ require_login($course);
|
||||
require_capability('moodle/course:update', context_course::instance($course->id));
|
||||
require_sesskey();
|
||||
|
||||
debugging(
|
||||
'The changenumsections.php script is deprecated. Please use course/format/update.php instead.',
|
||||
DEBUG_DEVELOPER,
|
||||
);
|
||||
|
||||
$desirednumsections = 0;
|
||||
$courseformat = course_get_format($course);
|
||||
$lastsectionnumber = $courseformat->get_last_section_number();
|
||||
|
||||
@@ -29,6 +29,7 @@ use core_courseformat\base as course_format;
|
||||
use core_courseformat\output\local\courseformat_named_templatable;
|
||||
use moodle_url;
|
||||
use renderable;
|
||||
use section_info;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
@@ -45,13 +46,18 @@ class addsection implements named_templatable, renderable {
|
||||
/** @var course_format the course format class */
|
||||
protected $format;
|
||||
|
||||
/** @var section_info|null the target section information */
|
||||
protected section_info|null $targetsection;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param course_format $format the course format
|
||||
* @param section_info|null $targetsection the target section information
|
||||
*/
|
||||
public function __construct(course_format $format) {
|
||||
public function __construct(course_format $format, ?section_info $targetsection = null) {
|
||||
$this->format = $format;
|
||||
$this->targetsection = $targetsection;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,6 +82,7 @@ class addsection implements named_templatable, renderable {
|
||||
// Component based formats handle add section button in the frontend.
|
||||
$show = $format->supports_components();
|
||||
|
||||
// Todo: remove the legacy $supportsnumsections in Moodle 6.0 (MDL-86395).
|
||||
$supportsnumsections = array_key_exists('numsections', $options);
|
||||
if ($supportsnumsections) {
|
||||
$data = $this->get_num_sections_data($output, $lastsection);
|
||||
@@ -96,12 +103,20 @@ class addsection implements named_templatable, renderable {
|
||||
* Current course format has 'numsections' option, which is very confusing and we suggest course format
|
||||
* developers to get rid of it (see MDL-57769 on how to do it).
|
||||
*
|
||||
* @deprecated Since Moodle 5.1.
|
||||
* @todo Remove in Moodle 6.0 (MDL-86395).
|
||||
* @param \renderer_base $output typically, the renderer that's calling this function
|
||||
* @param int $lastsection the last section number
|
||||
* @param int $maxsections unused (max sections is not needed anymore)
|
||||
* @return stdClass data context for a mustache template
|
||||
*/
|
||||
#[\core\attribute\deprecated(
|
||||
reason: 'Buttons to increase and decrease sections are deprecated and will be removed in Moodle 6.0',
|
||||
since: '5.1',
|
||||
mdl: 'MDL-85284',
|
||||
)]
|
||||
protected function get_num_sections_data(\renderer_base $output, int $lastsection, int $maxsections = 0): stdClass {
|
||||
\core\deprecation::emit_deprecation([self::class, __FUNCTION__]);
|
||||
$format = $this->format;
|
||||
$course = $format->get_course();
|
||||
$data = new stdClass();
|
||||
@@ -127,7 +142,7 @@ class addsection implements named_templatable, renderable {
|
||||
/**
|
||||
* Get the add section button data.
|
||||
*
|
||||
* Current course format does not have 'numsections' option but it has multiple sections suppport.
|
||||
* Current course format does not have 'numsections' option but it has multiple sections support.
|
||||
* 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'.
|
||||
@@ -144,14 +159,12 @@ class addsection implements named_templatable, renderable {
|
||||
|
||||
$addstring = $format->get_format_string('addsection');
|
||||
|
||||
$params = ['courseid' => $course->id, 'insertsection' => 0, 'sesskey' => sesskey()];
|
||||
|
||||
$singlesection = $this->format->get_sectionnum();
|
||||
if ($singlesection) {
|
||||
$params['sectionreturn'] = $singlesection;
|
||||
}
|
||||
$data->addsections = (object) [
|
||||
'url' => new moodle_url('/course/changenumsections.php', $params),
|
||||
'url' => $this->format->get_update_url(
|
||||
action: 'section_add',
|
||||
targetsectionid: $this->targetsection ? $this->targetsection->id : null,
|
||||
returnurl: $format->get_view_url($format->get_sectionnum(), ['navigation' => true]),
|
||||
),
|
||||
'title' => $addstring,
|
||||
'newsection' => $lastsection + 1,
|
||||
'canaddsection' => true,
|
||||
|
||||
@@ -248,8 +248,6 @@ class stateactions {
|
||||
/**
|
||||
* Create a course section.
|
||||
*
|
||||
* This method follows the same logic as changenumsections.php.
|
||||
*
|
||||
* @param stateupdates $updates the affected course elements track
|
||||
* @param stdClass $course the course object
|
||||
* @param int[] $ids not used
|
||||
@@ -275,7 +273,7 @@ class stateactions {
|
||||
$targetsection = $modinfo->get_section_info_by_id($targetsectionid, MUST_EXIST);
|
||||
// Inserting sections at any position except in the very end requires capability to move sections.
|
||||
require_capability('moodle/course:movesections', $coursecontext);
|
||||
$insertposition = $targetsection->section + 1;
|
||||
$insertposition = $targetsection->sectionnum + 1;
|
||||
} else {
|
||||
// Get last section.
|
||||
$insertposition = 0;
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
}}
|
||||
{{#showaddsection}}
|
||||
<div id="course-addsection" class="changenumsections bulk-hidden mt-5">
|
||||
{{! Remove the increase and decrease buttons in Moodle 6.0 (MDL-86395) }}
|
||||
{{#increase}}
|
||||
<a href="{{{url}}}" class="increase-sections">
|
||||
{{#pix}}t/switch_plus, moodle, {{#str}} increasesections, moodle {{/str}}{{/pix}}
|
||||
|
||||
@@ -49,3 +49,18 @@ Feature: Validate some section editing has a non-ajax alternative
|
||||
And I should see "This will delete Section 1 and all the activities it contains."
|
||||
And I click on "Delete" "button"
|
||||
And I should not see "Section 1"
|
||||
|
||||
Scenario: Adding a section at the end of the course can be done without ajax
|
||||
Given I log in as "teacher1"
|
||||
And I am on "Course 1" course homepage with editing mode on
|
||||
When I click on "Add section" "link" in the "course-addsection" "region"
|
||||
Then I should see "New section" in the "New section" "section"
|
||||
And "Section 3" "text" should appear before "New section" "text"
|
||||
|
||||
Scenario: Adding a section between sections can be done without ajax
|
||||
Given I log in as "teacher1"
|
||||
And I am on "Course 1" course homepage with editing mode on
|
||||
When I click on "Add section" "link" in the "Section 2" "section"
|
||||
Then I should see "New section" in the "New section" "section"
|
||||
And "Section 2" "text" should appear before "New section" "text"
|
||||
And "New section" "text" should appear before "Section 3" "text"
|
||||
|
||||
@@ -47,7 +47,7 @@ class section extends section_base {
|
||||
|
||||
if (!$this->format->get_sectionnum() && !$this->section->get_component_instance()) {
|
||||
$addsectionclass = $format->get_output_classname('content\\addsection');
|
||||
$addsection = new $addsectionclass($format);
|
||||
$addsection = new $addsectionclass($format, $this->section);
|
||||
$data->numsections = $addsection->export_for_template($output);
|
||||
$data->insertafter = true;
|
||||
}
|
||||
|
||||
@@ -42,10 +42,8 @@ $returnurl = optional_param('returnurl', null, PARAM_LOCALURL);
|
||||
// accept single id values for simplicity.
|
||||
$ids = optional_param_array('ids', [], PARAM_INT);
|
||||
if (empty($ids)) {
|
||||
$ids = [required_param('id', PARAM_INT)];
|
||||
}
|
||||
if (empty($ids)) {
|
||||
throw new moodle_exception('missingparam', '', '', 'ids');
|
||||
$idparam = optional_param('id', null, PARAM_INT);
|
||||
$ids = $idparam ? [$idparam] : [];
|
||||
}
|
||||
|
||||
$format = course_get_format($courseid);
|
||||
|
||||
Reference in New Issue
Block a user