MDL-39962 - Events: Replace the legacy event workshop_viewed
[moodle.git] / mod / workshop / view.php
CommitLineData
4eab2e7f 1<?php
53fad4b9
DM
2
3// This file is part of Moodle - http://moodle.org/
4//
4eab2e7f
DM
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
53fad4b9 14//
4eab2e7f
DM
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
53fad4b9 17
4eab2e7f
DM
18/**
19 * Prints a particular instance of workshop
20 *
21 * You can have a rather longer description of the file as well,
22 * if you like, and it can span multiple lines.
23 *
65601f04
DM
24 * @package mod
25 * @subpackage workshop
26 * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
4eab2e7f
DM
28 */
29
4eab2e7f 30require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
ffac17df 31require_once(dirname(__FILE__).'/locallib.php');
516c5eca 32require_once($CFG->libdir.'/completionlib.php');
4eab2e7f 33
f82567af
DM
34$id = optional_param('id', 0, PARAM_INT); // course_module ID, or
35$w = optional_param('w', 0, PARAM_INT); // workshop instance ID
36$editmode = optional_param('editmode', null, PARAM_BOOL);
8a237337 37$page = optional_param('page', 0, PARAM_INT);
11a97e66 38$perpage = optional_param('perpage', null, PARAM_INT);
8a237337
DM
39$sortby = optional_param('sortby', 'lastname', PARAM_ALPHA);
40$sorthow = optional_param('sorthow', 'ASC', PARAM_ALPHA);
a93dc3ec 41$eval = optional_param('eval', null, PARAM_PLUGIN);
4eab2e7f
DM
42
43if ($id) {
d76a0eec
AG
44 $cm = get_coursemodule_from_id('workshop', $id, 0, false, MUST_EXIST);
45 $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
46 $workshoprecord = $DB->get_record('workshop', array('id' => $cm->instance), '*', MUST_EXIST);
4eab2e7f 47} else {
d76a0eec
AG
48 $workshoprecord = $DB->get_record('workshop', array('id' => $w), '*', MUST_EXIST);
49 $course = $DB->get_record('course', array('id' => $workshoprecord->course), '*', MUST_EXIST);
50 $cm = get_coursemodule_from_instance('workshop', $workshoprecord->id, $course->id, false, MUST_EXIST);
4eab2e7f
DM
51}
52
53require_login($course, true, $cm);
b761e6d9 54require_capability('mod/workshop:view', $PAGE->context);
6e309973 55
d76a0eec 56$workshop = new workshop($workshoprecord, $cm, $course);
4eab2e7f 57
6553cda7 58// Mark viewed
59$completion = new completion_info($course);
60$completion->set_module_viewed($cm);
61
d76a0eec
AG
62$eventdata = array();
63$eventdata['objectid'] = $workshop->id;
64$eventdata['context'] = $workshop->context;
65$eventdata['courseid'] = $course->id;
66$eventdata['other']['content'] = $workshop->phase;
67
68$PAGE->set_url($workshop->view_url());
69$event = \mod_workshop\event\course_module_viewed::create($eventdata);
70$event->add_record_snapshot('course', $course);
71$event->add_record_snapshot('workshop', $workshoprecord);
72$event->add_record_snapshot('course_modules', $cm);
73$event->set_page_detail();
74$event->trigger();
85f1c2d6
DM
75
76// If the phase is to be switched, do it asap. This just has to happen after triggering
77// the event so that the scheduled allocator had a chance to allocate submissions.
78if ($workshop->phase == workshop::PHASE_SUBMISSION and $workshop->phaseswitchassessment
79 and $workshop->submissionend > 0 and $workshop->submissionend < time()) {
80 $workshop->switch_phase(workshop::PHASE_ASSESSMENT);
81 $workshop->log('update switch phase', $workshop->view_url(), $workshop->phase);
82 // Disable the automatic switching now so that it is not executed again by accident
83 // if the teacher changes the phase back to the submission one.
84 $DB->set_field('workshop', 'phaseswitchassessment', 0, array('id' => $workshop->id));
85 $workshop->phaseswitchassessment = 0;
86}
87
f82567af
DM
88if (!is_null($editmode) && $PAGE->user_allowed_editing()) {
89 $USER->editing = $editmode;
a39d7d87
DM
90}
91
ffac17df 92$PAGE->set_title($workshop->name);
6e309973 93$PAGE->set_heading($course->fullname);
b761e6d9 94
11a97e66
DM
95if ($perpage and $perpage > 0 and $perpage <= 1000) {
96 require_sesskey();
97 set_user_preference('workshop_perpage', $perpage);
98 redirect($PAGE->url);
99}
100
a93dc3ec
DM
101if ($eval) {
102 require_sesskey();
103 require_capability('mod/workshop:overridegrades', $workshop->context);
104 $workshop->set_grading_evaluation_method($eval);
105 redirect($PAGE->url);
106}
107
55fc1e59 108$output = $PAGE->get_renderer('mod_workshop');
cff28ef0 109$userplan = new workshop_user_plan($workshop, $USER->id);
b761e6d9 110
b8ead2e6 111/// Output starts here
66c9894d 112
55fc1e59
DM
113echo $output->header();
114echo $output->heading_with_help(format_string($workshop->name), 'userplan', 'workshop');
cff28ef0 115echo $output->render($userplan);
b761e6d9 116
b761e6d9
DM
117switch ($workshop->phase) {
118case workshop::PHASE_SETUP:
bfbca63d 119 if (trim($workshop->intro)) {
ef96efe0 120 print_collapsible_region_start('', 'workshop-viewlet-intro', get_string('introduction', 'workshop'));
55fc1e59 121 echo $output->box(format_module_intro('workshop', $workshop, $workshop->cm->id), 'generalbox');
ef96efe0 122 print_collapsible_region_end();
b761e6d9 123 }
81eccf0a 124 if ($workshop->useexamples and has_capability('mod/workshop:manageexamples', $PAGE->context)) {
ef96efe0 125 print_collapsible_region_start('', 'workshop-viewlet-allexamples', get_string('examplesubmissions', 'workshop'));
55fc1e59 126 echo $output->box_start('generalbox examples');
cbf87967
DM
127 if ($workshop->grading_strategy_instance()->form_ready()) {
128 if (! $examples = $workshop->get_examples_for_manager()) {
55fc1e59 129 echo $output->container(get_string('noexamples', 'workshop'), 'noexamples');
cbf87967
DM
130 }
131 foreach ($examples as $example) {
132 $summary = $workshop->prepare_example_summary($example);
81b22887
DM
133 $summary->editable = true;
134 echo $output->render($summary);
cbf87967 135 }
3ba60ee1 136 $aurl = new moodle_url($workshop->exsubmission_url(0), array('edit' => 'on'));
55fc1e59 137 echo $output->single_button($aurl, get_string('exampleadd', 'workshop'), 'get');
cbf87967 138 } else {
55fc1e59 139 echo $output->container(get_string('noexamplesformready', 'workshop'));
81eccf0a 140 }
55fc1e59 141 echo $output->box_end();
4437929e 142 print_collapsible_region_end();
81eccf0a 143 }
b761e6d9
DM
144 break;
145case workshop::PHASE_SUBMISSION:
bfbca63d 146 if (trim($workshop->instructauthors)) {
6516b9e9 147 $instructions = file_rewrite_pluginfile_urls($workshop->instructauthors, 'pluginfile.php', $PAGE->context->id,
64f93798 148 'mod_workshop', 'instructauthors', 0, workshop::instruction_editors_options($PAGE->context));
ef96efe0 149 print_collapsible_region_start('', 'workshop-viewlet-instructauthors', get_string('instructauthors', 'workshop'));
367a75fa 150 echo $output->box(format_text($instructions, $workshop->instructauthorsformat, array('overflowdiv'=>true)), array('generalbox', 'instructions'));
ef96efe0
DM
151 print_collapsible_region_end();
152 }
ef96efe0 153
2f289d36
DM
154 // does the user have to assess examples before submitting their own work?
155 $examplesmust = ($workshop->useexamples and $workshop->examplesmode == workshop::EXAMPLES_BEFORE_SUBMISSION);
156
157 // is the assessment of example submissions considered finished?
158 $examplesdone = has_capability('mod/workshop:manageexamples', $workshop->context);
cbf87967
DM
159 if ($workshop->assessing_examples_allowed()
160 and has_capability('mod/workshop:submit', $workshop->context)
161 and ! has_capability('mod/workshop:manageexamples', $workshop->context)) {
cff28ef0 162 $examples = $userplan->get_examples();
cbf87967 163 $total = count($examples);
514d8c22 164 $left = 0;
cbf87967
DM
165 // make sure the current user has all examples allocated
166 foreach ($examples as $exampleid => $example) {
167 if (is_null($example->assessmentid)) {
67ae13d9 168 $examples[$exampleid]->assessmentid = $workshop->add_allocation($example, $USER->id, 0);
cbf87967
DM
169 }
170 if (is_null($example->grade)) {
514d8c22 171 $left++;
ef96efe0
DM
172 }
173 }
514d8c22 174 if ($left > 0 and $workshop->examplesmode != workshop::EXAMPLES_VOLUNTARY) {
cbf87967 175 $examplesdone = false;
514d8c22
DM
176 } else {
177 $examplesdone = true;
ef96efe0 178 }
cff28ef0 179 print_collapsible_region_start('', 'workshop-viewlet-examples', get_string('exampleassessments', 'workshop'), false, $examplesdone);
55fc1e59 180 echo $output->box_start('generalbox exampleassessments');
cbf87967 181 if ($total == 0) {
55fc1e59 182 echo $output->heading(get_string('noexamples', 'workshop'), 3);
cbf87967
DM
183 } else {
184 foreach ($examples as $example) {
185 $summary = $workshop->prepare_example_summary($example);
81b22887 186 echo $output->render($summary);
cbf87967 187 }
ef96efe0 188 }
55fc1e59 189 echo $output->box_end();
cbf87967 190 print_collapsible_region_end();
6516b9e9 191 }
cbf87967 192
2f289d36 193 if (has_capability('mod/workshop:submit', $PAGE->context) and (!$examplesmust or $examplesdone)) {
ef96efe0 194 print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'));
55fc1e59 195 echo $output->box_start('generalbox ownsubmission');
e9b0f0ab 196 if ($submission = $workshop->get_submission_by_author($USER->id)) {
81b22887 197 echo $output->render($workshop->prepare_submission_summary($submission, true));
9ddff589 198 if ($workshop->modifying_submission_allowed($USER->id)) {
2f289d36
DM
199 $btnurl = new moodle_url($workshop->submission_url(), array('edit' => 'on'));
200 $btntxt = get_string('editsubmission', 'workshop');
201 }
81eccf0a 202 } else {
55fc1e59 203 echo $output->container(get_string('noyoursubmission', 'workshop'));
9ddff589 204 if ($workshop->creating_submission_allowed($USER->id)) {
2f289d36
DM
205 $btnurl = new moodle_url($workshop->submission_url(), array('edit' => 'on'));
206 $btntxt = get_string('createsubmission', 'workshop');
207 }
81eccf0a 208 }
2f289d36
DM
209 if (!empty($btnurl)) {
210 echo $output->single_button($btnurl, $btntxt, 'get');
e9b0f0ab 211 }
55fc1e59 212 echo $output->box_end();
ef96efe0 213 print_collapsible_region_end();
e9b0f0ab 214 }
cbf87967 215
e9b0f0ab 216 if (has_capability('mod/workshop:viewallsubmissions', $PAGE->context)) {
1c0c3ef5
DM
217 $groupmode = groups_get_activity_groupmode($workshop->cm);
218 $groupid = groups_get_activity_group($workshop->cm, true);
219
220 if ($groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $workshop->context)) {
221 $allowedgroups = groups_get_activity_allowed_groups($workshop->cm);
222 if (empty($allowedgroups)) {
223 echo $output->container(get_string('groupnoallowed', 'mod_workshop'), 'groupwidget error');
224 break;
225 }
226 if (! in_array($groupid, array_keys($allowedgroups))) {
227 echo $output->container(get_string('groupnotamember', 'core_group'), 'groupwidget error');
228 break;
229 }
230 }
231
0d2331cc 232 $countsubmissions = $workshop->count_submissions('all', $groupid);
11a97e66 233 $perpage = get_user_preferences('workshop_perpage', 10);
0d2331cc 234 $pagingbar = new paging_bar($countsubmissions, $page, $perpage, $PAGE->url, 'page');
1c0c3ef5 235
0d2331cc 236 print_collapsible_region_start('', 'workshop-viewlet-allsubmissions', get_string('allsubmissions', 'workshop', $countsubmissions));
55fc1e59 237 echo $output->box_start('generalbox allsubmissions');
0d2331cc 238 echo $output->container(groups_print_activity_menu($workshop->cm, $PAGE->url, true), 'groupwidget');
0d2331cc
DM
239
240 if ($countsubmissions == 0) {
55fc1e59 241 echo $output->container(get_string('nosubmissions', 'workshop'), 'nosubmissions');
0d2331cc
DM
242
243 } else {
244 $submissions = $workshop->get_submissions('all', $groupid, $page * $perpage, $perpage);
245 $shownames = has_capability('mod/workshop:viewauthornames', $workshop->context);
11a97e66 246 echo $output->render($pagingbar);
0d2331cc
DM
247 foreach ($submissions as $submission) {
248 echo $output->render($workshop->prepare_submission_summary($submission, $shownames));
249 }
11a97e66
DM
250 echo $output->render($pagingbar);
251 echo $output->perpage_selector($perpage);
ddb59c77 252 }
0d2331cc 253
55fc1e59 254 echo $output->box_end();
ef96efe0 255 print_collapsible_region_end();
e9b0f0ab 256 }
cbf87967 257
e9b0f0ab 258 break;
cbf87967 259
b761e6d9 260case workshop::PHASE_ASSESSMENT:
2f289d36
DM
261
262 $ownsubmissionexists = null;
263 if (has_capability('mod/workshop:submit', $PAGE->context)) {
264 if ($ownsubmission = $workshop->get_submission_by_author($USER->id)) {
265 print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'), false, true);
266 echo $output->box_start('generalbox ownsubmission');
81b22887 267 echo $output->render($workshop->prepare_submission_summary($ownsubmission, true));
2f289d36
DM
268 $ownsubmissionexists = true;
269 } else {
270 print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'));
271 echo $output->box_start('generalbox ownsubmission');
272 echo $output->container(get_string('noyoursubmission', 'workshop'));
273 $ownsubmissionexists = false;
9ddff589 274 if ($workshop->creating_submission_allowed($USER->id)) {
2f289d36
DM
275 $btnurl = new moodle_url($workshop->submission_url(), array('edit' => 'on'));
276 $btntxt = get_string('createsubmission', 'workshop');
277 }
278 }
279 if (!empty($btnurl)) {
280 echo $output->single_button($btnurl, $btntxt, 'get');
281 }
282 echo $output->box_end();
283 print_collapsible_region_end();
284 }
285
d183140d 286 if (has_capability('mod/workshop:viewallassessments', $PAGE->context)) {
11a97e66 287 $perpage = get_user_preferences('workshop_perpage', 10);
dda42a19
DM
288 $groupid = groups_get_activity_group($workshop->cm, true);
289 $data = $workshop->prepare_grading_report_data($USER->id, $groupid, $page, $perpage, $sortby, $sorthow);
d183140d
DM
290 if ($data) {
291 $showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context);
292 $showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context);
293
294 // prepare paging bar
dda42a19
DM
295 $baseurl = new moodle_url($PAGE->url, array('sortby' => $sortby, 'sorthow' => $sorthow));
296 $pagingbar = new paging_bar($data->totalcount, $page, $perpage, $baseurl, 'page');
d183140d
DM
297
298 // grading report display options
7a789aa8 299 $reportopts = new stdclass();
d183140d
DM
300 $reportopts->showauthornames = $showauthornames;
301 $reportopts->showreviewernames = $showreviewernames;
302 $reportopts->sortby = $sortby;
303 $reportopts->sorthow = $sorthow;
304 $reportopts->showsubmissiongrade = false;
305 $reportopts->showgradinggrade = false;
d183140d 306
dda42a19
DM
307 print_collapsible_region_start('', 'workshop-viewlet-gradereport', get_string('gradesreport', 'workshop'));
308 echo $output->box_start('generalbox gradesreport');
309 echo $output->container(groups_print_activity_menu($workshop->cm, $PAGE->url, true), 'groupwidget');
55fc1e59 310 echo $output->render($pagingbar);
c2a35266 311 echo $output->render(new workshop_grading_report($data, $reportopts));
55fc1e59 312 echo $output->render($pagingbar);
11a97e66 313 echo $output->perpage_selector($perpage);
dda42a19
DM
314 echo $output->box_end();
315 print_collapsible_region_end();
d183140d
DM
316 }
317 }
bfbca63d 318 if (trim($workshop->instructreviewers)) {
15d12b54 319 $instructions = file_rewrite_pluginfile_urls($workshop->instructreviewers, 'pluginfile.php', $PAGE->context->id,
64f93798 320 'mod_workshop', 'instructreviewers', 0, workshop::instruction_editors_options($PAGE->context));
ef96efe0 321 print_collapsible_region_start('', 'workshop-viewlet-instructreviewers', get_string('instructreviewers', 'workshop'));
367a75fa 322 echo $output->box(format_text($instructions, $workshop->instructreviewersformat, array('overflowdiv'=>true)), array('generalbox', 'instructions'));
ef96efe0 323 print_collapsible_region_end();
15d12b54 324 }
2f289d36
DM
325
326 // does the user have to assess examples before assessing other's work?
327 $examplesmust = ($workshop->useexamples and $workshop->examplesmode == workshop::EXAMPLES_BEFORE_ASSESSMENT);
328
329 // is the assessment of example submissions considered finished?
330 $examplesdone = has_capability('mod/workshop:manageexamples', $workshop->context);
331
332 // can the examples be assessed?
333 $examplesavailable = true;
334
335 if (!$examplesdone and $examplesmust and ($ownsubmissionexists === false)) {
336 print_collapsible_region_start('', 'workshop-viewlet-examplesfail', get_string('exampleassessments', 'workshop'));
337 echo $output->box(get_string('exampleneedsubmission', 'workshop'));
338 print_collapsible_region_end();
339 $examplesavailable = false;
340 }
341
cff28ef0
DM
342 if ($workshop->assessing_examples_allowed()
343 and has_capability('mod/workshop:submit', $workshop->context)
2f289d36
DM
344 and ! has_capability('mod/workshop:manageexamples', $workshop->context)
345 and $examplesavailable) {
cff28ef0
DM
346 $examples = $userplan->get_examples();
347 $total = count($examples);
348 $left = 0;
349 // make sure the current user has all examples allocated
350 foreach ($examples as $exampleid => $example) {
351 if (is_null($example->assessmentid)) {
352 $examples[$exampleid]->assessmentid = $workshop->add_allocation($example, $USER->id, 0);
ddb59c77 353 }
cff28ef0
DM
354 if (is_null($example->grade)) {
355 $left++;
356 }
357 }
358 if ($left > 0 and $workshop->examplesmode != workshop::EXAMPLES_VOLUNTARY) {
359 $examplesdone = false;
360 } else {
361 $examplesdone = true;
362 }
363 print_collapsible_region_start('', 'workshop-viewlet-examples', get_string('exampleassessments', 'workshop'), false, $examplesdone);
364 echo $output->box_start('generalbox exampleassessments');
365 if ($total == 0) {
366 echo $output->heading(get_string('noexamples', 'workshop'), 3);
367 } else {
368 foreach ($examples as $example) {
369 $summary = $workshop->prepare_example_summary($example);
81b22887 370 echo $output->render($summary);
cff28ef0
DM
371 }
372 }
373 echo $output->box_end();
374 print_collapsible_region_end();
375 }
2f289d36 376 if (!$examplesmust or $examplesdone) {
cff28ef0
DM
377 print_collapsible_region_start('', 'workshop-viewlet-assignedassessments', get_string('assignedassessments', 'workshop'));
378 if (! $assessments = $workshop->get_assessments_by_reviewer($USER->id)) {
379 echo $output->box_start('generalbox assessment-none');
764d7ba9 380 echo $output->notification(get_string('assignedassessmentsnone', 'workshop'));
55fc1e59 381 echo $output->box_end();
cff28ef0
DM
382 } else {
383 $shownames = has_capability('mod/workshop:viewauthornames', $PAGE->context);
384 foreach ($assessments as $assessment) {
81b22887 385 $submission = new stdClass();
cff28ef0
DM
386 $submission->id = $assessment->submissionid;
387 $submission->title = $assessment->submissiontitle;
388 $submission->timecreated = $assessment->submissioncreated;
389 $submission->timemodified = $assessment->submissionmodified;
390 $submission->authorid = $assessment->authorid;
391 $submission->authorfirstname = $assessment->authorfirstname;
392 $submission->authorlastname = $assessment->authorlastname;
393 $submission->authorpicture = $assessment->authorpicture;
394 $submission->authorimagealt = $assessment->authorimagealt;
3a11c09f 395 $submission->authoremail = $assessment->authoremail;
81b22887
DM
396
397 // transform the submission object into renderable component
398 $submission = $workshop->prepare_submission_summary($submission, $shownames);
399
cff28ef0 400 if (is_null($assessment->grade)) {
4d63c194 401 $submission->status = 'notgraded';
81b22887 402 $class = ' notgraded';
cff28ef0
DM
403 $buttontext = get_string('assess', 'workshop');
404 } else {
4d63c194 405 $submission->status = 'graded';
81b22887 406 $class = ' graded';
cff28ef0
DM
407 $buttontext = get_string('reassess', 'workshop');
408 }
4d63c194 409
cff28ef0 410 echo $output->box_start('generalbox assessment-summary' . $class);
81b22887 411 echo $output->render($submission);
cff28ef0
DM
412 $aurl = $workshop->assess_url($assessment->id);
413 echo $output->single_button($aurl, $buttontext, 'get');
414 echo $output->box_end();
415 }
ddb59c77 416 }
cff28ef0 417 print_collapsible_region_end();
ddb59c77 418 }
00aca3c1 419 break;
b761e6d9 420case workshop::PHASE_EVALUATION:
d183140d 421 if (has_capability('mod/workshop:viewallassessments', $PAGE->context)) {
11a97e66 422 $perpage = get_user_preferences('workshop_perpage', 10);
dda42a19
DM
423 $groupid = groups_get_activity_group($workshop->cm, true);
424 $data = $workshop->prepare_grading_report_data($USER->id, $groupid, $page, $perpage, $sortby, $sorthow);
1fed6ce3 425 if ($data) {
f55650e6
DM
426 $showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context);
427 $showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context);
428
d183140d 429 if (has_capability('mod/workshop:overridegrades', $PAGE->context)) {
a93dc3ec
DM
430 // Print a drop-down selector to change the current evaluation method.
431 $selector = new single_select($PAGE->url, 'eval', workshop::available_evaluators_list(),
432 $workshop->evaluation, false, 'evaluationmethodchooser');
433 $selector->set_label(get_string('evaluationmethod', 'mod_workshop'));
434 $selector->set_help_icon('evaluationmethod', 'mod_workshop');
435 $selector->method = 'post';
436 echo $output->render($selector);
d183140d
DM
437 // load the grading evaluator
438 $evaluator = $workshop->grading_evaluation_instance();
439 $form = $evaluator->get_settings_form(new moodle_url($workshop->aggregate_url(),
440 compact('sortby', 'sorthow', 'page')));
441 $form->display();
442 }
1fed6ce3
DM
443
444 // prepare paging bar
dda42a19
DM
445 $baseurl = new moodle_url($PAGE->url, array('sortby' => $sortby, 'sorthow' => $sorthow));
446 $pagingbar = new paging_bar($data->totalcount, $page, $perpage, $baseurl, 'page');
1fed6ce3 447
d183140d 448 // grading report display options
7a789aa8 449 $reportopts = new stdclass();
d183140d
DM
450 $reportopts->showauthornames = $showauthornames;
451 $reportopts->showreviewernames = $showreviewernames;
452 $reportopts->sortby = $sortby;
453 $reportopts->sorthow = $sorthow;
454 $reportopts->showsubmissiongrade = true;
455 $reportopts->showgradinggrade = true;
d183140d 456
dda42a19
DM
457 print_collapsible_region_start('', 'workshop-viewlet-gradereport', get_string('gradesreport', 'workshop'));
458 echo $output->box_start('generalbox gradesreport');
459 echo $output->container(groups_print_activity_menu($workshop->cm, $PAGE->url, true), 'groupwidget');
55fc1e59 460 echo $output->render($pagingbar);
c2a35266 461 echo $output->render(new workshop_grading_report($data, $reportopts));
55fc1e59 462 echo $output->render($pagingbar);
11a97e66 463 echo $output->perpage_selector($perpage);
dda42a19
DM
464 echo $output->box_end();
465 print_collapsible_region_end();
e807e9a3 466 }
1fed6ce3 467 }
32c78bc3 468 if (has_capability('mod/workshop:overridegrades', $workshop->context)) {
e706b9c3 469 print_collapsible_region_start('', 'workshop-viewlet-cleargrades', get_string('toolbox', 'workshop'), false, true);
32c78bc3 470 echo $output->box_start('generalbox toolbox');
e706b9c3 471
32c78bc3 472 // Clear aggregated grades
e706b9c3 473 $url = new moodle_url($workshop->toolbox_url('clearaggregatedgrades'));
32c78bc3
DM
474 $btn = new single_button($url, get_string('clearaggregatedgrades', 'workshop'), 'post');
475 $btn->add_confirm_action(get_string('clearaggregatedgradesconfirm', 'workshop'));
e706b9c3 476 echo $output->container_start('toolboxaction');
32c78bc3
DM
477 echo $output->render($btn);
478 echo $output->help_icon('clearaggregatedgrades', 'workshop');
e706b9c3
DM
479 echo $output->container_end();
480 // Clear assessments
481 $url = new moodle_url($workshop->toolbox_url('clearassessments'));
482 $btn = new single_button($url, get_string('clearassessments', 'workshop'), 'post');
483 $btn->add_confirm_action(get_string('clearassessmentsconfirm', 'workshop'));
484 echo $output->container_start('toolboxaction');
485 echo $output->render($btn);
486 echo $output->help_icon('clearassessments', 'workshop');
487 echo html_writer::empty_tag('img', array('src' => $output->pix_url('i/risk_dataloss'),
488 'title' => get_string('riskdatalossshort', 'admin'),
94972cca
FM
489 'alt' => get_string('riskdatalossshort', 'admin'),
490 'class' => 'workshop-risk-dataloss'));
e706b9c3 491 echo $output->container_end();
32c78bc3
DM
492
493 echo $output->box_end();
494 print_collapsible_region_end();
495 }
4d63c194
DM
496 if (has_capability('mod/workshop:submit', $PAGE->context)) {
497 print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'));
498 echo $output->box_start('generalbox ownsubmission');
499 if ($submission = $workshop->get_submission_by_author($USER->id)) {
757bade1 500 echo $output->render($workshop->prepare_submission_summary($submission, true));
4d63c194
DM
501 } else {
502 echo $output->container(get_string('noyoursubmission', 'workshop'));
503 }
504 echo $output->box_end();
505 print_collapsible_region_end();
506 }
507 if ($assessments = $workshop->get_assessments_by_reviewer($USER->id)) {
508 print_collapsible_region_start('', 'workshop-viewlet-assignedassessments', get_string('assignedassessments', 'workshop'));
509 $shownames = has_capability('mod/workshop:viewauthornames', $PAGE->context);
510 foreach ($assessments as $assessment) {
511 $submission = new stdclass();
512 $submission->id = $assessment->submissionid;
513 $submission->title = $assessment->submissiontitle;
514 $submission->timecreated = $assessment->submissioncreated;
515 $submission->timemodified = $assessment->submissionmodified;
516 $submission->authorid = $assessment->authorid;
517 $submission->authorfirstname = $assessment->authorfirstname;
518 $submission->authorlastname = $assessment->authorlastname;
519 $submission->authorpicture = $assessment->authorpicture;
520 $submission->authorimagealt = $assessment->authorimagealt;
3a11c09f 521 $submission->authoremail = $assessment->authoremail;
4d63c194
DM
522
523 if (is_null($assessment->grade)) {
524 $class = ' notgraded';
525 $submission->status = 'notgraded';
526 $buttontext = get_string('assess', 'workshop');
527 } else {
528 $class = ' graded';
529 $submission->status = 'graded';
530 $buttontext = get_string('reassess', 'workshop');
531 }
532 echo $output->box_start('generalbox assessment-summary' . $class);
81b22887 533 echo $output->render($workshop->prepare_submission_summary($submission, $shownames));
4d63c194
DM
534 echo $output->box_end();
535 }
536 print_collapsible_region_end();
537 }
1fed6ce3
DM
538 break;
539case workshop::PHASE_CLOSED:
4c61fcd8
DM
540 if (trim($workshop->conclusion)) {
541 $conclusion = file_rewrite_pluginfile_urls($workshop->conclusion, 'pluginfile.php', $workshop->context->id,
542 'mod_workshop', 'conclusion', 0, workshop::instruction_editors_options($workshop->context));
543 print_collapsible_region_start('', 'workshop-viewlet-conclusion', get_string('conclusion', 'workshop'));
544 echo $output->box(format_text($conclusion, $workshop->conclusionformat, array('overflowdiv'=>true)), array('generalbox', 'conclusion'));
545 print_collapsible_region_end();
546 }
3cb4ce45
DM
547 $finalgrades = $workshop->get_gradebook_grades($USER->id);
548 if (!empty($finalgrades)) {
549 print_collapsible_region_start('', 'workshop-viewlet-yourgrades', get_string('yourgrades', 'workshop'));
550 echo $output->box_start('generalbox grades-yourgrades');
551 echo $output->render($finalgrades);
552 echo $output->box_end();
553 print_collapsible_region_end();
554 }
5a372494 555 if (has_capability('mod/workshop:viewallassessments', $PAGE->context)) {
11a97e66 556 $perpage = get_user_preferences('workshop_perpage', 10);
dda42a19
DM
557 $groupid = groups_get_activity_group($workshop->cm, true);
558 $data = $workshop->prepare_grading_report_data($USER->id, $groupid, $page, $perpage, $sortby, $sorthow);
5a372494
DM
559 if ($data) {
560 $showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context);
561 $showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context);
562
563 // prepare paging bar
dda42a19
DM
564 $baseurl = new moodle_url($PAGE->url, array('sortby' => $sortby, 'sorthow' => $sorthow));
565 $pagingbar = new paging_bar($data->totalcount, $page, $perpage, $baseurl, 'page');
5a372494
DM
566
567 // grading report display options
568 $reportopts = new stdclass();
569 $reportopts->showauthornames = $showauthornames;
570 $reportopts->showreviewernames = $showreviewernames;
571 $reportopts->sortby = $sortby;
572 $reportopts->sorthow = $sorthow;
573 $reportopts->showsubmissiongrade = true;
574 $reportopts->showgradinggrade = true;
575
576 print_collapsible_region_start('', 'workshop-viewlet-gradereport', get_string('gradesreport', 'workshop'));
dda42a19
DM
577 echo $output->box_start('generalbox gradesreport');
578 echo $output->container(groups_print_activity_menu($workshop->cm, $PAGE->url, true), 'groupwidget');
5a372494 579 echo $output->render($pagingbar);
c2a35266 580 echo $output->render(new workshop_grading_report($data, $reportopts));
5a372494 581 echo $output->render($pagingbar);
11a97e66 582 echo $output->perpage_selector($perpage);
dda42a19 583 echo $output->box_end();
5a372494
DM
584 print_collapsible_region_end();
585 }
586 }
0aed4a55
DM
587 if (has_capability('mod/workshop:submit', $PAGE->context)) {
588 print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'));
589 echo $output->box_start('generalbox ownsubmission');
590 if ($submission = $workshop->get_submission_by_author($USER->id)) {
81b22887 591 echo $output->render($workshop->prepare_submission_summary($submission, true));
0aed4a55
DM
592 } else {
593 echo $output->container(get_string('noyoursubmission', 'workshop'));
594 }
595 echo $output->box_end();
0dfb4bad
DM
596
597 if (!empty($submission->gradeoverby) and strlen(trim($submission->feedbackauthor)) > 0) {
598 echo $output->render(new workshop_feedback_author($submission));
599 }
600
0aed4a55
DM
601 print_collapsible_region_end();
602 }
00bc77ee 603 if (has_capability('mod/workshop:viewpublishedsubmissions', $workshop->context)) {
e13d02f5 604 $shownames = has_capability('mod/workshop:viewauthorpublished', $workshop->context);
00bc77ee
DM
605 if ($submissions = $workshop->get_published_submissions()) {
606 print_collapsible_region_start('', 'workshop-viewlet-publicsubmissions', get_string('publishedsubmissions', 'workshop'));
607 foreach ($submissions as $submission) {
608 echo $output->box_start('generalbox submission-summary');
e13d02f5 609 echo $output->render($workshop->prepare_submission_summary($submission, $shownames));
00bc77ee
DM
610 echo $output->box_end();
611 }
612 print_collapsible_region_end();
613 }
614 }
d67c20b8
DM
615 if ($assessments = $workshop->get_assessments_by_reviewer($USER->id)) {
616 print_collapsible_region_start('', 'workshop-viewlet-assignedassessments', get_string('assignedassessments', 'workshop'));
617 $shownames = has_capability('mod/workshop:viewauthornames', $PAGE->context);
618 foreach ($assessments as $assessment) {
619 $submission = new stdclass();
620 $submission->id = $assessment->submissionid;
621 $submission->title = $assessment->submissiontitle;
622 $submission->timecreated = $assessment->submissioncreated;
623 $submission->timemodified = $assessment->submissionmodified;
624 $submission->authorid = $assessment->authorid;
625 $submission->authorfirstname = $assessment->authorfirstname;
626 $submission->authorlastname = $assessment->authorlastname;
627 $submission->authorpicture = $assessment->authorpicture;
628 $submission->authorimagealt = $assessment->authorimagealt;
629 $submission->authoremail = $assessment->authoremail;
630
631 if (is_null($assessment->grade)) {
632 $class = ' notgraded';
633 $submission->status = 'notgraded';
634 $buttontext = get_string('assess', 'workshop');
635 } else {
636 $class = ' graded';
637 $submission->status = 'graded';
638 $buttontext = get_string('reassess', 'workshop');
639 }
640 echo $output->box_start('generalbox assessment-summary' . $class);
641 echo $output->render($workshop->prepare_submission_summary($submission, $shownames));
642 echo $output->box_end();
f68648e9
DM
643
644 if (strlen(trim($assessment->feedbackreviewer)) > 0) {
645 echo $output->render(new workshop_feedback_reviewer($assessment));
646 }
d67c20b8
DM
647 }
648 print_collapsible_region_end();
649 }
29dc43e7 650 break;
b761e6d9
DM
651default:
652}
653
55fc1e59 654echo $output->footer();