3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
19 * Workshop module renderering methods are defined here
22 * @subpackage workshop
23 * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 defined('MOODLE_INTERNAL') ||
die();
30 * Workshop module renderer class
32 * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35 class mod_workshop_renderer
extends plugin_renderer_base
{
37 ////////////////////////////////////////////////////////////////////////////
38 // External API - methods to render workshop renderable components
39 ////////////////////////////////////////////////////////////////////////////
42 * Renders workshop message
44 * @param workshop_message $message to display
45 * @return string html code
47 protected function render_workshop_message(workshop_message
$message) {
49 $text = $message->get_message();
50 $url = $message->get_action_url();
51 $label = $message->get_action_label();
53 if (empty($text) and empty($label)) {
57 switch ($message->get_type()) {
58 case workshop_message
::TYPE_OK
:
61 case workshop_message
::TYPE_ERROR
:
68 $o = html_writer
::tag('span', $message->get_message());
70 if (!is_null($url) and !is_null($label)) {
71 $o .= $this->output
->single_button($url, $label, 'get');
74 return $this->output
->container($o, array('message', $sty));
79 * Renders full workshop submission
81 * @param workshop_submission $submission
84 protected function render_workshop_submission(workshop_submission
$submission) {
87 $o = ''; // output HTML code
88 $anonymous = $submission->is_anonymous();
89 $classes = 'submission-full';
91 $classes .= ' anonymous';
93 $o .= $this->output
->container_start($classes);
94 $o .= $this->output
->container_start('header');
96 $title = format_string($submission->title
);
98 if ($this->page
->url
!= $submission->url
) {
99 $title = html_writer
::link($submission->url
, $title);
102 $o .= $this->output
->heading($title, 3, 'title');
105 $author = new stdclass();
106 $author->id
= $submission->authorid
;
107 $author->firstname
= $submission->authorfirstname
;
108 $author->lastname
= $submission->authorlastname
;
109 $author->picture
= $submission->authorpicture
;
110 $author->imagealt
= $submission->authorimagealt
;
111 $author->email
= $submission->authoremail
;
112 $userpic = $this->output
->user_picture($author, array('courseid' => $this->page
->course
->id
, 'size' => 64));
113 $userurl = new moodle_url('/user/view.php',
114 array('id' => $author->id
, 'course' => $this->page
->course
->id
));
116 $a->name
= fullname($author);
117 $a->url
= $userurl->out();
118 $byfullname = get_string('byfullname', 'workshop', $a);
119 $oo = $this->output
->container($userpic, 'picture');
120 $oo .= $this->output
->container($byfullname, 'fullname');
122 $o .= $this->output
->container($oo, 'author');
125 $created = get_string('userdatecreated', 'workshop', userdate($submission->timecreated
));
126 $o .= $this->output
->container($created, 'userdate created');
128 if ($submission->timemodified
> $submission->timecreated
) {
129 $modified = get_string('userdatemodified', 'workshop', userdate($submission->timemodified
));
130 $o .= $this->output
->container($modified, 'userdate modified');
133 $o .= $this->output
->container_end(); // end of header
135 $content = format_text($submission->content
, $submission->contentformat
, array('overflowdiv'=>true));
136 $content = file_rewrite_pluginfile_urls($content, 'pluginfile.php', $this->page
->context
->id
,
137 'mod_workshop', 'submission_content', $submission->id
);
138 if (!empty($content)) {
139 if (!empty($CFG->enableplagiarism
)) {
140 require_once($CFG->libdir
.'/plagiarismlib.php');
141 $content .= plagiarism_get_links(array('userid' => $submission->authorid
,
142 'content' => $submission->content
,
143 'cmid' => $this->page
->cm
->id
,
144 'course' => $this->page
->course
));
147 $o .= $this->output
->container($content, 'content');
149 $o .= $this->helper_submission_attachments($submission->id
, 'html');
151 $o .= $this->output
->container_end(); // end of submission-full
157 * Renders short summary of the submission
159 * @param workshop_submission_summary $summary
160 * @return string text to be echo'ed
162 protected function render_workshop_submission_summary(workshop_submission_summary
$summary) {
164 $o = ''; // output HTML code
165 $anonymous = $summary->is_anonymous();
166 $classes = 'submission-summary';
169 $classes .= ' anonymous';
174 if ($summary->status
== 'notgraded') {
175 $classes .= ' notgraded';
176 $gradestatus = $this->output
->container(get_string('nogradeyet', 'workshop'), 'grade-status');
178 } else if ($summary->status
== 'graded') {
179 $classes .= ' graded';
180 $gradestatus = $this->output
->container(get_string('alreadygraded', 'workshop'), 'grade-status');
183 $o .= $this->output
->container_start($classes); // main wrapper
184 $o .= html_writer
::link($summary->url
, format_string($summary->title
), array('class' => 'title'));
187 $author = new stdClass();
188 $author->id
= $summary->authorid
;
189 $author->firstname
= $summary->authorfirstname
;
190 $author->lastname
= $summary->authorlastname
;
191 $author->picture
= $summary->authorpicture
;
192 $author->imagealt
= $summary->authorimagealt
;
193 $author->email
= $summary->authoremail
;
194 $userpic = $this->output
->user_picture($author, array('courseid' => $this->page
->course
->id
, 'size' => 35));
195 $userurl = new moodle_url('/user/view.php',
196 array('id' => $author->id
, 'course' => $this->page
->course
->id
));
198 $a->name
= fullname($author);
199 $a->url
= $userurl->out();
200 $byfullname = get_string('byfullname', 'workshop', $a);
202 $oo = $this->output
->container($userpic, 'picture');
203 $oo .= $this->output
->container($byfullname, 'fullname');
204 $o .= $this->output
->container($oo, 'author');
207 $created = get_string('userdatecreated', 'workshop', userdate($summary->timecreated
));
208 $o .= $this->output
->container($created, 'userdate created');
210 if ($summary->timemodified
> $summary->timecreated
) {
211 $modified = get_string('userdatemodified', 'workshop', userdate($summary->timemodified
));
212 $o .= $this->output
->container($modified, 'userdate modified');
216 $o .= $this->output
->container_end(); // end of the main wrapper
221 * Renders full workshop example submission
223 * @param workshop_example_submission $example
224 * @return string HTML
226 protected function render_workshop_example_submission(workshop_example_submission
$example) {
228 $o = ''; // output HTML code
229 $classes = 'submission-full example';
230 $o .= $this->output
->container_start($classes);
231 $o .= $this->output
->container_start('header');
232 $o .= $this->output
->heading(format_string($example->title
), 3, 'title');
233 $o .= $this->output
->container_end(); // end of header
235 $content = format_text($example->content
, $example->contentformat
, array('overflowdiv'=>true));
236 $content = file_rewrite_pluginfile_urls($content, 'pluginfile.php', $this->page
->context
->id
,
237 'mod_workshop', 'submission_content', $example->id
);
238 $o .= $this->output
->container($content, 'content');
240 $o .= $this->helper_submission_attachments($example->id
, 'html');
242 $o .= $this->output
->container_end(); // end of submission-full
248 * Renders short summary of the example submission
250 * @param workshop_example_submission_summary $summary
251 * @return string text to be echo'ed
253 protected function render_workshop_example_submission_summary(workshop_example_submission_summary
$summary) {
255 $o = ''; // output HTML code
258 $o .= $this->output
->box_start('generalbox example-summary ' . $summary->status
);
261 $o .= $this->output
->container_start('example-title');
262 $o .= html_writer
::link($summary->url
, format_string($summary->title
), array('class' => 'title'));
264 if ($summary->editable
) {
265 $o .= $this->output
->action_icon($summary->editurl
, new pix_icon('i/edit', get_string('edit')));
267 $o .= $this->output
->container_end();
270 if ($summary->status
== 'notgraded') {
271 $o .= $this->output
->container(get_string('nogradeyet', 'workshop'), 'example-info nograde');
273 $o .= $this->output
->container(get_string('gradeinfo', 'workshop' , $summary->gradeinfo
), 'example-info grade');
277 $button = new single_button($summary->assessurl
, $summary->assesslabel
, 'get');
278 $o .= $this->output
->container($this->output
->render($button), 'example-actions');
280 // end of wrapping box
281 $o .= $this->output
->box_end();
287 * Renders the user plannner tool
289 * @param workshop_user_plan $plan prepared for the user
290 * @return string html code to be displayed
292 protected function render_workshop_user_plan(workshop_user_plan
$plan) {
293 $table = new html_table();
294 $table->attributes
['class'] = 'userplan';
295 $table->head
= array();
296 $table->colclasses
= array();
297 $row = new html_table_row();
298 $row->attributes
['class'] = 'phasetasks';
299 foreach ($plan->phases
as $phasecode => $phase) {
300 $title = html_writer
::tag('span', $phase->title
);
302 foreach ($phase->actions
as $action) {
303 switch ($action->type
) {
306 if ($phasecode == workshop
::PHASE_ASSESSMENT
307 and $plan->workshop
->phase
== workshop
::PHASE_SUBMISSION
308 and $plan->workshop
->phaseswitchassessment
) {
309 $icon = 'i/scheduled';
311 $actions .= $this->output
->action_icon($action->url
, new pix_icon($icon, get_string('switchphase', 'workshop')));
315 if (!empty($actions)) {
316 $actions = $this->output
->container($actions, 'actions');
318 $table->head
[] = $this->output
->container($title . $actions);
319 $classes = 'phase' . $phasecode;
320 if ($phase->active
) {
321 $classes .= ' active';
323 $classes .= ' nonactive';
325 $table->colclasses
[] = $classes;
326 $cell = new html_table_cell();
327 $cell->text
= $this->helper_user_plan_tasks($phase->tasks
);
328 $row->cells
[] = $cell;
330 $table->data
= array($row);
332 return html_writer
::table($table);
336 * Renders the result of the submissions allocation process
338 * @param workshop_allocation_result $result as returned by the allocator's init() method
339 * @return string HTML to be echoed
341 protected function render_workshop_allocation_result(workshop_allocation_result
$result) {
343 $status = $result->get_status();
345 if (is_null($status) or $status == workshop_allocation_result
::STATUS_VOID
) {
346 debugging('Attempt to render workshop_allocation_result with empty status', DEBUG_DEVELOPER
);
351 case workshop_allocation_result
::STATUS_FAILED
:
352 if ($message = $result->get_message()) {
353 $message = new workshop_message($message, workshop_message
::TYPE_ERROR
);
355 $message = new workshop_message(get_string('allocationerror', 'workshop'), workshop_message
::TYPE_ERROR
);
359 case workshop_allocation_result
::STATUS_CONFIGURED
:
360 if ($message = $result->get_message()) {
361 $message = new workshop_message($message, workshop_message
::TYPE_INFO
);
363 $message = new workshop_message(get_string('allocationconfigured', 'workshop'), workshop_message
::TYPE_INFO
);
367 case workshop_allocation_result
::STATUS_EXECUTED
:
368 if ($message = $result->get_message()) {
369 $message = new workshop_message($message, workshop_message
::TYPE_OK
);
371 $message = new workshop_message(get_string('allocationdone', 'workshop'), workshop_message
::TYPE_OK
);
376 throw new coding_exception('Unknown allocation result status', $status);
379 // start with the message
380 $o = $this->render($message);
382 // display the details about the process if available
383 $logs = $result->get_logs();
384 if (is_array($logs) and !empty($logs)) {
385 $o .= html_writer
::start_tag('ul', array('class' => 'allocation-init-results'));
386 foreach ($logs as $log) {
387 if ($log->type
== 'debug' and !debugging('', DEBUG_DEVELOPER
)) {
388 // display allocation debugging messages for developers only
395 $o .= html_writer
::tag('li', $log->message
, array('class' => $class)).PHP_EOL
;
397 $o .= html_writer
::end_tag('ul');
404 * Renders the workshop grading report
406 * @param workshop_grading_report $gradingreport
407 * @return string html code
409 protected function render_workshop_grading_report(workshop_grading_report
$gradingreport) {
411 $data = $gradingreport->get_data();
412 $options = $gradingreport->get_options();
413 $grades = $data->grades
;
414 $userinfo = $data->userinfo
;
416 if (empty($grades)) {
420 $table = new html_table();
421 $table->attributes
['class'] = 'grading-report';
423 $sortbyfirstname = $this->helper_sortable_heading(get_string('firstname'), 'firstname', $options->sortby
, $options->sorthow
);
424 $sortbylastname = $this->helper_sortable_heading(get_string('lastname'), 'lastname', $options->sortby
, $options->sorthow
);
425 if (self
::fullname_format() == 'lf') {
426 $sortbyname = $sortbylastname . ' / ' . $sortbyfirstname;
428 $sortbyname = $sortbyfirstname . ' / ' . $sortbylastname;
431 $table->head
= array();
432 $table->head
[] = $sortbyname;
433 $table->head
[] = $this->helper_sortable_heading(get_string('submission', 'workshop'), 'submissiontitle',
434 $options->sortby
, $options->sorthow
);
435 $table->head
[] = $this->helper_sortable_heading(get_string('receivedgrades', 'workshop'));
436 if ($options->showsubmissiongrade
) {
437 $table->head
[] = $this->helper_sortable_heading(get_string('submissiongradeof', 'workshop', $data->maxgrade
),
438 'submissiongrade', $options->sortby
, $options->sorthow
);
440 $table->head
[] = $this->helper_sortable_heading(get_string('givengrades', 'workshop'));
441 if ($options->showgradinggrade
) {
442 $table->head
[] = $this->helper_sortable_heading(get_string('gradinggradeof', 'workshop', $data->maxgradinggrade
),
443 'gradinggrade', $options->sortby
, $options->sorthow
);
446 $table->rowclasses
= array();
447 $table->colclasses
= array();
448 $table->data
= array();
450 foreach ($grades as $participant) {
451 $numofreceived = count($participant->reviewedby
);
452 $numofgiven = count($participant->reviewerof
);
453 $published = $participant->submissionpublished
;
455 // compute the number of <tr> table rows needed to display this participant
456 if ($numofreceived > 0 and $numofgiven > 0) {
457 $numoftrs = workshop
::lcm($numofreceived, $numofgiven);
458 $spanreceived = $numoftrs / $numofreceived;
459 $spangiven = $numoftrs / $numofgiven;
460 } elseif ($numofreceived == 0 and $numofgiven > 0) {
461 $numoftrs = $numofgiven;
462 $spanreceived = $numoftrs;
463 $spangiven = $numoftrs / $numofgiven;
464 } elseif ($numofreceived > 0 and $numofgiven == 0) {
465 $numoftrs = $numofreceived;
466 $spanreceived = $numoftrs / $numofreceived;
467 $spangiven = $numoftrs;
474 for ($tr = 0; $tr < $numoftrs; $tr++
) {
475 $row = new html_table_row();
477 $row->attributes
['class'] = 'published';
479 // column #1 - participant - spans over all rows
481 $cell = new html_table_cell();
482 $cell->text
= $this->helper_grading_report_participant($participant, $userinfo);
483 $cell->rowspan
= $numoftrs;
484 $cell->attributes
['class'] = 'participant';
485 $row->cells
[] = $cell;
487 // column #2 - submission - spans over all rows
489 $cell = new html_table_cell();
490 $cell->text
= $this->helper_grading_report_submission($participant);
491 $cell->rowspan
= $numoftrs;
492 $cell->attributes
['class'] = 'submission';
493 $row->cells
[] = $cell;
495 // column #3 - received grades
496 if ($tr %
$spanreceived == 0) {
497 $idx = intval($tr / $spanreceived);
498 $assessment = self
::array_nth($participant->reviewedby
, $idx);
499 $cell = new html_table_cell();
500 $cell->text
= $this->helper_grading_report_assessment($assessment, $options->showreviewernames
, $userinfo,
501 get_string('gradereceivedfrom', 'workshop'));
502 $cell->rowspan
= $spanreceived;
503 $cell->attributes
['class'] = 'receivedgrade';
504 if (is_null($assessment) or is_null($assessment->grade
)) {
505 $cell->attributes
['class'] .= ' null';
507 $cell->attributes
['class'] .= ' notnull';
509 $row->cells
[] = $cell;
511 // column #4 - total grade for submission
512 if ($options->showsubmissiongrade
and $tr == 0) {
513 $cell = new html_table_cell();
514 $cell->text
= $this->helper_grading_report_grade($participant->submissiongrade
, $participant->submissiongradeover
);
515 $cell->rowspan
= $numoftrs;
516 $cell->attributes
['class'] = 'submissiongrade';
517 $row->cells
[] = $cell;
519 // column #5 - given grades
520 if ($tr %
$spangiven == 0) {
521 $idx = intval($tr / $spangiven);
522 $assessment = self
::array_nth($participant->reviewerof
, $idx);
523 $cell = new html_table_cell();
524 $cell->text
= $this->helper_grading_report_assessment($assessment, $options->showauthornames
, $userinfo,
525 get_string('gradegivento', 'workshop'));
526 $cell->rowspan
= $spangiven;
527 $cell->attributes
['class'] = 'givengrade';
528 if (is_null($assessment) or is_null($assessment->grade
)) {
529 $cell->attributes
['class'] .= ' null';
531 $cell->attributes
['class'] .= ' notnull';
533 $row->cells
[] = $cell;
535 // column #6 - total grade for assessment
536 if ($options->showgradinggrade
and $tr == 0) {
537 $cell = new html_table_cell();
538 $cell->text
= $this->helper_grading_report_grade($participant->gradinggrade
);
539 $cell->rowspan
= $numoftrs;
540 $cell->attributes
['class'] = 'gradinggrade';
541 $row->cells
[] = $cell;
544 $table->data
[] = $row;
548 return html_writer
::table($table);
552 * Renders the feedback for the author of the submission
554 * @param workshop_feedback_author $feedback
555 * @return string HTML
557 protected function render_workshop_feedback_author(workshop_feedback_author
$feedback) {
558 return $this->helper_render_feedback($feedback);
562 * Renders the feedback for the reviewer of the submission
564 * @param workshop_feedback_reviewer $feedback
565 * @return string HTML
567 protected function render_workshop_feedback_reviewer(workshop_feedback_reviewer
$feedback) {
568 return $this->helper_render_feedback($feedback);
572 * Helper method to rendering feedback
574 * @param workshop_feedback_author|workshop_feedback_reviewer $feedback
575 * @return string HTML
577 private function helper_render_feedback($feedback) {
579 $o = ''; // output HTML code
580 $o .= $this->output
->container_start('feedback feedbackforauthor');
581 $o .= $this->output
->container_start('header');
582 $o .= $this->output
->heading(get_string('feedbackby', 'workshop', s(fullname($feedback->get_provider()))), 3, 'title');
584 $userpic = $this->output
->user_picture($feedback->get_provider(), array('courseid' => $this->page
->course
->id
, 'size' => 32));
585 $o .= $this->output
->container($userpic, 'picture');
586 $o .= $this->output
->container_end(); // end of header
588 $content = format_text($feedback->get_content(), $feedback->get_format(), array('overflowdiv' => true));
589 $o .= $this->output
->container($content, 'content');
591 $o .= $this->output
->container_end();
597 * Renders the full assessment
599 * @param workshop_assessment $assessment
600 * @return string HTML
602 protected function render_workshop_assessment(workshop_assessment
$assessment) {
604 $o = ''; // output HTML code
605 $anonymous = is_null($assessment->reviewer
);
606 $classes = 'assessment-full';
608 $classes .= ' anonymous';
611 $o .= $this->output
->container_start($classes);
612 $o .= $this->output
->container_start('header');
614 if (!empty($assessment->title
)) {
615 $title = s($assessment->title
);
617 $title = get_string('assessment', 'workshop');
619 if (($assessment->url
instanceof moodle_url
) and ($this->page
->url
!= $assessment->url
)) {
620 $o .= $this->output
->container(html_writer
::link($assessment->url
, $title), 'title');
622 $o .= $this->output
->container($title, 'title');
626 $reviewer = $assessment->reviewer
;
627 $userpic = $this->output
->user_picture($reviewer, array('courseid' => $this->page
->course
->id
, 'size' => 32));
629 $userurl = new moodle_url('/user/view.php',
630 array('id' => $reviewer->id
, 'course' => $this->page
->course
->id
));
632 $a->name
= fullname($reviewer);
633 $a->url
= $userurl->out();
634 $byfullname = get_string('assessmentby', 'workshop', $a);
635 $oo = $this->output
->container($userpic, 'picture');
636 $oo .= $this->output
->container($byfullname, 'fullname');
638 $o .= $this->output
->container($oo, 'reviewer');
641 if (is_null($assessment->realgrade
)) {
642 $o .= $this->output
->container(
643 get_string('notassessed', 'workshop'),
648 $a->max
= $assessment->maxgrade
;
649 $a->received
= $assessment->realgrade
;
650 $o .= $this->output
->container(
651 get_string('gradeinfo', 'workshop', $a),
655 if (!is_null($assessment->weight
) and $assessment->weight
!= 1) {
656 $o .= $this->output
->container(
657 get_string('weightinfo', 'workshop', $assessment->weight
),
663 $o .= $this->output
->container_start('actions');
664 foreach ($assessment->actions
as $action) {
665 $o .= $this->output
->single_button($action->url
, $action->label
, $action->method
);
667 $o .= $this->output
->container_end(); // actions
669 $o .= $this->output
->container_end(); // header
671 if (!is_null($assessment->form
)) {
672 $o .= print_collapsible_region_start('assessment-form-wrapper', uniqid('workshop-assessment'),
673 get_string('assessmentform', 'workshop'), '', false, true);
674 $o .= $this->output
->container(self
::moodleform($assessment->form
), 'assessment-form');
675 $o .= print_collapsible_region_end(true);
678 $o .= $this->output
->container_end(); // main wrapper
684 * Renders the assessment of an example submission
686 * @param workshop_example_assessment $assessment
687 * @return string HTML
689 protected function render_workshop_example_assessment(workshop_example_assessment
$assessment) {
690 return $this->render_workshop_assessment($assessment);
694 * Renders the reference assessment of an example submission
696 * @param workshop_example_reference_assessment $assessment
697 * @return string HTML
699 protected function render_workshop_example_reference_assessment(workshop_example_reference_assessment
$assessment) {
700 return $this->render_workshop_assessment($assessment);
704 * Renders a perpage selector for workshop listings
706 * The scripts using this have to define the $PAGE->url prior to calling this
707 * and deal with eventually submitted value themselves.
709 * @param int $current current value of the perpage parameter
710 * @return string HTML
712 public function perpage_selector($current=10) {
715 foreach (array(10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300, 400, 500, 1000) as $option) {
716 if ($option != $current) {
717 $options[$option] = $option;
720 $select = new single_select($this->page
->url
, 'perpage', $options, '', array('' => get_string('showingperpagechange', 'mod_workshop')));
721 $select->label
= get_string('showingperpage', 'mod_workshop', $current);
722 $select->method
= 'post';
724 return $this->output
->container($this->output
->render($select), 'perpagewidget');
728 * Renders the user's final grades
730 * @param workshop_final_grades $grades with the info about grades in the gradebook
731 * @return string HTML
733 protected function render_workshop_final_grades(workshop_final_grades
$grades) {
735 $out = html_writer
::start_tag('div', array('class' => 'finalgrades'));
737 if (!empty($grades->submissiongrade
)) {
738 $cssclass = 'grade submissiongrade';
739 if ($grades->submissiongrade
->hidden
) {
740 $cssclass .= ' hiddengrade';
742 $out .= html_writer
::tag(
744 html_writer
::tag('div', get_string('submissiongrade', 'mod_workshop'), array('class' => 'gradetype')) .
745 html_writer
::tag('div', $grades->submissiongrade
->str_long_grade
, array('class' => 'gradevalue')),
746 array('class' => $cssclass)
750 if (!empty($grades->assessmentgrade
)) {
751 $cssclass = 'grade assessmentgrade';
752 if ($grades->assessmentgrade
->hidden
) {
753 $cssclass .= ' hiddengrade';
755 $out .= html_writer
::tag(
757 html_writer
::tag('div', get_string('gradinggrade', 'mod_workshop'), array('class' => 'gradetype')) .
758 html_writer
::tag('div', $grades->assessmentgrade
->str_long_grade
, array('class' => 'gradevalue')),
759 array('class' => $cssclass)
763 $out .= html_writer
::end_tag('div');
768 ////////////////////////////////////////////////////////////////////////////
769 // Internal rendering helper methods
770 ////////////////////////////////////////////////////////////////////////////
773 * Renders a list of files attached to the submission
775 * If format==html, then format a html string. If format==text, then format a text-only string.
776 * Otherwise, returns html for non-images and html to display the image inline.
778 * @param int $submissionid submission identifier
779 * @param string format the format of the returned string - html|text
780 * @return string formatted text to be echoed
782 protected function helper_submission_attachments($submissionid, $format = 'html') {
784 require_once($CFG->libdir
.'/filelib.php');
786 $fs = get_file_storage();
787 $ctx = $this->page
->context
;
788 $files = $fs->get_area_files($ctx->id
, 'mod_workshop', 'submission_attachment', $submissionid);
790 $outputimgs = ''; // images to be displayed inline
791 $outputfiles = ''; // list of attachment files
793 foreach ($files as $file) {
794 if ($file->is_directory()) {
798 $filepath = $file->get_filepath();
799 $filename = $file->get_filename();
800 $fileurl = file_encode_url($CFG->wwwroot
. '/pluginfile.php',
801 '/' . $ctx->id
. '/mod_workshop/submission_attachment/' . $submissionid . $filepath . $filename, true);
802 $type = $file->get_mimetype();
803 $image = $this->output
->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon'));
805 $linkhtml = html_writer
::link($fileurl, $image) . substr($filepath, 1) . html_writer
::link($fileurl, $filename);
806 $linktxt = "$filename [$fileurl]";
808 if ($format == 'html') {
809 if (file_mimetype_in_typegroup($type, 'web_image')) {
810 $preview = html_writer
::empty_tag('img', array('src' => $fileurl, 'alt' => '', 'class' => 'preview'));
811 $preview = html_writer
::tag('a', $preview, array('href' => $fileurl));
812 $outputimgs .= $this->output
->container($preview);
815 $outputfiles .= html_writer
::tag('li', $linkhtml, array('class' => $type));
818 } else if ($format == 'text') {
819 $outputfiles .= $linktxt . PHP_EOL
;
822 if (!empty($CFG->enableplagiarism
)) {
823 require_once($CFG->libdir
.'/plagiarismlib.php');
824 $outputfiles .= plagiarism_get_links(array('userid' => $file->get_userid(),
826 'cmid' => $this->page
->cm
->id
,
827 'course' => $this->page
->course
->id
));
831 if ($format == 'html') {
833 $outputimgs = $this->output
->container($outputimgs, 'images');
837 $outputfiles = html_writer
::tag('ul', $outputfiles, array('class' => 'files'));
840 return $this->output
->container($outputimgs . $outputfiles, 'attachments');
848 * Renders the tasks for the single phase in the user plan
850 * @param stdClass $tasks
851 * @return string html code
853 protected function helper_user_plan_tasks(array $tasks) {
855 foreach ($tasks as $taskcode => $task) {
858 if ($task->completed
=== true) {
859 $classes .= ' completed';
860 } elseif ($task->completed
=== false) {
862 } elseif ($task->completed
=== 'info') {
865 if (is_null($task->link
)) {
866 $title = $task->title
;
868 $title = html_writer
::link($task->link
, $task->title
);
870 $title = $this->output
->container($title, 'title');
871 $details = $this->output
->container($task->details
, 'details');
872 $out .= html_writer
::tag('li', $title . $details, array('class' => $classes));
875 $out = html_writer
::tag('ul', $out, array('class' => 'tasks'));
881 * Renders a text with icons to sort by the given column
883 * This is intended for table headings.
885 * @param string $text The heading text
886 * @param string $sortid The column id used for sorting
887 * @param string $sortby Currently sorted by (column id)
888 * @param string $sorthow Currently sorted how (ASC|DESC)
892 protected function helper_sortable_heading($text, $sortid=null, $sortby=null, $sorthow=null) {
895 $out = html_writer
::tag('span', $text, array('class'=>'text'));
897 if (!is_null($sortid)) {
898 if ($sortby !== $sortid or $sorthow !== 'ASC') {
899 $url = new moodle_url($PAGE->url
);
900 $url->params(array('sortby' => $sortid, 'sorthow' => 'ASC'));
901 $out .= $this->output
->action_icon($url, new pix_icon('t/sort_asc', get_string('sortasc', 'workshop')),
902 null, array('class' => 'iconsort sort asc'));
904 if ($sortby !== $sortid or $sorthow !== 'DESC') {
905 $url = new moodle_url($PAGE->url
);
906 $url->params(array('sortby' => $sortid, 'sorthow' => 'DESC'));
907 $out .= $this->output
->action_icon($url, new pix_icon('t/sort_desc', get_string('sortdesc', 'workshop')),
908 null, array('class' => 'iconsort sort desc'));
915 * @param stdClass $participant
916 * @param array $userinfo
919 protected function helper_grading_report_participant(stdclass
$participant, array $userinfo) {
920 $userid = $participant->userid
;
921 $out = $this->output
->user_picture($userinfo[$userid], array('courseid' => $this->page
->course
->id
, 'size' => 35));
922 $out .= html_writer
::tag('span', fullname($userinfo[$userid]));
928 * @param stdClass $participant
931 protected function helper_grading_report_submission(stdclass
$participant) {
934 if (is_null($participant->submissionid
)) {
935 $out = $this->output
->container(get_string('nosubmissionfound', 'workshop'), 'info');
937 $url = new moodle_url('/mod/workshop/submission.php',
938 array('cmid' => $this->page
->context
->instanceid
, 'id' => $participant->submissionid
));
939 $out = html_writer
::link($url, format_string($participant->submissiontitle
), array('class'=>'title'));
946 * @todo Highlight the nulls
947 * @param stdClass|null $assessment
948 * @param bool $shownames
949 * @param string $separator between the grade and the reviewer/author
952 protected function helper_grading_report_assessment($assessment, $shownames, array $userinfo, $separator) {
955 if (is_null($assessment)) {
956 return get_string('nullgrade', 'workshop');
959 $a->grade
= is_null($assessment->grade
) ?
get_string('nullgrade', 'workshop') : $assessment->grade
;
960 $a->gradinggrade
= is_null($assessment->gradinggrade
) ?
get_string('nullgrade', 'workshop') : $assessment->gradinggrade
;
961 $a->weight
= $assessment->weight
;
962 // grrr the following logic should really be handled by a future language pack feature
963 if (is_null($assessment->gradinggradeover
)) {
964 if ($a->weight
== 1) {
965 $grade = get_string('formatpeergrade', 'workshop', $a);
967 $grade = get_string('formatpeergradeweighted', 'workshop', $a);
970 $a->gradinggradeover
= $assessment->gradinggradeover
;
971 if ($a->weight
== 1) {
972 $grade = get_string('formatpeergradeover', 'workshop', $a);
974 $grade = get_string('formatpeergradeoverweighted', 'workshop', $a);
977 $url = new moodle_url('/mod/workshop/assessment.php',
978 array('asid' => $assessment->assessmentid
));
979 $grade = html_writer
::link($url, $grade, array('class'=>'grade'));
982 $userid = $assessment->userid
;
983 $name = $this->output
->user_picture($userinfo[$userid], array('courseid' => $this->page
->course
->id
, 'size' => 16));
984 $name .= html_writer
::tag('span', fullname($userinfo[$userid]), array('class' => 'fullname'));
985 $name = $separator . html_writer
::tag('span', $name, array('class' => 'user'));
990 return $this->output
->container($grade . $name, 'assessmentdetails');
994 * Formats the aggreagated grades
996 protected function helper_grading_report_grade($grade, $over=null) {
998 $a->grade
= is_null($grade) ?
get_string('nullgrade', 'workshop') : $grade;
999 if (is_null($over)) {
1000 $text = get_string('formataggregatedgrade', 'workshop', $a);
1002 $a->over
= is_null($over) ?
get_string('nullgrade', 'workshop') : $over;
1003 $text = get_string('formataggregatedgradeover', 'workshop', $a);
1008 ////////////////////////////////////////////////////////////////////////////
1010 ////////////////////////////////////////////////////////////////////////////
1013 * Helper method dealing with the fact we can not just fetch the output of moodleforms
1015 * @param moodleform $mform
1016 * @return string HTML
1018 protected static function moodleform(moodleform
$mform) {
1022 $o = ob_get_contents();
1029 * Helper function returning the n-th item of the array
1032 * @param int $n from 0 to m, where m is th number of items in the array
1033 * @return mixed the $n-th element of $a
1035 protected static function array_nth(array $a, $n) {
1036 $keys = array_keys($a);
1037 if ($n < 0 or $n > count($keys) - 1) {
1045 * Tries to guess the fullname format set at the site
1047 * @return string fl|lf
1049 protected static function fullname_format() {
1050 $fake = new stdclass(); // fake user
1051 $fake->lastname
= 'LLLL';
1052 $fake->firstname
= 'FFFF';
1053 $fullname = get_string('fullnamedisplay', '', $fake);
1054 if (strpos($fullname, 'LLLL') < strpos($fullname, 'FFFF')) {