Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | 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
 
1441 ariadna 35
if (!$section = $DB->get_record('course_sections', ['id' => $sectionid], '*')) {
36
    $url = new moodle_url('/');
37
    $PAGE->set_context(\core\context\system::instance());
38
    $PAGE->set_url($url);
39
    $PAGE->set_pagelayout('course');
40
    $PAGE->add_body_classes(['limitedwidth', 'single-section-page']);
41
    $PAGE->set_title(get_string('notfound', 'error'));
42
    $PAGE->set_heading($SITE->fullname);
43
    echo $OUTPUT->header();
1 efrain 44
 
1441 ariadna 45
    $errortext = new \core\output\notification(
46
            get_string('sectioncantbefound', 'error'),
47
            \core\output\notification::NOTIFY_ERROR
48
    );
49
    echo $OUTPUT->render($errortext);
50
 
51
    $button = new single_button($url, get_string('gobacktosite'), 'get', single_button::BUTTON_PRIMARY);
52
    $button->class = 'continuebutton';
53
    echo $OUTPUT->render($button);
54
 
55
    echo $OUTPUT->footer();
56
    die();
57
}
58
 
1 efrain 59
// Defined here to avoid notices on errors.
60
$PAGE->set_url('/course/section.php', ['id' => $sectionid]);
61
 
62
if ($section->course == SITEID) {
63
    // The home page is not a real course.
64
    redirect($CFG->wwwroot .'/?redirect=0');
65
}
66
 
67
$course = get_course($section->course);
68
// Fix course format if it is no longer installed.
69
$format = course_get_format($course);
70
$course->format = $format->get_format();
71
$format->set_sectionid($section->id);
72
 
73
// When the course format doesn't support sections, redirect to course page.
74
if (!course_format_uses_sections($course->format)) {
75
    redirect(new moodle_url('/course/view.php', ['id' => $course->id]));
76
}
77
 
78
// Prevent caching of this page to stop confusion when changing page after making AJAX changes.
79
$PAGE->set_cacheable(false);
80
 
81
context_helper::preload_course($course->id);
82
$context = context_course::instance($course->id, MUST_EXIST);
83
 
84
require_login($course);
85
 
86
// Must set layout before getting section info. See MDL-47555.
87
$PAGE->set_pagelayout('course');
88
$PAGE->add_body_classes(['limitedwidth', 'single-section-page']);
89
 
90
// Get section details and check it exists.
91
$modinfo = get_fast_modinfo($course);
92
$sectioninfo = $modinfo->get_section_info($section->section, MUST_EXIST);
93
 
94
// Check user is allowed to see it.
95
if (!$sectioninfo->uservisible) {
96
    // Check if coursesection has conditions affecting availability and if
97
    // so, output availability info.
98
    if ($sectioninfo->visible && $sectioninfo->availableinfo) {
99
        $sectionname = get_section_name($course, $sectioninfo);
100
        $message = get_string('notavailablecourse', '', $sectionname);
101
        redirect(course_get_url($course), $message, null, \core\output\notification::NOTIFY_ERROR);
102
    } else {
103
        // Note: We actually already know they don't have this capability
104
        // or uservisible would have been true; this is just to get the
105
        // correct error message shown.
106
        require_capability('moodle/course:viewhiddensections', $context);
107
    }
108
}
109
 
110
$PAGE->set_pagetype('course-view-section-' . $course->format);
111
$PAGE->set_other_editing_capability('moodle/course:update');
112
$PAGE->set_other_editing_capability('moodle/course:manageactivities');
113
$PAGE->set_other_editing_capability('moodle/course:activityvisibility');
114
$PAGE->set_other_editing_capability('moodle/course:sectionvisibility');
115
$PAGE->set_other_editing_capability('moodle/course:movesections');
116
 
117
$renderer = $PAGE->get_renderer('format_' . $course->format);
118
 
119
// This is used by the Classic theme to change the editing mode based on the 'edit' parameter value.
120
if (!isset($USER->editing)) {
121
    $USER->editing = 0;
122
}
123
if ($PAGE->user_allowed_editing()) {
124
    if (($edit == 1) && confirm_sesskey()) {
125
        $USER->editing = 1;
126
        $url = new moodle_url($PAGE->url, ['notifyeditingon' => 1]);
127
        redirect($url);
128
    } else if (($edit == 0) && confirm_sesskey()) {
129
        $USER->editing = 0;
130
        if (!empty($USER->activitycopy) && $USER->activitycopycourse == $course->id) {
131
            $USER->activitycopy = false;
132
            $USER->activitycopycourse = null;
133
        }
134
        redirect($PAGE->url);
135
    }
136
}
137
 
