MDL-67264 core_course: Activity chooser new feature
[moodle.git] / course / editdefaultcompletion.php
CommitLineData
7f53e8aa
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
25require_once(__DIR__ . "/../config.php");
26require_once($CFG->libdir . '/completionlib.php');
27
28$courseid = required_param('id', PARAM_INT);
29$modids = optional_param_array('modids', [], PARAM_INT);
30$course = get_course($courseid);
31require_login($course);
32
33navigation_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');
38
4088416c 39require_capability('moodle/course:manageactivities', context_course::instance($course->id));
7f53e8aa
MG
40
41// Prepare list of selected modules.
42$manager = new \core_completion\manager($course->id);
43$allmodules = $manager->get_activities_and_resources();
44$modules = [];
45foreach ($allmodules->modules as $module) {
46 if ($module->canmanage && in_array($module->id, $modids)) {
47 $modules[$module->id] = $module;
48 }
49}
50
51$returnurl = new moodle_url('/course/defaultcompletion.php', ['id' => $course->id]);
52if (empty($modules)) {
53 redirect($returnurl);
54}
55
56$form = new core_completion_defaultedit_form(null, ['course' => $course, 'modules' => $modules]);
57
58if ($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);
63}
64
65$renderer = $PAGE->get_renderer('core_course', 'bulk_activity_completion');
66
67echo $OUTPUT->header();
68echo $OUTPUT->heading(get_string('defaultcompletion', 'completion'));
69
a64a9f9c 70echo $renderer->navigation($course, 'defaultcompletion');
7f53e8aa
MG
71
72echo $renderer->edit_default_completion($form, $modules);
73
74echo $OUTPUT->footer();
75