mod-forum MDL-17550 Converted subscribers.php to use the new user_selector control
[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 *
21 * @package forum
22 * @copyright 2009 Sam Hemelryk
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
26/**
27 * A custom renderer class that extends the moodle_renderer_base and
28 * is used by the forum module.
29 *
30 * @package forum
31 * @copyright 2009 Sam Hemelryk
32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33 **/
34class moodle_mod_forum_renderer extends moodle_renderer_base {
35
36 /**
37 * A reference to the current general renderer probably {@see moodle_core_renderer}
38 * @var moodle_renderer_base
39 */
40 protected $output;
41
42 /**
43 * Contructor method, calls the parent constructor
44 * @param moodle_page $page
45 * @param moodle_renderer_base $output Probably moodle_core_renderer
46 */
47 public function __construct($page, $output) {
48 parent::__construct($page);
49 $this->output = $output;
50 }
51
52 /**
53 * This method is used to generate HTML for a subscriber selection form that
54 * uses two user_selector controls
55 *
56 * @param user_selector_base $existinguc
57 * @param user_selector_base $potentialuc
58 * @return string
59 */
60 public function subscriber_selection_form(user_selector_base $existinguc, user_selector_base $potentialuc) {
61 $output = '';
62 $formattributes = array();
63 $formattributes['id'] = 'subscriberform';
64 $formattributes['action'] = '';
65 $formattributes['method'] = 'post';
66 $output .= $this->output_start_tag('form', $formattributes);
67 $output .= $this->output_empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=>sesskey()));
68
69 $existingcell = new html_table_cell();
70 $existingcell->text = $existinguc->display(true);
71 $existingcell->set_classes(array('existing'));
72 $actioncell = new html_table_cell();
73 $actioncell->text = $this->output_start_tag('div', array());
74 $actioncell->text .= $this->output_empty_tag('input', array('type'=>'submit', 'name'=>'subscribe', 'value'=>$this->page->theme->larrow.' '.get_string('add'), 'class'=>'actionbutton'));
75 $actioncell->text .= $this->output_empty_tag('br', array());
76 $actioncell->text .= $this->output_empty_tag('input', array('type'=>'submit', 'name'=>'unsubscribe', 'value'=>$this->page->theme->rarrow.' '.get_string('remove'), 'class'=>'actionbutton'));
77 $actioncell->text .= $this->output_end_tag('div', array());
78 $actioncell->set_classes(array('actions'));
79 $potentialcell = new html_table_cell();
80 $potentialcell->text = $potentialuc->display(true);
81 $potentialcell->set_classes(array('potential'));
82
83 $table = new html_table();
84 $table->set_classes(array('subscribertable','boxaligncenter'));
85 $table->data = array(html_table_row::make(array($existingcell, $actioncell, $potentialcell)));
86 $output .= $this->output->table($table);
87
88 $output .= $this->output_end_tag('form');
89 return $output;
90 }
91
92 /**
93 * This function generates HTML to display a subscriber overview, primarily used on
94 * the subscribers page if editing was turned off
95 *
96 * @param array $users
97 * @param object $forum
98 * @param object $course
99 * @return string
100 */
101 public function subscriber_overview($users, $forum , $course) {
102 $output = '';
103 if (!$users || !is_array($users) || count($users)===0) {
104 $output .= $this->output->heading(get_string("nosubscribers", "forum"));
105 } else {
106 $output .= $this->output->heading(get_string("subscribersto","forum", "'".format_string($forum->name)."'"));
107 $table = new html_table();
108 $table->cellpadding = 5;
109 $table->cellspacing = 5;
110 $table->tablealign = 'center';
111 $table->data = array();
112 foreach ($users as $user) {
113 $table->data[] = array($this->output->user_picture(moodle_user_picture::make($user, $course->id)), fullname($user), $user->email);
114 }
115 $output .= $this->output->table($table);
116 }
117 return $output;
118 }
119
120 /**
121 * This is used to display a control containing all of the subscribed users so that
122 * it can be searched
123 *
124 * @param user_selector_base $existingusers
125 * @return string
126 */
127 public function subscribed_users(user_selector_base $existingusers) {
128 $output = $this->output->box_start('subscriberdiv boxaligncenter');
129 $output .= $this->output_tag('p', array(), get_string('forcessubscribe', 'forum'));
130 $output .= $existingusers->display(true);
131 $output .= $this->output->box_end();
132 return $output;
133 }
134
135
136}