Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
 * @category    completion
22
 * @copyright   2017 Adrian Greeve
23
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
 
26
require_once(__DIR__.'/../config.php');
27
require_once($CFG->dirroot.'/course/lib.php');
28
require_once($CFG->libdir.'/completionlib.php');
29
 
30
$id = required_param('id', PARAM_INT);       // Course id.
31
$modids = optional_param_array('modids', [], PARAM_INT);
32
 
33
if ($id) {
34
    if (!$course = $DB->get_record('course', array('id' => $id))) {
35
        throw new \moodle_exception('invalidcourseid');
36
    }
37
}
38
 
39
if ($id == SITEID) {
40
    $context = context_system::instance();
41
    $title = get_string('defaultcompletion', 'completion');
42
    $heading = format_string($SITE->fullname, true, ['context' => $context]);
43
} else {
44
    $context = context_course::instance($id);
45
    $title = $course->shortname;
46
    $heading = $course->fullname;
47
}
48
require_login($course);
49
require_capability('moodle/course:manageactivities', $context);
50
 
51
// Set up the page.
52
if ($id != SITEID) {
53
    navigation_node::override_active_url(new moodle_url('/course/completion.php', array('id' => $course->id)));
54
    $PAGE->set_course($course);
55
}
56
$PAGE->set_url('/course/defaultcompletion.php', ['id' => $id]);
57
$PAGE->set_context($context);
58
$PAGE->set_pagelayout('admin');
59
$PAGE->set_title($title);
60
$PAGE->set_heading($heading);
61
 
62
 
63
// Get list of modules that have been sent in the form.
64
$manager = new \core_completion\manager($course->id);
65
$allmodules = $manager->get_activities_and_resources(false);
66
$modules = [];
67
foreach ($allmodules->modules as $module) {
68
    if ($module->canmanage && in_array($module->id, $modids)) {
69
        $modules[$module->id] = $module;
70
    }
71
}
72
 
73
$form = null;
74
if (!empty($modules)) {
75
    $form = new core_completion_defaultedit_form(
76
        null,
77
        ['course' => $course, 'modules' => $modules, 'displaycancel' => false, 'forceuniqueid' => true]
78
    );
79
    if (!$form->is_cancelled() && $data = $form->get_data()) {
80
        $data->modules = $modules;
81
        $manager->apply_default_completion($data, $form->has_custom_completion_rules(), $form->get_suffix());
82
    }
83
}
84
 
85
$renderer = $PAGE->get_renderer('core_course', 'bulk_activity_completion');
86
 
87
// Print the form.
88
echo $renderer->header();
89
 
90
if ($id == SITEID) {
91
    echo $renderer->heading($title);
92
} else {
93
    $actionbar = new \core_course\output\completion_action_bar($course->id, $PAGE->url);
94
    echo $renderer->render_course_completion_action_bar($actionbar);
95
}
96
 
97
echo $renderer->defaultcompletion($allmodules, $modules, $form);
98
 
99
echo $OUTPUT->footer();