@@ -34,11 +34,21 @@ class block_my_feedback extends block_base {
34
34
*/
35
35
private static array $ markerroles ;
36
36
37
+ /**
38
+ * @var array array of roles a marker may have.
39
+ */
40
+ private static array $ studentroles ;
41
+
37
42
/**
38
43
* @var bool marker status.
39
44
*/
40
45
private static bool $ ismarker ;
41
46
47
+ /**
48
+ * @var bool student status.
49
+ */
50
+ private static bool $ isstudent ;
51
+
42
52
/**
43
53
* Initialises the block.
44
54
*
@@ -48,15 +58,12 @@ public function init() {
48
58
global $ USER ;
49
59
50
60
self ::$ markerroles = self ::get_marker_role_ids ();
61
+ self ::$ studentroles = self ::get_student_role_ids ();
51
62
self ::$ ismarker = self ::is_marker ();
63
+ self ::$ isstudent = self ::is_student ();
52
64
53
- if (!isset ($ USER ->firstname )) {
54
- $ this ->title = get_string ('pluginname ' , 'block_my_feedback ' );
55
- } else if (self ::$ ismarker ) {
56
- $ this ->title = get_string ('markingfor ' , 'block_my_feedback ' ).' ' .$ USER ->firstname ;
57
- } else {
58
- $ this ->title = get_string ('feedbackfor ' , 'block_my_feedback ' ).' ' .$ USER ->firstname ;
59
- }
65
+ // No title for the block as each section will have one.
66
+ $ this ->title = '' ;
60
67
}
61
68
62
69
/**
@@ -78,6 +85,22 @@ private static function get_marker_role_ids(): array {
78
85
);
79
86
}
80
87
88
+ /**
89
+ * Get the marker role IDs.
90
+ *
91
+ * @return array
92
+ */
93
+ private static function get_student_role_ids (): array {
94
+ global $ DB ;
95
+
96
+ return $ DB ->get_fieldset_select ('role ' , 'id ' ,
97
+ 'shortname IN (:role1) ' ,
98
+ [
99
+ 'role1 ' => 'student ' ,
100
+ ]
101
+ );
102
+ }
103
+
81
104
/**
82
105
* Gets the block contents.
83
106
*
@@ -95,16 +118,20 @@ public function get_content(): stdClass {
95
118
96
119
$ template = new stdClass ();
97
120
98
- if (self ::$ ismarker ) {
99
- // Marker content.
100
- $ template ->mods = self ::fetch_marking ($ USER );
101
- } else {
102
- // Student content.
103
- $ template ->mods = $ this ->fetch_feedback ($ USER );
121
+ // Marker content.
122
+ if (self ::$ ismarker && $ template ->markingmods = self ::fetch_marking ($ USER )) {
123
+ $ template ->showmarkings = true ;
124
+ $ template ->markingheader = get_string ('markingfor ' , 'block_my_feedback ' ).' ' .$ USER ->firstname ;
125
+ }
126
+
127
+ // Student content.
128
+ if (self ::$ isstudent && $ template ->assessmentmods = $ this ->fetch_feedback ($ USER )) {
104
129
$ template ->showfeedbacktrackerlink = true ;
130
+ $ template ->showassessments = true ;
131
+ $ template ->assessmentheader = get_string ('feedbackfor ' , 'block_my_feedback ' ).' ' .$ USER ->firstname ;
105
132
}
106
133
107
- if (isset ($ template ->mods )) {
134
+ if (isset ($ template ->markingmods ) || isset ( $ template -> assessmentmods )) {
108
135
$ this ->content ->text = $ OUTPUT ->render_from_template ('block_my_feedback/content ' , $ template );
109
136
}
110
137
@@ -139,7 +166,8 @@ private static function is_marker(): bool {
139
166
* @param stdClass $course
140
167
* @return bool
141
168
*/
142
- private static function is_course_marker (stdClass $ course ): bool {
169
+ private static function is_course_marker (stdClass $ course ): bool
170
+ {
143
171
global $ USER ;
144
172
145
173
if (!$ course ) {
@@ -148,13 +176,35 @@ private static function is_course_marker(stdClass $course): bool {
148
176
149
177
// Check if user has a merker role in the given course.
150
178
foreach (self ::$ markerroles as $ role ) {
151
- if (user_has_role_assignment ($ USER ->id , (int ) $ role , $ course ->ctxid )) {
179
+ if (user_has_role_assignment ($ USER ->id , (int )$ role , $ course ->ctxid )) {
152
180
return true ;
153
181
}
154
182
}
155
183
return false ;
156
184
}
157
185
186
+ /**
187
+ * Return if user has archetype student.
188
+ *
189
+ * @return bool
190
+ */
191
+ public static function is_student (): bool {
192
+ global $ DB , $ USER ;
193
+ // Get id's from role where archetype is student.
194
+ if ($ roles = self ::$ studentroles ) {
195
+ // Check if user has editingteacher role on any courses.
196
+ list ($ roles , $ params ) = $ DB ->get_in_or_equal ($ roles , SQL_PARAMS_NAMED );
197
+ $ params ['userid ' ] = $ USER ->id ;
198
+ $ sql = "SELECT id
199
+ FROM {role_assignments}
200
+ WHERE userid = :userid
201
+ AND roleid $ roles " ;
202
+ return $ DB ->record_exists_sql ($ sql , $ params );
203
+ } else {
204
+ return false ;
205
+ }
206
+ }
207
+
158
208
/**
159
209
* Return marking for a user.
160
210
*
0 commit comments