@@ -32,6 +32,8 @@ class sectionactions extends base_sectionactions {
3232 /**
3333 * Create a course section using a record object.
3434 *
35+ * If no position is specified, the section is added to the end of the course.
36+ *
3537 * @param stdClass $fields the fields to set on the section
3638 * @param bool $skipcheck the position check has already been made and we know it can be used
3739 * @return stdClass the created section record
@@ -73,7 +75,7 @@ public function fmt_create_from_object(stdClass $fields, bool $skipcheck = false
7375 'timemodified ' => time (),
7476 ];
7577 $ sectionrecord ->id = $ DB ->insert_record ("course_sections " , $ sectionrecord );
76- if (empty ($ fields ->component ) && !($ skipcheck && ($ createnum > 0 ))) {
78+ if (empty ($ fields ->component ) && !($ skipcheck && ($ fields -> section > 0 ))) {
7779 $ DB ->insert_record ("course_format_options " , [
7880 'courseid ' => $ this ->course ->id ,
7981 'format ' => 'multitopic ' ,
@@ -84,7 +86,8 @@ public function fmt_create_from_object(stdClass $fields, bool $skipcheck = false
8486 }
8587
8688 // Now move it to the specified position, if necessary.
87- if (!$ skipcheck && !(!empty ($ fields ->component ) && property_exists ($ fields , 'nextupid ' ) && ($ fields ->nextupid == null ))) {
89+ $ skipmove = $ skipcheck || !empty ($ fields ->component ) && property_exists ($ fields , 'nextupid ' ) && ($ fields ->nextupid == null );
90+ if (!$ skipmove ) {
8891 try {
8992 $ movednews = format_multitopic_move_section_to (
9093 $ this ->course , [$ sectionrecord ], $ fields , !empty ($ fields ->component ) ? 2 : 1
0 commit comments