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 DM |
83 | if (trim(strip_tags($workshop->intro))) { |
84 | echo $OUTPUT->box(format_module_intro('workshop', $workshop, $workshop->cm->id), 'generalbox', 'intro'); | |
85 | } | |
81eccf0a DM |
86 | if ($workshop->useexamples and has_capability('mod/workshop:manageexamples', $PAGE->context)) { |
87 | echo $OUTPUT->box_start('generalbox examples'); | |
88 | echo $OUTPUT->heading(get_string('examplesubmissions', 'workshop'), 3); | |
89 | if (! $examples = $workshop->get_examples()) { | |
90 | echo $OUTPUT->container(get_string('noexamples', 'workshop'), 'noexamples'); | |
91 | } | |
92 | foreach ($examples as $example) { | |
93 | echo $wsoutput->example_summary($example); | |
94 | } | |
95 | $editbutton = new html_form(); | |
96 | $editbutton->method = 'get'; | |
97 | $editbutton->button->text = get_string('exampleadd', 'workshop'); | |
becec954 | 98 | $editbutton->url = new moodle_url($workshop->exsubmission_url(0), array('edit' => 'on')); |
81eccf0a DM |
99 | echo $OUTPUT->button($editbutton); |
100 | echo $OUTPUT->box_end(); | |
101 | } | |
b761e6d9 DM |
102 | break; |
103 | case workshop::PHASE_SUBMISSION: | |
6516b9e9 DM |
104 | if (trim(strip_tags($workshop->instructauthors))) { |
105 | $instructions = file_rewrite_pluginfile_urls($workshop->instructauthors, 'pluginfile.php', $PAGE->context->id, | |
106 | 'workshop_instructauthors', 0, workshop::instruction_editors_options($PAGE->context)); | |
107 | echo $OUTPUT->box(format_text($instructions, $workshop->instructauthorsformat), array('generalbox', 'instructions')); | |
108 | } | |
e9b0f0ab | 109 | if (has_capability('mod/workshop:submit', $PAGE->context)) { |
81eccf0a DM |
110 | echo $OUTPUT->box_start('generalbox ownsubmission'); |
111 | echo $OUTPUT->heading(get_string('yoursubmission', 'workshop'), 3); | |
e9b0f0ab | 112 | if ($submission = $workshop->get_submission_by_author($USER->id)) { |
e9b0f0ab | 113 | echo $wsoutput->submission_summary($submission, true); |
81eccf0a DM |
114 | } else { |
115 | echo $OUTPUT->container(get_string('noyoursubmission', 'workshop')); | |
116 | } | |
117 | if ($workshop->submitting_allowed()) { | |
118 | $editbutton = new html_form(); | |
119 | $editbutton->method = 'get'; | |
120 | $editbutton->button->text = get_string('editsubmission', 'workshop'); | |
121 | $editbutton->url = new moodle_url($workshop->submission_url(), array('edit' => 'on')); | |
122 | echo $OUTPUT->button($editbutton); | |
e9b0f0ab | 123 | } |
81eccf0a | 124 | echo $OUTPUT->box_end(); |
e9b0f0ab DM |
125 | } |
126 | if (has_capability('mod/workshop:viewallsubmissions', $PAGE->context)) { | |
127 | $shownames = has_capability('mod/workshop:viewauthornames', $PAGE->context); | |
128 | echo $OUTPUT->box_start('generalbox allsubmissions'); | |
81eccf0a | 129 | echo $OUTPUT->heading(get_string('allsubmissions', 'workshop'), 3); |
29dc43e7 | 130 | if (! $submissions = $workshop->get_submissions('all')) { |
ddb59c77 DM |
131 | echo $OUTPUT->container(get_string('nosubmissions', 'workshop'), 'nosubmissions'); |
132 | } | |
3dc78e5b | 133 | foreach ($submissions as $submission) { |
e9b0f0ab DM |
134 | echo $wsoutput->submission_summary($submission, $shownames); |
135 | } | |
e9b0f0ab DM |
136 | echo $OUTPUT->box_end(); |
137 | } | |
138 | break; | |
b761e6d9 | 139 | case workshop::PHASE_ASSESSMENT: |
d183140d DM |
140 | if (has_capability('mod/workshop:viewallassessments', $PAGE->context)) { |
141 | $page = optional_param('page', 0, PARAM_INT); | |
142 | $sortby = optional_param('sortby', 'lastname', PARAM_ALPHA); | |
143 | $sorthow = optional_param('sorthow', 'ASC', PARAM_ALPHA); | |
144 | $perpage = 10; // todo let the user modify this | |
145 | $groups = ''; // todo let the user choose the group | |
146 | $PAGE->set_url(new moodle_url($PAGE->url, compact('sortby', 'sorthow', 'page'))); | |
147 | $data = $workshop->prepare_grading_report($USER->id, $groups, $page, $perpage, $sortby, $sorthow); | |
148 | if ($data) { | |
149 | $showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context); | |
150 | $showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context); | |
151 | ||
152 | // prepare paging bar | |
153 | $pagingbar = new moodle_paging_bar(); | |
154 | $pagingbar->totalcount = $data->totalcount; | |
155 | $pagingbar->page = $page; | |
156 | $pagingbar->perpage = $perpage; | |
157 | $pagingbar->baseurl = $PAGE->url; | |
158 | $pagingbar->pagevar = 'page'; | |
159 | ||
160 | // grading report display options | |
161 | $reportopts = new stdClass(); | |
162 | $reportopts->showauthornames = $showauthornames; | |
163 | $reportopts->showreviewernames = $showreviewernames; | |
164 | $reportopts->sortby = $sortby; | |
165 | $reportopts->sorthow = $sorthow; | |
166 | $reportopts->showsubmissiongrade = false; | |
167 | $reportopts->showgradinggrade = false; | |
d183140d DM |
168 | |
169 | echo $OUTPUT->paging_bar($pagingbar); | |
170 | echo $wsoutput->grading_report($data, $reportopts); | |
171 | echo $OUTPUT->paging_bar($pagingbar); | |
172 | } | |
173 | } | |
15d12b54 DM |
174 | if (trim(strip_tags($workshop->instructreviewers))) { |
175 | $instructions = file_rewrite_pluginfile_urls($workshop->instructreviewers, 'pluginfile.php', $PAGE->context->id, | |
176 | 'workshop_instructreviewers', 0, workshop::instruction_editors_options($PAGE->context)); | |
177 | echo $OUTPUT->box(format_text($instructions, $workshop->instructreviewersformat), array('generalbox', 'instructions')); | |
178 | } | |
ddb59c77 DM |
179 | if (! $assessments = $workshop->get_assessments_by_reviewer($USER->id)) { |
180 | echo $OUTPUT->heading(get_string('assignedassessmentsnone', 'workshop'), 3); | |
181 | } else { | |
182 | echo $OUTPUT->heading(get_string('assignedassessments', 'workshop'), 3); | |
183 | $shownames = has_capability('mod/workshop:viewauthornames', $PAGE->context); | |
184 | foreach ($assessments as $assessment) { | |
8d57ce64 DM |
185 | $submission = new stdClass(); |
186 | $submission->id = $assessment->submissionid; | |
187 | $submission->title = $assessment->submissiontitle; | |
188 | $submission->timecreated = $assessment->submissioncreated; | |
189 | $submission->timemodified = $assessment->submissionmodified; | |
190 | $submission->authorid = $assessment->authorid; | |
191 | $submission->authorfirstname = $assessment->authorfirstname; | |
192 | $submission->authorlastname = $assessment->authorlastname; | |
193 | $submission->authorpicture = $assessment->authorpicture; | |
194 | $submission->authorimagealt = $assessment->authorimagealt; | |
195 | ||
ddb59c77 DM |
196 | if (is_null($assessment->grade)) { |
197 | $class = ' notgraded'; | |
8d57ce64 | 198 | $status = get_string('nogradeyet', 'workshop'); |
ddb59c77 DM |
199 | $buttontext = get_string('assess', 'workshop'); |
200 | } else { | |
201 | $class = ' graded'; | |
8d57ce64 | 202 | $status = get_string('alreadygraded', 'workshop'); |
ddb59c77 DM |
203 | $buttontext = get_string('reassess', 'workshop'); |
204 | } | |
205 | echo $OUTPUT->box_start('generalbox assessment-summary' . $class); | |
206 | echo $wsoutput->submission_summary($submission, $shownames); | |
8d57ce64 | 207 | echo get_string('givengradestatus', 'workshop', $status); |
ddb59c77 DM |
208 | $button = new html_form(); |
209 | $button->method = 'get'; | |
210 | $button->button->text = $buttontext; | |
211 | $button->url = $workshop->assess_url($assessment->id); | |
212 | echo $OUTPUT->button($button); | |
213 | echo $OUTPUT->box_end(); | |
214 | } | |
215 | } | |
00aca3c1 | 216 | break; |
b761e6d9 | 217 | case workshop::PHASE_EVALUATION: |
d183140d | 218 | if (has_capability('mod/workshop:viewallassessments', $PAGE->context)) { |
1fed6ce3 DM |
219 | $page = optional_param('page', 0, PARAM_INT); |
220 | $sortby = optional_param('sortby', 'lastname', PARAM_ALPHA); | |
221 | $sorthow = optional_param('sorthow', 'ASC', PARAM_ALPHA); | |
222 | $perpage = 10; // todo let the user modify this | |
223 | $groups = ''; // todo let the user choose the group | |
224 | $PAGE->set_url(new moodle_url($PAGE->url, compact('sortby', 'sorthow', 'page'))); | |
225 | $data = $workshop->prepare_grading_report($USER->id, $groups, $page, $perpage, $sortby, $sorthow); | |
226 | if ($data) { | |
f55650e6 DM |
227 | $showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context); |
228 | $showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context); | |
229 | ||
d183140d DM |
230 | if (has_capability('mod/workshop:overridegrades', $PAGE->context)) { |
231 | // load the grading evaluator | |
232 | $evaluator = $workshop->grading_evaluation_instance(); | |
233 | $form = $evaluator->get_settings_form(new moodle_url($workshop->aggregate_url(), | |
234 | compact('sortby', 'sorthow', 'page'))); | |
235 | $form->display(); | |
236 | } | |
1fed6ce3 DM |
237 | |
238 | // prepare paging bar | |
239 | $pagingbar = new moodle_paging_bar(); | |
240 | $pagingbar->totalcount = $data->totalcount; | |
241 | $pagingbar->page = $page; | |
242 | $pagingbar->perpage = $perpage; | |
243 | $pagingbar->baseurl = $PAGE->url; | |
244 | $pagingbar->pagevar = 'page'; | |
245 | ||
d183140d DM |
246 | // grading report display options |
247 | $reportopts = new stdClass(); | |
248 | $reportopts->showauthornames = $showauthornames; | |
249 | $reportopts->showreviewernames = $showreviewernames; | |
250 | $reportopts->sortby = $sortby; | |
251 | $reportopts->sorthow = $sorthow; | |
252 | $reportopts->showsubmissiongrade = true; | |
253 | $reportopts->showgradinggrade = true; | |
d183140d | 254 | |
1fed6ce3 | 255 | echo $OUTPUT->paging_bar($pagingbar); |
d183140d | 256 | echo $wsoutput->grading_report($data, $reportopts); |
1fed6ce3 | 257 | echo $OUTPUT->paging_bar($pagingbar); |
e807e9a3 | 258 | } |
1fed6ce3 DM |
259 | } |
260 | break; | |
261 | case workshop::PHASE_CLOSED: | |
29dc43e7 | 262 | break; |
b761e6d9 DM |
263 | default: |
264 | } | |
265 | ||
ffac17df | 266 | echo $OUTPUT->footer(); |