Proyectos de Subversion Moodle

Rev

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

Rev 11 Rev 1441
Línea 31... Línea 31...
31
use course_modinfo;
31
use course_modinfo;
32
use html_writer;
32
use html_writer;
33
use section_info;
33
use section_info;
34
use context_course;
34
use context_course;
35
use editsection_form;
35
use editsection_form;
36
use moodle_exception;
36
use core\exception\moodle_exception;
37
use coding_exception;
37
use core\exception\coding_exception;
38
use moodle_url;
38
use moodle_url;
39
use lang_string;
39
use lang_string;
40
use core_external\external_api;
40
use core_external\external_api;
41
use stdClass;
41
use stdClass;
42
use cache;
42
use cache;
Línea 282... Línea 282...
282
        }
282
        }
283
        return self::session_cache_reset($course);
283
        return self::session_cache_reset($course);
284
    }
284
    }
Línea 285... Línea 285...
285
 
285
 
-
 
286
    /**
-
 
287
     * Prune a course state cache for all open sessions.
-
 
288
     *
-
 
289
     * Most course edits does not require to invalidate the cache for all users
-
 
290
     * because the cache relies on the course cacherev value. However, there are
-
 
291
     * actions like editing the groups that do not change the course cacherev.
-
 
292
     *
-
 
293
     * @param \stdClass $course
-
 
294
     * @return void
-
 
295
     */
-
 
296
    public static function invalidate_all_session_caches_for_course(stdClass $course): void {
-
 
297
        \cache_helper::invalidate_by_event('changesincoursestate', [$course->id]);
-
 
298
    }
-
 
299
 
286
    /**
300
    /**
287
     * Returns the format name used by this course
301
     * Returns the format name used by this course
288
     *
302
     *
289
     * @return string
303
     * @return string
290
     */
304
     */
Línea 372... Línea 386...
372
        }
386
        }
373
        return $this->modinfo;
387
        return $this->modinfo;
374
    }
388
    }
Línea 375... Línea 389...
375
 
389
 
-
 
390
    /**
-
 
391
     * Return a format state updates instance.
-
 
392
     */
-
 
393
    public function get_stateupdates_instance(): \core_courseformat\stateupdates {
-
 
394
        $defaultupdatesclass = 'core_courseformat\\stateupdates';
-
 
395
        $updatesclass = 'format_' . $this->format . '\\courseformat\\stateupdates';
-
 
396
        if (!class_exists($updatesclass)) {
-
 
397
            $updatesclass = $defaultupdatesclass;
-
 
398
        }
-
 
399
 
-
 
400
        $updates = new $updatesclass($this);
-
 
401
        if (!is_a($updates, $defaultupdatesclass)) {
-
 
402
            throw new coding_exception("The \"$updatesclass\" class must extend \"$defaultupdatesclass\"");
-
 
403
        }
-
 
404
 
-
 
405
        return $updates;
-
 
406
    }
-
 
407
 
-
 
408
    /**
-
 
409
     * Return a format state actions instance.
-
 
410
     * @return \core_courseformat\stateactions
-
 
411
     */
-
 
412
    public function get_stateactions_instance(): \core_courseformat\stateactions {
-
 
413
        // Get the actions class from the course format.
-
 
414
        $actionsclass = 'format_'. $this->format.'\\courseformat\\stateactions';
-
 
415
        if (!class_exists($actionsclass)) {
-
 
416
            $actionsclass = 'core_courseformat\\stateactions';
-
 
417
        }
-
 
418
        return new $actionsclass();
-
 
419
    }
-
 
420
 
376
    /**
421
    /**
377
     * Method used in the rendered and during backup instead of legacy 'numsections'
422
     * Method used in the rendered and during backup instead of legacy 'numsections'
378
     *
423
     *
379
     * Default renderer will treat sections with sectionnumber greater that the value returned by this
424
     * Default renderer will treat sections with sectionnumber greater that the value returned by this
380
     * method as "orphaned" and not display them on the course page unless in editing mode.
425
     * method as "orphaned" and not display them on the course page unless in editing mode.
Línea 550... Línea 595...
550
    public function get_default_section_name($section) {
595
    public function get_default_section_name($section) {
551
        return self::get_section_name($section);
596
        return self::get_section_name($section);
552
    }
597
    }
Línea 553... Línea 598...
553
 
598
 
-
 
599
    /**
-
 
600
     * Returns the generic name for sections in this course format.
-
 
601
     *
-
 
602
     * @return string
-
 
603
     */
