2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * Bulk activity completion selection
20 * @package core_completion
21 * @copyright 2017 Marina Glancy
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require_once(__DIR__
. "/../config.php");
26 require_once($CFG->libdir
. '/completionlib.php');
28 $courseid = required_param('id', PARAM_INT
);
29 $cmids = optional_param_array('cmid', [], PARAM_INT
);
30 $course = get_course($courseid);
31 require_login($course);
33 navigation_node
::override_active_url(new moodle_url('/course/completion.php', array('id' => $course->id
)));
34 $PAGE->set_url(new moodle_url('/course/editbulkcompletion.php', ['id' => $courseid]));
35 $PAGE->set_title($course->shortname
);
36 $PAGE->set_heading($course->fullname
);
37 $PAGE->set_pagelayout('admin');
39 if (!core_completion\manager
::can_edit_bulk_completion($course)) {
40 require_capability('moodle/course:manageactivities', context_course
::instance($course->id
));
43 // Prepare list of modules to be updated.
44 $modinfo = get_fast_modinfo($courseid);
46 foreach ($cmids as $cmid) {
47 $cm = $modinfo->get_cm($cmid);
48 if (core_completion\manager
::can_edit_bulk_completion($course, $cm)) {
53 $returnurl = new moodle_url('/course/bulkcompletion.php', ['id' => $course->id
]);
54 $manager = new \core_completion\
manager($course->id
);
58 $form = new core_completion_bulkedit_form(null, ['cms' => $cms]);
60 if ($form->is_cancelled()) {
62 } else if ($data = $form->get_data()) {
63 $manager->apply_completion($data, $form->has_custom_completion_rules());
67 $renderer = $PAGE->get_renderer('core_course', 'bulk_activity_completion');
69 echo $OUTPUT->header();
70 echo $OUTPUT->heading(get_string('bulkactivitycompletion', 'completion'));
72 echo $renderer->navigation($course, 'bulkcompletion');
74 echo $renderer->edit_bulk_completion($form, $manager->get_activities(array_keys($cms)));
76 echo $OUTPUT->footer();