Merge branch 'mdl-78080-main-split' of https://github.com/james-cnz/moodle

This commit is contained in:
Shamim Rezaie 2024-06-18 16:05:48 +10:00
commit fe7738b7da
2 changed files with 49 additions and 22 deletions

View File

@ -2051,19 +2051,42 @@ abstract class base {
}
$course = $this->get_course();
$oldsectioninfo = get_fast_modinfo($course)->get_section_info($originalsection->section);
$newsection = course_create_section($course, $oldsectioninfo->section + 1); // Place new section after existing one.
$context = context_course::instance($course->id);
$newsection = course_create_section($course, $originalsection->section + 1); // Place new section after existing one.
$newsectiondata = new stdClass();
if (!empty($originalsection->name)) {
$newsection->name = get_string('duplicatedsection', 'moodle', $originalsection->name);
$newsectiondata->name = get_string('duplicatedsection', 'moodle', $originalsection->name);
} else {
$newsection->name = $originalsection->name;
$newsectiondata->name = $originalsection->name;
}
$newsectiondata->summary = $originalsection->summary;
$newsectiondata->summaryformat = $originalsection->summaryformat;
$newsectiondata->visible = $originalsection->visible;
$newsectiondata->availability = $originalsection->availability;
foreach ($this->section_format_options() as $key => $value) {
$newsectiondata->$key = $originalsection->$key;
}
course_update_section($course, $newsection, $newsectiondata);
try {
$fs = get_file_storage();
$files = $fs->get_area_files($context->id, 'course', 'section', $originalsection->id);
foreach ($files as $f) {
$fileinfo = [
'contextid' => $context->id,
'component' => 'course',
'filearea' => 'section',
'itemid' => $newsection->id,
];
$fs->create_file_from_storedfile($fileinfo, $f);
}
} catch (\Exception $e) {
debugging('Error copying section files.' . $e->getMessage(), DEBUG_DEVELOPER);
}
$newsection->summary = $originalsection->summary;
$newsection->summaryformat = $originalsection->summaryformat;
$newsection->visible = $originalsection->visible;
$newsection->availability = $originalsection->availability;
course_update_section($course, $newsection, $newsection);
$modinfo = $this->get_modinfo();
@ -2071,7 +2094,9 @@ abstract class base {
if (array_key_exists($originalsection->section, $modinfo->sections)) {
foreach ($modinfo->sections[$originalsection->section] as $modnumber) {
$originalcm = $modinfo->cms[$modnumber];
duplicate_module($course, $originalcm, $newsection->id, false);
if (!$originalcm->deletioninprogress) {
duplicate_module($course, $originalcm, $newsection->id, false);
}
}
}

View File

@ -193,19 +193,21 @@ class controlmenu implements named_templatable, renderable {
'attr' => ['class' => 'icon edit'],
];
$duplicatesectionurl = clone($baseurl);
$duplicatesectionurl->param('section', $section->section);
$duplicatesectionurl->param('duplicatesection', $section->section);
if (!is_null($sectionreturn)) {
$duplicatesectionurl->param('sr', $sectionreturn);
if ($section->section) {
$duplicatesectionurl = clone($baseurl);
$duplicatesectionurl->param('sectionid', $section->id);
$duplicatesectionurl->param('duplicatesection', 1);
if (!is_null($sectionreturn)) {
$duplicatesectionurl->param('sr', $sectionreturn);
}
$controls['duplicate'] = [
'url' => $duplicatesectionurl,
'icon' => 't/copy',
'name' => get_string('duplicate'),
'pixattr' => ['class' => ''],
'attr' => ['class' => 'icon duplicate'],
];
}
$controls['duplicate'] = [
'url' => $duplicatesectionurl,
'icon' => 't/copy',
'name' => get_string('duplicate'),
'pixattr' => ['class' => ''],
'attr' => ['class' => 'icon duplicate'],
];
}
if ($section->section) {