Skip to content

Commit 8c4fbc2

Browse files
committed
Create section method (MDL-80187) WIP 6
1 parent 70f5923 commit 8c4fbc2

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

classes/courseformat/sectionactions.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,11 @@ public function create_from_object(stdClass $fields, bool $skipcheck = false): s
5050
'SELECT max(section) from {course_sections} WHERE course = ?',
5151
[$this->course->id]
5252
) + 1;
53-
if (!isset($fields->section) && !isset($fields->previd) && !isset($fields->nextid) && !isset($fields->parentid)) {
54-
$fields->nextid = null;
53+
if (!isset($fields->section) && !isset($fields->prevupid) && !isset($fields->nextupid) && !isset($fields->parentid)) {
54+
$fields->nextupid = null;
55+
}
56+
if (!isset($fields->level)) {
57+
$fields->level = !empty($fields->component) ? 0 : 2;
5558
}
5659
}
5760

@@ -81,7 +84,7 @@ public function create_from_object(stdClass $fields, bool $skipcheck = false): s
8184
}
8285

8386
// Now move it to the specified position, if necessary.
84-
if (!$skipcheck && !(!empty($fields->component) && property_exists($fields, 'nextid') && $fields->nextid == null)) {
87+
if (!$skipcheck && !(!empty($fields->component) && property_exists($fields, 'nextupid') && ($fields->nextupid == null))) {
8588
try {
8689
$movednews = format_multitopic_move_section_to(
8790
$this->course, [$sectionrecord], $fields, !empty($fields->component) ? 2 : 1

locallib.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ function format_multitopic_reorder_sections(array $sectionsextra, $origins, \std
235235
$prevextra = null;
236236
$found = false;
237237
$appendextraarray = [];
238+
$newposition = 0;
238239
foreach ($sectionsextra as $id => $sectionextra) {
239240
if ($found) {
240241
// Target position already found, extract remaining sections.
@@ -257,7 +258,8 @@ function format_multitopic_reorder_sections(array $sectionsextra, $origins, \std
257258
} else if (isset($parentextra)
258259
&& ($sectionextra->levelsan < $target->level || $sectionextra->levelsan <= $parentextra->levelsan)
259260
|| isset($prevextra) && ($sectionextra->levelsan <= $target->level)
260-
|| isset($target->nextupid) && $sectionextra->id == $target->nextupid) {
261+
|| isset($target->nextupid) && ($sectionextra->id == $target->nextupid)
262+
|| isset($target->section) && ($newposition == $target->section)) {
261263
// Reached the last position in a specified parent in which the moved section would be a (direct) child,
262264
// or the appropriate position after a specified previous section,
263265
// or the position before a specified next section.
@@ -269,8 +271,11 @@ function format_multitopic_reorder_sections(array $sectionsextra, $origins, \std
269271
unset($sectionsextra[$id]);
270272
$found = true;
271273
}
274+
$newposition++;
272275
}
273-
if (isset($parentextra) || isset($prevextra)) {
276+
if (isset($parentextra) || isset($prevextra)
277+
|| property_exists($target, 'nextupid') && ($target->nextupid == null)
278+
|| isset($target->section) && ($newposition == $target->section)) {
274279
// If a specified parent or previous was found, but no position within the section list was appropriate,
275280
// the appropriate position must be the end of the section list.
276281
$found = true;

0 commit comments

Comments
 (0)