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 |
namespace gradepenalty_duedate\output;
|
|
|
18 |
|
|
|
19 |
use core_grades\output\action_bar;
|
|
|
20 |
use core\output\notification;
|
|
|
21 |
use core\output\single_button;
|
|
|
22 |
use core\url;
|
|
|
23 |
use gradepenalty_duedate\penalty_rule;
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* Renderable class for the action bar elements in the penalty rule page.
|
|
|
27 |
*
|
|
|
28 |
* @package gradepenalty_duedate
|
|
|
29 |
* @copyright 2024 Catalyst IT Australia Pty Ltd
|
|
|
30 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
31 |
*/
|
|
|
32 |
class view_penalty_rule_action_bar extends action_bar {
|
|
|
33 |
/** @var string $title The title of the page. */
|
|
|
34 |
protected string $title;
|
|
|
35 |
|
|
|
36 |
/** @var url $url The URL of the page. */
|
|
|
37 |
protected url $url;
|
|
|
38 |
|
|
|
39 |
/**
|
|
|
40 |
* Constructor.
|
|
|
41 |
*
|
|
|
42 |
* @param \context $context The context object.
|
|
|
43 |
* @param string $title The title of the page.
|
|
|
44 |
* @param url $url The URL of the page.
|
|
|
45 |
*/
|
|
|
46 |
public function __construct(\context $context, string $title, url $url) {
|
|
|
47 |
parent::__construct($context);
|
|
|
48 |
$this->title = $title;
|
|
|
49 |
$this->url = $url;
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
#[\Override]
|
|
|
53 |
public function get_template(): string {
|
|
|
54 |
return 'gradepenalty_duedate/view_penalty_rule_action_bar';
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
#[\Override]
|
|
|
58 |
public function export_for_template(\renderer_base $output): array {
|
|
|
59 |
$data = [];
|
|
|
60 |
|
|
|
61 |
$contextid = $this->context->id;
|
|
|
62 |
|
|
|
63 |
// Title.
|
|
|
64 |
$data['title'] = $output->heading($this->title);
|
|
|
65 |
|
|
|
66 |
// If the context is not system context, show the reset button when rules are overridden.
|
|
|
67 |
if (penalty_rule::is_overridden($contextid)) {
|
|
|
68 |
// Show information about the overridden rules.
|
|
|
69 |
$info = new notification(
|
|
|
70 |
get_string('penaltyrule_overridden', 'gradepenalty_duedate'),
|
|
|
71 |
notification::NOTIFY_INFO,
|
|
|
72 |
);
|
|
|
73 |
$data['info'] = $info->export_for_template($output);
|
|
|
74 |
|
|
|
75 |
// Reset button.
|
|
|
76 |
$reseturl = new url($this->url->out(), [
|
|
|
77 |
'contextid' => $contextid,
|
|
|
78 |
'reset' => 1,
|
|
|
79 |
]);
|
|
|
80 |
$resetbutton = new single_button($reseturl, get_string('reset'), 'get', single_button::BUTTON_DANGER);
|
|
|
81 |
$data['resetbutton'] = $resetbutton->export_for_template($output);
|
|
|
82 |
} else {
|
|
|
83 |
if (penalty_rule::is_inherited($contextid)) {
|
|
|
84 |
// Show information about the inherited rules.
|
|
|
85 |
$info = new notification(
|
|
|
86 |
get_string('penaltyrule_inherited', 'gradepenalty_duedate'),
|
|
|
87 |
notification::NOTIFY_INFO,
|
|
|
88 |
);
|
|
|
89 |
$data['info'] = $info->export_for_template($output);
|
|
|
90 |
} else {
|
|
|
91 |
// No rules from parent context.
|
|
|
92 |
$info = new notification(
|
|
|
93 |
get_string('penaltyrule_not_inherited', 'gradepenalty_duedate'),
|
|
|
94 |
notification::NOTIFY_INFO,
|
|
|
95 |
);
|
|
|
96 |
$data['info'] = $info->export_for_template($output);
|
|
|
97 |
}
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
// Edit button.
|
|
|
101 |
$editurl = new url($this->url->out(), [
|
|
|
102 |
'contextid' => $contextid,
|
|
|
103 |
'edit' => 1,
|
|
|
104 |
]);
|
|
|
105 |
$editbutton = new single_button($editurl, get_string('edit'), 'get', single_button::BUTTON_PRIMARY);
|
|
|
106 |
$data['editbutton'] = $editbutton->export_for_template($output);
|
|
|
107 |
|
|
|
108 |
return $data;
|
|
|
109 |
}
|
|
|
110 |
}
|