MDL-8501 mod_forum: Test coverage of neighbour discussions
[moodle.git] / mod / forum / renderer.php
CommitLineData
c23c9009
SH
1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
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/>.
17
18/**
19 * This file contains a custom renderer class used by the forum module.
20 *
01030f1b 21 * @package mod_forum
c23c9009
SH
22 * @copyright 2009 Sam Hemelryk
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
26/**
75590935 27 * A custom renderer class that extends the plugin_renderer_base and
c23c9009 28 * is used by the forum module.
2f67a9b3 29 *
01030f1b 30 * @package mod_forum
c23c9009
SH
31 * @copyright 2009 Sam Hemelryk
32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33 **/
75590935 34class mod_forum_renderer extends plugin_renderer_base {
c23c9009
SH
35 /**
36 * This method is used to generate HTML for a subscriber selection form that
37 * uses two user_selector controls
38 *
39 * @param user_selector_base $existinguc
40 * @param user_selector_base $potentialuc
41 * @return string
42 */
43 public function subscriber_selection_form(user_selector_base $existinguc, user_selector_base $potentialuc) {
44 $output = '';
45 $formattributes = array();
46 $formattributes['id'] = 'subscriberform';
47 $formattributes['action'] = '';
48 $formattributes['method'] = 'post';
5d0c95a5
PS
49 $output .= html_writer::start_tag('form', $formattributes);
50 $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=>sesskey()));
c23c9009
SH
51
52 $existingcell = new html_table_cell();
53 $existingcell->text = $existinguc->display(true);
16be8974 54 $existingcell->attributes['class'] = 'existing';
c23c9009 55 $actioncell = new html_table_cell();
5d0c95a5
PS
56 $actioncell->text = html_writer::start_tag('div', array());
57 $actioncell->text .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'subscribe', 'value'=>$this->page->theme->larrow.' '.get_string('add'), 'class'=>'actionbutton'));
58 $actioncell->text .= html_writer::empty_tag('br', array());
59 $actioncell->text .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'unsubscribe', 'value'=>$this->page->theme->rarrow.' '.get_string('remove'), 'class'=>'actionbutton'));
60 $actioncell->text .= html_writer::end_tag('div', array());
16be8974 61 $actioncell->attributes['class'] = 'actions';
c23c9009
SH
62 $potentialcell = new html_table_cell();
63 $potentialcell->text = $potentialuc->display(true);
16be8974 64 $potentialcell->attributes['class'] = 'potential';
c23c9009
SH
65
66 $table = new html_table();
16be8974 67 $table->attributes['class'] = 'subscribertable boxaligncenter';
8cea545e 68 $table->data = array(new html_table_row(array($existingcell, $actioncell, $potentialcell)));
16be8974 69 $output .= html_writer::table($table);
2f67a9b3 70
5d0c95a5 71 $output .= html_writer::end_tag('form');
c23c9009
SH
72 return $output;
73 }
74
75 /**
76 * This function generates HTML to display a subscriber overview, primarily used on
77 * the subscribers page if editing was turned off
78 *
79 * @param array $users
80 * @param object $forum
81 * @param object $course
82 * @return string
83 */
84 public function subscriber_overview($users, $forum , $course) {
85 $output = '';
dc8f55c3 86 $modinfo = get_fast_modinfo($course);
c23c9009
SH
87 if (!$users || !is_array($users) || count($users)===0) {
88 $output .= $this->output->heading(get_string("nosubscribers", "forum"));
dc8f55c3
MT
89 } else if (!isset($modinfo->instances['forum'][$forum->id])) {
90 $output .= $this->output->heading(get_string("invalidmodule", "error"));
c23c9009 91 } else {
dc8f55c3
MT
92 $cm = $modinfo->instances['forum'][$forum->id];
93 $canviewemail = in_array('email', get_extra_user_fields(context_module::instance($cm->id)));
c23c9009
SH
94 $output .= $this->output->heading(get_string("subscribersto","forum", "'".format_string($forum->name)."'"));
95 $table = new html_table();
96 $table->cellpadding = 5;
97 $table->cellspacing = 5;
98 $table->tablealign = 'center';
99 $table->data = array();
100 foreach ($users as $user) {
dc8f55c3
MT
101 $info = array($this->output->user_picture($user, array('courseid'=>$course->id)), fullname($user));
102 if ($canviewemail) {
103 array_push($info, $user->email);
104 }
105 $table->data[] = $info;
c23c9009 106 }
16be8974 107 $output .= html_writer::table($table);
c23c9009
SH
108 }
109 return $output;
110 }
111
112 /**
113 * This is used to display a control containing all of the subscribed users so that
114 * it can be searched
115 *
116 * @param user_selector_base $existingusers
117 * @return string
118 */
119 public function subscribed_users(user_selector_base $existingusers) {
120 $output = $this->output->box_start('subscriberdiv boxaligncenter');
ebfb73db 121 $output .= html_writer::tag('p', get_string('forcesubscribed', 'forum'));
c23c9009
SH
122 $output .= $existingusers->display(true);
123 $output .= $this->output->box_end();
124 return $output;
125 }
2f67a9b3 126
c23c9009 127
16be8974 128}