Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * Display a course section.
19
 *
20
 * @package     core_course
21
 * @copyright   2023 Sara Arjona <sara@moodle.com>
22
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
require_once('../config.php');
26
require_once('lib.php');
27
require_once($CFG->libdir.'/completionlib.php');
28
 
29
redirect_if_major_upgrade_required();
30
 
31
$sectionid = required_param('id', PARAM_INT);
32
// This parameter is used by the classic theme to force editing on.
33
$edit = optional_param('edit', -1, PARAM_BOOL);
34
 
35
$section = $DB->get_record('course_sections', ['id' => $sectionid], '*', MUST_EXIST);
36
 
37
// Defined here to avoid notices on errors.
38
$PAGE->set_url('/course/section.php', ['id' => $sectionid]);
39
 
40
if ($section->course == SITEID) {
41
    // The home page is not a real course.
42
    redirect($CFG->wwwroot .'/?redirect=0');
43
}
44
 
45
$course = get_course($section->course);
46
// Fix course format if it is no longer installed.
47
$format = course_get_format($course);
48
$course->format = $format->get_format();
49
$format->set_sectionid($section->id);
50
 
51
// When the course format doesn't support sections, redirect to course page.
52
if (!course_format_uses_sections($course->format)) {
53
    redirect(new moodle_url('/course/view.php', ['id' => $course->id]));
54
}
55
 
56
// Prevent caching of this page to stop confusion when changing page after making AJAX changes.
57
$PAGE->set_cacheable(false);
58
 
59
context_helper::preload_course($course->id);
60
$context = context_course::instance($course->id, MUST_EXIST);
61
 
62
require_login($course);
63
 
64
// Must set layout before getting section info. See MDL-47555.
65
$PAGE->set_pagelayout('course');
66
$PAGE->add_body_classes(['limitedwidth', 'single-section-page']);
67
 
68
// Get section details and check it exists.
69
$modinfo = get_fast_modinfo($course);
70
$sectioninfo = $modinfo->get_section_info($section->section, MUST_EXIST);
71
 
72
// Check user is allowed to see it.
73
if (!$sectioninfo->uservisible) {
74
    // Check if coursesection has conditions affecting availability and if
75
    // so, output availability info.
76
    if ($sectioninfo->visible && $sectioninfo->availableinfo) {
77
        $sectionname = get_section_name($course, $sectioninfo);
78
        $message = get_string('notavailablecourse', '', $sectionname);
79
        redirect(course_get_url($course), $message, null, \core\output\notification::NOTIFY_ERROR);
80
    } else {
81
        // Note: We actually already know they don't have this capability
82
        // or uservisible would have been true; this is just to get the
83
        // correct error message shown.
84
        require_capability('moodle/course:viewhiddensections', $context);
85
    }
86
}
87
 
88
$PAGE->set_pagetype('course-view-section-' . $course->format);
89
$PAGE->set_other_editing_capability('moodle/course:update');
90
$PAGE->set_other_editing_capability('moodle/course:manageactivities');
91
$PAGE->set_other_editing_capability('moodle/course:activityvisibility');
92
$PAGE->set_other_editing_capability('moodle/course:sectionvisibility');
93
$PAGE->set_other_editing_capability('moodle/course:movesections');
94
 
95
$renderer = $PAGE->get_renderer('format_' . $course->format);
96
 
97
// This is used by the Classic theme to change the editing mode based on the 'edit' parameter value.
98
if (!isset($USER->editing)) {
99
    $USER->editing = 0;
100
}
101
if ($PAGE->user_allowed_editing()) {
102
    if (($edit == 1) && confirm_sesskey()) {
103
        $USER->editing = 1;
104
        $url = new moodle_url($PAGE->url, ['notifyeditingon' => 1]);
105
        redirect($url);
106
    } else if (($edit == 0) && confirm_sesskey()) {
107
        $USER->editing = 0;
108
        if (!empty($USER->activitycopy) && $USER->activitycopycourse == $course->id) {
109
            $USER->activitycopy = false;
110
            $USER->activitycopycourse = null;
111
        }
112
        redirect($PAGE->url);
113
    }
114
}
115
 