-
 
604
    public function get_generic_section_name() {
-
 
605
        if (get_string_manager()->string_exists('sectionname', 'format_' . $this->format)) {
-
 
606
            return get_string('sectionname', 'format_' . $this->format);
-
 
607
        }
-
 
608
        return get_string('section');
-
 
609
    }
-
 
610
 
554
    /**
611
    /**
555
     * Returns the name for the highlighted section.
612
     * Returns the name for the highlighted section.
556
     *
613
     *
557
     * @return string The name for the highlighted section based on the given course format.
614
     * @return string The name for the highlighted section based on the given course format.
558
     */
615
     */
Línea 596... Línea 653...
596
    public function get_sectionid(): ?int {
653
    public function get_sectionid(): ?int {
597
        return $this->singlesectionid;
654
        return $this->singlesectionid;
598
    }
655
    }
Línea 599... Línea 656...
599
 
656
 
600
    /**
-
 
601
     * Set if the current format instance will show multiple sections or an individual one.
-
 
602
     *
-
 
603
     * Some formats has the hability to swith from one section to multiple sections per page.
-
 
604
     *
-
 
605
     * @param int $singlesection zero for all sections or a section number
657
    /**
606
     * @deprecated Since 4.4. Use set_sectionnum instead.
-
 
607
     * @todo MDL-80116 This will be deleted in Moodle 4.8.
658
     * @deprecated Since 4.4. Use set_sectionnum instead.
-
 
659
     */
-
 
660
    #[\core\attribute\deprecated(
-
 
661
        replacement: 'base::set_sectionnum',
-
 
662
        since: '4.4',
-
 
663
        mdl: 'MDL-80248',
-
 
664
        final: true,
608
     */
665
    )]
609
    public function set_section_number(int $singlesection): void {
-
 
610
 
-
 
611
        debugging(
-
 
612
            'The method core_courseformat\base::set_section_number() has been deprecated, please use set_sectionnum() instead.',
-
 
613
            DEBUG_DEVELOPER
-
 
614
        );
-
 
615
 
-
 
616
        if ($singlesection === 0) {
-
 
617
            // Convert zero to null, to guarantee all the sections are displayed.
-
 
618
            $singlesection = null;
-
 
619
        }
666
    public function set_section_number(int $singlesection): void {
620
        $this->set_sectionnum($singlesection);
667
        \core\deprecation::emit_deprecation([self::class, __FUNCTION__]);
Línea 621... Línea 668...
621
    }
668
    }
622
 
669
 
623
    /**
670
    /**
Línea 654... Línea 701...
654
    public function get_sectionnum(): ?int {
701
    public function get_sectionnum(): ?int {
655
        return $this->singlesection;
702
        return $this->singlesection;
656
    }
703
    }
Línea 657... Línea 704...
657
 
704
 
658
    /**
-
 
659
     * Set if the current format instance will show multiple sections or an individual one.
-
 
660
     *
-
 
661
     * Some formats has the hability to swith from one section to multiple sections per page,
-
 
662
     * output components will use this method to know if the current display is a single or
-
 
663
     * multiple sections.
-
 
664
     *
-
 
665
     * @return int zero for all sections or the sectin number
705
    /**
666
     * @deprecated Since 4.4. Use get_sectionnum instead.
-
 
667
     * @todo MDL-80116 This will be deleted in Moodle 4.8.
706
     * @deprecated Since 4.4. Use get_sectionnum instead.
-
 
707
     */
-
 
708
    #[\core\attribute\deprecated(
-
 
709
        replacement: 'base::get_sectionnum',
-
 
710
        since: '4.4',
-
 
711
        mdl: 'MDL-80248',
-
 
