MDL-67264 core_course: Begin set up for Activity chooser
[moodle.git] / course / bulkcompletion.php
CommitLineData
0b620801 1<?php
0b620801
AG
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 * Bulk activity completion selection
19 *
20 * @package core_completion
21 * @category completion
22 * @copyright 2017 Adrian Greeve
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
26require_once(__DIR__.'/../config.php');
27require_once($CFG->dirroot.'/course/lib.php');
28require_once($CFG->libdir.'/completionlib.php');
29
b17ee682 30$id = required_param('id', PARAM_INT); // Course id.
0b620801
AG
31$cmids = optional_param_array('cmid', [], PARAM_INT);
32
33// Perform some basic access control checks.
34if ($id) {
35
b17ee682 36 if ($id == SITEID) {
0b620801
AG
37 // Don't allow editing of 'site course' using this form.
38 print_error('cannoteditsiteform');
39 }
40
41 if (!$course = $DB->get_record('course', array('id' => $id))) {
42 print_error('invalidcourseid');
43 }
44 require_login($course);
0b620801
AG
45
46} else {
47 require_login();
48 print_error('needcourseid');
49}
50
51// Set up the page.
0cbc248d 52navigation_node::override_active_url(new moodle_url('/course/completion.php', array('id' => $course->id)));
0b620801
AG
53$PAGE->set_course($course);
54$PAGE->set_url('/course/bulkcompletion.php', array('id' => $course->id));
55$PAGE->set_title($course->shortname);
56$PAGE->set_heading($course->fullname);
57$PAGE->set_pagelayout('admin');
58
a64a9f9c 59// Check access.
0cbc248d 60if (!core_completion\manager::can_edit_bulk_completion($id)) {
a64a9f9c 61 require_capability('moodle/course:manageactivities', context_course::instance($course->id));
0cbc248d
MG
62}
63
a64a9f9c 64// Get all that stuff I need for the renderer.
0b620801
AG
65$manager = new \core_completion\manager($id);
66$bulkcompletiondata = $manager->get_activities_and_headings();
67
68$renderer = $PAGE->get_renderer('core_course', 'bulk_activity_completion');
69
70// Print the form.
71echo $OUTPUT->header();
7f53e8aa 72echo $OUTPUT->heading(get_string('bulkactivitycompletion', 'completion'));
0b620801 73
a64a9f9c 74echo $renderer->navigation($course, 'bulkcompletion');
0b620801 75
6e605119
AG
76$PAGE->requires->yui_module('moodle-core-formchangechecker',
77 'M.core_formchangechecker.init',
78 array(array(
79 'formid' => 'theform'
80 ))
81);
82$PAGE->requires->string_for_js('changesmadereallygoaway', 'moodle');
83
84
0b620801
AG
85echo $renderer->bulkcompletion($bulkcompletiondata);
86
87echo $OUTPUT->footer();