MDL-21695 adding help string
[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
6adbcb80 60$wsoutput = $PAGE->get_renderer('mod_workshop');
b761e6d9 61
b8ead2e6 62/// Output starts here
66c9894d 63
39861053 64echo $OUTPUT->header();
3dc6a7b9 65echo $OUTPUT->heading_with_help(format_string($workshop->name), 'userplan', 'workshop');
f05c168d 66echo $wsoutput->user_plan($workshop->prepare_user_plan($USER->id, $PAGE->context));
b761e6d9 67
b761e6d9
DM
68switch ($workshop->phase) {
69case workshop::PHASE_SETUP:
b761e6d9 70 if (trim(strip_tags($workshop->intro))) {
ef96efe0
DM
71 print_collapsible_region_start('', 'workshop-viewlet-intro', get_string('introduction', 'workshop'));
72 echo $OUTPUT->box(format_module_intro('workshop', $workshop, $workshop->cm->id), 'generalbox');
73 print_collapsible_region_end();
b761e6d9 74 }
81eccf0a 75 if ($workshop->useexamples and has_capability('mod/workshop:manageexamples', $PAGE->context)) {
ef96efe0 76 print_collapsible_region_start('', 'workshop-viewlet-allexamples', get_string('examplesubmissions', 'workshop'));
81eccf0a 77 echo $OUTPUT->box_start('generalbox examples');
cbf87967
DM
78 if ($workshop->grading_strategy_instance()->form_ready()) {
79 if (! $examples = $workshop->get_examples_for_manager()) {
80 echo $OUTPUT->container(get_string('noexamples', 'workshop'), 'noexamples');
81 }
82 foreach ($examples as $example) {
83 $summary = $workshop->prepare_example_summary($example);
84 echo $wsoutput->example_summary($summary);
85 }
3ba60ee1
PS
86 $aurl = new moodle_url($workshop->exsubmission_url(0), array('edit' => 'on'));
87 echo $OUTPUT->single_button($aurl, get_string('exampleadd', 'workshop'), 'get');
cbf87967
DM
88 } else {
89 echo $OUTPUT->container(get_string('noexamplesformready', 'workshop'));
81eccf0a 90 }
81eccf0a 91 echo $OUTPUT->box_end();
4437929e 92 print_collapsible_region_end();
81eccf0a 93 }
b761e6d9
DM
94 break;
95case workshop::PHASE_SUBMISSION:
6516b9e9
DM
96 if (trim(strip_tags($workshop->instructauthors))) {
97 $instructions = file_rewrite_pluginfile_urls($workshop->instructauthors, 'pluginfile.php', $PAGE->context->id,
98 'workshop_instructauthors', 0, workshop::instruction_editors_options($PAGE->context));
ef96efe0 99 print_collapsible_region_start('', 'workshop-viewlet-instructauthors', get_string('instructauthors', 'workshop'));
6516b9e9 100 echo $OUTPUT->box(format_text($instructions, $workshop->instructauthorsformat), array('generalbox', 'instructions'));
ef96efe0
DM
101 print_collapsible_region_end();
102 }
ef96efe0 103
cbf87967
DM
104 $examplesdone = true;
105 if ($workshop->assessing_examples_allowed()
106 and has_capability('mod/workshop:submit', $workshop->context)
107 and ! has_capability('mod/workshop:manageexamples', $workshop->context)) {
108 $examples = $workshop->get_examples_for_reviewer($USER->id);
109 $total = count($examples);
110 $done = 0;
111 $todo = 0;
112 // make sure the current user has all examples allocated
113 foreach ($examples as $exampleid => $example) {
114 if (is_null($example->assessmentid)) {
115 $examples[$exampleid]->assessmentid = $workshop->add_allocation($example, $USER->id, false, 0);
116 }
117 if (is_null($example->grade)) {
118 $todo++;
ef96efe0 119 } else {
cbf87967 120 $done++;
ef96efe0
DM
121 }
122 }
cbf87967
DM
123 if ($todo > 0 and $workshop->examplesmode != workshop::EXAMPLES_VOLUNTARY) {
124 $examplesdone = false;
ef96efe0 125 }
cbf87967
DM
126 print_collapsible_region_start('', 'workshop-viewlet-examples', get_string('exampleassessments', 'workshop'));
127 echo $OUTPUT->box_start('generalbox exampleassessments');
128 if ($total == 0) {
129 echo $OUTPUT->heading(get_string('noexamples', 'workshop'), 3);
130 } else {
131 foreach ($examples as $example) {
132 $summary = $workshop->prepare_example_summary($example);
133 echo $wsoutput->example_summary($summary);
134 }
ef96efe0 135 }
cbf87967
DM
136 echo $OUTPUT->box_end();
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'));
81eccf0a 144 echo $OUTPUT->box_start('generalbox ownsubmission');
e9b0f0ab 145 if ($submission = $workshop->get_submission_by_author($USER->id)) {
e9b0f0ab 146 echo $wsoutput->submission_summary($submission, true);
81eccf0a
DM
147 } else {
148 echo $OUTPUT->container(get_string('noyoursubmission', 'workshop'));
149 }
150 if ($workshop->submitting_allowed()) {
3ba60ee1
PS
151 $aurl = new moodle_url($workshop->submission_url(), array('edit' => 'on'));
152 echo $OUTPUT->single_button($aurl, get_string('editsubmission', 'workshop'), 'get');
e9b0f0ab 153 }
81eccf0a 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'));
e9b0f0ab 161 echo $OUTPUT->box_start('generalbox allsubmissions');
29dc43e7 162 if (! $submissions = $workshop->get_submissions('all')) {
ddb59c77
DM
163 echo $OUTPUT->container(get_string('nosubmissions', 'workshop'), 'nosubmissions');
164 }
3dc78e5b 165 foreach ($submissions as $submission) {
e9b0f0ab
DM
166 echo $wsoutput->submission_summary($submission, $shownames);
167 }
e9b0f0ab 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
929d7a83 199 echo $OUTPUT->render($pagingbar);
d183140d 200 echo $wsoutput->grading_report($data, $reportopts);
929d7a83 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'));
15d12b54 208 echo $OUTPUT->box(format_text($instructions, $workshop->instructreviewersformat), array('generalbox', 'instructions'));
ef96efe0 209 print_collapsible_region_end();
15d12b54 210 }
ef96efe0 211 print_collapsible_region_start('', 'workshop-viewlet-assignedassessments', get_string('assignedassessments', 'workshop'));
ddb59c77 212 if (! $assessments = $workshop->get_assessments_by_reviewer($USER->id)) {
ef96efe0 213 echo $OUTPUT->box_start('generalbox assessment-none');
ddb59c77 214 echo $OUTPUT->heading(get_string('assignedassessmentsnone', 'workshop'), 3);
ef96efe0 215 echo $OUTPUT->box_end();
ddb59c77 216 } else {
ddb59c77
DM
217 $shownames = has_capability('mod/workshop:viewauthornames', $PAGE->context);
218 foreach ($assessments as $assessment) {
7a789aa8 219 $submission = new stdclass();
8d57ce64
DM
220 $submission->id = $assessment->submissionid;
221 $submission->title = $assessment->submissiontitle;
222 $submission->timecreated = $assessment->submissioncreated;
223 $submission->timemodified = $assessment->submissionmodified;
224 $submission->authorid = $assessment->authorid;
225 $submission->authorfirstname = $assessment->authorfirstname;
226 $submission->authorlastname = $assessment->authorlastname;
227 $submission->authorpicture = $assessment->authorpicture;
228 $submission->authorimagealt = $assessment->authorimagealt;
229
ddb59c77
DM
230 if (is_null($assessment->grade)) {
231 $class = ' notgraded';
8d57ce64 232 $status = get_string('nogradeyet', 'workshop');
ddb59c77
DM
233 $buttontext = get_string('assess', 'workshop');
234 } else {
235 $class = ' graded';
8d57ce64 236 $status = get_string('alreadygraded', 'workshop');
ddb59c77
DM
237 $buttontext = get_string('reassess', 'workshop');
238 }
239 echo $OUTPUT->box_start('generalbox assessment-summary' . $class);
240 echo $wsoutput->submission_summary($submission, $shownames);
3ba60ee1
PS
241 $aurl = $workshop->assess_url($assessment->id);
242 echo $OUTPUT->single_button($aurl, $buttontext, 'get');
ddb59c77
DM
243 echo $OUTPUT->box_end();
244 }
245 }
ef96efe0 246 print_collapsible_region_end();
00aca3c1 247 break;
b761e6d9 248case workshop::PHASE_EVALUATION:
d183140d 249 if (has_capability('mod/workshop:viewallassessments', $PAGE->context)) {
1fed6ce3
DM
250 $page = optional_param('page', 0, PARAM_INT);
251 $sortby = optional_param('sortby', 'lastname', PARAM_ALPHA);
252 $sorthow = optional_param('sorthow', 'ASC', PARAM_ALPHA);
253 $perpage = 10; // todo let the user modify this
254 $groups = ''; // todo let the user choose the group
a6855934 255 $PAGE->set_url($PAGE->url, compact('sortby', 'sorthow', 'page')); // TODO: this is suspicious
1fed6ce3
DM
256 $data = $workshop->prepare_grading_report($USER->id, $groups, $page, $perpage, $sortby, $sorthow);
257 if ($data) {
f55650e6
DM
258 $showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context);
259 $showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context);
260
d183140d
DM
261 if (has_capability('mod/workshop:overridegrades', $PAGE->context)) {
262 // load the grading evaluator
263 $evaluator = $workshop->grading_evaluation_instance();
264 $form = $evaluator->get_settings_form(new moodle_url($workshop->aggregate_url(),
265 compact('sortby', 'sorthow', 'page')));
266 $form->display();
267 }
1fed6ce3
DM
268
269 // prepare paging bar
929d7a83 270 $pagingbar = new paging_bar($data->totalcount, $page, $perpage, $PAGE->url, 'page');
1fed6ce3 271
d183140d 272 // grading report display options
7a789aa8 273 $reportopts = new stdclass();
d183140d
DM
274 $reportopts->showauthornames = $showauthornames;
275 $reportopts->showreviewernames = $showreviewernames;
276 $reportopts->sortby = $sortby;
277 $reportopts->sorthow = $sorthow;
278 $reportopts->showsubmissiongrade = true;
279 $reportopts->showgradinggrade = true;
d183140d 280
929d7a83 281 echo $OUTPUT->render($pagingbar);
d183140d 282 echo $wsoutput->grading_report($data, $reportopts);
929d7a83 283 echo $OUTPUT->render($pagingbar);
e807e9a3 284 }
1fed6ce3
DM
285 }
286 break;
287case workshop::PHASE_CLOSED:
29dc43e7 288 break;
b761e6d9
DM
289default:
290}
291
ffac17df 292echo $OUTPUT->footer();