-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathview.php
More file actions
268 lines (243 loc) · 9.87 KB
/
Copy pathview.php
File metadata and controls
268 lines (243 loc) · 9.87 KB
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
<?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/>.
/**
* Prints an instance of mod_verbalfeedback.
*
* @package mod_verbalfeedback
* @copyright 2020 Kevin Tippenhauer <kevin.tippenhauer@bfh.ch>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use mod_verbalfeedback\model\instance;
use mod_verbalfeedback\output\list_participants;
use mod_verbalfeedback\repository\instance_repository;
use mod_verbalfeedback\utils\instance_utils;
use mod_verbalfeedback\utils\user_utils;
require_once(__DIR__ . '/../../config.php');
require_once('lib.php');
$id = required_param('id', PARAM_INT);
$makeavailable = optional_param('makeavailable', false, PARAM_BOOL);
$release = optional_param('release', -1, PARAM_INT);
[$course, $cm] = get_course_and_cm_from_cmid($id, 'verbalfeedback');
require_login($course, true, $cm);
$instancerepository = new instance_repository();
$context = context_module::instance($cm->id);
$instance = $instancerepository->get_by_id($cm->instance);
$PAGE->set_context($context);
$PAGE->set_cm($cm, $course);
$PAGE->set_pagelayout('incourse');
// If we got this far, we can consider the activity "viewed".
$completion = new completion_info($course);
$completion->set_module_viewed($cm);
$pageparams = ['id' => $cm->id];
$filter = [];
$currentgroup = optional_param('group', 0, PARAM_INT);
if ($currentgroup > 0) {
$pageparams['group'] = $currentgroup;
$filter['group'] = $currentgroup;
}
$PAGE->set_url('/mod/verbalfeedback/view.php', $pageparams);
$title = format_string($instance->get_name());
$PAGE->set_title($title);
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();
$canparticipate = user_utils::can_participate($instance, $USER->id);
$canrespond = user_utils::can_respond($instance, $USER->id);
$canviewallreports = user_utils::can_view_all_reports($context, $USER->id);
if (is_string($canparticipate)) {
echo $OUTPUT->heading(get_string('students'), 3);
\core\notification::warning($canparticipate);
echo $OUTPUT->footer();
return;
}
if ($canparticipate === true && ($canrespond === true || $canviewallreports === true)) {
echo $OUTPUT->heading(get_string('students'), 3);
}
if ($release != -1) {
// Toggle the released flag.
\mod_verbalfeedback\api::toggle_released_flag($instance, $release);
}
// Edit items.
$instanceready = $instancerepository->is_ready($instance->get_id());
$canedit = user_utils::can_edit_items($instance, $context);
// If the user has edit capabilities and the instance is not ready, create the "make available"
// button or show a warning that the instance has no criteria yet.
if ($canedit && !$instanceready && !$makeavailable) {
$edititemsurl = new moodle_url('edit_instance.php');
$edititemsurl->param('id', $cm->id);
echo html_writer::link(
$edititemsurl,
get_string('edititems', 'verbalfeedback'),
['class' => 'btn btn-primary me-1']
);
// Check if we can make the instance available to the respondents.
if ($instancerepository->has_items($instance->get_id())) {
$url = $PAGE->url;
$url->param('makeavailable', true);
echo html_writer::link(
$url,
get_string('makeavailable'),
['class' => 'btn btn-secondary pull-right']
);
} else {
\core\notification::warning(get_string('noitemsyet', 'mod_verbalfeedback'));
}
}
// Process "make available" button click event.
if ($canedit && !$instanceready && $makeavailable) {
if ($instancerepository->has_items($instance->get_id())) {
if (instance_utils::make_ready($instance)) {
\core\notification::success(get_string('instancenowready', 'mod_verbalfeedback'));
// Instance is now ready once made available.
$instanceready = true;
}
}
}
// If instance is ready, render participant list.
if ($instanceready) {
// Whether to include self in the participants list.
$includeself = false;
if (($canrespond === true) || (has_capability('moodle/site:config', $context))) {
try {
$participantslistrenderer = $PAGE->get_renderer('mod_verbalfeedback');
draw_participants_list($instance, $USER->id, $canparticipate, $canviewallreports, $filter, $participantslistrenderer);
} catch (moodle_exception $e) {
\core\notification::error($e->getMessage());
}
} else {
// User can not respond.
if (user_utils::can_view_own_report($instance, $context)) {
draw_view_own_report_button($instance->get_id(), $USER->id);
} else {
// Results are not yet released to students.
\core\notification::error(get_string('instancenotyetopen', 'mod_verbalfeedback'));
}
}
} else {
// Show error to respondents that indicate that the activity is not yet ready.
if ($canparticipate === true) {
if (($canrespond === true) && ($canedit === true)) {
// A person who can grade, e.g. a teacher.
\core\notification::error(get_string('instancenotready', 'mod_verbalfeedback'));
} else {
// A person who can grade, e.g. a student.
\core\notification::error(get_string('instancenotreadystudents', 'mod_verbalfeedback'));
}
}
}
echo $OUTPUT->footer();
/**
* Draws the button for students to view their own report.
*
* @param int $instanceid The verbal feedback instance id.
* @param int $userid The user id
* @throws coding_exception
*/
function draw_view_own_report_button($instanceid, $userid) {
$reportsurl = new moodle_url('/mod/verbalfeedback/report.php');
$reportsurl->params([
'instance' => $instanceid,
'touser' => $userid,
]);
$feedbackreport = html_writer::link(
$reportsurl,
get_string('viewfeedbackreport', 'verbalfeedback'),
['class' => 'btn btn-secondary']
);
echo html_writer::div($feedbackreport, 'text-end');
}
/**
* Draws the participants list on view.php.
*
* @param instance $instance The verbal feedback activity instance.
* @param int $currentuserid The user ID.
* @param bool $canparticipate Whether the user can participate in this activity or not.
* @param bool $canviewallreports Whether the user can view the reports of all enrolled users within the activity.
* @param array $filter The filter parameters.
* @param mixed $participantslistrenderer The renderer for the participants list.
*/
function draw_participants_list(
instance $instance,
$currentuserid,
$canparticipate,
$canviewallreports,
$filter,
$participantslistrenderer
) {
// Filter participants by group if group filter is applied.
$filter = ['group' => get_current_group($instance)];
$filter['tifirst'] = optional_param('tifirst', 0, PARAM_ALPHA);
$filter['tilast'] = optional_param('tilast', 0, PARAM_ALPHA);
$filter['userid'] = optional_param('userid', 0, PARAM_INT);
$filter['usersearch'] = optional_param('search', '', PARAM_TEXT);
$filter['status'] = optional_param('status', -1, PARAM_INT);
// Generate statuses if you can respond to the feedback.
\mod_verbalfeedback\api::generate_verbalfeedback_feedback_states($instance->get_id(), $currentuserid, $filter);
// Check if instance is already open.
$isopen = $instance->is_open(true);
if ($isopen !== true) {
// Show warning.
\core\notification::warning($isopen);
// Ensure that $isopen is a boolean. is_open() can return a string in some cases.
$isopen = false;
}
$participants = \mod_verbalfeedback\api::get_participants($instance->get_id(), $currentuserid, $filter);
// Verbalfeedback To-do list.
if ($canparticipate === true) {
$participantslist = new list_participants(
$instance,
$currentuserid,
$participants,
$canviewallreports,
$isopen
);
$participantslist->set_filter($filter);
echo $participantslistrenderer->render($participantslist);
}
}
/**
* Gets the current group id for the verbal feedback instance.
*
* @param instance $instance The verbal feedback instance.
* @return int The current group id, 0 if no group filter is applied.
*/
function get_current_group(instance $instance): int {
global $USER;
$cm = get_coursemodule_from_instance('verbalfeedback', $instance->get_id());
$course = get_course($cm->course);
$currentgroup = 0;
if (groups_get_activity_groupmode($cm) != NOGROUPS) {
$grp = groups_get_activity_group($cm, true);
$currentgroup = ($grp !== false) ? (int)$grp : 0;
} else if ($course->groupmode != NOGROUPS) {
$grp = groups_get_course_group($course, true);
$currentgroup = ($grp !== false) ? (int)$grp : 0;
}
if ($currentgroup === 0) {
$requestedgroup = optional_param('group', 0, PARAM_INT);
if ($requestedgroup > 0) {
$contextcourse = context_course::instance($course->id);
if (has_capability('moodle/site:accessallgroups', $contextcourse)) {
$allowedgroups = groups_get_all_groups($course->id, 0, 0);
} else {
$allowedgroups = groups_get_all_groups($course->id, $USER->id, 0);
}
if (isset($allowedgroups[$requestedgroup])) {
$currentgroup = (int)$requestedgroup;
}
}
}
return $currentgroup;
}