mirrored from git://git.moodle.org/moodle.git
/
renderer.php
785 lines (678 loc) · 31.9 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
<?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/>.
/**
* Workshop module renderering methods are defined here
*
* @package mod
* @subpackage workshop
* @copyright 2009 David Mudrak <david.mudrak@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Workshop module renderer class
*
* @copyright 2009 David Mudrak <david.mudrak@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_workshop_renderer extends plugin_renderer_base {
////////////////////////////////////////////////////////////////////////////
// External API - methods to render workshop renderable components
////////////////////////////////////////////////////////////////////////////
/**
* Renders workshop message
*
* @param workshop_message $message to display
* @return string html code
*/
protected function render_workshop_message(workshop_message $message) {
$text = $message->get_message();
$url = $message->get_action_url();
$label = $message->get_action_label();
if (empty($text) and empty($label)) {
return '';
}
switch ($message->get_type()) {
case workshop_message::TYPE_OK:
$sty = 'ok';
break;
case workshop_message::TYPE_ERROR:
$sty = 'error';
break;
default:
$sty = 'info';
}
$o = html_writer::tag('span', $message->get_message());
if (!is_null($url) and !is_null($label)) {
$o .= $this->output->single_button($url, $label, 'get');
}
return $this->output->container($o, array('message', $sty));
}
/**
* Renders full workshop submission
*
* @param workshop_submission $submission
* @return string HTML
*/
protected function render_workshop_submission(workshop_submission $submission) {
$o = ''; // output HTML code
$anonymous = $submission->is_anonymous();
$classes = 'submission-full';
if ($anonymous) {
$classes .= ' anonymous';
}
$o .= $this->output->container_start($classes);
$o .= $this->output->container_start('header');
$o .= $this->output->heading(format_string($submission->title), 3, 'title');
if (!$anonymous) {
$author = new stdclass();
$author->id = $submission->authorid;
$author->firstname = $submission->authorfirstname;
$author->lastname = $submission->authorlastname;
$author->picture = $submission->authorpicture;
$author->imagealt = $submission->authorimagealt;
$author->email = $submission->authoremail;
$userpic = $this->output->user_picture($author, array('courseid' => $this->page->course->id, 'size' => 64));
$userurl = new moodle_url('/user/view.php',
array('id' => $author->id, 'course' => $this->page->course->id));
$a = new stdclass();
$a->name = fullname($author);
$a->url = $userurl->out();
$byfullname = get_string('byfullname', 'workshop', $a);
$oo = $this->output->container($userpic, 'picture');
$oo .= $this->output->container($byfullname, 'fullname');
$o .= $this->output->container($oo, 'author');
}
$created = get_string('userdatecreated', 'workshop', userdate($submission->timecreated));
$o .= $this->output->container($created, 'userdate created');
if ($submission->timemodified > $submission->timecreated) {
$modified = get_string('userdatemodified', 'workshop', userdate($submission->timemodified));
$o .= $this->output->container($modified, 'userdate modified');
}
$o .= $this->output->container_end(); // end of header
$content = format_text($submission->content, $submission->contentformat, array('overflowdiv'=>true));
$content = file_rewrite_pluginfile_urls($content, 'pluginfile.php', $this->page->context->id,
'mod_workshop', 'submission_content', $submission->id);
$o .= $this->output->container($content, 'content');
$o .= $this->helper_submission_attachments($submission->id, 'html');
$o .= $this->output->container_end(); // end of submission-full
return $o;
}
/**
* Renders short summary of the submission
*
* @param workshop_submission_summary $summary
* @return string text to be echo'ed
*/
protected function render_workshop_submission_summary(workshop_submission_summary $summary) {
$o = ''; // output HTML code
$anonymous = $summary->is_anonymous();
$classes = 'submission-summary';
if ($anonymous) {
$classes .= ' anonymous';
}
$gradestatus = '';
if ($summary->status == 'notgraded') {
$classes .= ' notgraded';
$gradestatus = $this->output->container(get_string('nogradeyet', 'workshop'), 'grade-status');
} else if ($summary->status == 'graded') {
$classes .= ' graded';
$gradestatus = $this->output->container(get_string('alreadygraded', 'workshop'), 'grade-status');
}
$o .= $this->output->container_start($classes); // main wrapper
$o .= html_writer::link($summary->url, format_string($summary->title), array('class' => 'title'));
if (!$anonymous) {
$author = new stdClass();
$author->id = $summary->authorid;
$author->firstname = $summary->authorfirstname;
$author->lastname = $summary->authorlastname;
$author->picture = $summary->authorpicture;
$author->imagealt = $summary->authorimagealt;
$author->email = $summary->authoremail;
$userpic = $this->output->user_picture($author, array('courseid' => $this->page->course->id, 'size' => 35));
$userurl = new moodle_url('/user/view.php',
array('id' => $author->id, 'course' => $this->page->course->id));
$a = new stdClass();
$a->name = fullname($author);
$a->url = $userurl->out();
$byfullname = get_string('byfullname', 'workshop', $a);
$oo = $this->output->container($userpic, 'picture');
$oo .= $this->output->container($byfullname, 'fullname');
$o .= $this->output->container($oo, 'author');
}
$created = get_string('userdatecreated', 'workshop', userdate($summary->timecreated));
$o .= $this->output->container($created, 'userdate created');
if ($summary->timemodified > $summary->timecreated) {
$modified = get_string('userdatemodified', 'workshop', userdate($summary->timemodified));
$o .= $this->output->container($modified, 'userdate modified');
}
$o .= $gradestatus;
$o .= $this->output->container_end(); // end of the main wrapper
return $o;
}
/**
* Renders full workshop example submission
*
* @param workshop_example_submission $example
* @return string HTML
*/
protected function render_workshop_example_submission(workshop_example_submission $example) {
$o = ''; // output HTML code
$classes = 'submission-full example';
$o .= $this->output->container_start($classes);
$o .= $this->output->container_start('header');
$o .= $this->output->heading(format_string($example->title), 3, 'title');
$o .= $this->output->container_end(); // end of header
$content = format_text($example->content, $example->contentformat, array('overflowdiv'=>true));
$content = file_rewrite_pluginfile_urls($content, 'pluginfile.php', $this->page->context->id,
'mod_workshop', 'submission_content', $example->id);
$o .= $this->output->container($content, 'content');
$o .= $this->helper_submission_attachments($example->id, 'html');
$o .= $this->output->container_end(); // end of submission-full
return $o;
}
/**
* Renders short summary of the example submission
*
* @param workshop_example_submission_summary $summary
* @return string text to be echo'ed
*/
protected function render_workshop_example_submission_summary(workshop_example_submission_summary $summary) {
$o = ''; // output HTML code
// wrapping box
$o .= $this->output->box_start('generalbox example-summary ' . $summary->status);
// title
$o .= $this->output->container_start('example-title');
$o .= html_writer::link($summary->url, format_string($summary->title), array('class' => 'title'));
if ($summary->editable) {
$o .= $this->output->action_icon($summary->editurl, new pix_icon('i/edit', get_string('edit')));
}
$o .= $this->output->container_end();
// additional info
if ($summary->status == 'notgraded') {
$o .= $this->output->container(get_string('nogradeyet', 'workshop'), 'example-info nograde');
} else {
$o .= $this->output->container(get_string('gradeinfo', 'workshop' , $summary->gradeinfo), 'example-info grade');
}
// button to assess
$button = new single_button($summary->assessurl, $summary->assesslabel, 'get');
$o .= $this->output->container($this->output->render($button), 'example-actions');
// end of wrapping box
$o .= $this->output->box_end();
return $o;
}
/**
* Renders the user plannner tool
*
* @param workshop_user_plan $plan prepared for the user
* @return string html code to be displayed
*/
protected function render_workshop_user_plan(workshop_user_plan $plan) {
$table = new html_table();
$table->attributes['class'] = 'userplan';
$table->head = array();
$table->colclasses = array();
$row = new html_table_row();
$row->attributes['class'] = 'phasetasks';
foreach ($plan->phases as $phasecode => $phase) {
$title = html_writer::tag('span', $phase->title);
$actions = '';
foreach ($phase->actions as $action) {
switch ($action->type) {
case 'switchphase':
$actions .= $this->output->action_icon($action->url, new pix_icon('i/marker', get_string('switchphase', 'workshop')));
break;
}
}
if (!empty($actions)) {
$actions = $this->output->container($actions, 'actions');
}
$table->head[] = $this->output->container($title . $actions);
$classes = 'phase' . $phasecode;
if ($phase->active) {
$classes .= ' active';
} else {
$classes .= ' nonactive';
}
$table->colclasses[] = $classes;
$cell = new html_table_cell();
$cell->text = $this->helper_user_plan_tasks($phase->tasks);
$row->cells[] = $cell;
}
$table->data = array($row);
return html_writer::table($table);
}
/**
* Renders the result of the submissions allocation process
*
* @param workshop_allocation_init_result
* @return string html to be echoed
*/
protected function render_workshop_allocation_init_result(workshop_allocation_init_result $result) {
// start with the message
$o = $this->render($result->get_message());
// display the details about the process if available
$info = $result->get_info();
if (is_array($info) and !empty($info)) {
$o .= html_writer::start_tag('ul', array('class' => 'allocation-init-results'));
foreach ($info as $message) {
$parts = explode('::', $message);
$text = array_pop($parts);
$class = implode(' ', $parts);
if (in_array('debug', $parts) && !debugging('', DEBUG_DEVELOPER)) {
// do not display allocation debugging messages
continue;
}
$o .= html_writer::tag('li', $text, array('class' => $class)) . "\n";
}
$o .= html_writer::end_tag('ul');
}
$o .= $this->output->continue_button($result->get_continue_url());
return $o;
}
/**
* Renders the workshop grading report
*
* @param workshop_grading_report $gradingreport
* @return string html code
*/
protected function render_workshop_grading_report(workshop_grading_report $gradingreport) {
$data = $gradingreport->get_data();
$options = $gradingreport->get_options();
$grades = $data->grades;
$userinfo = $data->userinfo;
if (empty($grades)) {
return '';
}
$table = new html_table();
$table->attributes['class'] = 'grading-report';
$sortbyfirstname = $this->helper_sortable_heading(get_string('firstname'), 'firstname', $options->sortby, $options->sorthow);
$sortbylastname = $this->helper_sortable_heading(get_string('lastname'), 'lastname', $options->sortby, $options->sorthow);
if (self::fullname_format() == 'lf') {
$sortbyname = $sortbylastname . ' / ' . $sortbyfirstname;
} else {
$sortbyname = $sortbyfirstname . ' / ' . $sortbylastname;
}
$table->head = array();
$table->head[] = $sortbyname;
$table->head[] = $this->helper_sortable_heading(get_string('submission', 'workshop'), 'submissiontitle',
$options->sortby, $options->sorthow);
$table->head[] = $this->helper_sortable_heading(get_string('receivedgrades', 'workshop'));
if ($options->showsubmissiongrade) {
$table->head[] = $this->helper_sortable_heading(get_string('submissiongradeof', 'workshop', $data->maxgrade),
'submissiongrade', $options->sortby, $options->sorthow);
}
$table->head[] = $this->helper_sortable_heading(get_string('givengrades', 'workshop'));
if ($options->showgradinggrade) {
$table->head[] = $this->helper_sortable_heading(get_string('gradinggradeof', 'workshop', $data->maxgradinggrade),
'gradinggrade', $options->sortby, $options->sorthow);
}
$table->rowclasses = array();
$table->colclasses = array();
$table->data = array();
foreach ($grades as $participant) {
$numofreceived = count($participant->reviewedby);
$numofgiven = count($participant->reviewerof);
$published = $participant->submissionpublished;
// compute the number of <tr> table rows needed to display this participant
if ($numofreceived > 0 and $numofgiven > 0) {
$numoftrs = workshop::lcm($numofreceived, $numofgiven);
$spanreceived = $numoftrs / $numofreceived;
$spangiven = $numoftrs / $numofgiven;
} elseif ($numofreceived == 0 and $numofgiven > 0) {
$numoftrs = $numofgiven;
$spanreceived = $numoftrs;
$spangiven = $numoftrs / $numofgiven;
} elseif ($numofreceived > 0 and $numofgiven == 0) {
$numoftrs = $numofreceived;
$spanreceived = $numoftrs / $numofreceived;
$spangiven = $numoftrs;
} else {
$numoftrs = 1;
$spanreceived = 1;
$spangiven = 1;
}
for ($tr = 0; $tr < $numoftrs; $tr++) {
$row = new html_table_row();
if ($published) {
$row->attributes['class'] = 'published';
}
// column #1 - participant - spans over all rows
if ($tr == 0) {
$cell = new html_table_cell();
$cell->text = $this->helper_grading_report_participant($participant, $userinfo);
$cell->rowspan = $numoftrs;
$cell->attributes['class'] = 'participant';
$row->cells[] = $cell;
}
// column #2 - submission - spans over all rows
if ($tr == 0) {
$cell = new html_table_cell();
$cell->text = $this->helper_grading_report_submission($participant);
$cell->rowspan = $numoftrs;
$cell->attributes['class'] = 'submission';
$row->cells[] = $cell;
}
// column #3 - received grades
if ($tr % $spanreceived == 0) {
$idx = intval($tr / $spanreceived);
$assessment = self::array_nth($participant->reviewedby, $idx);
$cell = new html_table_cell();
$cell->text = $this->helper_grading_report_assessment($assessment, $options->showreviewernames, $userinfo,
get_string('gradereceivedfrom', 'workshop'));
$cell->rowspan = $spanreceived;
$cell->attributes['class'] = 'receivedgrade';
if (is_null($assessment) or is_null($assessment->grade)) {
$cell->attributes['class'] .= ' null';
} else {
$cell->attributes['class'] .= ' notnull';
}
$row->cells[] = $cell;
}
// column #4 - total grade for submission
if ($options->showsubmissiongrade and $tr == 0) {
$cell = new html_table_cell();
$cell->text = $this->helper_grading_report_grade($participant->submissiongrade, $participant->submissiongradeover);
$cell->rowspan = $numoftrs;
$cell->attributes['class'] = 'submissiongrade';
$row->cells[] = $cell;
}
// column #5 - given grades
if ($tr % $spangiven == 0) {
$idx = intval($tr / $spangiven);
$assessment = self::array_nth($participant->reviewerof, $idx);
$cell = new html_table_cell();
$cell->text = $this->helper_grading_report_assessment($assessment, $options->showauthornames, $userinfo,
get_string('gradegivento', 'workshop'));
$cell->rowspan = $spangiven;
$cell->attributes['class'] = 'givengrade';
if (is_null($assessment) or is_null($assessment->grade)) {
$cell->attributes['class'] .= ' null';
} else {
$cell->attributes['class'] .= ' notnull';
}
$row->cells[] = $cell;
}
// column #6 - total grade for assessment
if ($options->showgradinggrade and $tr == 0) {
$cell = new html_table_cell();
$cell->text = $this->helper_grading_report_grade($participant->gradinggrade);
$cell->rowspan = $numoftrs;
$cell->attributes['class'] = 'gradinggrade';
$row->cells[] = $cell;
}
$table->data[] = $row;
}
}
return html_writer::table($table);
}
/**
* Renders the feedback for the author of the submission
*
* @param workshop_feedback_author $feedback
* @return string HTML
*/
protected function render_workshop_feedback_author(workshop_feedback_author $feedback) {
$o = ''; // output HTML code
$o .= $this->output->container_start('feedback feedbackforauthor');
$o .= $this->output->container_start('header');
$o .= $this->output->heading(get_string('feedbackby', 'workshop', s(fullname($feedback->get_provider()))), 3, 'title');
$userpic = $this->output->user_picture($feedback->get_provider(), array('courseid' => $this->page->course->id, 'size' => 32));
$o .= $this->output->container($userpic, 'picture');
$o .= $this->output->container_end(); // end of header
$content = format_text($feedback->get_content(), $feedback->get_format(), array('overflowdiv' => true));
$o .= $this->output->container($content, 'content');
$o .= $this->output->container_end(); // end of submission-full
return $o;
}
////////////////////////////////////////////////////////////////////////////
// Internal rendering helper methods
////////////////////////////////////////////////////////////////////////////
/**
* Renders a list of files attached to the submission
*
* If format==html, then format a html string. If format==text, then format a text-only string.
* Otherwise, returns html for non-images and html to display the image inline.
*
* @param int $submissionid submission identifier
* @param string format the format of the returned string - html|text
* @return string formatted text to be echoed
*/
protected function helper_submission_attachments($submissionid, $format = 'html') {
global $CFG;
require_once($CFG->libdir.'/filelib.php');
$fs = get_file_storage();
$ctx = $this->page->context;
$files = $fs->get_area_files($ctx->id, 'mod_workshop', 'submission_attachment', $submissionid);
$outputimgs = ''; // images to be displayed inline
$outputfiles = ''; // list of attachment files
foreach ($files as $file) {
if ($file->is_directory()) {
continue;
}
$filepath = $file->get_filepath();
$filename = $file->get_filename();
$fileurl = file_encode_url($CFG->wwwroot . '/pluginfile.php',
'/' . $ctx->id . '/mod_workshop/submission_attachment/' . $submissionid . $filepath . $filename, true);
$type = $file->get_mimetype();
$type = mimeinfo_from_type('type', $type);
$image = html_writer::empty_tag('img', array('src'=>$this->output->pix_url(file_mimetype_icon($type)), 'alt'=>$type, 'class'=>'icon'));
$linkhtml = html_writer::link($fileurl, $image) . substr($filepath, 1) . html_writer::link($fileurl, $filename);
$linktxt = "$filename [$fileurl]";
if ($format == 'html') {
if (in_array($type, array('image/gif', 'image/jpeg', 'image/png'))) {
$preview = html_writer::empty_tag('img', array('src' => $fileurl, 'alt' => '', 'class' => 'preview'));
$preview = html_writer::tag('a', $preview, array('href' => $fileurl));
$outputimgs .= $this->output->container($preview);
} else {
$outputfiles .= html_writer::tag('li', $linkhtml, array('class' => $type));
}
} else if ($format == 'text') {
$outputfiles .= $linktxt . PHP_EOL;
}
}
if ($format == 'html') {
if ($outputimgs) {
$outputimgs = $this->output->container($outputimgs, 'images');
}
if ($outputfiles) {
$outputfiles = html_writer::tag('ul', $outputfiles, array('class' => 'files'));
}
return $this->output->container($outputimgs . $outputfiles, 'attachments');
} else {
return $outputfiles;
}
}
/**
* Renders the tasks for the single phase in the user plan
*
* @param stdClass $tasks
* @return string html code
*/
protected function helper_user_plan_tasks(array $tasks) {
$out = '';
foreach ($tasks as $taskcode => $task) {
$classes = '';
$icon = null;
if ($task->completed === true) {
$classes .= ' completed';
} elseif ($task->completed === false) {
$classes .= ' fail';
} elseif ($task->completed === 'info') {
$classes .= ' info';
}
if (is_null($task->link)) {
$title = $task->title;
} else {
$title = html_writer::link($task->link, $task->title);
}
$title = $this->output->container($title, 'title');
$details = $this->output->container($task->details, 'details');
$out .= html_writer::tag('li', $title . $details, array('class' => $classes));
}
if ($out) {
$out = html_writer::tag('ul', $out, array('class' => 'tasks'));
}
return $out;
}
/**
* Renders a text with icons to sort by the given column
*
* This is intended for table headings.
*
* @param string $text The heading text
* @param string $sortid The column id used for sorting
* @param string $sortby Currently sorted by (column id)
* @param string $sorthow Currently sorted how (ASC|DESC)
*
* @return string
*/
protected function helper_sortable_heading($text, $sortid=null, $sortby=null, $sorthow=null) {
global $PAGE;
$out = html_writer::tag('span', $text, array('class'=>'text'));
if (!is_null($sortid)) {
if ($sortby !== $sortid or $sorthow !== 'ASC') {
$url = new moodle_url($PAGE->url);
$url->params(array('sortby' => $sortid, 'sorthow' => 'ASC'));
$out .= $this->output->action_icon($url, new pix_icon('t/up', get_string('sortasc', 'workshop')), null, array('class' => 'sort asc'));
}
if ($sortby !== $sortid or $sorthow !== 'DESC') {
$url = new moodle_url($PAGE->url);
$url->params(array('sortby' => $sortid, 'sorthow' => 'DESC'));
$out .= $this->output->action_icon($url, new pix_icon('t/down', get_string('sortdesc', 'workshop')), null, array('class' => 'sort desc'));
}
}
return $out;
}
/**
* @param stdClass $participant
* @param array $userinfo
* @return string
*/
protected function helper_grading_report_participant(stdclass $participant, array $userinfo) {
$userid = $participant->userid;
$out = $this->output->user_picture($userinfo[$userid], array('courseid' => $this->page->course->id, 'size' => 35));
$out .= html_writer::tag('span', fullname($userinfo[$userid]));
return $out;
}
/**
* @param stdClass $participant
* @return string
*/
protected function helper_grading_report_submission(stdclass $participant) {
global $CFG;
if (is_null($participant->submissionid)) {
$out = $this->output->container(get_string('nosubmissionfound', 'workshop'), 'info');
} else {
$url = new moodle_url('/mod/workshop/submission.php',
array('cmid' => $this->page->context->instanceid, 'id' => $participant->submissionid));
$out = html_writer::link($url, format_string($participant->submissiontitle), array('class'=>'title'));
}
return $out;
}
/**
* @todo Highlight the nulls
* @param stdClass|null $assessment
* @param bool $shownames
* @param string $separator between the grade and the reviewer/author
* @return string
*/
protected function helper_grading_report_assessment($assessment, $shownames, array $userinfo, $separator) {
global $CFG;
if (is_null($assessment)) {
return get_string('nullgrade', 'workshop');
}
$a = new stdclass();
$a->grade = is_null($assessment->grade) ? get_string('nullgrade', 'workshop') : $assessment->grade;
$a->gradinggrade = is_null($assessment->gradinggrade) ? get_string('nullgrade', 'workshop') : $assessment->gradinggrade;
$a->weight = $assessment->weight;
// grrr the following logic should really be handled by a future language pack feature
if (is_null($assessment->gradinggradeover)) {
if ($a->weight == 1) {
$grade = get_string('formatpeergrade', 'workshop', $a);
} else {
$grade = get_string('formatpeergradeweighted', 'workshop', $a);
}
} else {
$a->gradinggradeover = $assessment->gradinggradeover;
if ($a->weight == 1) {
$grade = get_string('formatpeergradeover', 'workshop', $a);
} else {
$grade = get_string('formatpeergradeoverweighted', 'workshop', $a);
}
}
$url = new moodle_url('/mod/workshop/assessment.php',
array('asid' => $assessment->assessmentid));
$grade = html_writer::link($url, $grade, array('class'=>'grade'));
if ($shownames) {
$userid = $assessment->userid;
$name = $this->output->user_picture($userinfo[$userid], array('courseid' => $this->page->course->id, 'size' => 16));
$name .= html_writer::tag('span', fullname($userinfo[$userid]), array('class' => 'fullname'));
$name = $separator . html_writer::tag('span', $name, array('class' => 'user'));
} else {
$name = '';
}
return $this->output->container($grade . $name, 'assessmentdetails');
}
/**
* Formats the aggreagated grades
*/
protected function helper_grading_report_grade($grade, $over=null) {
$a = new stdclass();
$a->grade = is_null($grade) ? get_string('nullgrade', 'workshop') : $grade;
if (is_null($over)) {
$text = get_string('formataggregatedgrade', 'workshop', $a);
} else {
$a->over = is_null($over) ? get_string('nullgrade', 'workshop') : $over;
$text = get_string('formataggregatedgradeover', 'workshop', $a);
}
return $text;
}
////////////////////////////////////////////////////////////////////////////
// Static helpers
////////////////////////////////////////////////////////////////////////////
/**
* Helper function returning the n-th item of the array
*
* @param array $a
* @param int $n from 0 to m, where m is th number of items in the array
* @return mixed the $n-th element of $a
*/
protected static function array_nth(array $a, $n) {
$keys = array_keys($a);
if ($n < 0 or $n > count($keys) - 1) {
return null;
}
$key = $keys[$n];
return $a[$key];
}
/**
* Tries to guess the fullname format set at the site
*
* @return string fl|lf
*/
protected static function fullname_format() {
$fake = new stdclass(); // fake user
$fake->lastname = 'LLLL';
$fake->firstname = 'FFFF';
$fullname = get_string('fullnamedisplay', '', $fake);
if (strpos($fullname, 'LLLL') < strpos($fullname, 'FFFF')) {
return 'lf';
} else {
return 'fl';
}
}
}