MDL-74741 javascript: A11y fix for dialogues visible from beginning
[moodle.git] / course / editdefaultcompletion.php
blob5ae3c27924ed32ad85c106ea5ce96581f8381efb
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.
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/>.
17 /**
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 $modids = optional_param_array('modids', [], 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/editdefaultcompletion.php', ['id' => $courseid]));
35 $PAGE->set_title($course->shortname);
36 $PAGE->set_heading($course->fullname);
37 $PAGE->set_pagelayout('admin');
39 require_capability('moodle/course:manageactivities', context_course::instance($course->id));
41 // Prepare list of selected modules.
42 $manager = new \core_completion\manager($course->id);
43 $allmodules = $manager->get_activities_and_resources();
44 $modules = [];
45 foreach ($allmodules->modules as $module) {
46 if ($module->canmanage && in_array($module->id, $modids)) {
47 $modules[$module->id] = $module;
51 $returnurl = new moodle_url('/course/defaultcompletion.php', ['id' => $course->id]);
52 if (empty($modules)) {
53 redirect($returnurl);
56 $form = new core_completion_defaultedit_form(null, ['course' => $course, 'modules' => $modules]);
58 if ($form->is_cancelled()) {
59 redirect($returnurl);
60 } else if ($data = $form->get_data()) {
61 $manager->apply_default_completion($data, $form->has_custom_completion_rules());
62 redirect($returnurl);
65 $renderer = $PAGE->get_renderer('core_course', 'bulk_activity_completion');
67 echo $OUTPUT->header();
68 echo $OUTPUT->heading(get_string('defaultcompletion', 'completion'));
70 echo $renderer->navigation($course, 'defaultcompletion');
72 echo $renderer->edit_default_completion($form, $modules);
74 echo $OUTPUT->footer();