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