Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 11
Línea 2049... Línea 2049...
2049
        if (!$this->uses_sections()) {
2049
        if (!$this->uses_sections()) {
2050
            throw new moodle_exception('sectionsnotsupported', 'core_courseformat');
2050
            throw new moodle_exception('sectionsnotsupported', 'core_courseformat');
2051
        }
2051
        }
Línea 2052... Línea 2052...
2052
 
2052
 
2053
        $course = $this->get_course();
2053
        $course = $this->get_course();
2054
        $oldsectioninfo = get_fast_modinfo($course)->get_section_info($originalsection->section);
2054
        $context = context_course::instance($course->id);
Línea -... Línea 2055...
-
 
2055
        $newsection = course_create_section($course, $originalsection->section + 1); // Place new section after existing one.
2055
        $newsection = course_create_section($course, $oldsectioninfo->section + 1); // Place new section after existing one.
2056
 
2056
 
2057
        $newsectiondata = new stdClass();
2057
        if (!empty($originalsection->name)) {
2058
        if (!empty($originalsection->name)) {
2058
            $newsection->name = get_string('duplicatedsection', 'moodle', $originalsection->name);
2059
            $newsectiondata->name = get_string('duplicatedsection', 'moodle', $originalsection->name);
-
 
2060
        } else {
-
 
2061
            $newsectiondata->name = $originalsection->name;
-
 
2062
        }
-
 
2063
        $newsectiondata->summary = $originalsection->summary;
-
 
2064
        $newsectiondata->summaryformat = $originalsection->summaryformat;
-
 
2065
        $newsectiondata->visible = $originalsection->visible;
-
 
2066
        $newsectiondata->availability = $originalsection->availability;
-
 
2067
        foreach ($this->section_format_options() as $key => $value) {
-
 
2068
            $newsectiondata->$key = $originalsection->$key;
-
 
2069
        }
-
 
2070
        course_update_section($course, $newsection, $newsectiondata);
-
 
2071
 
-
 
2072
        try {
-
 
2073
            $fs = get_file_storage();
-
 
2074
            $files = $fs->get_area_files($context->id, 'course', 'section', $originalsection->id);
-
 
2075
 
-
 
2076
            foreach ($files as $f) {
-
 
2077
 
-
 
2078
                $fileinfo = [
-
 
2079
                    'contextid' => $context->id,
-
 
2080
                    'component' => 'course',
-
 
2081
                    'filearea' => 'section',
-
 
2082
                    'itemid' => $newsection->id,
-
 
2083
                ];
-
 
2084
 
-
 
2085
                $fs->create_file_from_storedfile($fileinfo, $f);
-
 
2086
            }
2059
        } else {
2087
        } catch (\Exception $e) {
2060
            $newsection->name = $originalsection->name;
-
 
2061
        }
-
 
2062
        $newsection->summary = $originalsection->summary;
-
 
2063
        $newsection->summaryformat = $originalsection->summaryformat;
-
 
2064
        $newsection->visible = $originalsection->visible;
-
 
Línea 2065... Línea 2088...
2065
        $newsection->availability = $originalsection->availability;
2088
            debugging('Error copying section files.' . $e->getMessage(), DEBUG_DEVELOPER);
Línea 2066... Línea 2089...
2066
        course_update_section($course, $newsection, $newsection);
2089
        }
2067
 
2090
 
2068
        $modinfo = $this->get_modinfo();
2091
        $modinfo = $this->get_modinfo();
2069
 
2092
 
-
 
2093
        // Duplicate the section modules, should they exist.
2070
        // Duplicate the section modules, should they exist.
2094
        if (array_key_exists($originalsection->section, $modinfo->sections)) {
-
 
2095
            foreach ($modinfo->sections[$originalsection->section] as $modnumber) {
2071
        if (array_key_exists($originalsection->section, $modinfo->sections)) {
2096
                $originalcm = $modinfo->cms[$modnumber];
2072
            foreach ($modinfo->sections[$originalsection->section] as $modnumber) {
2097
                if (!$originalcm->deletioninprogress) {
Línea 2073... Línea 2098...
2073
                $originalcm = $modinfo->cms[$modnumber];
2098
                    duplicate_module($course, $originalcm, $newsection->id, false);
2074
                duplicate_module($course, $originalcm, $newsection->id, false);
2099
                }