mirrored from git://git.moodle.org/moodle.git
/
renderer.php
792 lines (690 loc) · 32.6 KB
/
renderer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains a renderer for the assignment class
*
* @package mod_assign
* @copyright 2012 NetSpot {@link http://www.netspot.com.au}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/** Include locallib.php */
require_once($CFG->dirroot . '/mod/assign/locallib.php');
/**
* A custom renderer class that extends the plugin_renderer_base and is used by the assign module.
*
* @package mod_assign
* @copyright 2012 NetSpot {@link http://www.netspot.com.au}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_assign_renderer extends plugin_renderer_base {
/**
* rendering assignment files
*
* @param context $context
* @param int $userid
* @param string $filearea
* @param string $component
* @return string
*/
public function assign_files(context $context, $userid, $filearea, $component) {
return $this->render(new assign_files($context, $userid, $filearea, $component));
}
/**
* rendering assignment files
*
* @param assign_files $tree
* @return string
*/
public function render_assign_files(assign_files $tree) {
$this->htmlid = 'assign_files_tree_'.uniqid();
$this->page->requires->js_init_call('M.mod_assign.init_tree', array(true, $this->htmlid));
$html = '<div id="'.$this->htmlid.'">';
$html .= $this->htmllize_tree($tree, $tree->dir);
$html .= '</div>';
if ($tree->portfolioform) {
$html .= $tree->portfolioform;
}
return $html;
}
/**
* Utility function to add a row of data to a table with 2 columns. Modified
* the table param and does not return a value
*
* @param html_table $table The table to append the row of data to
* @param string $first The first column text
* @param string $second The second column text
* @return void
*/
private function add_table_row_tuple(html_table $table, $first, $second) {
$row = new html_table_row();
$cell1 = new html_table_cell($first);
$cell2 = new html_table_cell($second);
$row->cells = array($cell1, $cell2);
$table->data[] = $row;
}
/**
* Render a grading error notification
* @param assign_quickgrading_result $result The result to render
* @return string
*/
public function render_assign_quickgrading_result(assign_quickgrading_result $result) {
$url = new moodle_url('/mod/assign/view.php', array('id' => $result->coursemoduleid, 'action'=>'grading'));
$o = '';
$o .= $this->output->heading(get_string('quickgradingresult', 'assign'), 4);
$o .= $this->output->notification($result->message);
$o .= $this->output->continue_button($url);
return $o;
}
/**
* Render the generic form
* @param assign_form $form The form to render
* @return string
*/
public function render_assign_form(assign_form $form) {
$o = '';
if ($form->jsinitfunction) {
$this->page->requires->js_init_call($form->jsinitfunction, array());
}
$o .= $this->output->box_start('boxaligncenter ' . $form->classname);
$o .= $this->moodleform($form->form);
$o .= $this->output->box_end();
return $o;
}
/**
* Render the user summary
*
* @param assign_user_summary $summary The user summary to render
* @return string
*/
public function render_assign_user_summary(assign_user_summary $summary) {
$o = '';
if (!$summary->user) {
return;
}
$o .= $this->output->container_start('usersummary');
$o .= $this->output->box_start('boxaligncenter usersummarysection');
if ($summary->blindmarking) {
$o .= get_string('hiddenuser', 'assign', $summary->uniqueidforuser);
} else {
$o .= $this->output->user_picture($summary->user);
$o .= $this->output->spacer(array('width'=>30));
$o .= $this->output->action_link(new moodle_url('/user/view.php',
array('id' => $summary->user->id,
'course'=>$summary->courseid)),
fullname($summary->user, $summary->viewfullnames));
}
$o .= $this->output->box_end();
$o .= $this->output->container_end();
return $o;
}
/**
* Render the submit for grading page
*
* @param assign_submit_for_grading_page $page
* @return string
*/
public function render_assign_submit_for_grading_page($page) {
$o = '';
$o .= $this->output->container_start('submitforgrading');
$o .= $this->output->heading(get_string('submitassignment', 'assign'), 3);
$o .= $this->output->spacer(array('height'=>30));
$cancelurl = new moodle_url('/mod/assign/view.php', array('id' => $page->coursemoduleid));
if (count($page->notifications)) {
// At least one of the submission plugins is not ready for submission
$o .= $this->output->heading(get_string('submissionnotready', 'assign'), 4);
foreach ($page->notifications as $notification) {
$o .= $this->output->notification($notification);
}
$o .= $this->output->continue_button($cancelurl);
} else {
// All submission plugins ready - show the confirmation form (may contain submission statement)
$o .= $this->moodleform($page->confirmform);
}
$o .= $this->output->container_end();
return $o;
}
/**
* Page is done - render the footer
*
* @return void
*/
public function render_footer() {
return $this->output->footer();
}
/**
* render the header
*
* @param assign_header $header
* @return string
*/
public function render_assign_header(assign_header $header) {
$o = '';
if ($header->subpage) {
$this->page->navbar->add($header->subpage);
}
$this->page->set_title(get_string('pluginname', 'assign'));
$this->page->set_heading($header->assign->name);
$o .= $this->output->header();
if ($header->preface) {
$o .= $header->preface;
}
$o .= $this->output->heading(format_string($header->assign->name,false, array('context' => $header->context)));
if ($header->showintro) {
$o .= $this->output->box_start('generalbox boxaligncenter', 'intro');
$o .= format_module_intro('assign', $header->assign, $header->coursemoduleid);
$o .= $this->output->box_end();
}
return $o;
}
/**
* render a table containing the current status of the grading process
*
* @param assign_grading_summary $summary
* @return string
*/
public function render_assign_grading_summary(assign_grading_summary $summary) {
// create a table for the data
$o = '';
$o .= $this->output->container_start('gradingsummary');
$o .= $this->output->heading(get_string('gradingsummary', 'assign'), 3);
$o .= $this->output->box_start('boxaligncenter gradingsummarytable');
$t = new html_table();
// status
if ($summary->teamsubmission) {
$this->add_table_row_tuple($t, get_string('numberofteams', 'assign'),
$summary->participantcount);
} else {
$this->add_table_row_tuple($t, get_string('numberofparticipants', 'assign'),
$summary->participantcount);
}
// drafts
if ($summary->submissiondraftsenabled) {
$this->add_table_row_tuple($t, get_string('numberofdraftsubmissions', 'assign'),
$summary->submissiondraftscount);
}
// submitted for grading
if ($summary->submissionsenabled) {
$this->add_table_row_tuple($t, get_string('numberofsubmittedassignments', 'assign'),
$summary->submissionssubmittedcount);
$this->add_table_row_tuple($t, get_string('numberofsubmissionsneedgrading', 'assign'),
$summary->submissionsneedgradingcount);
}
$time = time();
if ($summary->duedate) {
// due date
// submitted for grading
$duedate = $summary->duedate;
$this->add_table_row_tuple($t, get_string('duedate', 'assign'),
userdate($duedate));
// time remaining
$due = '';
if ($duedate - $time <= 0) {
$due = get_string('assignmentisdue', 'assign');
} else {
$due = format_time($duedate - $time);
}
$this->add_table_row_tuple($t, get_string('timeremaining', 'assign'), $due);
if ($duedate < $time) {
$cutoffdate = $summary->cutoffdate;
if ($cutoffdate) {
if ($cutoffdate > $time) {
$late = get_string('latesubmissionsaccepted', 'assign');
} else {
$late = get_string('nomoresubmissionsaccepted', 'assign');
}
$this->add_table_row_tuple($t, get_string('latesubmissions', 'assign'), $late);
}
}
}
// all done - write the table
$o .= html_writer::table($t);
$o .= $this->output->box_end();
// link to the grading page
$o .= $this->output->container_start('submissionlinks');
$o .= $this->output->action_link(new moodle_url('/mod/assign/view.php',
array('id' => $summary->coursemoduleid,
'action'=>'grading')),
get_string('viewgrading', 'assign'));
$o .= $this->output->container_end();
// close the container and insert a spacer
$o .= $this->output->container_end();
return $o;
}
/**
* render a table containing all the current grades and feedback
*
* @param assign_feedback_status $status
* @return string
*/
public function render_assign_feedback_status(assign_feedback_status $status) {
global $DB, $CFG;
$o = '';
$o .= $this->output->container_start('feedback');
$o .= $this->output->heading(get_string('feedback', 'assign'), 3);
$o .= $this->output->box_start('boxaligncenter feedbacktable');
$t = new html_table();
$row = new html_table_row();
$cell1 = new html_table_cell(get_string('grade'));
$cell2 = new html_table_cell($status->gradefordisplay);
$row->cells = array($cell1, $cell2);
$t->data[] = $row;
$row = new html_table_row();
$cell1 = new html_table_cell(get_string('gradedon', 'assign'));
$cell2 = new html_table_cell(userdate($status->gradeddate));
$row->cells = array($cell1, $cell2);
$t->data[] = $row;
if ($status->grader) {
$row = new html_table_row();
$cell1 = new html_table_cell(get_string('gradedby', 'assign'));
$cell2 = new html_table_cell($this->output->user_picture($status->grader) . $this->output->spacer(array('width'=>30)) . fullname($status->grader));
$row->cells = array($cell1, $cell2);
$t->data[] = $row;
}
foreach ($status->feedbackplugins as $plugin) {
if ($plugin->is_enabled() && $plugin->is_visible() && !empty($status->grade) && !$plugin->is_empty($status->grade)) {
$row = new html_table_row();
$cell1 = new html_table_cell($plugin->get_name());
$pluginfeedback = new assign_feedback_plugin_feedback($plugin, $status->grade, assign_feedback_plugin_feedback::SUMMARY, $status->coursemoduleid, $status->returnaction, $status->returnparams);
$cell2 = new html_table_cell($this->render($pluginfeedback));
$row->cells = array($cell1, $cell2);
$t->data[] = $row;
}
}
$o .= html_writer::table($t);
$o .= $this->output->box_end();
$o .= $this->output->container_end();
return $o;
}
/**
* render a table containing the current status of the submission
*
* @param assign_submission_status $status
* @return string
*/
public function render_assign_submission_status(assign_submission_status $status) {
$o = '';
$o .= $this->output->container_start('submissionstatustable');
$o .= $this->output->heading(get_string('submissionstatusheading', 'assign'), 3);
$time = time();
if ($status->allowsubmissionsfromdate &&
$time <= $status->allowsubmissionsfromdate) {
$o .= $this->output->box_start('generalbox boxaligncenter submissionsalloweddates');
if ($status->alwaysshowdescription) {
$o .= get_string('allowsubmissionsfromdatesummary', 'assign', userdate($status->allowsubmissionsfromdate));
} else {
$o .= get_string('allowsubmissionsanddescriptionfromdatesummary', 'assign', userdate($status->allowsubmissionsfromdate));
}
$o .= $this->output->box_end();
}
$o .= $this->output->box_start('boxaligncenter submissionsummarytable');
$t = new html_table();
if ($status->teamsubmissionenabled) {
$row = new html_table_row();
$cell1 = new html_table_cell(get_string('submissionteam', 'assign'));
$group = $status->submissiongroup;
if ($group) {
$cell2 = new html_table_cell(format_string($group->name, false, $status->context));
} else {
$cell2 = new html_table_cell(get_string('defaultteam', 'assign'));
}
$row->cells = array($cell1, $cell2);
$t->data[] = $row;
}
$row = new html_table_row();
$cell1 = new html_table_cell(get_string('submissionstatus', 'assign'));
if (!$status->teamsubmissionenabled) {
if ($status->submission) {
$cell2 = new html_table_cell(get_string('submissionstatus_' . $status->submission->status, 'assign'));
$cell2->attributes = array('class'=>'submissionstatus' . $status->submission->status);
} else {
if (!$status->submissionsenabled) {
$cell2 = new html_table_cell(get_string('noonlinesubmissions', 'assign'));
} else {
$cell2 = new html_table_cell(get_string('nosubmission', 'assign'));
}
}
$row->cells = array($cell1, $cell2);
$t->data[] = $row;
} else {
$row = new html_table_row();
$cell1 = new html_table_cell(get_string('submissionstatus', 'assign'));
if ($status->teamsubmission) {
$submissionsummary = get_string('submissionstatus_' . $status->teamsubmission->status, 'assign');
$groupid = 0;
if ($status->submissiongroup) {
$groupid = $status->submissiongroup->id;
}
$members = $status->submissiongroupmemberswhoneedtosubmit;
$userslist = array();
foreach ($members as $member) {
$url = new moodle_url('/user/view.php', array('id' => $member->id, 'course'=>$status->courseid));
if ($status->view == assign_submission_status::GRADER_VIEW && $status->blindmarking) {
$userslist[] = $member->alias;
} else {
$userslist[] = $this->output->action_link($url, fullname($member, $status->canviewfullnames));
}
}
if (count($userslist) > 0) {
$userstr = join(', ', $userslist);
$submissionsummary .= $this->output->container(get_string('userswhoneedtosubmit', 'assign', $userstr));
}
$cell2 = new html_table_cell($submissionsummary);
$cell2->attributes = array('class'=>'submissionstatus' . $status->teamsubmission->status);
} else {
$cell2 = new html_table_cell(get_string('nosubmission', 'assign'));
if (!$status->submissionsenabled) {
$cell2 = new html_table_cell(get_string('noonlinesubmissions', 'assign'));
} else {
$cell2 = new html_table_cell(get_string('nosubmission', 'assign'));
}
}
$row->cells = array($cell1, $cell2);
$t->data[] = $row;
}
// status
if ($status->locked) {
$row = new html_table_row();
$cell1 = new html_table_cell();
$cell2 = new html_table_cell(get_string('submissionslocked', 'assign'));
$cell2->attributes = array('class'=>'submissionlocked');
$row->cells = array($cell1, $cell2);
$t->data[] = $row;
}
// grading status
$row = new html_table_row();
$cell1 = new html_table_cell(get_string('gradingstatus', 'assign'));
if ($status->graded) {
$cell2 = new html_table_cell(get_string('graded', 'assign'));
$cell2->attributes = array('class'=>'submissiongraded');
} else {
$cell2 = new html_table_cell(get_string('notgraded', 'assign'));
$cell2->attributes = array('class'=>'submissionnotgraded');
}
$row->cells = array($cell1, $cell2);
$t->data[] = $row;
$duedate = $status->duedate;
if ($duedate > 0) {
$row = new html_table_row();
$cell1 = new html_table_cell(get_string('duedate', 'assign'));
$cell2 = new html_table_cell(userdate($duedate));
$row->cells = array($cell1, $cell2);
$t->data[] = $row;
if ($status->view == assign_submission_status::GRADER_VIEW) {
if ($status->cutoffdate) {
$row = new html_table_row();
$cell1 = new html_table_cell(get_string('cutoffdate', 'assign'));
$cell2 = new html_table_cell(userdate($status->cutoffdate));
$row->cells = array($cell1, $cell2);
$t->data[] = $row;
}
}
if ($status->extensionduedate) {
$row = new html_table_row();
$cell1 = new html_table_cell(get_string('extensionduedate', 'assign'));
$cell2 = new html_table_cell(userdate($status->extensionduedate));
$row->cells = array($cell1, $cell2);
$t->data[] = $row;
$duedate = $status->extensionduedate;
}
// Time remaining.
$row = new html_table_row();
$cell1 = new html_table_cell(get_string('timeremaining', 'assign'));
if ($duedate - $time <= 0) {
if (!$status->submission || $status->submission->status != ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
if ($status->submissionsenabled) {
$cell2 = new html_table_cell(get_string('overdue', 'assign', format_time($time - $duedate)));
$cell2->attributes = array('class'=>'overdue');
} else {
$cell2 = new html_table_cell(get_string('duedatereached', 'assign'));
}
} else {
if ($status->submission->timemodified > $duedate) {
$cell2 = new html_table_cell(get_string('submittedlate', 'assign', format_time($status->submission->timemodified - $duedate)));
$cell2->attributes = array('class'=>'latesubmission');
} else {
$cell2 = new html_table_cell(get_string('submittedearly', 'assign', format_time($status->submission->timemodified - $duedate)));
$cell2->attributes = array('class'=>'earlysubmission');
}
}
} else {
$cell2 = new html_table_cell(format_time($duedate - $time));
}
$row->cells = array($cell1, $cell2);
$t->data[] = $row;
}
// Show graders whether this submission is editable by students.
if ($status->view == assign_submission_status::GRADER_VIEW) {
$row = new html_table_row();
$cell1 = new html_table_cell(get_string('open', 'assign'));
if ($status->canedit) {
$cell2 = new html_table_cell(get_string('submissioneditable', 'assign'));
$cell2->attributes = array('class'=>'submissioneditable');
} else {
$cell2 = new html_table_cell(get_string('submissionnoteditable', 'assign'));
$cell2->attributes = array('class'=>'submissionnoteditable');
}
}
// Grading criteria preview.
if (!empty($status->gradingcontrollerpreview)) {
$row = new html_table_row();
$cell1 = new html_table_cell(get_string('gradingmethodpreview', 'assign'));
$cell2 = new html_table_cell($status->gradingcontrollerpreview);
$row->cells = array($cell1, $cell2);
$t->data[] = $row;
}
// Last modified.
$submission = $status->teamsubmission ? $status->teamsubmission : $status->submission;
if ($submission) {
$row = new html_table_row();
$cell1 = new html_table_cell(get_string('timemodified', 'assign'));
$cell2 = new html_table_cell(userdate($submission->timemodified));
$row->cells = array($cell1, $cell2);
$t->data[] = $row;
foreach ($status->submissionplugins as $plugin) {
if ($plugin->is_enabled() && $plugin->is_visible() && !$plugin->is_empty($submission)) {
$row = new html_table_row();
$cell1 = new html_table_cell($plugin->get_name());
$pluginsubmission = new assign_submission_plugin_submission($plugin,
$submission,
assign_submission_plugin_submission::SUMMARY,
$status->coursemoduleid,
$status->returnaction,
$status->returnparams);
$cell2 = new html_table_cell($this->render($pluginsubmission));
$row->cells = array($cell1, $cell2);
$t->data[] = $row;
}
}
}
$o .= html_writer::table($t);
$o .= $this->output->box_end();
// Links.
if ($status->view == assign_submission_status::STUDENT_VIEW) {
if ($status->canedit) {
if (!$submission) {
$urlparams = array('id' => $status->coursemoduleid, 'action' => 'editsubmission');
$o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
get_string('addsubmission', 'assign'), 'get');
} else {
$urlparams = array('id' => $status->coursemoduleid, 'action' => 'editsubmission');
$o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
get_string('editsubmission', 'assign'), 'get');
}
}
if ($status->cansubmit) {
$urlparams = array('id' => $status->coursemoduleid, 'action'=>'submit');
$o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
get_string('submitassignment', 'assign'), 'get');
$o .= $this->output->box_start('boxaligncenter submithelp');
$o .= get_string('submitassignment_help', 'assign');
$o .= $this->output->box_end();
}
}
$o .= $this->output->container_end();
return $o;
}
/**
* render a submission plugin submission
*
* @param assign_submission_plugin_submission $submissionplugin
* @return string
*/
public function render_assign_submission_plugin_submission(assign_submission_plugin_submission $submissionplugin) {
$o = '';
if ($submissionplugin->view == assign_submission_plugin_submission::SUMMARY) {
$icon = $this->output->pix_icon('t/preview', get_string('view' . substr($submissionplugin->plugin->get_subtype(), strlen('assign')), 'mod_assign'));
$link = '';
$showviewlink = false;
$summary = $submissionplugin->plugin->view_summary($submissionplugin->submission, $showviewlink);
if ($showviewlink) {
$link = $this->output->action_link(
new moodle_url('/mod/assign/view.php',
array('id' => $submissionplugin->coursemoduleid,
'sid'=>$submissionplugin->submission->id,
'plugin'=>$submissionplugin->plugin->get_type(),
'action'=>'viewplugin' . $submissionplugin->plugin->get_subtype(),
'returnaction'=>$submissionplugin->returnaction,
'returnparams'=>http_build_query($submissionplugin->returnparams))),
$icon);
$link .= $this->output->spacer(array('width'=>15));
}
$o .= $link . $summary;
} else if ($submissionplugin->view == assign_submission_plugin_submission::FULL) {
$o .= $this->output->box_start('boxaligncenter submissionfull');
$o .= $submissionplugin->plugin->view($submissionplugin->submission);
$o .= $this->output->box_end();
}
return $o;
}
/**
* render the grading table
*
* @param assign_grading_table $table
* @return string
*/
public function render_assign_grading_table(assign_grading_table $table) {
$o = '';
$o .= $this->output->box_start('boxaligncenter gradingtable');
$this->page->requires->js_init_call('M.mod_assign.init_grading_table', array());
$this->page->requires->string_for_js('nousersselected', 'assign');
$this->page->requires->string_for_js('batchoperationconfirmgrantextension', 'assign');
$this->page->requires->string_for_js('batchoperationconfirmlock', 'assign');
$this->page->requires->string_for_js('batchoperationconfirmreverttodraft', 'assign');
$this->page->requires->string_for_js('batchoperationconfirmunlock', 'assign');
$this->page->requires->string_for_js('editaction', 'assign');
// need to get from prefs
$o .= $this->flexible_table($table, $table->get_rows_per_page(), true);
$o .= $this->output->box_end();
return $o;
}
/**
* Render a feedback plugin feedback
*
* @param assign_feedback_plugin_feedback $feedbackplugin
* @return string
*/
public function render_assign_feedback_plugin_feedback(assign_feedback_plugin_feedback $feedbackplugin) {
$o = '';
if ($feedbackplugin->view == assign_feedback_plugin_feedback::SUMMARY) {
$icon = $this->output->pix_icon('t/preview', get_string('view' . substr($feedbackplugin->plugin->get_subtype(), strlen('assign')), 'mod_assign'));
$link = '';
$showviewlink = false;
$summary = $feedbackplugin->plugin->view_summary($feedbackplugin->grade, $showviewlink);
if ($showviewlink) {
$link = $this->output->action_link(
new moodle_url('/mod/assign/view.php',
array('id' => $feedbackplugin->coursemoduleid,
'gid'=>$feedbackplugin->grade->id,
'plugin'=>$feedbackplugin->plugin->get_type(),
'action'=>'viewplugin' . $feedbackplugin->plugin->get_subtype(),
'returnaction'=>$feedbackplugin->returnaction,
'returnparams'=>http_build_query($feedbackplugin->returnparams))),
$icon);
$link .= $this->output->spacer(array('width'=>15));
}
$o .= $link . $summary;
} else if ($feedbackplugin->view == assign_feedback_plugin_feedback::FULL) {
$o .= $this->output->box_start('boxaligncenter feedbackfull');
$o .= $feedbackplugin->plugin->view($feedbackplugin->grade);
$o .= $this->output->box_end();
}
return $o;
}
/**
* Internal function - creates htmls structure suitable for YUI tree.
*
* @param assign_files $tree
* @param array $dir
* @return string
*/
protected function htmllize_tree(assign_files $tree, $dir) {
global $CFG;
$yuiconfig = array();
$yuiconfig['type'] = 'html';
if (empty($dir['subdirs']) and empty($dir['files'])) {
return '';
}
$result = '<ul>';
foreach ($dir['subdirs'] as $subdir) {
$image = $this->output->pix_icon(file_folder_icon(), $subdir['dirname'], 'moodle', array('class'=>'icon'));
$result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.s($subdir['dirname']).'</div> '.$this->htmllize_tree($tree, $subdir).'</li>';
}
foreach ($dir['files'] as $file) {
$filename = $file->get_filename();
if ($CFG->enableplagiarism) {
require_once($CFG->libdir.'/plagiarismlib.php');
$plagiarsmlinks = plagiarism_get_links(array('userid'=>$file->get_userid(), 'file'=>$file, 'cmid'=>$tree->cm->id, 'course'=>$tree->course));
} else {
$plagiarsmlinks = '';
}
$image = $this->output->pix_icon(file_file_icon($file), $filename, 'moodle', array('class'=>'icon'));
$result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.$file->fileurl.' '.$plagiarsmlinks.$file->portfoliobutton.'</div></li>';
}
$result .= '</ul>';
return $result;
}
/**
* Helper method dealing with the fact we can not just fetch the output of flexible_table
*
* @param flexible_table $table The table to render
* @param int $rowsperpage How many assignments to render in a page
* @param bool $displaylinks - Whether to render links in the table (e.g. downloads would not enable this)
* @return string HTML
*/
protected function flexible_table(flexible_table $table, $rowsperpage, $displaylinks) {
$o = '';
ob_start();
$table->out($rowsperpage, $displaylinks);
$o = ob_get_contents();
ob_end_clean();
return $o;
}
/**
* Helper method dealing with the fact we can not just fetch the output of moodleforms
*
* @param moodleform $mform
* @return string HTML
*/
protected function moodleform(moodleform $mform) {
$o = '';
ob_start();
$mform->display();
$o = ob_get_contents();
ob_end_clean();
return $o;
}
}