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