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 |
* The gradepenalty_duedate lib file.
|
|
|
19 |
*
|
|
|
20 |
* @package gradepenalty_duedate
|
|
|
21 |
* @copyright 2024 Catalyst IT Australia Pty Ltd
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
use core\url;
|
|
|
26 |
|
|
|
27 |
/**
|
|
|
28 |
* Extend the course navigation with a penalty rule settings.
|
|
|
29 |
*
|
|
|
30 |
* @param navigation_node $navigation The settings navigation object
|
|
|
31 |
* @param stdClass $course The course
|
|
|
32 |
* @param context $context Course context
|
|
|
33 |
* @return void
|
|
|
34 |
*/
|
|
|
35 |
function gradepenalty_duedate_extend_navigation_course(navigation_node $navigation, stdClass $course, context $context): void {
|
|
|
36 |
if (has_capability('gradepenalty/duedate:manage', $context)) {
|
|
|
37 |
$url = new url('/grade/penalty/duedate/manage_penalty_rule.php', ['contextid' => $context->id]);
|
|
|
38 |
$name = get_string('penaltyrule', 'gradepenalty_duedate');
|
|
|
39 |
$navigation->add($name, $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/settings', ''));
|
|
|
40 |
}
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
* Extend the module navigation with a penalty rule settings.
|
|
|
45 |
*
|
|
|
46 |
* @param navigation_node $navigation The settings navigation object
|
|
|
47 |
* @param cm_info $cm The course module
|
|
|
48 |
* @return void
|
|
|
49 |
*/
|
|
|
50 |
function gradepenalty_duedate_extend_navigation_module(navigation_node $navigation, cm_info $cm): void {
|
|
|
51 |
$context = context_module::instance($cm->id);
|
|
|
52 |
if (has_capability('gradepenalty/duedate:manage', $context)) {
|
|
|
53 |
$url = new url('/grade/penalty/duedate/manage_penalty_rule.php', ['contextid' => $context->id]);
|
|
|
54 |
$name = get_string('penaltyrule', 'gradepenalty_duedate');
|
|
|
55 |
$navigation->add($name, $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/settings', ''));
|
|
|
56 |
}
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
/**
|
|
|
60 |
* Load penalty rule form.
|
|
|
61 |
*
|
|
|
62 |
* @param array $args parameters to load the form
|
|
|
63 |
* @return string html and js of the form
|
|
|
64 |
*/
|
|
|
65 |
function gradepenalty_duedate_output_fragment_penalty_rule_form(array $args): string {
|
|
|
66 |
$context = $args['context'];
|
|
|
67 |
|
|
|
68 |
$params = [
|
|
|
69 |
'contextid' => $context->id,
|
|
|
70 |
'action' => new url('/grade/penalty/duedate/manage_penalty_rule.php', ['contextid' => $context->id]),
|
|
|
71 |
'penaltyrules' => json_decode($args['penaltyrules'], true),
|
|
|
72 |
'finalpenaltyrule' => $args['finalpenaltyrule'],
|
|
|
73 |
];
|
|
|
74 |
|
|
|
75 |
// Load edit penalty form.
|
|
|
76 |
$form = new gradepenalty_duedate\output\form\edit_penalty_form($params['action'], $params);
|
|
|
77 |
|
|
|
78 |
// Return html and js.
|
|
|
79 |
return $form->render();
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
/**
|
|
|
83 |
* Define the setting page for the penalty rule.
|
|
|
84 |
*/
|
|
|
85 |
function gradepenalty_duedate_get_settings_url(): url {
|
|
|
86 |
return new url('/grade/penalty/duedate/manage_penalty_rule.php', [
|
|
|
87 |
'contextid' => \core\context\system::instance()->id,
|
|
|
88 |
]);
|
|
|
89 |
}
|