Commit | Line | Data |
---|---|---|
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 | 29 | require_once(dirname(dirname(dirname(__FILE__))).'/config.php'); |
ffac17df | 30 | require_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 | |
36 | if ($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 | ||
46 | require_login($course, true, $cm); | |
b761e6d9 | 47 | require_capability('mod/workshop:view', $PAGE->context); |
a3610b08 | 48 | add_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 |
52 | if (!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 DM |
59 | |
60 | // todo | |
a39d7d87 DM |
61 | $buttons = array(); |
62 | if ($PAGE->user_allowed_editing()) { | |
63 | $editblocks = new html_form(); | |
64 | $editblocks->method = 'get'; | |
65 | $editblocks->button->text = get_string($PAGE->user_is_editing() ? 'blockseditoff' : 'blocksediton'); | |
f82567af | 66 | $editblocks->url = new moodle_url($PAGE->url, array('editmode' => $PAGE->user_is_editing() ? 'off' : 'on')); |
a39d7d87 DM |
67 | $buttons[] = $OUTPUT->button($editblocks); |
68 | } | |
088e75ca | 69 | $buttons[] = $OUTPUT->update_module_button($cm->id, 'workshop'); |
a39d7d87 | 70 | $PAGE->set_button(implode('', $buttons)); |
ffac17df | 71 | |
6adbcb80 | 72 | $wsoutput = $PAGE->get_renderer('mod_workshop'); |
b761e6d9 | 73 | |
b8ead2e6 | 74 | /// Output starts here |
66c9894d | 75 | |
39861053 | 76 | echo $OUTPUT->header(); |
b761e6d9 | 77 | include(dirname(__FILE__) . '/tabs.php'); |
e9b0f0ab | 78 | echo $OUTPUT->heading(format_string($workshop->name), 2); |
f05c168d | 79 | echo $wsoutput->user_plan($workshop->prepare_user_plan($USER->id, $PAGE->context)); |
b761e6d9 | 80 | |
b761e6d9 DM |
81 | switch ($workshop->phase) { |
82 | case workshop::PHASE_SETUP: | |
b761e6d9 | 83 | if (trim(strip_tags($workshop->intro))) { |
ef96efe0 DM |
84 | print_collapsible_region_start('', 'workshop-viewlet-intro', get_string('introduction', 'workshop')); |
85 | echo $OUTPUT->box(format_module_intro('workshop', $workshop, $workshop->cm->id), 'generalbox'); | |
86 | print_collapsible_region_end(); | |
b761e6d9 | 87 | } |
81eccf0a | 88 | if ($workshop->useexamples and has_capability('mod/workshop:manageexamples', $PAGE->context)) { |
ef96efe0 | 89 | print_collapsible_region_start('', 'workshop-viewlet-allexamples', get_string('examplesubmissions', 'workshop')); |
81eccf0a DM |
90 | echo $OUTPUT->box_start('generalbox examples'); |
91 | echo $OUTPUT->heading(get_string('examplesubmissions', 'workshop'), 3); | |
92 | if (! $examples = $workshop->get_examples()) { | |
93 | echo $OUTPUT->container(get_string('noexamples', 'workshop'), 'noexamples'); | |
94 | } | |
95 | foreach ($examples as $example) { | |
96 | echo $wsoutput->example_summary($example); | |
97 | } | |
98 | $editbutton = new html_form(); | |
99 | $editbutton->method = 'get'; | |
100 | $editbutton->button->text = get_string('exampleadd', 'workshop'); | |
becec954 | 101 | $editbutton->url = new moodle_url($workshop->exsubmission_url(0), array('edit' => 'on')); |
81eccf0a DM |
102 | echo $OUTPUT->button($editbutton); |
103 | echo $OUTPUT->box_end(); | |
104 | } | |
b761e6d9 DM |
105 | break; |
106 | case workshop::PHASE_SUBMISSION: | |
6516b9e9 DM |
107 | if (trim(strip_tags($workshop->instructauthors))) { |
108 | $instructions = file_rewrite_pluginfile_urls($workshop->instructauthors, 'pluginfile.php', $PAGE->context->id, | |
109 | 'workshop_instructauthors', 0, workshop::instruction_editors_options($PAGE->context)); | |
ef96efe0 | 110 | print_collapsible_region_start('', 'workshop-viewlet-instructauthors', get_string('instructauthors', 'workshop')); |
6516b9e9 | 111 | echo $OUTPUT->box(format_text($instructions, $workshop->instructauthorsformat), array('generalbox', 'instructions')); |
ef96efe0 DM |
112 | print_collapsible_region_end(); |
113 | } | |
114 | //print_collapsible_region_start('', 'workshop-viewlet-examples', get_string('hideshow', 'workshop')); | |
115 | //echo 'Hello'; | |
116 | //print_collapsible_region_end(); | |
117 | /* todo pseudocode follows | |
118 | if ($workshop->useexamples) { | |
119 | if (examples are voluntary) { | |
120 | submitting is allowed | |
121 | assessing is allowed | |
122 | display the example assessment tool - just offer the posibility to train assessment | |
123 | } | |
124 | if (examples must be done before submission) { | |
125 | if (student assessed all example submissions) { | |
126 | submitting is allowed | |
127 | assessing is allowed | |
128 | display - let the student to reassess to train | |
129 | } else { | |
130 | submitting is not allowed | |
131 | assessing is not allowed | |
132 | display - force student to assess the examples | |
133 | } | |
134 | } | |
135 | ||
136 | ||
137 | // the following goes into the next PHASE | |
138 | if (examples must be done before assessment) { | |
139 | if (student assessed all example submissions) { | |
140 | assessing is allowed | |
141 | let the student to optionally reassess to train | |
142 | } else { | |
143 | assessing is not allowed | |
144 | force student to assess the examples | |
145 | } | |
146 | } | |
147 | } | |
148 | ||
149 | */ | |
150 | if ($workshop->useexamples and $workshop->examplesmode == workshop::EXAMPLES_BEFORE_SUBMISSION) { | |
151 | if (has_capability('mod/workshop:manageexamples', $workshop->context)) { | |
152 | // todo what is teacher expected to see here? some stats probably... | |
153 | } | |
154 | if (has_capability('mod/workshop:peerassess', $workshop->context)) { | |
155 | ||
156 | } | |
6516b9e9 | 157 | } |
e9b0f0ab | 158 | if (has_capability('mod/workshop:submit', $PAGE->context)) { |
ef96efe0 | 159 | print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop')); |
81eccf0a | 160 | echo $OUTPUT->box_start('generalbox ownsubmission'); |
e9b0f0ab | 161 | if ($submission = $workshop->get_submission_by_author($USER->id)) { |
e9b0f0ab | 162 | echo $wsoutput->submission_summary($submission, true); |
81eccf0a DM |
163 | } else { |
164 | echo $OUTPUT->container(get_string('noyoursubmission', 'workshop')); | |
165 | } | |
166 | if ($workshop->submitting_allowed()) { | |
167 | $editbutton = new html_form(); | |
168 | $editbutton->method = 'get'; | |
169 | $editbutton->button->text = get_string('editsubmission', 'workshop'); | |
170 | $editbutton->url = new moodle_url($workshop->submission_url(), array('edit' => 'on')); | |
171 | echo $OUTPUT->button($editbutton); | |
e9b0f0ab | 172 | } |
81eccf0a | 173 | echo $OUTPUT->box_end(); |
ef96efe0 | 174 | print_collapsible_region_end(); |
e9b0f0ab DM |
175 | } |
176 | if (has_capability('mod/workshop:viewallsubmissions', $PAGE->context)) { | |
177 | $shownames = has_capability('mod/workshop:viewauthornames', $PAGE->context); | |
ef96efe0 | 178 | print_collapsible_region_start('', 'workshop-viewlet-allsubmissions', get_string('allsubmissions', 'workshop')); |
e9b0f0ab | 179 | echo $OUTPUT->box_start('generalbox allsubmissions'); |
29dc43e7 | 180 | if (! $submissions = $workshop->get_submissions('all')) { |
ddb59c77 DM |
181 | echo $OUTPUT->container(get_string('nosubmissions', 'workshop'), 'nosubmissions'); |
182 | } | |
3dc78e5b | 183 | foreach ($submissions as $submission) { |
e9b0f0ab DM |
184 | echo $wsoutput->submission_summary($submission, $shownames); |
185 | } | |
e9b0f0ab | 186 | echo $OUTPUT->box_end(); |
ef96efe0 | 187 | print_collapsible_region_end(); |
e9b0f0ab DM |
188 | } |
189 | break; | |
b761e6d9 | 190 | case workshop::PHASE_ASSESSMENT: |
d183140d DM |
191 | if (has_capability('mod/workshop:viewallassessments', $PAGE->context)) { |
192 | $page = optional_param('page', 0, PARAM_INT); | |
193 | $sortby = optional_param('sortby', 'lastname', PARAM_ALPHA); | |
194 | $sorthow = optional_param('sorthow', 'ASC', PARAM_ALPHA); | |
195 | $perpage = 10; // todo let the user modify this | |
196 | $groups = ''; // todo let the user choose the group | |
197 | $PAGE->set_url(new moodle_url($PAGE->url, compact('sortby', 'sorthow', 'page'))); | |
198 | $data = $workshop->prepare_grading_report($USER->id, $groups, $page, $perpage, $sortby, $sorthow); | |
199 | if ($data) { | |
200 | $showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context); | |
201 | $showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context); | |
202 | ||
203 | // prepare paging bar | |
204 | $pagingbar = new moodle_paging_bar(); | |
205 | $pagingbar->totalcount = $data->totalcount; | |
206 | $pagingbar->page = $page; | |
207 | $pagingbar->perpage = $perpage; | |
208 | $pagingbar->baseurl = $PAGE->url; | |
209 | $pagingbar->pagevar = 'page'; | |
210 | ||
211 | // grading report display options | |
212 | $reportopts = new stdClass(); | |
213 | $reportopts->showauthornames = $showauthornames; | |
214 | $reportopts->showreviewernames = $showreviewernames; | |
215 | $reportopts->sortby = $sortby; | |
216 | $reportopts->sorthow = $sorthow; | |
217 | $reportopts->showsubmissiongrade = false; | |
218 | $reportopts->showgradinggrade = false; | |
d183140d DM |
219 | |
220 | echo $OUTPUT->paging_bar($pagingbar); | |
221 | echo $wsoutput->grading_report($data, $reportopts); | |
222 | echo $OUTPUT->paging_bar($pagingbar); | |
223 | } | |
224 | } | |
15d12b54 DM |
225 | if (trim(strip_tags($workshop->instructreviewers))) { |
226 | $instructions = file_rewrite_pluginfile_urls($workshop->instructreviewers, 'pluginfile.php', $PAGE->context->id, | |
227 | 'workshop_instructreviewers', 0, workshop::instruction_editors_options($PAGE->context)); | |
ef96efe0 | 228 | print_collapsible_region_start('', 'workshop-viewlet-instructreviewers', get_string('instructreviewers', 'workshop')); |
15d12b54 | 229 | echo $OUTPUT->box(format_text($instructions, $workshop->instructreviewersformat), array('generalbox', 'instructions')); |
ef96efe0 | 230 | print_collapsible_region_end(); |
15d12b54 | 231 | } |
ef96efe0 | 232 | print_collapsible_region_start('', 'workshop-viewlet-assignedassessments', get_string('assignedassessments', 'workshop')); |
ddb59c77 | 233 | if (! $assessments = $workshop->get_assessments_by_reviewer($USER->id)) { |
ef96efe0 | 234 | echo $OUTPUT->box_start('generalbox assessment-none'); |
ddb59c77 | 235 | echo $OUTPUT->heading(get_string('assignedassessmentsnone', 'workshop'), 3); |
ef96efe0 | 236 | echo $OUTPUT->box_end(); |
ddb59c77 | 237 | } else { |
ddb59c77 DM |
238 | $shownames = has_capability('mod/workshop:viewauthornames', $PAGE->context); |
239 | foreach ($assessments as $assessment) { | |
8d57ce64 DM |
240 | $submission = new stdClass(); |
241 | $submission->id = $assessment->submissionid; | |
242 | $submission->title = $assessment->submissiontitle; | |
243 | $submission->timecreated = $assessment->submissioncreated; | |
244 | $submission->timemodified = $assessment->submissionmodified; | |
245 | $submission->authorid = $assessment->authorid; | |
246 | $submission->authorfirstname = $assessment->authorfirstname; | |
247 | $submission->authorlastname = $assessment->authorlastname; | |
248 | $submission->authorpicture = $assessment->authorpicture; | |
249 | $submission->authorimagealt = $assessment->authorimagealt; | |
250 | ||
ddb59c77 DM |
251 | if (is_null($assessment->grade)) { |
252 | $class = ' notgraded'; | |
8d57ce64 | 253 | $status = get_string('nogradeyet', 'workshop'); |
ddb59c77 DM |
254 | $buttontext = get_string('assess', 'workshop'); |
255 | } else { | |
256 | $class = ' graded'; | |
8d57ce64 | 257 | $status = get_string('alreadygraded', 'workshop'); |
ddb59c77 DM |
258 | $buttontext = get_string('reassess', 'workshop'); |
259 | } | |
260 | echo $OUTPUT->box_start('generalbox assessment-summary' . $class); | |
261 | echo $wsoutput->submission_summary($submission, $shownames); | |
8d57ce64 | 262 | echo get_string('givengradestatus', 'workshop', $status); |
ddb59c77 DM |
263 | $button = new html_form(); |
264 | $button->method = 'get'; | |
265 | $button->button->text = $buttontext; | |
266 | $button->url = $workshop->assess_url($assessment->id); | |
267 | echo $OUTPUT->button($button); | |
268 | echo $OUTPUT->box_end(); | |
269 | } | |
270 | } | |
ef96efe0 | 271 | print_collapsible_region_end(); |
00aca3c1 | 272 | break; |
b761e6d9 | 273 | case workshop::PHASE_EVALUATION: |
d183140d | 274 | if (has_capability('mod/workshop:viewallassessments', $PAGE->context)) { |
1fed6ce3 DM |
275 | $page = optional_param('page', 0, PARAM_INT); |
276 | $sortby = optional_param('sortby', 'lastname', PARAM_ALPHA); | |
277 | $sorthow = optional_param('sorthow', 'ASC', PARAM_ALPHA); | |
278 | $perpage = 10; // todo let the user modify this | |
279 | $groups = ''; // todo let the user choose the group | |
280 | $PAGE->set_url(new moodle_url($PAGE->url, compact('sortby', 'sorthow', 'page'))); | |
281 | $data = $workshop->prepare_grading_report($USER->id, $groups, $page, $perpage, $sortby, $sorthow); | |
282 | if ($data) { | |
f55650e6 DM |
283 | $showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context); |
284 | $showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context); | |
285 | ||
d183140d DM |
286 | if (has_capability('mod/workshop:overridegrades', $PAGE->context)) { |
287 | // load the grading evaluator | |
288 | $evaluator = $workshop->grading_evaluation_instance(); | |
289 | $form = $evaluator->get_settings_form(new moodle_url($workshop->aggregate_url(), | |
290 | compact('sortby', 'sorthow', 'page'))); | |
291 | $form->display(); | |
292 | } | |
1fed6ce3 DM |
293 | |
294 | // prepare paging bar | |
295 | $pagingbar = new moodle_paging_bar(); | |
296 | $pagingbar->totalcount = $data->totalcount; | |
297 | $pagingbar->page = $page; | |
298 | $pagingbar->perpage = $perpage; | |
299 | $pagingbar->baseurl = $PAGE->url; | |
300 | $pagingbar->pagevar = 'page'; | |
301 | ||
d183140d DM |
302 | // grading report display options |
303 | $reportopts = new stdClass(); | |
304 | $reportopts->showauthornames = $showauthornames; | |
305 | $reportopts->showreviewernames = $showreviewernames; | |
306 | $reportopts->sortby = $sortby; | |
307 | $reportopts->sorthow = $sorthow; | |
308 | $reportopts->showsubmissiongrade = true; | |
309 | $reportopts->showgradinggrade = true; | |
d183140d | 310 | |
1fed6ce3 | 311 | echo $OUTPUT->paging_bar($pagingbar); |
d183140d | 312 | echo $wsoutput->grading_report($data, $reportopts); |
1fed6ce3 | 313 | echo $OUTPUT->paging_bar($pagingbar); |
e807e9a3 | 314 | } |
1fed6ce3 DM |
315 | } |
316 | break; | |
317 | case workshop::PHASE_CLOSED: | |
29dc43e7 | 318 | break; |
b761e6d9 DM |
319 | default: |
320 | } | |
321 | ||
ffac17df | 322 | echo $OUTPUT->footer(); |