712
        final: true,
668
     */
713
    )]
669
    public function get_section_number(): int {
-
 
670
 
-
 
671
        debugging(
-
 
672
            'The method core_courseformat\base::get_section_number() has been deprecated, please use get_sectionnum() instead.',
-
 
673
            DEBUG_DEVELOPER
-
 
674
        );
-
 
675
 
-
 
676
        if ($this->singlesection === null) {
714
    public function get_section_number(): int {
677
            // Convert null to zero, to guarantee all the sections are displayed.
715
        \core\deprecation::emit_deprecation([self::class, __FUNCTION__]);
678
            return 0;
-
 
679
        }
-
 
680
 
-
 
681
        return $this->singlesection;
716
        return 0;
Línea 682... Línea 717...
682
    }
717
    }
683
 
718
 
684
    /**
719
    /**
Línea 858... Línea 893...
858
     * Please note that course view page /course/view.php?id=COURSEID is hardcoded in many
893
     * Please note that course view page /course/view.php?id=COURSEID is hardcoded in many
859
     * places in core and contributed modules. If course format wants to change the location
894
     * places in core and contributed modules. If course format wants to change the location
860
     * of the view script, it is not enough to change just this function. Do not forget
895
     * of the view script, it is not enough to change just this function. Do not forget
861
     * to add proper redirection.
896
     * to add proper redirection.
862
     *
897
     *
863
     * @param int|stdClass $section Section object from database or just field course_sections.section
898
     * @param int|stdClass|section_info|null $section Section object from database or just field course_sections.section
864
     *     if null the course view page is returned
899
     *     if null the course view page is returned
865
     * @param array $options options for view URL. At the moment core uses:
900
     * @param array $options options for view URL. At the moment core uses:
866
     *     'navigation' (bool) if true and section not empty, the function returns section page; otherwise, it returns course page.
901
     *     'navigation' (bool) if true and section not empty, the function returns section page; otherwise, it returns course page.
867
     *     'sr' (int) used by course formats to specify to which section to return
902
     *     'sr' (int) used by course formats to specify to which section to return
868
     *     'expanded' (bool) if true the section will be shown expanded, true by default
903
     *     'expanded' (bool) if true the section will be shown expanded, true by default
Línea 898... Línea 933...
898
 
933
 
899
        return $url;
934
        return $url;
Línea 900... Línea 935...
900
    }
935
    }
-
 
936
 
-
 
937
    /**
-
 
938
     * The URL to update the course format.
-
 
939
     *
-
 
940
     * If no section is specified, the update will redirect to the general course page.
-
 
941
     *
-
 
942
     * @param string $action action name the reactive action
-
 
943
     * @param array $ids list of ids to update
-
 
944
     * @param int|null $targetsectionid optional target section id
-
 
945
     * @param int|null $targetcmid optional target cm id
-
 
946
     * @param moodle_url|null $returnurl optional custom return url
-
 
947
     * @return moodle_url
-
 
948
     */
-
 
949
    public function get_update_url(
-
 
950
        string $action,
-
 
951
        array $ids = [],
-
 
952
        ?int $targetsectionid = null,
-
 
953
        ?int $targetcmid = null,
-
 
954
        ?moodle_url $returnurl = null
-
 
955
    ): moodle_url {
-
 
956
        $params = [
-
 
957
            'courseid' => $this->get_courseid(),
-
 
958
            'sesskey' => sesskey(),
-
 
959
            'action' => $action,
-
 
960
        ];
-
 
961
 
-
 
962
        if (count($ids) === 1) {
-
 
963
            $params['id'] = reset($ids);
-
 
964
        } else {
-
 
965
            foreach ($ids as $key => $id) {
-
 
966
                $params["ids[]"] = $id;
-
 
967
            }
-
 
968
        }
-
 
969
 
-
 
970
        if (isset($targetsectionid)) {
-
 
971
            $params['targetsectionid'] = $targetsectionid;
-
 
972
        }
-
 
973
        if (isset($targetcmid)) {
-
 
974
            $params['targetcmid'] = $targetcmid;
-
 
975
        }
-
 
976
        if ($returnurl) {
-
 
977
            $params['returnurl'] = $returnurl->out_as_local_url();
-
 
978
        }
-
 
979
        return new moodle_url('/course/format/update.php', $params);
-
 
980
    }
