Proyectos de Subversion Moodle

Rev

Rev 1420 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1419 ariadna 1
<?php
2
defined('MOODLE_INTERNAL') || die();
3
 
4
require_once($CFG->dirroot . '/course/format/lib.php');
5
 
1420 ariadna 6
use core_courseformat\base as course_format;
7
 
1419 ariadna 8
/**
9
 * Main class for the Remui format.
10
 *
11
 * @package    format_remuiformat
12
 * @copyright  2024
13
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
14
 */
1420 ariadna 15
class format_remuiformat extends course_format
1419 ariadna 16
{
17
 
18
    /**
19
     * Creates a new instance of class
20
     *
21
     * Please use {@see course_get_format($courseorid)} to get an instance of the format class
22
     *
23
     * @param string $format
24
     * @param int $courseid
25
     * @return format_remuiformat
26
     */
27
    protected function __construct($format, $courseid)
28
    {
29
        parent::__construct($format, $courseid);
30
    }
31
 
32
    /**
33
     * Returns true if this course format uses sections
34
     *
35
     * @return bool
36
     */
37
    public function uses_sections()
38
    {
39
        return true;
40
    }
41
 
42
    /**
43
     * Returns the display name of the given section that the course prefers.
44
     *
45
     * @param int|stdClass $section Section object from database or just field section.section
46
     * @return string Display name that the course format prefers, e.g. "Topic 2"
47
     */
48
    public function get_section_name($section)
49
    {
50
        $section = $this->get_section($section);
51
        if ((string)$section->name !== '') {
52
            return format_string(
53
                $section->name,
54
                true,
1420 ariadna 55
                array('context' => \context_course::instance($this->courseid))
1419 ariadna 56
            );
57
        } else {
58
            return $this->get_default_section_name($section);
59
        }
60
    }
61
 
62
    /**
63
     * Returns the default section name for the remui format.
64
     *
65
     * @param stdClass $section Section object from database
66
     * @return string The default value for the section name.
67
     */
68
    public function get_default_section_name($section)
69
    {
70
        if ($section->section == 0) {
71
            return get_string('section0name', 'format_topics');
72
        } else {
73
            return get_string('topic') . ' ' . $section->section;
74
        }
75
    }
76
 
77
    /**
78
     * The URL to use for the specified course (with section)
79
     *
80
     * @param int|stdClass $section Section object from database or just field course_sections.section
81
     *     if omitted the course view page is returned
82
     * @param array $options options for view URL. At the moment core uses:
83
     *     'navigation' (bool) if true and section has no separate page, the function returns null
84
     *     'sr' (int) used by multipage formats to specify to which section to return
85
     * @return null|moodle_url
86
     */
87
    public function get_view_url($section, $options = array())
88
    {
89
        $course = $this->get_course();
90
        $url = new moodle_url('/course/view.php', array('id' => $course->id));
91
 
92
        $sr = null;
93
        if (array_key_exists('sr', $options)) {
94
            $sr = $options['sr'];
95
        }
96
        if (is_object($section)) {
97
            $sectionno = $section->section;
98
        } else {
99
            $sectionno = $section;
100
        }
101
        if ($sectionno !== null) {
102
            if ($sr !== null) {
103
                if ($sr) {
104
                    $usercoursedisplay = COURSE_DISPLAY_MULTIPAGE;
105
                    $sectionno = $sr;
106
                } else {
107
                    $usercoursedisplay = COURSE_DISPLAY_SINGLEPAGE;
108
                }
109
            } else {
110
                $usercoursedisplay = $course->coursedisplay;
111
            }
112
            if ($sectionno != 0 && $usercoursedisplay == COURSE_DISPLAY_MULTIPAGE) {
113
                $url->param('section', $sectionno);
114
            } else {
115
                if (empty($CFG->linkcoursesections) && !empty($options['navigation'])) {
116
                    return null;
117
                }
118
                $url->set_anchor('section-' . $sectionno);
119
            }
120
        }
121
        return $url;
122
    }
123
 
124
    /**
125
     * Definitions of the additional options that this course format uses for course
126
     *
127
     * @param bool $foreditform
128
     * @return array of options
129
     */
130
    public function course_format_options($foreditform = false)
131
    {
132
        static $courseformatoptions = false;
133
        if ($courseformatoptions === false) {
134
            $courseconfig = get_config('moodlecourse');
135
            $courseformatoptions = array(
136
                'hiddensections' => array(
137
                    'default' => $courseconfig->hiddensections,
138
                    'type' => PARAM_INT,
139
                ),
140
                'coursedisplay' => array(
141
                    'default' => $courseconfig->coursedisplay,
142
                    'type' => PARAM_INT,
143
                ),
144
            );
145
        }
146
        if ($foreditform && !isset($courseformatoptions['coursedisplay']['label'])) {
147
            $courseformatoptionsedit = array(
148
                'hiddensections' => array(
149
                    'label' => new lang_string('hiddensections'),
150
                    'help' => 'hiddensections',
151
                    'help_component' => 'moodle',
152
                    'element_type' => 'select',
153
                    'element_attributes' => array(
154
                        array(
155
 
156
                            1 => new lang_string('hiddensectionsinvisible')
157
                        )
158
                    ),
159
                ),
160
                'coursedisplay' => array(
161
                    'label' => new lang_string('coursedisplay'),
162
                    'element_type' => 'select',
163
                    'element_attributes' => array(
164
                        array(
165
                            COURSE_DISPLAY_SINGLEPAGE => new lang_string('coursedisplay_single'),
166
                            COURSE_DISPLAY_MULTIPAGE => new lang_string('coursedisplay_multi')
167
                        )
168
                    ),
169
                    'help' => 'coursedisplay',
170
                    'help_component' => 'moodle',
171
                )
172
            );
173
            $courseformatoptions = array_merge_recursive($courseformatoptions, $courseformatoptionsedit);
174
        }
175
        return $courseformatoptions;
176
    }
177
}