Skip to content

Commit 684b30a

Browse files
committed
Add new separator (MDL-80621)
1 parent 9e9d7a7 commit 684b30a

6 files changed

Lines changed: 141 additions & 13 deletions

File tree

_course_changenumsections.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,22 @@
3737
$courseid = required_param('courseid', PARAM_INT);
3838
$increase = optional_param('increase', null, PARAM_BOOL);
3939
$insertparentid = optional_param('insertparentid', null, PARAM_INT); // CHANGED: Insert nested in section with ID.
40+
$insertprevupid = optional_param('insertprevupid', null, PARAM_INT);
4041
$insertlevel = optional_param('insertlevel', null, PARAM_INT); // ADDED: Level for inserted section.
4142
$numsections = optional_param('numsections', 1, PARAM_INT); // Number of sections to insert.
4243
$returnurl = optional_param('returnurl', null, PARAM_LOCALURL); // Where to return to after the action.
4344
// REMOVED: sectionreturn .
4445

4546
// ADDED: Create section info object.
4647
$insertsection = null;
47-
if (isset($insertparentid)) {
48+
if (isset($insertparentid) || isset($insertprevupid)) {
4849
$insertsection = new \stdClass();
49-
$insertsection->parentid = $insertparentid;
50+
if (isset($insertparentid)) {
51+
$insertsection->parentid = $insertparentid;
52+
}
53+
if (isset($insertprevupid)) {
54+
$insertsection->prevupid = $insertprevupid;
55+
}
5056
$insertsection->level = $insertlevel ?? FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC;
5157
}
5258
// END ADDED.

classes/output/courseformat/content/addsection.php

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
1616

1717
/**
18-
* Contains the default section course format output class.
18+
* Contains the section course format output class.
1919
*
2020
* @package format_multitopic
2121
* @copyright 2019 onwards James Calder and Otago Polytechnic
@@ -26,6 +26,8 @@
2626
namespace format_multitopic\output\courseformat\content;
2727

2828
use core_courseformat\output\local\content\addsection as addsection_base;
29+
use core_courseformat\base as course_format;
30+
use section_info;
2931
use stdClass;
3032

3133
/**
@@ -38,6 +40,20 @@
3840
*/
3941
class addsection extends addsection_base {
4042

43+
/** @var section_info|null the section info */
44+
protected $section;
45+
46+
/**
47+
* Constructor.
48+
*
49+
* @param course_format $format the course format
50+
* @param section_info|null $section the section info
51+
*/
52+
public function __construct(course_format $format, ?section_info $section = null) {
53+
parent::__construct($format);
54+
$this->section = $section;
55+
}
56+
4157
/**
4258
* Get the add section button data.
4359
*
@@ -49,9 +65,9 @@ class addsection extends addsection_base {
4965
* @param \renderer_base $output typically, the renderer that's calling this function
5066
* @param int $lastsection the last section number
5167
* @param int $maxsections the maximum number of sections (deprecated since Moodle 5.1)
52-
* @return \stdClass data context for a mustache template
68+
* @return stdClass data context for a mustache template
5369
*/
54-
protected function get_add_section_data(\renderer_base $output, int $lastsection, int $maxsections = 0): \stdClass {
70+
protected function get_add_section_data(\renderer_base $output, int $lastsection, int $maxsections = 0): stdClass {
5571
$format = $this->format;
5672
$course = $format->get_course();
5773
$data = parent::get_add_section_data($output, $lastsection, $maxsections);
@@ -62,13 +78,21 @@ protected function get_add_section_data(\renderer_base $output, int $lastsection
6278
$addstring = get_string('addsections');
6379
}
6480

65-
$params = ['courseid' => $course->id, // CHANGED.
66-
'insertparentid' => $format->get_sectionid(),
67-
'insertlevel' => FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC,
68-
'sesskey' => sesskey(),
69-
'returnurl' => new \moodle_url("/course/view.php?id={$course->id}"
70-
. (($format->get_sectionid() != $format->fmtrootsectionid) ?
71-
"&sectionid={$format->get_sectionid()}" : "")), ];
81+
$params = [
82+
'courseid' => $course->id, // CHANGED.
83+
'insertlevel' => FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC,
84+
'sesskey' => sesskey(),
85+
'returnurl' => new \moodle_url(
86+
"/course/view.php?id={$course->id}"
87+
. (($format->get_sectionid() != $format->fmtrootsectionid) ?
88+
"&sectionid={$format->get_sectionid()}" : "")
89+
),
90+
];
91+
if ($this->section) {
92+
$params['insertprevupid'] = $this->section->id;
93+
} else {
94+
$params['insertparentid'] = $format->get_sectionid();
95+
}
7296

7397
$data->addsections->url = new \moodle_url('/course/format/multitopic/_course_changenumsections.php', $params);
7498
$data->addsections->title = $addstring;

classes/output/courseformat/content/section.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,22 @@ public function __construct(course_format $format, \section_info $section) {
6262
* @return \stdClass data context for a mustache template
6363
*/
6464
public function export_for_template(\renderer_base $output): \stdClass {
65+
$format = $this->format;
66+
6567
$data = parent::export_for_template($output);
6668

6769
$sectionextra = $this->fmtsectionextra;
6870
unset($data->displayonesection);
6971
$data->levelsan = $sectionextra->levelsan;
7072
$data->fmtispage = ($sectionextra->levelsan < 2);
7173

74+
if (!$this->section->get_component_instance()) {
75+
$addsectionclass = $format->get_output_classname('content\\addsection');
76+
$addsection = new $addsectionclass($format, $this->section);
77+
$data->numsections = $addsection->export_for_template($output);
78+
$data->insertafter = true;
79+
}
80+
7281
return $data;
7382
}
7483

templates/courseformat/content/section.mustache

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,12 @@
108108
{{/ core_courseformat/local/content/section/content }}
109109
</div>
110110

111+
{{#insertafter}}
112+
{{#numsections}}
113+
{{$ core_courseformat/local/content/addsection}}
114+
{{> format_multitopic/courseformat/content/section/addsectiondivider }}
115+
{{/ core_courseformat/local/content/addsection}}
116+
{{/numsections}}
117+
{{/insertafter}}
111118
</li>
112119
{{#testingsection}}</ul>{{/testingsection}}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{{!
2+
This file is part of Moodle - http://moodle.org/
3+
4+
Moodle is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
Moodle is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
}}
17+
{{!
18+
@template format_multitopic/courseformat/content/section/addsectiondivider
19+
20+
Displays the add section divider inside a section.
21+
22+
Example context (json):
23+
{
24+
"showaddsection": true,
25+
"id": 42,
26+
"insertafter": true,
27+
"num": 0,
28+
"addsections": {
29+
"url": "#",
30+
"title": "Add section",
31+
"newsection": 3
32+
}
33+
}
34+
}}
35+
{{#showaddsection}}
36+
<div class="changenumsections bulk-hidden {{^canaddsection}}disabled{{/canaddsection}}" data-region="fmt-section-addsection">
37+
{{#addsections}}
38+
{{< core_courseformat/local/content/divider}}
39+
{{$extraclasses}}always-hidden mt-2{{/extraclasses}}
40+
{{$content}}
41+
<a href="{{{url}}}"
42+
class="btn add-content section-modchooser section-modchooser-link d-flex justify-content-center align-items-center p-1 icon-no-margin
43+
{{^canaddsection}}disabled{{/canaddsection}}"
44+
data-add-sections="{{title}}"
45+
data-new-sections="{{newsection}}"
46+
47+
{{#insertafter}} data-id="{{id}}" {{/insertafter}}
48+
title="{{#canaddsection}}{{title}}{{/canaddsection}}{{^canaddsection}}{{#str}}sectionaddmax, core_courseformat{{/str}}{{/canaddsection}}"
49+
>
50+
{{#pix}} t/add, core {{/pix}}
51+
</a>
52+
{{/content}}
53+
{{/ core_courseformat/local/content/divider}}
54+
{{/addsections}}
55+
</div>
56+
{{/showaddsection}}

tests/behat/edit_delete_sections.feature

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,32 @@ Feature: Sections can be edited and deleted in Multitopic format
6969
@javascript
7070
Scenario: Adding sections at the end of a Multitopic format
7171
Given I am on "Course 1" course homepage with editing mode on
72-
When I follow "Add topic"
72+
When I click on "Add topic" "link" in the "fmt-course-addsection" "region"
7373
Then I should see "Section 6" in the "Section 6" "section"
7474
And I should see "Test choice name" in the "Section 5" "section"
75+
76+
@javascript
77+
Scenario: Adding topics between topics in Multitopic format
78+
Given I am on "Course 1" course homepage with editing mode on
79+
When I hover over the "Add topic" "link" in the "Section 4" "section"
80+
When I click on "Add topic" "link" in the "Section 4" "section"
81+
Then I should see "Section 6" in the "Section 6" "section"
82+
And I should not see "Test choice name" in the "Section 5" "section"
83+
And I should see "Test choice name" in the "Section 6" "section"
84+
85+
@javascript
86+
Scenario: Add a topic and then add an activity in it
87+
Given I am on "Course 1" course homepage with editing mode on
88+
When I click on "Add topic" "link" in the "fmt-course-addsection" "region"
89+
And I add an assign activity to course "Course 1" section "6" and I fill the form with:
90+
| Assignment name | Very new activity |
91+
| Description | Test |
92+
Then I should see "Very new activity" in the "Section 6" "section"
93+
94+
@javascript
95+
Scenario: Copy section permalink URL to clipboard
96+
Given I am on "Course 1" course homepage with editing mode on
97+
When I open section "1" edit menu
98+
And I click on "Permalink" "link" in the "Section 1" "section"
99+
And I click on "Copy to clipboard" "link" in the "Permalink" "dialogue"
100+
Then I should see "Text copied to clipboard"

0 commit comments

Comments
 (0)