901
 
981
 
902
    /**
982
    /**
903
     * Return the old non-ajax activity action url.
983
     * Return the old non-ajax activity action url.
904
     *
984
     *
905
     * BrowserKit behats tests cannot trigger javascript events,
985
     * BrowserKit behats tests cannot trigger javascript events,
906
     * so we must translate to an old non-ajax url while non-ajax
986
     * so we must translate to an old non-ajax url while non-ajax
-
 
987
     * course editing is still supported.
-
 
988
     *
-
 
989
     * @deprecated since Moodle 5.0
907
     * course editing is still supported.
990
     * @todo Remove this method in Moodle 6.0 (MDL-83530).
908
     *
991
     *
909
     * @param string $action action name the reactive action
992
     * @param string $action action name the reactive action
910
     * @param cm_info $cm course module
993
     * @param cm_info $cm course module
-
 
994
     * @return moodle_url
-
 
995
     */
-
 
996
    #[\core\attribute\deprecated(
-
 
997
        replacement: 'core_courseformat\base::get_update_url',
-
 
998
        since: '5.0',
911
     * @return moodle_url
999
        mdl: 'MDL-82767',
912
     */
1000
    )]
913
    public function get_non_ajax_cm_action_url(string $action, cm_info $cm): moodle_url {
1001
    public function get_non_ajax_cm_action_url(string $action, cm_info $cm): moodle_url {
914
        $nonajaxactions = [
1002
        $nonajaxactions = [
915
            'cmDelete' => 'delete',
1003
            'cmDelete' => 'cm_delete',
916
            'cmDuplicate' => 'duplicate',
1004
            'cmDuplicate' => 'cm_duplicate',
917
            'cmHide' => 'hide',
1005
            'cmHide' => 'cm_hide',
918
            'cmShow' => 'show',
1006
            'cmShow' => 'cm_show',
919
            'cmStealth' => 'stealth',
1007
            'cmStealth' => 'cm_stealth',
920
        ];
1008
        ];
921
        if (!isset($nonajaxactions[$action])) {
1009
        if (!isset($nonajaxactions[$action])) {
-
 
1010
            throw new coding_exception('Unknown activity action: ' . $action);
922
            throw new coding_exception('Unknown activity action: ' . $action);
1011
        }
923
        }
1012
        \core\deprecation::emit_deprecation([$this, __FUNCTION__]);
-
 
1013
        $nonajaxaction = $nonajaxactions[$action];
924
        $nonajaxaction = $nonajaxactions[$action];
1014
        return $this->get_update_url(
925
        $nonajaxurl = new moodle_url(
1015
            action: $nonajaxaction,
926
            '/course/mod.php',
1016
            ids: [$cm->id],
927
            ['sesskey' => sesskey(), $nonajaxaction => $cm->id]
-
 
928
        );
-
 
929
        if (!is_null($this->get_sectionid())) {
-
 
930
            $nonajaxurl->param('sr', $this->get_sectionnum());
-
 
931
        }
1017
            returnurl: $this->get_view_url($this->get_sectionnum(), ['navigation' => true]),
Línea 932... Línea 1018...
932
        return $nonajaxurl;
1018
        );
933
    }
1019
    }
934
 
1020
 
Línea 1265... Línea 1351...
1265
     *
1351
     *
1266
     * @param array $rawdata associative array of the proposed course/section format options
1352
     * @param array $rawdata associative array of the proposed course/section format options
1267
     * @param int|null $sectionid null if it is course format option
1353
     * @param int|null $sectionid null if it is course format option
1268
     * @return array array of options that have valid values
1354
     * @return array array of options that have valid values
1269
     */
1355
     */
