Commit | Line | Data |
---|---|---|
06cdda46 MG |
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 | * Bulk activity completion selection | |
19 | * | |
20 | * @package core_completion | |
21 | * @copyright 2017 Marina Glancy | |
22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
23 | */ | |
24 | ||
7f53e8aa | 25 | require_once(__DIR__ . "/../config.php"); |
06cdda46 MG |
26 | require_once($CFG->libdir . '/completionlib.php'); |
27 | ||
28 | $courseid = required_param('id', PARAM_INT); | |
29 | $cmids = optional_param_array('cmid', [], PARAM_INT); | |
30 | $course = get_course($courseid); | |
31 | require_login($course); | |
32 | ||
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'); | |
38 | ||
39 | if (!core_completion\manager::can_edit_bulk_completion($course)) { | |
a64a9f9c | 40 | require_capability('moodle/course:manageactivities', context_course::instance($course->id)); |
06cdda46 MG |
41 | } |
42 | ||
43 | // Prepare list of modules to be updated. | |
44 | $modinfo = get_fast_modinfo($courseid); | |
45 | $cms = []; | |
46 | foreach ($cmids as $cmid) { | |
47 | $cm = $modinfo->get_cm($cmid); | |
48 | if (core_completion\manager::can_edit_bulk_completion($course, $cm)) { | |
49 | $cms[$cm->id] = $cm; | |
50 | } | |
51 | } | |
52 | ||
53 | $returnurl = new moodle_url('/course/bulkcompletion.php', ['id' => $course->id]); | |
54 | $manager = new \core_completion\manager($course->id); | |
55 | if (empty($cms)) { | |
56 | redirect($returnurl); | |
57 | } | |
58 | $form = new core_completion_bulkedit_form(null, ['cms' => $cms]); | |
59 | ||
60 | if ($form->is_cancelled()) { | |
61 | redirect($returnurl); | |
62 | } else if ($data = $form->get_data()) { | |
63 | $manager->apply_completion($data, $form->has_custom_completion_rules()); | |
64 | redirect($returnurl); | |
65 | } | |
66 | ||
67 | $renderer = $PAGE->get_renderer('core_course', 'bulk_activity_completion'); | |
68 | ||
69 | echo $OUTPUT->header(); | |
7f53e8aa | 70 | echo $OUTPUT->heading(get_string('bulkactivitycompletion', 'completion')); |
06cdda46 | 71 | |
a64a9f9c | 72 | echo $renderer->navigation($course, 'bulkcompletion'); |
06cdda46 | 73 | |
7f53e8aa | 74 | echo $renderer->edit_bulk_completion($form, $manager->get_activities(array_keys($cms))); |
06cdda46 MG |
75 | |
76 | echo $OUTPUT->footer(); | |
77 |