Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 52... Línea 52...
52
            'summary' => $fields->summary ?? '',
52
            'summary' => $fields->summary ?? '',
53
            'summaryformat' => $fields->summaryformat ?? FORMAT_HTML,
53
            'summaryformat' => $fields->summaryformat ?? FORMAT_HTML,
54
            'sequence' => '',
54
            'sequence' => '',
55
            'name' => $fields->name ?? null,
55
            'name' => $fields->name ?? null,
56
            'visible' => $fields->visible ?? 1,
56
            'visible' => $fields->visible ?? 1,
57
            'availability' => null,
57
            'availability' => $fields->availability ?? null,
58
            'component' => $fields->component ?? null,
58
            'component' => $fields->component ?? null,
59
            'itemid' => $fields->itemid ?? null,
59
            'itemid' => $fields->itemid ?? null,
60
            'timemodified' => time(),
60
            'timemodified' => time(),
61
        ];
61
        ];
62
        $sectionrecord->id = $DB->insert_record("course_sections", $sectionrecord);
62
        $sectionrecord->id = $DB->insert_record("course_sections", $sectionrecord);
Línea 160... Línea 160...
160
     * This will become sectionnum of the new section. All existing sections at this or bigger
160
     * This will become sectionnum of the new section. All existing sections at this or bigger
161
     * position will be shifted down.
161
     * position will be shifted down.
162
     *
162
     *
163
     * @param int $position The position to add to, 0 means to the end.
163
     * @param int $position The position to add to, 0 means to the end.
164
     * @param bool $skipcheck the check has already been made and we know that the section with this position does not exist
164
     * @param bool $skipcheck the check has already been made and we know that the section with this position does not exist
165
     * @return stdClass created section object)
165
     * @return stdClass created section object
166
     */
166
     */
167
    public function create(int $position = 0, bool $skipcheck = false): stdClass {
167
    public function create(int $position = 0, bool $skipcheck = false): stdClass {
168
        $record = (object) [
168
        $record = (object) [
169
            'section' => $position,
169
            'section' => ($position == 0 && !$skipcheck) ? null : $position,
170
        ];
170
        ];
171
        return $this->create_from_object($record, $skipcheck);
171
        return $this->create_from_object($record, $skipcheck);
172
    }
172
    }
Línea 173... Línea 173...
173
 
173
 
Línea 316... Línea 316...
316
            '1',
316
            '1',
317
            ['course' => $this->course->id, 'section' => $sectioninfo->id]
317
            ['course' => $this->course->id, 'section' => $sectioninfo->id]
318
        );
318
        );
Línea 319... Línea 319...
319
 
319
 
320
        // Move all modules to section 0.
320
        // Move all modules to section 0.
321
        $sectionzero = $DB->get_record('course_sections', ['course' => $this->course->id, 'section' => '0']);
321
        $modinfo = get_fast_modinfo($this->course->id);
322
        $modules = $DB->get_records('course_modules', ['section' => $sectioninfo->id], '');
322
        foreach ($modinfo->get_cms() as $cm) {
323
        foreach ($modules as $mod) {
323
            if ($cm->sectionnum == $sectioninfo->section) {
-
 
324
                moveto_module($cm, $modinfo->get_section_info(0));
324
            moveto_module($mod, $sectionzero);
325
            }
Línea 325... Línea 326...
325
        }
326
        }
326
 
327
 
327
        $removaltask = new \core_course\task\course_delete_modules();
328
        $removaltask = new \core_course\task\course_delete_modules();
Línea 365... Línea 366...
365
 
366
 
366
        $fields['id'] = $sectioninfo->id;
367
        $fields['id'] = $sectioninfo->id;
367
        $fields['timemodified'] = time();
368
        $fields['timemodified'] = time();
Línea -... Línea 369...
-
 
369
        $DB->update_record('course_sections', $fields);
-
 
370
 
368
        $DB->update_record('course_sections', $fields);
371
        $sectioninfo->get_component_instance()?->section_updated((object) $fields);
369
 
372
 
370
        // We need to update the section cache before the format options are updated.
373
        // We need to update the section cache before the format options are updated.
Línea 371... Línea 374...
371
        \course_modinfo::purge_course_section_cache_by_id($courseid, $sectioninfo->id);
374
        \course_modinfo::purge_course_section_cache_by_id($courseid, $sectioninfo->id);
Línea 402... Línea 405...
402
            return;
405
            return;
403
        }
406
        }
Línea 404... Línea 407...
404
 
407
 
405
        $modules = explode(',', $sectioninfo->sequence);
408
        $modules = explode(',', $sectioninfo->sequence);
-
 
409
        $cmids = [];
-
 
410
 
-
 
411
        // In case the section is delegated by a module, we change also the visibility for the source module.
-
 
412
        $delegateinstance = $sectioninfo->get_component_instance();
-
 
413
        if ($delegateinstance) {
-
 
414
            // We only return sections delegated by course modules. Sections delegated to other
-
 
415
            // types of components must implement their own methods to get the section.
-
 
416
            if ($delegateinstance && ($delegateinstance instanceof \core_courseformat\sectiondelegatemodule)) {
-
 
417
                $delegator = $delegateinstance->get_cm();
-
 
418
                $modules[] = $delegator->id;
-
 
419
            }
-
 
420
        }
406
        $cmids = [];
421
 
407
        foreach ($modules as $moduleid) {
422
        foreach ($modules as $moduleid) {
408
            $cm = get_coursemodule_from_id(null, $moduleid, $this->course->id);
423
            $cm = get_coursemodule_from_id(null, $moduleid, $this->course->id);
409
            if (!$cm) {
424
            if (!$cm) {
410
                continue;
425
                continue;