1270
    protected function validate_format_options(array $rawdata, int $sectionid = null): array {
1356
    protected function validate_format_options(array $rawdata, ?int $sectionid = null): array {
1271
        if (!$sectionid) {
1357
        if (!$sectionid) {
1272
            $allformatoptions = $this->course_format_options(true);
1358
            $allformatoptions = $this->course_format_options(true);
1273
        } else {
1359
        } else {
1274
            $allformatoptions = $this->section_format_options(true);
1360
            $allformatoptions = $this->section_format_options(true);
1275
        }
1361
        }
Línea 1590... Línea 1676...
1590
     *
1676
     *
1591
     * @param section_info $section the section modinfo
1677
     * @param section_info $section the section modinfo
1592
     * @return bool;
1678
     * @return bool;
1593
     */
1679
     */
1594
    public function is_section_visible(section_info $section): bool {
1680
    public function is_section_visible(section_info $section): bool {
-
 
1681
        // It is unlikely that a section is orphan, but it needs to be checked.
-
 
1682
        if ($section->is_orphan() && !has_capability('moodle/course:viewhiddensections', $this->get_context())) {
-
 
1683
            return false;
-
 
1684
        }
1595
        // Previous to Moodle 4.0 thas logic was hardcoded. To prevent errors in the contrib plugins
1685
        // Previous to Moodle 4.0 thas logic was hardcoded. To prevent errors in the contrib plugins
1596
        // the default logic is the same required for topics and weeks format and still uses
1686
        // the default logic is the same required for topics and weeks format and still uses
1597
        // a "hiddensections" format setting.
1687
        // a "hiddensections" format setting.
1598
        $course = $this->get_course();
1688
        $course = $this->get_course();
1599
        $hidesections = $course->hiddensections ?? true;
1689
        $hidesections = $course->hiddensections ?? true;
Línea 2092... Línea 2182...
2092
 
2182
 
2093
        // Duplicate the section modules, should they exist.
2183
        // Duplicate the section modules, should they exist.
2094
        if (array_key_exists($originalsection->section, $modinfo->sections)) {
2184
        if (array_key_exists($originalsection->section, $modinfo->sections)) {
2095
            foreach ($modinfo->sections[$originalsection->section] as $modnumber) {
2185
            foreach ($modinfo->sections[$originalsection->section] as $modnumber) {
-
 
2186
                $originalcm = $modinfo->cms[$modnumber];
-
 
2187
                // We don't want to duplicate any modules with the FEATURE_CAN_DISPLAY set to false.
-
 
2188
                // These mod types are always in section 0 so safe to say we are currently duplicating that section,
-
 
2189
                // and we don't want to inadvertantly duplicate mods we can't see.
-
 
2190
                if (!$originalcm->is_of_type_that_can_display()) {
-
 
2191
                    continue;
2096
                $originalcm = $modinfo->cms[$modnumber];
2192
                }
2097
                if (!$originalcm->deletioninprogress) {
2193
                if (!$originalcm->deletioninprogress) {
2098
                    duplicate_module($course, $originalcm, $newsection->id, false);
2194
                    duplicate_module($course, $originalcm, $newsection->id, false);
2099
                }
2195
                }
2100
            }
2196
            }
Línea 2119... Línea 2215...
2119
     * @return bool True if sections can be removed, false otherwise.
2215
     * @return bool True if sections can be removed, false otherwise.
2120
     */
2216
     */
2121
    public function can_sections_be_removed_from_navigation(): bool {
2217
    public function can_sections_be_removed_from_navigation(): bool {
2122
        return false;
2218
        return false;
2123
    }
2219
    }
-
 
2220
 
-
 
2221
    /**
-
 
2222
     * Determines whether the course module should display the activity editor options.
-
 
2223
     *
-
 
2224
     * @param cm_info $cm The activity module.
-
 
2225
     * @return bool True if the activity editor options are displayed, false otherwise.
-
 
2226
     */
-
 
2227
    public function show_activity_editor_options(cm_info $cm): bool {
-
 
2228
        if ($cm->get_delegated_section_info() && component_callback_exists('mod_' . $cm->modname, 'cm_info_view')) {
-
 
2229
            return false;
-
 
2230
        }
-
 
2231
        return true;
-
 
2232
    }
2124
}
2233
}