Commit | Line | Data |
---|---|---|
bbd0e548 DW |
1 | <?php |
2 | // This file is part of Moodle - http://moodle.org/ | |
3 | // | |
4 | // Moodle is free software: you can redistribute it and/or modify | |
5 | // it under the terms of the GNU General Public License as published by | |
6 | // the Free Software Foundation, either version 3 of the License, or | |
7 | // (at your option) any later version. | |
8 | // | |
9 | // Moodle is distributed in the hope that it will be useful, | |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | // GNU General Public License for more details. | |
13 | // | |
14 | // You should have received a copy of the GNU General Public License | |
15 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. | |
16 | ||
17 | /** | |
18 | * This file contains a renderer for the assignment class | |
19 | * | |
20 | * @package mod_assign | |
21 | * @copyright 2012 NetSpot {@link http://www.netspot.com.au} | |
22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
23 | */ | |
24 | ||
25 | defined('MOODLE_INTERNAL') || die(); | |
26 | ||
bbd0e548 DW |
27 | require_once($CFG->dirroot . '/mod/assign/locallib.php'); |
28 | ||
bbd0e548 DW |
29 | /** |
30 | * A custom renderer class that extends the plugin_renderer_base and is used by the assign module. | |
31 | * | |
32 | * @package mod_assign | |
33 | * @copyright 2012 NetSpot {@link http://www.netspot.com.au} | |
34 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
35 | */ | |
36 | class mod_assign_renderer extends plugin_renderer_base { | |
37 | ||
38 | /** | |
e5403f8c | 39 | * Rendering assignment files |
bbd0e548 DW |
40 | * |
41 | * @param context $context | |
42 | * @param int $userid | |
43 | * @param string $filearea | |
44 | * @param string $component | |
45 | * @return string | |
46 | */ | |
47 | public function assign_files(context $context, $userid, $filearea, $component) { | |
48 | return $this->render(new assign_files($context, $userid, $filearea, $component)); | |
49 | } | |
50 | ||
51 | /** | |
e5403f8c | 52 | * Rendering assignment files |
bbd0e548 DW |
53 | * |
54 | * @param assign_files $tree | |
55 | * @return string | |
56 | */ | |
57 | public function render_assign_files(assign_files $tree) { | |
58 | $this->htmlid = 'assign_files_tree_'.uniqid(); | |
59 | $this->page->requires->js_init_call('M.mod_assign.init_tree', array(true, $this->htmlid)); | |
60 | $html = '<div id="'.$this->htmlid.'">'; | |
61 | $html .= $this->htmllize_tree($tree, $tree->dir); | |
62 | $html .= '</div>'; | |
63 | ||
64 | if ($tree->portfolioform) { | |
65 | $html .= $tree->portfolioform; | |
66 | } | |
67 | return $html; | |
68 | } | |
69 | ||
70 | /** | |
71 | * Utility function to add a row of data to a table with 2 columns. Modified | |
72 | * the table param and does not return a value | |
73 | * | |
74 | * @param html_table $table The table to append the row of data to | |
75 | * @param string $first The first column text | |
76 | * @param string $second The second column text | |
77 | * @return void | |
78 | */ | |
79 | private function add_table_row_tuple(html_table $table, $first, $second) { | |
80 | $row = new html_table_row(); | |
81 | $cell1 = new html_table_cell($first); | |
82 | $cell2 = new html_table_cell($second); | |
83 | $row->cells = array($cell1, $cell2); | |
84 | $table->data[] = $row; | |
85 | } | |
86 | ||
bf78ebd6 DW |
87 | /** |
88 | * Render a grading error notification | |
89 | * @param assign_quickgrading_result $result The result to render | |
90 | * @return string | |
91 | */ | |
92 | public function render_assign_quickgrading_result(assign_quickgrading_result $result) { | |
e5403f8c DW |
93 | $urlparams = array('id' => $result->coursemoduleid, 'action'=>'grading'); |
94 | $url = new moodle_url('/mod/assign/view.php', $urlparams); | |
2a4fbc32 | 95 | |
bf78ebd6 DW |
96 | $o = ''; |
97 | $o .= $this->output->heading(get_string('quickgradingresult', 'assign'), 4); | |
bf78ebd6 | 98 | $o .= $this->output->notification($result->message); |
2a4fbc32 | 99 | $o .= $this->output->continue_button($url); |
bf78ebd6 DW |
100 | return $o; |
101 | } | |
102 | ||
bbd0e548 DW |
103 | /** |
104 | * Render the generic form | |
105 | * @param assign_form $form The form to render | |
106 | * @return string | |
107 | */ | |
108 | public function render_assign_form(assign_form $form) { | |
109 | $o = ''; | |
bf78ebd6 DW |
110 | if ($form->jsinitfunction) { |
111 | $this->page->requires->js_init_call($form->jsinitfunction, array()); | |
112 | } | |
bbd0e548 DW |
113 | $o .= $this->output->box_start('boxaligncenter ' . $form->classname); |
114 | $o .= $this->moodleform($form->form); | |
115 | $o .= $this->output->box_end(); | |
116 | return $o; | |
117 | } | |
118 | ||
119 | /** | |
120 | * Render the user summary | |
121 | * | |
122 | * @param assign_user_summary $summary The user summary to render | |
123 | * @return string | |
124 | */ | |
125 | public function render_assign_user_summary(assign_user_summary $summary) { | |
126 | $o = ''; | |
127 | ||
128 | if (!$summary->user) { | |
129 | return; | |
130 | } | |
131 | $o .= $this->output->container_start('usersummary'); | |
132 | $o .= $this->output->box_start('boxaligncenter usersummarysection'); | |
b473171a | 133 | if ($summary->blindmarking) { |
df47b77f | 134 | $o .= get_string('hiddenuser', 'assign') . $summary->uniqueidforuser; |
b473171a DW |
135 | } else { |
136 | $o .= $this->output->user_picture($summary->user); | |
137 | $o .= $this->output->spacer(array('width'=>30)); | |
e5403f8c DW |
138 | $urlparams = array('id' => $summary->user->id, 'course'=>$summary->courseid); |
139 | $url = new moodle_url('/user/view.php', $urlparams); | |
d08e6c31 DW |
140 | $fullname = fullname($summary->user, $summary->viewfullnames); |
141 | $extrainfo = array(); | |
142 | foreach ($summary->extrauserfields as $extrafield) { | |
143 | $extrainfo[] = $summary->user->$extrafield; | |
144 | } | |
145 | if (count($extrainfo)) { | |
146 | $fullname .= ' (' . implode(', ', $extrainfo) . ')'; | |
147 | } | |
148 | $o .= $this->output->action_link($url, $fullname); | |
b473171a | 149 | } |
bbd0e548 DW |
150 | $o .= $this->output->box_end(); |
151 | $o .= $this->output->container_end(); | |
152 | ||
153 | return $o; | |
154 | } | |
155 | ||
156 | /** | |
157 | * Render the submit for grading page | |
158 | * | |
159 | * @param assign_submit_for_grading_page $page | |
160 | * @return string | |
161 | */ | |
162 | public function render_assign_submit_for_grading_page($page) { | |
163 | $o = ''; | |
164 | ||
165 | $o .= $this->output->container_start('submitforgrading'); | |
166 | $o .= $this->output->heading(get_string('submitassignment', 'assign'), 3); | |
167 | $o .= $this->output->spacer(array('height'=>30)); | |
168 | ||
169 | $cancelurl = new moodle_url('/mod/assign/view.php', array('id' => $page->coursemoduleid)); | |
170 | if (count($page->notifications)) { | |
e5403f8c | 171 | // At least one of the submission plugins is not ready for submission. |
bbd0e548 DW |
172 | |
173 | $o .= $this->output->heading(get_string('submissionnotready', 'assign'), 4); | |
174 | ||
175 | foreach ($page->notifications as $notification) { | |
176 | $o .= $this->output->notification($notification); | |
177 | } | |
178 | ||
179 | $o .= $this->output->continue_button($cancelurl); | |
180 | } else { | |
e5403f8c | 181 | // All submission plugins ready - show the confirmation form. |
94f26900 | 182 | $o .= $this->moodleform($page->confirmform); |
bbd0e548 DW |
183 | } |
184 | $o .= $this->output->container_end(); | |
185 | ||
bbd0e548 DW |
186 | return $o; |
187 | } | |
188 | ||
189 | /** | |
e5403f8c | 190 | * Page is done - render the footer. |
bbd0e548 DW |
191 | * |
192 | * @return void | |
193 | */ | |
194 | public function render_footer() { | |
195 | return $this->output->footer(); | |
196 | } | |
197 | ||
198 | /** | |
e5403f8c | 199 | * Render the header. |
bbd0e548 DW |
200 | * |
201 | * @param assign_header $header | |
202 | * @return string | |
203 | */ | |
204 | public function render_assign_header(assign_header $header) { | |
205 | $o = ''; | |
206 | ||
207 | if ($header->subpage) { | |
208 | $this->page->navbar->add($header->subpage); | |
209 | } | |
210 | ||
211 | $this->page->set_title(get_string('pluginname', 'assign')); | |
212 | $this->page->set_heading($header->assign->name); | |
213 | ||
214 | $o .= $this->output->header(); | |
a1e54f4d DW |
215 | if ($header->preface) { |
216 | $o .= $header->preface; | |
217 | } | |
e5403f8c DW |
218 | $heading = format_string($header->assign->name, false, array('context' => $header->context)); |
219 | $o .= $this->output->heading($heading); | |
bbd0e548 DW |
220 | |
221 | if ($header->showintro) { | |
222 | $o .= $this->output->box_start('generalbox boxaligncenter', 'intro'); | |
223 | $o .= format_module_intro('assign', $header->assign, $header->coursemoduleid); | |
224 | $o .= $this->output->box_end(); | |
225 | } | |
226 | ||
227 | return $o; | |
228 | } | |
229 | ||
230 | /** | |
e5403f8c | 231 | * Render a table containing the current status of the grading process. |
bbd0e548 DW |
232 | * |
233 | * @param assign_grading_summary $summary | |
234 | * @return string | |
235 | */ | |
236 | public function render_assign_grading_summary(assign_grading_summary $summary) { | |
e5403f8c | 237 | // Create a table for the data. |
bbd0e548 DW |
238 | $o = ''; |
239 | $o .= $this->output->container_start('gradingsummary'); | |
240 | $o .= $this->output->heading(get_string('gradingsummary', 'assign'), 3); | |
241 | $o .= $this->output->box_start('boxaligncenter gradingsummarytable'); | |
242 | $t = new html_table(); | |
243 | ||
e5403f8c | 244 | // Status. |
12a1a0da DW |
245 | if ($summary->teamsubmission) { |
246 | $this->add_table_row_tuple($t, get_string('numberofteams', 'assign'), | |
247 | $summary->participantcount); | |
248 | } else { | |
249 | $this->add_table_row_tuple($t, get_string('numberofparticipants', 'assign'), | |
250 | $summary->participantcount); | |
251 | } | |
bbd0e548 | 252 | |
e5403f8c | 253 | // Drafts. |
bbd0e548 DW |
254 | if ($summary->submissiondraftsenabled) { |
255 | $this->add_table_row_tuple($t, get_string('numberofdraftsubmissions', 'assign'), | |
256 | $summary->submissiondraftscount); | |
e5403f8c | 257 | } |
bbd0e548 | 258 | |
e5403f8c | 259 | // Submitted for grading. |
bbd0e548 DW |
260 | if ($summary->submissionsenabled) { |
261 | $this->add_table_row_tuple($t, get_string('numberofsubmittedassignments', 'assign'), | |
262 | $summary->submissionssubmittedcount); | |
8f7e1c05 DW |
263 | if (!$summary->teamsubmission) { |
264 | $this->add_table_row_tuple($t, get_string('numberofsubmissionsneedgrading', 'assign'), | |
265 | $summary->submissionsneedgradingcount); | |
266 | } | |
bbd0e548 DW |
267 | } |
268 | ||
269 | $time = time(); | |
270 | if ($summary->duedate) { | |
e5403f8c | 271 | // Due date. |
bbd0e548 DW |
272 | $duedate = $summary->duedate; |
273 | $this->add_table_row_tuple($t, get_string('duedate', 'assign'), | |
274 | userdate($duedate)); | |
275 | ||
e5403f8c | 276 | // Time remaining. |
bbd0e548 DW |
277 | $due = ''; |
278 | if ($duedate - $time <= 0) { | |
279 | $due = get_string('assignmentisdue', 'assign'); | |
280 | } else { | |
281 | $due = format_time($duedate - $time); | |
282 | } | |
283 | $this->add_table_row_tuple($t, get_string('timeremaining', 'assign'), $due); | |
9e795179 DW |
284 | |
285 | if ($duedate < $time) { | |
286 | $cutoffdate = $summary->cutoffdate; | |
287 | if ($cutoffdate) { | |
288 | if ($cutoffdate > $time) { | |
289 | $late = get_string('latesubmissionsaccepted', 'assign'); | |
290 | } else { | |
291 | $late = get_string('nomoresubmissionsaccepted', 'assign'); | |
292 | } | |
293 | $this->add_table_row_tuple($t, get_string('latesubmissions', 'assign'), $late); | |
294 | } | |
295 | } | |
296 | ||
bbd0e548 DW |
297 | } |
298 | ||
e5403f8c | 299 | // All done - write the table. |
bbd0e548 DW |
300 | $o .= html_writer::table($t); |
301 | $o .= $this->output->box_end(); | |
302 | ||
e5403f8c | 303 | // Link to the grading page. |
d9a88f42 | 304 | $o .= $this->output->container_start('submissionlinks'); |
e5403f8c DW |
305 | $urlparams = array('id' => $summary->coursemoduleid, 'action'=>'grading'); |
306 | $url = new moodle_url('/mod/assign/view.php', $urlparams); | |
307 | $o .= $this->output->action_link($url, get_string('viewgrading', 'assign')); | |
d9a88f42 | 308 | $o .= $this->output->container_end(); |
bbd0e548 | 309 | |
e5403f8c | 310 | // Close the container and insert a spacer. |
bbd0e548 DW |
311 | $o .= $this->output->container_end(); |
312 | ||
313 | return $o; | |
314 | } | |
315 | ||
316 | /** | |
e5403f8c | 317 | * Render a table containing all the current grades and feedback. |
bbd0e548 DW |
318 | * |
319 | * @param assign_feedback_status $status | |
320 | * @return string | |
321 | */ | |
322 | public function render_assign_feedback_status(assign_feedback_status $status) { | |
323 | global $DB, $CFG; | |
324 | $o = ''; | |
325 | ||
326 | $o .= $this->output->container_start('feedback'); | |
327 | $o .= $this->output->heading(get_string('feedback', 'assign'), 3); | |
328 | $o .= $this->output->box_start('boxaligncenter feedbacktable'); | |
329 | $t = new html_table(); | |
330 | ||
e5403f8c | 331 | // Grade. |
46692c3a DW |
332 | if (isset($status->gradefordisplay)) { |
333 | $row = new html_table_row(); | |
334 | $cell1 = new html_table_cell(get_string('grade')); | |
335 | $cell2 = new html_table_cell($status->gradefordisplay); | |
336 | $row->cells = array($cell1, $cell2); | |
337 | $t->data[] = $row; | |
bbd0e548 | 338 | |
46692c3a DW |
339 | // Grade date. |
340 | $row = new html_table_row(); | |
341 | $cell1 = new html_table_cell(get_string('gradedon', 'assign')); | |
342 | $cell2 = new html_table_cell(userdate($status->gradeddate)); | |
343 | $row->cells = array($cell1, $cell2); | |
344 | $t->data[] = $row; | |
345 | } | |
bbd0e548 DW |
346 | |
347 | if ($status->grader) { | |
e5403f8c | 348 | // Grader. |
bbd0e548 DW |
349 | $row = new html_table_row(); |
350 | $cell1 = new html_table_cell(get_string('gradedby', 'assign')); | |
e5403f8c DW |
351 | $userdescription = $this->output->user_picture($status->grader) . |
352 | $this->output->spacer(array('width'=>30)) . | |
353 | fullname($status->grader); | |
354 | $cell2 = new html_table_cell($userdescription); | |
bbd0e548 DW |
355 | $row->cells = array($cell1, $cell2); |
356 | $t->data[] = $row; | |
357 | } | |
358 | ||
359 | foreach ($status->feedbackplugins as $plugin) { | |
df47b77f DW |
360 | if ($plugin->is_enabled() && |
361 | $plugin->is_visible() && | |
362 | $plugin->has_user_summary() && | |
363 | !empty($status->grade) && | |
364 | !$plugin->is_empty($status->grade)) { | |
365 | ||
bbd0e548 DW |
366 | $row = new html_table_row(); |
367 | $cell1 = new html_table_cell($plugin->get_name()); | |
e5403f8c DW |
368 | $displaymode = assign_feedback_plugin_feedback::SUMMARY; |
369 | $pluginfeedback = new assign_feedback_plugin_feedback($plugin, | |
370 | $status->grade, | |
371 | $displaymode, | |
372 | $status->coursemoduleid, | |
373 | $status->returnaction, | |
374 | $status->returnparams); | |
bbd0e548 DW |
375 | $cell2 = new html_table_cell($this->render($pluginfeedback)); |
376 | $row->cells = array($cell1, $cell2); | |
377 | $t->data[] = $row; | |
378 | } | |
379 | } | |
380 | ||
bbd0e548 DW |
381 | $o .= html_writer::table($t); |
382 | $o .= $this->output->box_end(); | |
383 | ||
384 | $o .= $this->output->container_end(); | |
385 | return $o; | |
386 | } | |
387 | ||
388 | /** | |
e5403f8c | 389 | * Render a table containing the current status of the submission. |
bbd0e548 DW |
390 | * |
391 | * @param assign_submission_status $status | |
392 | * @return string | |
393 | */ | |
394 | public function render_assign_submission_status(assign_submission_status $status) { | |
395 | $o = ''; | |
396 | $o .= $this->output->container_start('submissionstatustable'); | |
397 | $o .= $this->output->heading(get_string('submissionstatusheading', 'assign'), 3); | |
398 | $time = time(); | |
399 | ||
400 | if ($status->allowsubmissionsfromdate && | |
401 | $time <= $status->allowsubmissionsfromdate) { | |
402 | $o .= $this->output->box_start('generalbox boxaligncenter submissionsalloweddates'); | |
403 | if ($status->alwaysshowdescription) { | |
e5403f8c DW |
404 | $date = userdate($status->allowsubmissionsfromdate); |
405 | $o .= get_string('allowsubmissionsfromdatesummary', 'assign', $date); | |
bbd0e548 | 406 | } else { |
e5403f8c DW |
407 | $date = userdate($status->allowsubmissionsfromdate); |
408 | $o .= get_string('allowsubmissionsanddescriptionfromdatesummary', 'assign', $date); | |
bbd0e548 DW |
409 | } |
410 | $o .= $this->output->box_end(); | |
411 | } | |
412 | $o .= $this->output->box_start('boxaligncenter submissionsummarytable'); | |
413 | ||
414 | $t = new html_table(); | |
415 | ||
12a1a0da DW |
416 | if ($status->teamsubmissionenabled) { |
417 | $row = new html_table_row(); | |
418 | $cell1 = new html_table_cell(get_string('submissionteam', 'assign')); | |
419 | $group = $status->submissiongroup; | |
420 | if ($group) { | |
421 | $cell2 = new html_table_cell(format_string($group->name, false, $status->context)); | |
422 | } else { | |
423 | $cell2 = new html_table_cell(get_string('defaultteam', 'assign')); | |
424 | } | |
425 | $row->cells = array($cell1, $cell2); | |
426 | $t->data[] = $row; | |
427 | } | |
428 | ||
bbd0e548 DW |
429 | $row = new html_table_row(); |
430 | $cell1 = new html_table_cell(get_string('submissionstatus', 'assign')); | |
12a1a0da DW |
431 | if (!$status->teamsubmissionenabled) { |
432 | if ($status->submission) { | |
e5403f8c DW |
433 | $statusstr = get_string('submissionstatus_' . $status->submission->status, 'assign'); |
434 | $cell2 = new html_table_cell($statusstr); | |
12a1a0da DW |
435 | $cell2->attributes = array('class'=>'submissionstatus' . $status->submission->status); |
436 | } else { | |
437 | if (!$status->submissionsenabled) { | |
438 | $cell2 = new html_table_cell(get_string('noonlinesubmissions', 'assign')); | |
439 | } else { | |
440 | $cell2 = new html_table_cell(get_string('nosubmission', 'assign')); | |
441 | } | |
442 | } | |
443 | $row->cells = array($cell1, $cell2); | |
444 | $t->data[] = $row; | |
bbd0e548 | 445 | } else { |
12a1a0da DW |
446 | $row = new html_table_row(); |
447 | $cell1 = new html_table_cell(get_string('submissionstatus', 'assign')); | |
448 | if ($status->teamsubmission) { | |
e5403f8c DW |
449 | $teamstatus = $status->teamsubmission->status; |
450 | $submissionsummary = get_string('submissionstatus_' . $teamstatus, 'assign'); | |
12a1a0da DW |
451 | $groupid = 0; |
452 | if ($status->submissiongroup) { | |
453 | $groupid = $status->submissiongroup->id; | |
454 | } | |
455 | ||
456 | $members = $status->submissiongroupmemberswhoneedtosubmit; | |
457 | $userslist = array(); | |
458 | foreach ($members as $member) { | |
e5403f8c DW |
459 | $urlparams = array('id' => $member->id, 'course'=>$status->courseid); |
460 | $url = new moodle_url('/user/view.php', $urlparams); | |
88cfe469 DW |
461 | if ($status->view == assign_submission_status::GRADER_VIEW && $status->blindmarking) { |
462 | $userslist[] = $member->alias; | |
463 | } else { | |
e5403f8c DW |
464 | $fullname = fullname($member, $status->canviewfullnames); |
465 | $userslist[] = $this->output->action_link($url, $fullname); | |
88cfe469 | 466 | } |
12a1a0da DW |
467 | } |
468 | if (count($userslist) > 0) { | |
469 | $userstr = join(', ', $userslist); | |
e5403f8c DW |
470 | $formatteduserstr = get_string('userswhoneedtosubmit', 'assign', $userstr); |
471 | $submissionsummary .= $this->output->container($formatteduserstr); | |
12a1a0da DW |
472 | } |
473 | ||
474 | $cell2 = new html_table_cell($submissionsummary); | |
475 | $cell2->attributes = array('class'=>'submissionstatus' . $status->teamsubmission->status); | |
bbd0e548 DW |
476 | } else { |
477 | $cell2 = new html_table_cell(get_string('nosubmission', 'assign')); | |
12a1a0da DW |
478 | if (!$status->submissionsenabled) { |
479 | $cell2 = new html_table_cell(get_string('noonlinesubmissions', 'assign')); | |
480 | } else { | |
481 | $cell2 = new html_table_cell(get_string('nosubmission', 'assign')); | |
482 | } | |
bbd0e548 | 483 | } |
12a1a0da DW |
484 | $row->cells = array($cell1, $cell2); |
485 | $t->data[] = $row; | |
bbd0e548 | 486 | } |
bbd0e548 | 487 | |
e5403f8c | 488 | // Is locked? |
bbd0e548 DW |
489 | if ($status->locked) { |
490 | $row = new html_table_row(); | |
491 | $cell1 = new html_table_cell(); | |
492 | $cell2 = new html_table_cell(get_string('submissionslocked', 'assign')); | |
493 | $cell2->attributes = array('class'=>'submissionlocked'); | |
494 | $row->cells = array($cell1, $cell2); | |
495 | $t->data[] = $row; | |
496 | } | |
497 | ||
e5403f8c | 498 | // Grading status. |
bbd0e548 DW |
499 | $row = new html_table_row(); |
500 | $cell1 = new html_table_cell(get_string('gradingstatus', 'assign')); | |
501 | ||
502 | if ($status->graded) { | |
503 | $cell2 = new html_table_cell(get_string('graded', 'assign')); | |
504 | $cell2->attributes = array('class'=>'submissiongraded'); | |
505 | } else { | |
506 | $cell2 = new html_table_cell(get_string('notgraded', 'assign')); | |
507 | $cell2->attributes = array('class'=>'submissionnotgraded'); | |
508 | } | |
509 | $row->cells = array($cell1, $cell2); | |
510 | $t->data[] = $row; | |
511 | ||
bbd0e548 | 512 | $duedate = $status->duedate; |
9e795179 | 513 | if ($duedate > 0) { |
e5403f8c | 514 | // Due date. |
bbd0e548 DW |
515 | $row = new html_table_row(); |
516 | $cell1 = new html_table_cell(get_string('duedate', 'assign')); | |
517 | $cell2 = new html_table_cell(userdate($duedate)); | |
518 | $row->cells = array($cell1, $cell2); | |
519 | $t->data[] = $row; | |
520 | ||
9e795179 DW |
521 | if ($status->view == assign_submission_status::GRADER_VIEW) { |
522 | if ($status->cutoffdate) { | |
e5403f8c | 523 | // Cut off date. |
9e795179 DW |
524 | $row = new html_table_row(); |
525 | $cell1 = new html_table_cell(get_string('cutoffdate', 'assign')); | |
526 | $cell2 = new html_table_cell(userdate($status->cutoffdate)); | |
527 | $row->cells = array($cell1, $cell2); | |
528 | $t->data[] = $row; | |
529 | } | |
530 | } | |
531 | ||
532 | if ($status->extensionduedate) { | |
e5403f8c | 533 | // Extension date. |
9e795179 DW |
534 | $row = new html_table_row(); |
535 | $cell1 = new html_table_cell(get_string('extensionduedate', 'assign')); | |
536 | $cell2 = new html_table_cell(userdate($status->extensionduedate)); | |
537 | $row->cells = array($cell1, $cell2); | |
538 | $t->data[] = $row; | |
539 | $duedate = $status->extensionduedate; | |
540 | } | |
541 | ||
542 | // Time remaining. | |
bbd0e548 DW |
543 | $row = new html_table_row(); |
544 | $cell1 = new html_table_cell(get_string('timeremaining', 'assign')); | |
545 | if ($duedate - $time <= 0) { | |
e5403f8c DW |
546 | if (!$status->submission || |
547 | $status->submission->status != ASSIGN_SUBMISSION_STATUS_SUBMITTED) { | |
bbd0e548 | 548 | if ($status->submissionsenabled) { |
e5403f8c DW |
549 | $overduestr = get_string('overdue', 'assign', format_time($time - $duedate)); |
550 | $cell2 = new html_table_cell($overduestr); | |
bbd0e548 DW |
551 | $cell2->attributes = array('class'=>'overdue'); |
552 | } else { | |
553 | $cell2 = new html_table_cell(get_string('duedatereached', 'assign')); | |
554 | } | |
555 | } else { | |
556 | if ($status->submission->timemodified > $duedate) { | |
e5403f8c DW |
557 | $latestr = get_string('submittedlate', |
558 | 'assign', | |
559 | format_time($status->submission->timemodified - $duedate)); | |
560 | $cell2 = new html_table_cell($latestr); | |
bbd0e548 DW |
561 | $cell2->attributes = array('class'=>'latesubmission'); |
562 | } else { | |
e5403f8c DW |
563 | $earlystr = get_string('submittedearly', |
564 | 'assign', | |
565 | format_time($status->submission->timemodified - $duedate)); | |
566 | $cell2 = new html_table_cell($earlystr); | |
bbd0e548 DW |
567 | $cell2->attributes = array('class'=>'earlysubmission'); |
568 | } | |
569 | } | |
570 | } else { | |
571 | $cell2 = new html_table_cell(format_time($duedate - $time)); | |
572 | } | |
573 | $row->cells = array($cell1, $cell2); | |
574 | $t->data[] = $row; | |
575 | } | |
576 | ||
9e795179 DW |
577 | // Show graders whether this submission is editable by students. |
578 | if ($status->view == assign_submission_status::GRADER_VIEW) { | |
579 | $row = new html_table_row(); | |
848ade1d | 580 | $cell1 = new html_table_cell(get_string('editingstatus', 'assign')); |
9e795179 DW |
581 | if ($status->canedit) { |
582 | $cell2 = new html_table_cell(get_string('submissioneditable', 'assign')); | |
583 | $cell2->attributes = array('class'=>'submissioneditable'); | |
584 | } else { | |
585 | $cell2 = new html_table_cell(get_string('submissionnoteditable', 'assign')); | |
586 | $cell2->attributes = array('class'=>'submissionnoteditable'); | |
587 | } | |
6c712479 DW |
588 | $row->cells = array($cell1, $cell2); |
589 | $t->data[] = $row; | |
ec32d068 RW |
590 | } |
591 | ||
592 | // Grading criteria preview. | |
593 | if (!empty($status->gradingcontrollerpreview)) { | |
594 | $row = new html_table_row(); | |
595 | $cell1 = new html_table_cell(get_string('gradingmethodpreview', 'assign')); | |
596 | $cell2 = new html_table_cell($status->gradingcontrollerpreview); | |
9e795179 DW |
597 | $row->cells = array($cell1, $cell2); |
598 | $t->data[] = $row; | |
599 | } | |
600 | ||
601 | // Last modified. | |
12a1a0da DW |
602 | $submission = $status->teamsubmission ? $status->teamsubmission : $status->submission; |
603 | if ($submission) { | |
bbd0e548 DW |
604 | $row = new html_table_row(); |
605 | $cell1 = new html_table_cell(get_string('timemodified', 'assign')); | |
12a1a0da | 606 | $cell2 = new html_table_cell(userdate($submission->timemodified)); |
bbd0e548 DW |
607 | $row->cells = array($cell1, $cell2); |
608 | $t->data[] = $row; | |
609 | ||
610 | foreach ($status->submissionplugins as $plugin) { | |
7a9fd6da | 611 | $pluginshowsummary = !$plugin->is_empty($submission) || !$plugin->allow_submissions(); |
df47b77f DW |
612 | if ($plugin->is_enabled() && |
613 | $plugin->is_visible() && | |
614 | $plugin->has_user_summary() && | |
7a9fd6da | 615 | $pluginshowsummary) { |
df47b77f | 616 | |
bbd0e548 DW |
617 | $row = new html_table_row(); |
618 | $cell1 = new html_table_cell($plugin->get_name()); | |
e5403f8c | 619 | $displaymode = assign_submission_plugin_submission::SUMMARY; |
9e795179 | 620 | $pluginsubmission = new assign_submission_plugin_submission($plugin, |
dd1fe178 | 621 | $submission, |
e5403f8c | 622 | $displaymode, |
9e795179 DW |
623 | $status->coursemoduleid, |
624 | $status->returnaction, | |
625 | $status->returnparams); | |
bbd0e548 DW |
626 | $cell2 = new html_table_cell($this->render($pluginsubmission)); |
627 | $row->cells = array($cell1, $cell2); | |
628 | $t->data[] = $row; | |
629 | } | |
630 | } | |
631 | } | |
632 | ||
bbd0e548 DW |
633 | $o .= html_writer::table($t); |
634 | $o .= $this->output->box_end(); | |
635 | ||
9e795179 DW |
636 | // Links. |
637 | if ($status->view == assign_submission_status::STUDENT_VIEW) { | |
638 | if ($status->canedit) { | |
cd01491c | 639 | if (!$submission) { |
9e795179 DW |
640 | $urlparams = array('id' => $status->coursemoduleid, 'action' => 'editsubmission'); |
641 | $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams), | |
642 | get_string('addsubmission', 'assign'), 'get'); | |
643 | } else { | |
644 | $urlparams = array('id' => $status->coursemoduleid, 'action' => 'editsubmission'); | |
645 | $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams), | |
646 | get_string('editsubmission', 'assign'), 'get'); | |
647 | } | |
caff10a0 | 648 | } |
bbd0e548 | 649 | |
9e795179 DW |
650 | if ($status->cansubmit) { |
651 | $urlparams = array('id' => $status->coursemoduleid, 'action'=>'submit'); | |
652 | $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams), | |
653 | get_string('submitassignment', 'assign'), 'get'); | |
654 | $o .= $this->output->box_start('boxaligncenter submithelp'); | |
655 | $o .= get_string('submitassignment_help', 'assign'); | |
656 | $o .= $this->output->box_end(); | |
657 | } | |
bbd0e548 DW |
658 | } |
659 | ||
660 | $o .= $this->output->container_end(); | |
661 | return $o; | |
662 | } | |
663 | ||
664 | /** | |
e5403f8c | 665 | * Render a submission plugin submission |
bbd0e548 DW |
666 | * |
667 | * @param assign_submission_plugin_submission $submissionplugin | |
668 | * @return string | |
669 | */ | |
670 | public function render_assign_submission_plugin_submission(assign_submission_plugin_submission $submissionplugin) { | |
671 | $o = ''; | |
672 | ||
673 | if ($submissionplugin->view == assign_submission_plugin_submission::SUMMARY) { | |
bbd0e548 | 674 | $showviewlink = false; |
e5403f8c DW |
675 | $summary = $submissionplugin->plugin->view_summary($submissionplugin->submission, |
676 | $showviewlink); | |
677 | ||
678 | $classsuffix = $submissionplugin->plugin->get_subtype() . | |
679 | '_' . | |
680 | $submissionplugin->plugin->get_type() . | |
681 | '_' . | |
682 | $submissionplugin->submission->id; | |
66d3fe37 | 683 | |
66d3fe37 DW |
684 | $o .= $this->output->box_start('boxaligncenter plugincontentsummary summary_' . $classsuffix); |
685 | ||
686 | $link = ''; | |
bbd0e548 | 687 | if ($showviewlink) { |
66d3fe37 DW |
688 | $previewstr = get_string('viewsubmission', 'assign'); |
689 | $icon = $this->output->pix_icon('t/preview', $previewstr); | |
690 | ||
691 | $expandstr = get_string('viewfull', 'assign'); | |
e5403f8c DW |
692 | $options = array('class'=>'expandsummaryicon expand_' . $classsuffix); |
693 | $o .= $this->output->pix_icon('t/switch_plus', $expandstr, null, $options); | |
66d3fe37 DW |
694 | |
695 | $jsparams = array($submissionplugin->plugin->get_subtype(), | |
696 | $submissionplugin->plugin->get_type(), | |
697 | $submissionplugin->submission->id); | |
e5403f8c | 698 | |
66d3fe37 DW |
699 | $this->page->requires->js_init_call('M.mod_assign.init_plugin_summary', $jsparams); |
700 | ||
e5403f8c DW |
701 | $action = 'viewplugin' . $submissionplugin->plugin->get_subtype(); |
702 | $returnparams = http_build_query($submissionplugin->returnparams); | |
66d3fe37 | 703 | $link .= '<noscript>'; |
e5403f8c DW |
704 | $urlparams = array('id' => $submissionplugin->coursemoduleid, |
705 | 'sid'=>$submissionplugin->submission->id, | |
706 | 'plugin'=>$submissionplugin->plugin->get_type(), | |
707 | 'action'=>$action, | |
708 | 'returnaction'=>$submissionplugin->returnaction, | |
709 | 'returnparams'=>$returnparams); | |
710 | $url = new moodle_url('/mod/assign/view.php', $urlparams); | |
711 | $link .= $this->output->action_link($url, $icon); | |
66d3fe37 | 712 | $link .= '</noscript>'; |
bbd0e548 DW |
713 | |
714 | $link .= $this->output->spacer(array('width'=>15)); | |
715 | } | |
716 | ||
717 | $o .= $link . $summary; | |
66d3fe37 DW |
718 | $o .= $this->output->box_end(); |
719 | if ($showviewlink) { | |
720 | $o .= $this->output->box_start('boxaligncenter hidefull full_' . $classsuffix); | |
721 | $classes = 'expandsummaryicon contract_' . $classsuffix; | |
722 | $o .= $this->output->pix_icon('t/switch_minus', | |
723 | get_string('viewsummary', 'assign'), | |
724 | null, | |
725 | array('class'=>$classes)); | |
726 | $o .= $submissionplugin->plugin->view($submissionplugin->submission); | |
727 | $o .= $this->output->box_end(); | |
728 | } | |
bbd0e548 DW |
729 | } else if ($submissionplugin->view == assign_submission_plugin_submission::FULL) { |
730 | $o .= $this->output->box_start('boxaligncenter submissionfull'); | |
731 | $o .= $submissionplugin->plugin->view($submissionplugin->submission); | |
732 | $o .= $this->output->box_end(); | |
733 | } | |
734 | ||
735 | return $o; | |
736 | } | |
737 | ||
738 | /** | |
e5403f8c | 739 | * Render the grading table. |
bbd0e548 DW |
740 | * |
741 | * @param assign_grading_table $table | |
742 | * @return string | |
743 | */ | |
744 | public function render_assign_grading_table(assign_grading_table $table) { | |
745 | $o = ''; | |
746 | $o .= $this->output->box_start('boxaligncenter gradingtable'); | |
df47b77f | 747 | |
bbd0e548 DW |
748 | $this->page->requires->js_init_call('M.mod_assign.init_grading_table', array()); |
749 | $this->page->requires->string_for_js('nousersselected', 'assign'); | |
9e795179 | 750 | $this->page->requires->string_for_js('batchoperationconfirmgrantextension', 'assign'); |
bbd0e548 | 751 | $this->page->requires->string_for_js('batchoperationconfirmlock', 'assign'); |
bbd0e548 | 752 | $this->page->requires->string_for_js('batchoperationconfirmreverttodraft', 'assign'); |
9e795179 | 753 | $this->page->requires->string_for_js('batchoperationconfirmunlock', 'assign'); |
bbd0e548 | 754 | $this->page->requires->string_for_js('editaction', 'assign'); |
df47b77f DW |
755 | foreach ($table->plugingradingbatchoperations as $plugin => $operations) { |
756 | foreach ($operations as $operation => $description) { | |
e5403f8c DW |
757 | $this->page->requires->string_for_js('batchoperationconfirm' . $operation, |
758 | 'assignfeedback_' . $plugin); | |
df47b77f DW |
759 | } |
760 | } | |
bbd0e548 DW |
761 | $o .= $this->flexible_table($table, $table->get_rows_per_page(), true); |
762 | $o .= $this->output->box_end(); | |
763 | ||
764 | return $o; | |
e5403f8c | 765 | } |
bbd0e548 DW |
766 | |
767 | /** | |
768 | * Render a feedback plugin feedback | |
769 | * | |
770 | * @param assign_feedback_plugin_feedback $feedbackplugin | |
771 | * @return string | |
772 | */ | |
773 | public function render_assign_feedback_plugin_feedback(assign_feedback_plugin_feedback $feedbackplugin) { | |
774 | $o = ''; | |
775 | ||
776 | if ($feedbackplugin->view == assign_feedback_plugin_feedback::SUMMARY) { | |
bbd0e548 DW |
777 | $showviewlink = false; |
778 | $summary = $feedbackplugin->plugin->view_summary($feedbackplugin->grade, $showviewlink); | |
66d3fe37 | 779 | |
e5403f8c DW |
780 | $classsuffix = $feedbackplugin->plugin->get_subtype() . |
781 | '_' . | |
782 | $feedbackplugin->plugin->get_type() . | |
783 | '_' . | |
784 | $feedbackplugin->grade->id; | |
66d3fe37 DW |
785 | $o .= $this->output->box_start('boxaligncenter plugincontentsummary summary_' . $classsuffix); |
786 | ||
787 | $link = ''; | |
bbd0e548 | 788 | if ($showviewlink) { |
66d3fe37 DW |
789 | $previewstr = get_string('viewfeedback', 'assign'); |
790 | $icon = $this->output->pix_icon('t/preview', $previewstr); | |
791 | ||
792 | $expandstr = get_string('viewfull', 'assign'); | |
e5403f8c DW |
793 | $options = array('class'=>'expandsummaryicon expand_' . $classsuffix); |
794 | $o .= $this->output->pix_icon('t/switch_plus', $expandstr, null, $options); | |
66d3fe37 DW |
795 | |
796 | $jsparams = array($feedbackplugin->plugin->get_subtype(), | |
797 | $feedbackplugin->plugin->get_type(), | |
798 | $feedbackplugin->grade->id); | |
799 | $this->page->requires->js_init_call('M.mod_assign.init_plugin_summary', $jsparams); | |
800 | ||
e5403f8c DW |
801 | $urlparams = array('id' => $feedbackplugin->coursemoduleid, |
802 | 'gid'=>$feedbackplugin->grade->id, | |
803 | 'plugin'=>$feedbackplugin->plugin->get_type(), | |
804 | 'action'=>'viewplugin' . $feedbackplugin->plugin->get_subtype(), | |
805 | 'returnaction'=>$feedbackplugin->returnaction, | |
806 | 'returnparams'=>http_build_query($feedbackplugin->returnparams)); | |
807 | $url = new moodle_url('/mod/assign/view.php', $urlparams); | |
66d3fe37 | 808 | $link .= '<noscript>'; |
e5403f8c | 809 | $link .= $this->output->action_link($url, $icon); |
66d3fe37 DW |
810 | $link .= '</noscript>'; |
811 | ||
bbd0e548 DW |
812 | $link .= $this->output->spacer(array('width'=>15)); |
813 | } | |
814 | ||
815 | $o .= $link . $summary; | |
66d3fe37 DW |
816 | $o .= $this->output->box_end(); |
817 | if ($showviewlink) { | |
818 | $o .= $this->output->box_start('boxaligncenter hidefull full_' . $classsuffix); | |
819 | $classes = 'expandsummaryicon contract_' . $classsuffix; | |
820 | $o .= $this->output->pix_icon('t/switch_minus', | |
821 | get_string('viewsummary', 'assign'), | |
822 | null, | |
823 | array('class'=>$classes)); | |
824 | $o .= $feedbackplugin->plugin->view($feedbackplugin->grade); | |
825 | $o .= $this->output->box_end(); | |
826 | } | |
bbd0e548 DW |
827 | } else if ($feedbackplugin->view == assign_feedback_plugin_feedback::FULL) { |
828 | $o .= $this->output->box_start('boxaligncenter feedbackfull'); | |
829 | $o .= $feedbackplugin->plugin->view($feedbackplugin->grade); | |
830 | $o .= $this->output->box_end(); | |
831 | } | |
832 | ||
833 | return $o; | |
834 | } | |
835 | ||
64220210 DW |
836 | /** |
837 | * Render a course index summary | |
838 | * | |
839 | * @param assign_course_index_summary $indexsummary | |
840 | * @return string | |
841 | */ | |
842 | public function render_assign_course_index_summary(assign_course_index_summary $indexsummary) { | |
843 | $o = ''; | |
844 | ||
845 | $strplural = get_string('modulenameplural', 'assign'); | |
846 | $strsectionname = $indexsummary->courseformatname; | |
847 | $strduedate = get_string('duedate', 'assign'); | |
848 | $strsubmission = get_string('submission', 'assign'); | |
849 | $strgrade = get_string('grade'); | |
850 | ||
851 | $table = new html_table(); | |
852 | if ($indexsummary->usesections) { | |
853 | $table->head = array ($strsectionname, $strplural, $strduedate, $strsubmission, $strgrade); | |
854 | $table->align = array ('left', 'left', 'center', 'right', 'right'); | |
855 | } else { | |
856 | $table->head = array ($strplural, $strduedate, $strsubmission, $strgrade); | |
857 | $table->align = array ('left', 'left', 'center', 'right'); | |
858 | } | |
859 | $table->data = array(); | |
860 | ||
861 | $currentsection = ''; | |
862 | foreach ($indexsummary->assignments as $info) { | |
863 | $params = array('id' => $info['cmid']); | |
864 | $link = html_writer::link(new moodle_url('/mod/assign/view.php', $params), | |
865 | $info['cmname']); | |
866 | $due = $info['timedue'] ? userdate($info['timedue']) : '-'; | |
867 | ||
868 | $printsection = ''; | |
869 | if ($indexsummary->usesections) { | |
870 | if ($info['sectionname'] !== $currentsection) { | |
871 | if ($info['sectionname']) { | |
872 | $printsection = $info['sectionname']; | |
873 | } | |
874 | if ($currentsection !== '') { | |
875 | $table->data[] = 'hr'; | |
876 | } | |
877 | $currentsection = $info['sectionname']; | |
878 | } | |
879 | } | |
880 | ||
881 | if ($indexsummary->usesections) { | |
882 | $row = array($printsection, $link, $due, $info['submissioninfo'], $info['gradeinfo']); | |
883 | } else { | |
884 | $row = array($link, $due, $info['submissioninfo'], $info['gradeinfo']); | |
885 | } | |
886 | $table->data[] = $row; | |
887 | } | |
888 | ||
889 | $o .= html_writer::table($table); | |
890 | ||
891 | return $o; | |
892 | } | |
893 | ||
bbd0e548 DW |
894 | |
895 | ||
896 | /** | |
897 | * Internal function - creates htmls structure suitable for YUI tree. | |
898 | * | |
899 | * @param assign_files $tree | |
900 | * @param array $dir | |
901 | * @return string | |
902 | */ | |
903 | protected function htmllize_tree(assign_files $tree, $dir) { | |
904 | global $CFG; | |
905 | $yuiconfig = array(); | |
906 | $yuiconfig['type'] = 'html'; | |
907 | ||
908 | if (empty($dir['subdirs']) and empty($dir['files'])) { | |
909 | return ''; | |
910 | } | |
911 | ||
912 | $result = '<ul>'; | |
913 | foreach ($dir['subdirs'] as $subdir) { | |
e5403f8c DW |
914 | $image = $this->output->pix_icon(file_folder_icon(), |
915 | $subdir['dirname'], | |
916 | 'moodle', | |
917 | array('class'=>'icon')); | |
918 | $result .= '<li yuiConfig=\'' . json_encode($yuiconfig) . '\'>' . | |
919 | '<div>' . $image . ' ' . s($subdir['dirname']) . '</div> ' . | |
920 | $this->htmllize_tree($tree, $subdir) . | |
921 | '</li>'; | |
bbd0e548 DW |
922 | } |
923 | ||
924 | foreach ($dir['files'] as $file) { | |
925 | $filename = $file->get_filename(); | |
bbd0e548 DW |
926 | if ($CFG->enableplagiarism) { |
927 | require_once($CFG->libdir.'/plagiarismlib.php'); | |
e5403f8c DW |
928 | $plagiarismlinks = plagiarism_get_links(array('userid'=>$file->get_userid(), |
929 | 'file'=>$file, | |
930 | 'cmid'=>$tree->cm->id, | |
931 | 'course'=>$tree->course)); | |
bbd0e548 | 932 | } else { |
e5403f8c | 933 | $plagiarismlinks = ''; |
bbd0e548 | 934 | } |
e5403f8c DW |
935 | $image = $this->output->pix_icon(file_file_icon($file), |
936 | $filename, | |
937 | 'moodle', | |
938 | array('class'=>'icon')); | |
939 | $result .= '<li yuiConfig=\'' . json_encode($yuiconfig) . '\'>' . | |
940 | '<div>' . $image . ' ' . | |
941 | $file->fileurl . ' ' . | |
942 | $plagiarismlinks . | |
943 | $file->portfoliobutton . '</div>' . | |
944 | '</li>'; | |
bbd0e548 DW |
945 | } |
946 | ||
947 | $result .= '</ul>'; | |
948 | ||
949 | return $result; | |
950 | } | |
951 | ||
952 | /** | |
953 | * Helper method dealing with the fact we can not just fetch the output of flexible_table | |
954 | * | |
955 | * @param flexible_table $table The table to render | |
956 | * @param int $rowsperpage How many assignments to render in a page | |
e5403f8c DW |
957 | * @param bool $displaylinks - Whether to render links in the table |
958 | * (e.g. downloads would not enable this) | |
bbd0e548 DW |
959 | * @return string HTML |
960 | */ | |
961 | protected function flexible_table(flexible_table $table, $rowsperpage, $displaylinks) { | |
962 | ||
963 | $o = ''; | |
964 | ob_start(); | |
965 | $table->out($rowsperpage, $displaylinks); | |
966 | $o = ob_get_contents(); | |
967 | ob_end_clean(); | |
968 | ||
969 | return $o; | |
970 | } | |
971 | ||
972 | /** | |
973 | * Helper method dealing with the fact we can not just fetch the output of moodleforms | |
974 | * | |
975 | * @param moodleform $mform | |
976 | * @return string HTML | |
977 | */ | |
978 | protected function moodleform(moodleform $mform) { | |
979 | ||
980 | $o = ''; | |
981 | ob_start(); | |
982 | $mform->display(); | |
983 | $o = ob_get_contents(); | |
984 | ob_end_clean(); | |
985 | ||
986 | return $o; | |
987 | } | |
988 | ||
989 | } | |
990 |