Workshop: submissions can be marked as published
[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 *
24 * @package mod-workshop
25 * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
26 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 */
28
4eab2e7f 29require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
ffac17df 30require_once(dirname(__FILE__).'/locallib.php');
4eab2e7f 31
f82567af
DM
32$id = optional_param('id', 0, PARAM_INT); // course_module ID, or
33$w = optional_param('w', 0, PARAM_INT); // workshop instance ID
34$editmode = optional_param('editmode', null, PARAM_BOOL);
4eab2e7f
DM
35
36if ($id) {
66c9894d
DM
37 $cm = get_coursemodule_from_id('workshop', $id, 0, false, MUST_EXIST);
38 $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
39 $workshop = $DB->get_record('workshop', array('id' => $cm->instance), '*', MUST_EXIST);
4eab2e7f 40} else {
66c9894d
DM
41 $workshop = $DB->get_record('workshop', array('id' => $w), '*', MUST_EXIST);
42 $course = $DB->get_record('course', array('id' => $workshop->course), '*', MUST_EXIST);
43 $cm = get_coursemodule_from_instance('workshop', $workshop->id, $course->id, false, MUST_EXIST);
4eab2e7f
DM
44}
45
46require_login($course, true, $cm);
b761e6d9 47require_capability('mod/workshop:view', $PAGE->context);
a3610b08 48add_to_log($course->id, 'workshop', 'view', 'view.php?id=' . $cm->id, $workshop->name, $cm->id);
6e309973 49
b761e6d9 50$workshop = new workshop($workshop, $cm, $course);
4eab2e7f 51
f82567af
DM
52if (!is_null($editmode) && $PAGE->user_allowed_editing()) {
53 $USER->editing = $editmode;
a39d7d87
DM
54}
55
b8ead2e6 56$PAGE->set_url($workshop->view_url());
ffac17df 57$PAGE->set_title($workshop->name);
6e309973 58$PAGE->set_heading($course->fullname);
b761e6d9 59
55fc1e59 60$output = $PAGE->get_renderer('mod_workshop');
cff28ef0 61$userplan = new workshop_user_plan($workshop, $USER->id);
b761e6d9 62
b8ead2e6 63/// Output starts here
66c9894d 64
55fc1e59
DM
65echo $output->header();
66echo $output->heading_with_help(format_string($workshop->name), 'userplan', 'workshop');
cff28ef0 67echo $output->render($userplan);
b761e6d9 68
b761e6d9
DM
69switch ($workshop->phase) {
70case workshop::PHASE_SETUP:
b761e6d9 71 if (trim(strip_tags($workshop->intro))) {
ef96efe0 72 print_collapsible_region_start('', 'workshop-viewlet-intro', get_string('introduction', 'workshop'));
55fc1e59 73 echo $output->box(format_module_intro('workshop', $workshop, $workshop->cm->id), 'generalbox');
ef96efe0 74 print_collapsible_region_end();
b761e6d9 75 }
81eccf0a 76 if ($workshop->useexamples and has_capability('mod/workshop:manageexamples', $PAGE->context)) {
ef96efe0 77 print_collapsible_region_start('', 'workshop-viewlet-allexamples', get_string('examplesubmissions', 'workshop'));
55fc1e59 78 echo $output->box_start('generalbox examples');
cbf87967
DM
79 if ($workshop->grading_strategy_instance()->form_ready()) {
80 if (! $examples = $workshop->get_examples_for_manager()) {
55fc1e59 81 echo $output->container(get_string('noexamples', 'workshop'), 'noexamples');
cbf87967
DM
82 }
83 foreach ($examples as $example) {
84 $summary = $workshop->prepare_example_summary($example);
55fc1e59 85 echo $output->example_summary($summary);
cbf87967 86 }
3ba60ee1 87 $aurl = new moodle_url($workshop->exsubmission_url(0), array('edit' => 'on'));
55fc1e59 88 echo $output->single_button($aurl, get_string('exampleadd', 'workshop'), 'get');
cbf87967 89 } else {
55fc1e59 90 echo $output->container(get_string('noexamplesformready', 'workshop'));
81eccf0a 91 }
55fc1e59 92 echo $output->box_end();
4437929e 93 print_collapsible_region_end();
81eccf0a 94 }
b761e6d9
DM
95 break;
96case workshop::PHASE_SUBMISSION:
6516b9e9
DM
97 if (trim(strip_tags($workshop->instructauthors))) {
98 $instructions = file_rewrite_pluginfile_urls($workshop->instructauthors, 'pluginfile.php', $PAGE->context->id,
99 'workshop_instructauthors', 0, workshop::instruction_editors_options($PAGE->context));
ef96efe0 100 print_collapsible_region_start('', 'workshop-viewlet-instructauthors', get_string('instructauthors', 'workshop'));
55fc1e59 101 echo $output->box(format_text($instructions, $workshop->instructauthorsformat), array('generalbox', 'instructions'));
ef96efe0
DM
102 print_collapsible_region_end();
103 }
ef96efe0 104
cff28ef0 105 $examplesdone = (!$workshop->useexamples or has_capability('mod/workshop:manageexamples', $workshop->context));
cbf87967
DM
106 if ($workshop->assessing_examples_allowed()
107 and has_capability('mod/workshop:submit', $workshop->context)
108 and ! has_capability('mod/workshop:manageexamples', $workshop->context)) {
cff28ef0 109 $examples = $userplan->get_examples();
cbf87967 110 $total = count($examples);
514d8c22 111 $left = 0;
cbf87967
DM
112 // make sure the current user has all examples allocated
113 foreach ($examples as $exampleid => $example) {
114 if (is_null($example->assessmentid)) {
67ae13d9 115 $examples[$exampleid]->assessmentid = $workshop->add_allocation($example, $USER->id, 0);
cbf87967
DM
116 }
117 if (is_null($example->grade)) {
514d8c22 118 $left++;
ef96efe0
DM
119 }
120 }
514d8c22 121 if ($left > 0 and $workshop->examplesmode != workshop::EXAMPLES_VOLUNTARY) {
cbf87967 122 $examplesdone = false;
514d8c22
DM
123 } else {
124 $examplesdone = true;
ef96efe0 125 }
cff28ef0 126 print_collapsible_region_start('', 'workshop-viewlet-examples', get_string('exampleassessments', 'workshop'), false, $examplesdone);
55fc1e59 127 echo $output->box_start('generalbox exampleassessments');
cbf87967 128 if ($total == 0) {
55fc1e59 129 echo $output->heading(get_string('noexamples', 'workshop'), 3);
cbf87967
DM
130 } else {
131 foreach ($examples as $example) {
132 $summary = $workshop->prepare_example_summary($example);
55fc1e59 133 echo $output->example_summary($summary);
cbf87967 134 }
ef96efe0 135 }
55fc1e59 136 echo $output->box_end();
cbf87967 137 print_collapsible_region_end();
6516b9e9 138 }
cbf87967
DM
139
140 if ($workshop->submitting_allowed()
141 and has_capability('mod/workshop:submit', $PAGE->context)
142 and $examplesdone) {
ef96efe0 143 print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'));
55fc1e59 144 echo $output->box_start('generalbox ownsubmission');
e9b0f0ab 145 if ($submission = $workshop->get_submission_by_author($USER->id)) {
55fc1e59 146 echo $output->submission_summary($submission, true);
81eccf0a 147 } else {
55fc1e59 148 echo $output->container(get_string('noyoursubmission', 'workshop'));
81eccf0a
DM
149 }
150 if ($workshop->submitting_allowed()) {
3ba60ee1 151 $aurl = new moodle_url($workshop->submission_url(), array('edit' => 'on'));
55fc1e59 152 echo $output->single_button($aurl, get_string('editsubmission', 'workshop'), 'get');
e9b0f0ab 153 }
55fc1e59 154 echo $output->box_end();
ef96efe0 155 print_collapsible_region_end();
e9b0f0ab 156 }
cbf87967 157
e9b0f0ab
DM
158 if (has_capability('mod/workshop:viewallsubmissions', $PAGE->context)) {
159 $shownames = has_capability('mod/workshop:viewauthornames', $PAGE->context);
ef96efe0 160 print_collapsible_region_start('', 'workshop-viewlet-allsubmissions', get_string('allsubmissions', 'workshop'));
55fc1e59 161 echo $output->box_start('generalbox allsubmissions');
29dc43e7 162 if (! $submissions = $workshop->get_submissions('all')) {
55fc1e59 163 echo $output->container(get_string('nosubmissions', 'workshop'), 'nosubmissions');
ddb59c77 164 }
3dc78e5b 165 foreach ($submissions as $submission) {
55fc1e59 166 echo $output->submission_summary($submission, $shownames);
e9b0f0ab 167 }
55fc1e59 168 echo $output->box_end();
ef96efe0 169 print_collapsible_region_end();
e9b0f0ab 170 }
cbf87967 171
e9b0f0ab 172 break;
cbf87967 173
b761e6d9 174case workshop::PHASE_ASSESSMENT:
d183140d
DM
175 if (has_capability('mod/workshop:viewallassessments', $PAGE->context)) {
176 $page = optional_param('page', 0, PARAM_INT);
177 $sortby = optional_param('sortby', 'lastname', PARAM_ALPHA);
178 $sorthow = optional_param('sorthow', 'ASC', PARAM_ALPHA);
179 $perpage = 10; // todo let the user modify this
180 $groups = ''; // todo let the user choose the group
a6855934 181 $PAGE->set_url($PAGE->url, compact('sortby', 'sorthow', 'page')); // TODO: this is suspicious
d183140d
DM
182 $data = $workshop->prepare_grading_report($USER->id, $groups, $page, $perpage, $sortby, $sorthow);
183 if ($data) {
184 $showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context);
185 $showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context);
186
187 // prepare paging bar
929d7a83 188 $pagingbar = new paging_bar($data->totalcount, $page, $perpage, $PAGE->url, 'page');
d183140d
DM
189
190 // grading report display options
7a789aa8 191 $reportopts = new stdclass();
d183140d
DM
192 $reportopts->showauthornames = $showauthornames;
193 $reportopts->showreviewernames = $showreviewernames;
194 $reportopts->sortby = $sortby;
195 $reportopts->sorthow = $sorthow;
196 $reportopts->showsubmissiongrade = false;
197 $reportopts->showgradinggrade = false;
d183140d 198
55fc1e59
DM
199 echo $output->render($pagingbar);
200 echo $output->grading_report($data, $reportopts);
201 echo $output->render($pagingbar);
d183140d
DM
202 }
203 }
15d12b54
DM
204 if (trim(strip_tags($workshop->instructreviewers))) {
205 $instructions = file_rewrite_pluginfile_urls($workshop->instructreviewers, 'pluginfile.php', $PAGE->context->id,
206 'workshop_instructreviewers', 0, workshop::instruction_editors_options($PAGE->context));
ef96efe0 207 print_collapsible_region_start('', 'workshop-viewlet-instructreviewers', get_string('instructreviewers', 'workshop'));
55fc1e59 208 echo $output->box(format_text($instructions, $workshop->instructreviewersformat), array('generalbox', 'instructions'));
ef96efe0 209 print_collapsible_region_end();
15d12b54 210 }
cff28ef0
DM
211 $examplesdone = (!$workshop->useexamples or has_capability('mod/workshop:manageexamples', $workshop->context));
212 if ($workshop->assessing_examples_allowed()
213 and has_capability('mod/workshop:submit', $workshop->context)
214 and ! has_capability('mod/workshop:manageexamples', $workshop->context)) {
215 $examples = $userplan->get_examples();
216 $total = count($examples);
217 $left = 0;
218 // make sure the current user has all examples allocated
219 foreach ($examples as $exampleid => $example) {
220 if (is_null($example->assessmentid)) {
221 $examples[$exampleid]->assessmentid = $workshop->add_allocation($example, $USER->id, 0);
ddb59c77 222 }
cff28ef0
DM
223 if (is_null($example->grade)) {
224 $left++;
225 }
226 }
227 if ($left > 0 and $workshop->examplesmode != workshop::EXAMPLES_VOLUNTARY) {
228 $examplesdone = false;
229 } else {
230 $examplesdone = true;
231 }
232 print_collapsible_region_start('', 'workshop-viewlet-examples', get_string('exampleassessments', 'workshop'), false, $examplesdone);
233 echo $output->box_start('generalbox exampleassessments');
234 if ($total == 0) {
235 echo $output->heading(get_string('noexamples', 'workshop'), 3);
236 } else {
237 foreach ($examples as $example) {
238 $summary = $workshop->prepare_example_summary($example);
239 echo $output->example_summary($summary);
240 }
241 }
242 echo $output->box_end();
243 print_collapsible_region_end();
244 }
245 if ($examplesdone) {
246 print_collapsible_region_start('', 'workshop-viewlet-assignedassessments', get_string('assignedassessments', 'workshop'));
247 if (! $assessments = $workshop->get_assessments_by_reviewer($USER->id)) {
248 echo $output->box_start('generalbox assessment-none');
249 echo $output->heading(get_string('assignedassessmentsnone', 'workshop'), 3);
55fc1e59 250 echo $output->box_end();
cff28ef0
DM
251 } else {
252 $shownames = has_capability('mod/workshop:viewauthornames', $PAGE->context);
253 foreach ($assessments as $assessment) {
254 $submission = new stdclass();
255 $submission->id = $assessment->submissionid;
256 $submission->title = $assessment->submissiontitle;
257 $submission->timecreated = $assessment->submissioncreated;
258 $submission->timemodified = $assessment->submissionmodified;
259 $submission->authorid = $assessment->authorid;
260 $submission->authorfirstname = $assessment->authorfirstname;
261 $submission->authorlastname = $assessment->authorlastname;
262 $submission->authorpicture = $assessment->authorpicture;
263 $submission->authorimagealt = $assessment->authorimagealt;
264
265 if (is_null($assessment->grade)) {
266 $class = ' notgraded';
267 $status = get_string('nogradeyet', 'workshop');
268 $buttontext = get_string('assess', 'workshop');
269 } else {
270 $class = ' graded';
271 $status = get_string('alreadygraded', 'workshop');
272 $buttontext = get_string('reassess', 'workshop');
273 }
274 echo $output->box_start('generalbox assessment-summary' . $class);
275 echo $output->submission_summary($submission, $shownames);
276 $aurl = $workshop->assess_url($assessment->id);
277 echo $output->single_button($aurl, $buttontext, 'get');
278 echo $output->box_end();
279 }
ddb59c77 280 }
cff28ef0 281 print_collapsible_region_end();
ddb59c77 282 }
00aca3c1 283 break;
b761e6d9 284case workshop::PHASE_EVALUATION:
d183140d 285 if (has_capability('mod/workshop:viewallassessments', $PAGE->context)) {
1fed6ce3
DM
286 $page = optional_param('page', 0, PARAM_INT);
287 $sortby = optional_param('sortby', 'lastname', PARAM_ALPHA);
288 $sorthow = optional_param('sorthow', 'ASC', PARAM_ALPHA);
289 $perpage = 10; // todo let the user modify this
290 $groups = ''; // todo let the user choose the group
a6855934 291 $PAGE->set_url($PAGE->url, compact('sortby', 'sorthow', 'page')); // TODO: this is suspicious
1fed6ce3
DM
292 $data = $workshop->prepare_grading_report($USER->id, $groups, $page, $perpage, $sortby, $sorthow);
293 if ($data) {
f55650e6
DM
294 $showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context);
295 $showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context);
296
d183140d
DM
297 if (has_capability('mod/workshop:overridegrades', $PAGE->context)) {
298 // load the grading evaluator
299 $evaluator = $workshop->grading_evaluation_instance();
300 $form = $evaluator->get_settings_form(new moodle_url($workshop->aggregate_url(),
301 compact('sortby', 'sorthow', 'page')));
302 $form->display();
303 }
1fed6ce3
DM
304
305 // prepare paging bar
929d7a83 306 $pagingbar = new paging_bar($data->totalcount, $page, $perpage, $PAGE->url, 'page');
1fed6ce3 307
d183140d 308 // grading report display options
7a789aa8 309 $reportopts = new stdclass();
d183140d
DM
310 $reportopts->showauthornames = $showauthornames;
311 $reportopts->showreviewernames = $showreviewernames;
312 $reportopts->sortby = $sortby;
313 $reportopts->sorthow = $sorthow;
314 $reportopts->showsubmissiongrade = true;
315 $reportopts->showgradinggrade = true;
d183140d 316
55fc1e59
DM
317 echo $output->render($pagingbar);
318 echo $output->grading_report($data, $reportopts);
319 echo $output->render($pagingbar);
e807e9a3 320 }
1fed6ce3
DM
321 }
322 break;
323case workshop::PHASE_CLOSED:
29dc43e7 324 break;
b761e6d9
DM
325default:
326}
327
55fc1e59 328echo $output->footer();