116
// This is used by the Classic theme, to display the Turn editing on/off button.
117
// We are currently keeping the button here from 1.x to help new teachers figure out what to do, even though the link also appears
118
// in the course admin block. It also means you can back out of a situation where you removed the admin block.
119
if ($PAGE->user_allowed_editing()) {
120
    $buttons = $OUTPUT->edit_button($PAGE->url);
121
    $PAGE->set_button($buttons);
122
}
123
 
124
// Make the title more specific when editing, for accessibility reasons.
125
$editingtitle = '';
126
if ($PAGE->user_is_editing()) {
127
    $editingtitle = 'editing';
128
}
129
$sectionname = get_string('sectionname', "format_$course->format");
130
$sectiontitle = get_section_name($course, $section);
131
$PAGE->set_title(
132
    get_string(
133
        'coursesectiontitle' . $editingtitle,
134
        'moodle',
135
        ['course' => $course->fullname, 'sectiontitle' => $sectiontitle, 'sectionname' => $sectionname]
136
    )
137
);
138
 
139
// Add bulk editing control.
140
$bulkbutton = $renderer->bulk_editing_button($format);
141
if (!empty($bulkbutton)) {
142
    $PAGE->add_header_action($bulkbutton);
143
}
144
 
145
$outputclass = $format->get_output_classname('content');
146
/** @var \core_courseformat\output\local\content */
147
$sectionoutput = new $outputclass($format);
148
 
149
// Add to the header the control menu for the section.
150
if ($format->show_editor()) {
151
    $menu = $sectionoutput->get_page_header_action($renderer);
152
    if ($menu) {
153
        $PAGE->add_header_action($menu);
154
    }
155
    $sectionheading = $OUTPUT->container(
156
        $OUTPUT->render($format->inplace_editable_render_section_name($sectioninfo, false)),
157
        attributes: ['data-for' => 'section_title'],
158
    );
159
    $PAGE->set_heading($sectionheading, false, false);
160
} else {
161
    $PAGE->set_heading($sectiontitle);
162
}
163
 
164
$PAGE->set_secondary_navigation(false);
165
 
166
echo $OUTPUT->header();
167
 
168
// Show communication room status notification.
169
if (core_communication\api::is_available() && has_capability('moodle/course:update', $context)) {
170
    $communication = \core_communication\api::load_by_instance(
171
        $context,
172
        'core_course',
173
        'coursecommunication',
174
        $course->id
175
    );
176
    $communication->show_communication_room_status_notification();
177
}
178
 
179
// Display a warning if asynchronous backups are pending for this course.
180
if ($PAGE->user_is_editing()) {
181
    require_once($CFG->dirroot . '/backup/util/helper/async_helper.class.php');
182
    if (async_helper::is_async_pending($course->id, 'course', 'backup')) {
183
        echo $OUTPUT->notification(get_string('pendingasyncedit', 'backup'), 'warning');
184
    }
185
}
186
 
187
echo $renderer->container_start('course-content');
188
 
189
// Include course AJAX.
190
include_course_ajax($course, $modinfo->get_used_module_names());
191
 
192
echo $renderer->render($sectionoutput);
193
 
194
// Include course format javascript files.
195
$jsfiles = $format->get_required_jsfiles();
196
foreach ($jsfiles as $jsfile) {
197
    $PAGE->requires->js($jsfile);
198
}
199
 
200
echo $renderer->container_end();
201
 
202
// Trigger section viewed event.
203
course_section_view($context, $sectionid);
204
 
205
// Load the view JS module if completion tracking is enabled for this course.
206
$completion = new completion_info($course);
207
if ($completion->is_enabled()) {
208
    $PAGE->requires->js_call_amd('core_course/view', 'init');
209
}
210
 
211
echo $OUTPUT->footer();