Do not display given grade before the workshop is closed
[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
a39d7d87
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$edit = optional_param('edit', 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
a39d7d87
DM
52if (!is_null($edit) && $PAGE->user_allowed_editing()) {
53 $USER->editing = $edit;
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();
62if ($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');
66 $editblocks->url = new moodle_url($PAGE->url, array('edit' => $PAGE->user_is_editing() ? 'off' : 'on'));
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
b761e6d9
DM
72$wsoutput = $PAGE->theme->get_renderer('mod_workshop', $PAGE);
73
b8ead2e6 74/// Output starts here
66c9894d 75
39861053 76echo $OUTPUT->header();
b761e6d9 77include(dirname(__FILE__) . '/tabs.php');
e9b0f0ab 78echo $OUTPUT->heading(format_string($workshop->name), 2);
f05c168d 79echo $wsoutput->user_plan($workshop->prepare_user_plan($USER->id, $PAGE->context));
b761e6d9 80
b761e6d9
DM
81switch ($workshop->phase) {
82case 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 }
86 break;
87case workshop::PHASE_SUBMISSION:
6516b9e9
DM
88 if (trim(strip_tags($workshop->instructauthors))) {
89 $instructions = file_rewrite_pluginfile_urls($workshop->instructauthors, 'pluginfile.php', $PAGE->context->id,
90 'workshop_instructauthors', 0, workshop::instruction_editors_options($PAGE->context));
91 echo $OUTPUT->box(format_text($instructions, $workshop->instructauthorsformat), array('generalbox', 'instructions'));
92 }
e9b0f0ab
DM
93 if (has_capability('mod/workshop:submit', $PAGE->context)) {
94 if ($submission = $workshop->get_submission_by_author($USER->id)) {
95 echo $OUTPUT->box_start('generalbox mysubmission');
96 echo $wsoutput->submission_summary($submission, true);
51508f25
DM
97 if ($workshop->submitting_allowed()) {
98 $editbutton = new html_form();
99 $editbutton->method = 'get';
100 $editbutton->button->text = get_string('editsubmission', 'workshop');
7b9b33eb 101 $editbutton->url = new moodle_url($workshop->submission_url(), array('edit' => 'on', 'id' => $submission->id));
51508f25
DM
102 echo $OUTPUT->button($editbutton);
103 }
e9b0f0ab
DM
104 echo $OUTPUT->box_end();
105 }
106 }
107 if (has_capability('mod/workshop:viewallsubmissions', $PAGE->context)) {
108 $shownames = has_capability('mod/workshop:viewauthornames', $PAGE->context);
109 echo $OUTPUT->box_start('generalbox allsubmissions');
29dc43e7 110 if (! $submissions = $workshop->get_submissions('all')) {
ddb59c77
DM
111 echo $OUTPUT->container(get_string('nosubmissions', 'workshop'), 'nosubmissions');
112 }
3dc78e5b 113 foreach ($submissions as $submission) {
e9b0f0ab
DM
114 echo $wsoutput->submission_summary($submission, $shownames);
115 }
e9b0f0ab
DM
116 echo $OUTPUT->box_end();
117 }
118 break;
b761e6d9 119case workshop::PHASE_ASSESSMENT:
15d12b54
DM
120 if (trim(strip_tags($workshop->instructreviewers))) {
121 $instructions = file_rewrite_pluginfile_urls($workshop->instructreviewers, 'pluginfile.php', $PAGE->context->id,
122 'workshop_instructreviewers', 0, workshop::instruction_editors_options($PAGE->context));
123 echo $OUTPUT->box(format_text($instructions, $workshop->instructreviewersformat), array('generalbox', 'instructions'));
124 }
ddb59c77
DM
125 if (! $assessments = $workshop->get_assessments_by_reviewer($USER->id)) {
126 echo $OUTPUT->heading(get_string('assignedassessmentsnone', 'workshop'), 3);
127 } else {
128 echo $OUTPUT->heading(get_string('assignedassessments', 'workshop'), 3);
129 $shownames = has_capability('mod/workshop:viewauthornames', $PAGE->context);
130 foreach ($assessments as $assessment) {
8d57ce64
DM
131 $submission = new stdClass();
132 $submission->id = $assessment->submissionid;
133 $submission->title = $assessment->submissiontitle;
134 $submission->timecreated = $assessment->submissioncreated;
135 $submission->timemodified = $assessment->submissionmodified;
136 $submission->authorid = $assessment->authorid;
137 $submission->authorfirstname = $assessment->authorfirstname;
138 $submission->authorlastname = $assessment->authorlastname;
139 $submission->authorpicture = $assessment->authorpicture;
140 $submission->authorimagealt = $assessment->authorimagealt;
141
ddb59c77
DM
142 if (is_null($assessment->grade)) {
143 $class = ' notgraded';
8d57ce64 144 $status = get_string('nogradeyet', 'workshop');
ddb59c77
DM
145 $buttontext = get_string('assess', 'workshop');
146 } else {
147 $class = ' graded';
8d57ce64 148 $status = get_string('alreadygraded', 'workshop');
ddb59c77
DM
149 $buttontext = get_string('reassess', 'workshop');
150 }
151 echo $OUTPUT->box_start('generalbox assessment-summary' . $class);
152 echo $wsoutput->submission_summary($submission, $shownames);
8d57ce64 153 echo get_string('givengradestatus', 'workshop', $status);
ddb59c77
DM
154 $button = new html_form();
155 $button->method = 'get';
156 $button->button->text = $buttontext;
157 $button->url = $workshop->assess_url($assessment->id);
158 echo $OUTPUT->button($button);
159 echo $OUTPUT->box_end();
160 }
161 }
00aca3c1 162 break;
b761e6d9 163case workshop::PHASE_EVALUATION:
1fed6ce3
DM
164 if (has_capability('mod/workshop:overridegrades', $PAGE->context)) {
165 $page = optional_param('page', 0, PARAM_INT);
166 $sortby = optional_param('sortby', 'lastname', PARAM_ALPHA);
167 $sorthow = optional_param('sorthow', 'ASC', PARAM_ALPHA);
168 $perpage = 10; // todo let the user modify this
169 $groups = ''; // todo let the user choose the group
170 $PAGE->set_url(new moodle_url($PAGE->url, compact('sortby', 'sorthow', 'page')));
171 $data = $workshop->prepare_grading_report($USER->id, $groups, $page, $perpage, $sortby, $sorthow);
172 if ($data) {
f55650e6
DM
173 $showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context);
174 $showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context);
175
176 // load the grading evaluator
177 $evaluator = $workshop->grading_evaluation_instance();
178 $form = $evaluator->get_settings_form(new moodle_url($workshop->aggregate_url(), compact('sortby', 'sorthow', 'page')));
179 $form->display();
1fed6ce3
DM
180
181 // prepare paging bar
182 $pagingbar = new moodle_paging_bar();
183 $pagingbar->totalcount = $data->totalcount;
184 $pagingbar->page = $page;
185 $pagingbar->perpage = $perpage;
186 $pagingbar->baseurl = $PAGE->url;
187 $pagingbar->pagevar = 'page';
188
189 echo $OUTPUT->paging_bar($pagingbar);
190 echo $wsoutput->grading_report($data, $showauthornames, $showreviewernames, $sortby, $sorthow);
191 echo $OUTPUT->paging_bar($pagingbar);
e807e9a3 192 }
1fed6ce3
DM
193 }
194 break;
195case workshop::PHASE_CLOSED:
196 $page = optional_param('page', 0, PARAM_INT);
f55650e6
DM
197 $sortby = optional_param('sortby', 'totalgrade', PARAM_ALPHA);
198 $sorthow = optional_param('sorthow', 'DESC', PARAM_ALPHA);
1fed6ce3
DM
199 $perpage = 10; // todo let the user modify this
200 $groups = ''; // todo let the user choose the group
201 $PAGE->set_url(new moodle_url($PAGE->url, compact('sortby', 'sorthow', 'page')));
202 $data = $workshop->prepare_grading_report($USER->id, $groups, $page, $perpage, $sortby, $sorthow);
203 if ($data) {
f55650e6
DM
204 $showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context);
205 $showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context);
e807e9a3 206
29dc43e7
DM
207 // prepare paging bar
208 $pagingbar = new moodle_paging_bar();
209 $pagingbar->totalcount = $data->totalcount;
210 $pagingbar->page = $page;
5e71cefb 211 $pagingbar->perpage = $perpage;
29dc43e7 212 $pagingbar->baseurl = $PAGE->url;
a880be9b 213 $pagingbar->pagevar = 'page';
29dc43e7
DM
214
215 echo $OUTPUT->paging_bar($pagingbar);
d10ee0be 216 echo $wsoutput->grading_report($data, $showauthornames, $showreviewernames, $sortby, $sorthow);
29dc43e7 217 echo $OUTPUT->paging_bar($pagingbar);
00aca3c1 218 }
29dc43e7 219 break;
b761e6d9
DM
220default:
221}
222
ffac17df 223echo $OUTPUT->footer();