| 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 |
* Class that represents the exclude checkbox on a grade_grade.
|
|
|
19 |
*
|
|
|
20 |
* @package gradereport_singleview
|
|
|
21 |
* @copyright 2014 Moodle Pty Ltd (http://moodle.com)
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
namespace gradereport_singleview\local\ui;
|
|
|
26 |
|
|
|
27 |
defined('MOODLE_INTERNAL') || die;
|
|
|
28 |
|
| 1441 |
ariadna |
29 |
use context_course;
|
| 1 |
efrain |
30 |
use grade_grade;
|
|
|
31 |
|
|
|
32 |
/**
|
|
|
33 |
* Class that represents the exclude checkbox on a grade_grade.
|
|
|
34 |
*
|
|
|
35 |
* @package gradereport_singleview
|
|
|
36 |
* @copyright 2014 Moodle Pty Ltd (http://moodle.com)
|
|
|
37 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
38 |
*/
|
|
|
39 |
class exclude extends grade_attribute_format implements be_checked, be_disabled, be_readonly {
|
|
|
40 |
|
|
|
41 |
/**
|
|
|
42 |
* The name of the input
|
|
|
43 |
* @var string $name
|
|
|
44 |
*/
|
|
|
45 |
public $name = 'exclude';
|
|
|
46 |
|
|
|
47 |
/**
|
|
|
48 |
* Is the checkbox disabled?
|
|
|
49 |
* @var bool $disabled
|
|
|
50 |
*/
|
|
|
51 |
public $disabled = false;
|
|
|
52 |
|
|
|
53 |
/**
|
|
|
54 |
* Is it checked?
|
|
|
55 |
*
|
|
|
56 |
* @return bool
|
|
|
57 |
*/
|
|
|
58 |
public function is_checked(): bool {
|
|
|
59 |
return $this->grade->is_excluded();
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
/**
|
|
|
63 |
* Is it disabled?
|
|
|
64 |
*
|
|
|
65 |
* @return bool
|
|
|
66 |
*/
|
|
|
67 |
public function is_disabled(): bool {
|
|
|
68 |
return $this->disabled;
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
/**
|
|
|
72 |
* Return true if this is read-only.
|
|
|
73 |
*
|
|
|
74 |
* @return bool
|
|
|
75 |
*/
|
|
|
76 |
public function is_readonly(): bool {
|
|
|
77 |
global $USER;
|
|
|
78 |
return empty($USER->editing);
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
/**
|
|
|
82 |
* Generate the element used to render the UI
|
|
|
83 |
*
|
|
|
84 |
* @return element
|
|
|
85 |
*/
|
|
|
86 |
public function determine_format(): element {
|
| 1441 |
ariadna |
87 |
if (($this->grade->is_hidden() || $this->grade->grade_item->is_hidden()) &&
|
|
|
88 |
!has_capability('moodle/grade:viewhidden', context_course::instance($this->grade->grade_item->courseid))) {
|
|
|
89 |
return new empty_element();
|
|
|
90 |
}
|
| 1 |
efrain |
91 |
return new checkbox_attribute(
|
|
|
92 |
$this->get_name(),
|
|
|
93 |
$this->get_label(),
|
|
|
94 |
$this->is_checked(),
|
|
|
95 |
$this->is_disabled(),
|
|
|
96 |
$this->is_readonly()
|
|
|
97 |
);
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
/**
|
|
|
101 |
* Get the label for the form input
|
|
|
102 |
*
|
|
|
103 |
* @return string
|
|
|
104 |
*/
|
|
|
105 |
public function get_label(): string {
|
|
|
106 |
if (!isset($this->grade->label)) {
|
|
|
107 |
$this->grade->label = '';
|
|
|
108 |
}
|
|
|
109 |
return $this->grade->label;
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
/**
|
|
|
113 |
* Set the value that was changed in the form.
|
|
|
114 |
*
|
|
|
115 |
* @param string $value The value to set.
|
|
|
116 |
* @return mixed string|bool An error message or false.
|
|
|
117 |
*/
|
|
|
118 |
public function set($value) {
|
|
|
119 |
if (empty($this->grade->id)) {
|
|
|
120 |
if (empty($value)) {
|
|
|
121 |
return false;
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
$gradeitem = $this->grade->grade_item;
|
|
|
125 |
|
|
|
126 |
// Fill in arbitrary grade to be excluded.
|
|
|
127 |
$gradeitem->update_final_grade(
|
|
|
128 |
$this->grade->userid, null, 'singleview', null, FORMAT_MOODLE
|
|
|
129 |
);
|
|
|
130 |
|
|
|
131 |
$gradeparams = [
|
|
|
132 |
'userid' => $this->grade->userid,
|
|
|
133 |
'itemid' => $this->grade->itemid
|
|
|
134 |
];
|
|
|
135 |
|
|
|
136 |
$this->grade = grade_grade::fetch($gradeparams);
|
|
|
137 |
$this->grade->grade_item = $gradeitem;
|
|
|
138 |
}
|
|
|
139 |
|
|
|
140 |
$state = !($value == 0);
|
|
|
141 |
|
|
|
142 |
$this->grade->set_excluded($state);
|
|
|
143 |
|
|
|
144 |
$this->grade->grade_item->get_parent_category()->force_regrading();
|
|
|
145 |
return false;
|
|
|
146 |
}
|
|
|
147 |
}
|