138
// This is used by the Classic theme, to display the Turn editing on/off button.
139
// 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
140
// in the course admin block. It also means you can back out of a situation where you removed the admin block.
141
if ($PAGE->user_allowed_editing()) {
142
    $buttons = $OUTPUT->edit_button($PAGE->url);
143
    $PAGE->set_button($buttons);
144
}
145
 
146
// Make the title more specific when editing, for accessibility reasons.
147
$editingtitle = '';
148
if ($PAGE->user_is_editing()) {
149
    $editingtitle = 'editing';
150
}
1441 ariadna 151
$sectionname = $format->get_generic_section_name();
152
$sectiontitle = $format->get_section_name($section);
1 efrain 153
$PAGE->set_title(
154
    get_string(
155
        'coursesectiontitle' . $editingtitle,
156
        'moodle',
157
        ['course' => $course->fullname, 'sectiontitle' => $sectiontitle, 'sectionname' => $sectionname]
158
    )
159
);
160
 
161
// Add bulk editing control.
162
$bulkbutton = $renderer->bulk_editing_button($format);
163
if (!empty($bulkbutton)) {
164
    $PAGE->add_header_action($bulkbutton);
165
}
166
 
167
$outputclass = $format->get_output_classname('content');
168
/** @var \core_courseformat\output\local\content */
169
$sectionoutput = new $outputclass($format);
170
 
171
// Add to the header the control menu for the section.
172
if ($format->show_editor()) {
173
    $menu = $sectionoutput->get_page_header_action($renderer);
174
    if ($menu) {
175
        $PAGE->add_header_action($menu);
176
    }
177
    $sectionheading = $OUTPUT->container(
178
        $OUTPUT->render($format->inplace_editable_render_section_name($sectioninfo, false)),
179
        attributes: ['data-for' => 'section_title'],
180
    );
181
    $PAGE->set_heading($sectionheading, false, false);
182
} else {
183
    $PAGE->set_heading($sectiontitle);
184
}
185
 
186
$PAGE->set_secondary_navigation(false);
187
 
188
echo $OUTPUT->header();
189
 
190
// Show communication room status notification.
191
if (core_communication\api::is_available() && has_capability('moodle/course:update', $context)) {
192
    $communication = \core_communication\api::load_by_instance(
193
        $context,
194
        'core_course',
195
        'coursecommunication',
196
        $course->id
197
    );
198
    $communication->show_communication_room_status_notification();
199
}
200
 
1441 ariadna 201
$containerattributes = [];
1 efrain 202
if ($PAGE->user_is_editing()) {
203
    require_once($CFG->dirroot . '/backup/util/helper/async_helper.class.php');
1441 ariadna 204
    // Display a warning if asynchronous backups are pending for this course.
1 efrain 205
    if (async_helper::is_async_pending($course->id, 'course', 'backup')) {
206
        echo $OUTPUT->notification(get_string('pendingasyncedit', 'backup'), 'warning');
207
    }
1441 ariadna 208
 
209
    // Allow drag and drop in the course index.
210
    $containerattributes = [
211
        'data-courseindexdndallowed' => 'true',
212
    ];
1 efrain 213
}
214
 
1441 ariadna 215
echo $renderer->container_start('course-content', attributes: $containerattributes);
1 efrain 216
 
217
// Include course AJAX.
218
include_course_ajax($course, $modinfo->get_used_module_names());
219
 
220
echo $renderer->render($sectionoutput);
221
 
222
// Include course format javascript files.
223
$jsfiles = $format->get_required_jsfiles();
224
foreach ($jsfiles as $jsfile) {
225
    $PAGE->requires->js($jsfile);
226
}
227
 
228
echo $renderer->container_end();
229
 
230
// Trigger section viewed event.
231
course_section_view($context, $sectionid);
232
 
233
// Load the view JS module if completion tracking is enabled for this course.
234
$completion = new completion_info($course);
235
if ($completion->is_enabled()) {
236
    $PAGE->requires->js_call_amd('core_course/view', 'init');
237
}
238
 
239
echo $OUTPUT->footer();