Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 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
 * Page to view the course reports
19
 *
20
 * @package    core_grades
21
 * @subpackage report
22
 * @copyright  2021 Sujith Haridasan
23
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
 
26
require_once(__DIR__ . '/../../config.php');
27
 
28
use core\output\notification;
29
use core\url;
30
 
31
// Course id.
32
$contextid = required_param('contextid', PARAM_INT);
33
$cmid = optional_param('cm', null, PARAM_INT);
34
$recalculate = optional_param('recalculate', 0, PARAM_INT);
35
 
36
// Page URL.
37
$url = new moodle_url('/grade/penalty/view.php', ['contextid' => $contextid]);
38
if ($cmid !== null) {
39
    $url->param('cm', $cmid);
40
}
41
$PAGE->set_url($url);
42
 
43
$context = context::instance_by_id($contextid);
44
 
45
$courseid = $context->get_course_context()->instanceid;
46
$course = get_course($courseid);
47
 
48
$cm = null;
49
 
50
if (!is_null($cmid)) {
51
    $cm = get_coursemodule_from_id(null, $cmid, $course->id, false, MUST_EXIST);
52
}
53
 
54
require_login($course, false, $cm);
55
 
56
$PAGE->set_title(get_string('gradepenalty', 'core_grades'));
57
$PAGE->set_heading($course->fullname);
58
$PAGE->activityheader->disable();
59
 
60
// Check if the recalculate button is clicked.
61
if ($recalculate) {
62
    // Show message for user confirmation.
63
    $confirmurl = new url($url->out(), [
64
        'contextid' => $contextid,
65
        'recalculateconfirm' => 1,
66
        'sesskey' => sesskey(),
67
    ]);
68
    echo $OUTPUT->header();
69
    echo $OUTPUT->confirm(get_string('recalculatepenaltyconfirm', 'core_grades'), $confirmurl, $url);
70
    echo $OUTPUT->footer();
71
    die;
72
 
73
} else if (optional_param('recalculateconfirm', 0, PARAM_INT) && confirm_sesskey()) {
74
    \core_grades\penalty_manager::recalculate_penalty($context);
75
    redirect($url, get_string('recalculatepenaltysuccess', 'core_grades'), 0, notification::NOTIFY_SUCCESS);
76
}
77
 
78
// Show the page.
79
echo $OUTPUT->header();
80
echo $OUTPUT->heading(get_string('gradepenalty', 'core_grades'));
81
 
82
// Display the penalty recalculation button at course/module context.
83
if ($context->contextlevel == CONTEXT_COURSE || $context->contextlevel == CONTEXT_MODULE) {
84
    $buttonurl = $url;
85
    $buttonurl->params(['contextid' => $contextid, 'recalculate' => 1]);
86
    echo $OUTPUT->single_button($buttonurl, get_string('recalculatepenalty', 'core_grades'), 'get',
87
        ['type' => 'secondary']);
88
    // The empty paragraph is used as a spacer.
89
    echo $OUTPUT->paragraph('');
90
}
91
 
92
// Penalty plugins.
93
$haspenaltypluginnode = false;
94
if ($penaltynode = $PAGE->settingsnav->find('gradepenalty', \navigation_node::TYPE_CONTAINER)) {
95
    foreach ($penaltynode->children as $child) {
96
        if ($child->display) {
97
            $haspenaltypluginnode = true;
98
            break;
99
        }
100
    }
101
}
102
 
103
if ($haspenaltypluginnode) {
104
    echo $OUTPUT->heading(get_string('settings'));
105
 
106
    // Reuse the report link template.
107
    echo $OUTPUT->render_from_template('core/report_link_page', ['node' => $penaltynode]);
108
}
109
 
110
echo $OUTPUT->footer();