-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathassessor_feedback_row.php
241 lines (208 loc) · 5.73 KB
/
assessor_feedback_row.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @package mod_coursework
* @copyright 2017 University of London Computer Centre {@link https://www.cosector.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_coursework;
use mod_coursework\allocation\allocatable;
use mod_coursework\models\coursework;
use mod_coursework\models\submission;
use mod_coursework\models\user;
use mod_coursework\stages\base as stage_base;
defined('MOODLE_INTERNAL') || die();
/**
* Class that exists to tell the renderer to use a different function. This one will make the
* feedback into a row in the assessor feedbacks table of the grading report.
*/
class assessor_feedback_row {
/**
* @var int So we can have a row with no feedback, but still see who is allocated to mark it.
*/
private $assessorid;
/**
* @var models\submission|null
*/
private $submission;
/**
* @var stage_base
*/
private $stage;
/**
* @var allocatable
*/
private $allocatable;
/**
* @var coursework
*/
private $coursework;
/**
* @param stage_base $stage
* @param allocatable $allocatable
* @param coursework $coursework
*/
public function __construct($stage, $allocatable, $coursework) {
$this->stage = $stage;
$this->allocatable = $allocatable;
$this->coursework = $coursework;
}
/**
* Lets us know if the current user was the author of this bit of feedback.
*
* @return bool
*/
public function user_is_assessor() {
global $USER;
return $this->get_assessor_id() == $USER->id;
}
/**
* Chained getter for loose coupling.
*
* @return string
*/
public function get_assessor_username() {
return $this->get_stage()->get_allocated_assessor_name($this->get_allocatable());
}
/**
* Gets the assessor id from the feedback.
*
* @return mixed
*/
public function get_assessor_id() {
return $this->assessorid;
}
/**
* Gets the assessor from the feedback.
*
* @return user
*/
public function get_assessor() {
if (!$this->get_coursework()->allocation_enabled() && $this->has_feedback()) {
return $this->get_feedback()->assessor();
}
return $this->get_stage()->get_allocated_assessor($this->allocatable);
}
/**
* Gets the assessor id from the feedback
*
* @return user
*/
public function get_graded_by() {
return $this->get_feedback()->assessor();
}
/**
* Gets the grader's name and link to the profile
* @return string
*/
public function get_graders_name() {
return $this->get_graded_by()->profile_link();
}
/**
* @return models\coursework
*/
public function get_coursework() {
return $this->coursework;
}
/**
* Chained getter for loose coupling.
*
* @return int
*/
public function get_grade() {
if (!$this->has_feedback()) {
return null;
}
return $this->get_feedback()->get_grade();
}
/**
* Returns the maximum grade that this coursework will allow for a feedback.
*/
public function get_max_grade() {
return $this->get_coursework()->get_max_grade();
}
/**
* When was this feedback last altered?
*
* @return mixed
*/
public function get_time_modified() {
return $this->get_feedback()->timemodified;
}
/**
* Admins may see the feedback placeholder rows before there is anything to display.
*
* @return bool
*/
public function has_feedback(): bool {
return (bool)$this->get_feedback();
}
/**
* Getter
*
* @return models\feedback|null
*/
public function get_feedback() {
return $this->stage->get_feedback_for_allocatable($this->allocatable);
}
/**
* Getter
*
* @return models\submission|null
*/
public function get_submission() {
if (isset($this->submission)) {
return $this->submission;
}
$params = [
'courseworkid' => $this->get_coursework()->id,
'allocatableid' => $this->get_allocatable()->id(),
'allocatabletype' => $this->get_allocatable()->type(),
];
$this->submission = submission::find($params);
return $this->submission;
}
/**
* @return bool
*/
public function has_submission(): bool {
return (bool)$this->get_submission();
}
/**
* @return stage_base
*/
public function get_stage() {
return $this->stage;
}
/**
* @return allocatable
*/
public function get_allocatable() {
return $this->allocatable;
}
/**
* @return bool|models\allocation
*/
private function get_allocation() {
return $this->stage->get_allocation($this->get_allocatable());
}
/**
* @return bool
*/
private function has_allocation(): bool {
return (bool)$this->get_allocation();
}
}