Proyectos de Subversion Moodle

Rev

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