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 * This file contains a custom renderer class used by the forum module.
22 * @copyright 2009 Sam Hemelryk
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 * A custom renderer class that extends the plugin_renderer_base and
28 * is used by the forum module.
31 * @copyright 2009 Sam Hemelryk
32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34 class mod_forum_renderer extends plugin_renderer_base {
36 * This method is used to generate HTML for a subscriber selection form that
37 * uses two user_selector controls
39 * @param user_selector_base $existinguc
40 * @param user_selector_base $potentialuc
43 public function subscriber_selection_form(user_selector_base $existinguc, user_selector_base $potentialuc) {
45 $formattributes = array();
46 $formattributes['id'] = 'subscriberform';
47 $formattributes['action'] = '';
48 $formattributes['method'] = 'post';
49 $output .= html_writer::start_tag('form', $formattributes);
50 $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=>sesskey()));
52 $existingcell = new html_table_cell();
53 $existingcell->text = $existinguc->display(true);
54 $existingcell->attributes['class'] = 'existing';
55 $actioncell = new html_table_cell();
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());
61 $actioncell->attributes['class'] = 'actions';
62 $potentialcell = new html_table_cell();
63 $potentialcell->text = $potentialuc->display(true);
64 $potentialcell->attributes['class'] = 'potential';
66 $table = new html_table();
67 $table->attributes['class'] = 'subscribertable boxaligncenter';
68 $table->data = array(new html_table_row(array($existingcell, $actioncell, $potentialcell)));
69 $output .= html_writer::table($table);
71 $output .= html_writer::end_tag('form');
76 * This function generates HTML to display a subscriber overview, primarily used on
77 * the subscribers page if editing was turned off
80 * @param object $forum
81 * @param object $course
84 public function subscriber_overview($users, $forum , $course) {
86 $modinfo = get_fast_modinfo($course);
87 if (!$users || !is_array($users) || count($users)===0) {
88 $output .= $this->output->heading(get_string("nosubscribers", "forum"));
89 } else if (!isset($modinfo->instances['forum'][$forum->id])) {
90 $output .= $this->output->heading(get_string("invalidmodule", "error"));
92 $cm = $modinfo->instances['forum'][$forum->id];
93 $canviewemail = in_array('email', get_extra_user_fields(context_module::instance($cm->id)));
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) {
101 $info = array($this->output->user_picture($user, array('courseid'=>$course->id)), fullname($user));
103 array_push($info, $user->email);
105 $table->data[] = $info;
107 $output .= html_writer::table($table);
113 * This is used to display a control containing all of the subscribed users so that
116 * @param user_selector_base $existingusers
119 public function subscribed_users(user_selector_base $existingusers) {
120 $output = $this->output->box_start('subscriberdiv boxaligncenter');
121 $output .= html_writer::tag('p', get_string('forcesubscribed', 'forum'));
122 $output .= $existingusers->display(true);
123 $output .= $this->output->box_end();