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
2626namespace format_multitopic \output \courseformat \content ;
2727
2828use core_courseformat \output \local \content \addsection as addsection_base ;
29+ use core_courseformat \base as course_format ;
30+ use section_info ;
2931use stdClass ;
3032
3133/**
3840 */
3941class 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- "§ionid= {$ 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+ "§ionid= {$ 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 ;
0 commit comments