-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderer.php
206 lines (191 loc) · 8.63 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
<?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/>.
/**
* This file contains a custom renderer class used by the cybrary module.
*
* @package mod_cybrary
* @copyright 2009 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* A custom renderer class that extends the plugin_renderer_base and
* is used by the cybrary module.
*
* @package mod_cybrary
* @copyright 2009 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
**/
class mod_cybrary_renderer extends plugin_renderer_base {
/**
* Returns the navigation to the previous and next discussion.
*
* @param mixed $prev Previous discussion record, or false.
* @param mixed $next Next discussion record, or false.
* @return string The output.
*/
public function neighbouring_discussion_navigation($prev, $next) {
$html = '';
if ($prev || $next) {
$html .= html_writer::start_tag('div', array('class' => 'discussion-nav clearfix'));
$html .= html_writer::start_tag('ul');
if ($prev) {
$url = new moodle_url('/mod/cybrary/discuss.php', array('d' => $prev->id));
$html .= html_writer::start_tag('li', array('class' => 'prev-discussion'));
$html .= html_writer::link($url, format_string($prev->name),
array('aria-label' => get_string('prevdiscussiona', 'mod_cybrary', format_string($prev->name))));
$html .= html_writer::end_tag('li');
}
if ($next) {
$url = new moodle_url('/mod/cybrary/discuss.php', array('d' => $next->id));
$html .= html_writer::start_tag('li', array('class' => 'next-discussion'));
$html .= html_writer::link($url, format_string($next->name),
array('aria-label' => get_string('nextdiscussiona', 'mod_cybrary', format_string($next->name))));
$html .= html_writer::end_tag('li');
}
$html .= html_writer::end_tag('ul');
$html .= html_writer::end_tag('div');
}
return $html;
}
/**
* This method is used to generate HTML for a subscriber selection form that
* uses two user_selector controls
*
* @param user_selector_base $existinguc
* @param user_selector_base $potentialuc
* @return string
*/
public function subscriber_selection_form(user_selector_base $existinguc, user_selector_base $potentialuc) {
$output = '';
$formattributes = array();
$formattributes['id'] = 'subscriberform';
$formattributes['action'] = '';
$formattributes['method'] = 'post';
$output .= html_writer::start_tag('form', $formattributes);
$output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=>sesskey()));
$existingcell = new html_table_cell();
$existingcell->text = $existinguc->display(true);
$existingcell->attributes['class'] = 'existing';
$actioncell = new html_table_cell();
$actioncell->text = html_writer::start_tag('div', array());
$actioncell->text .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'subscribe', 'value'=>$this->page->theme->larrow.' '.get_string('add'), 'class'=>'actionbutton'));
$actioncell->text .= html_writer::empty_tag('br', array());
$actioncell->text .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'unsubscribe', 'value'=>$this->page->theme->rarrow.' '.get_string('remove'), 'class'=>'actionbutton'));
$actioncell->text .= html_writer::end_tag('div', array());
$actioncell->attributes['class'] = 'actions';
$potentialcell = new html_table_cell();
$potentialcell->text = $potentialuc->display(true);
$potentialcell->attributes['class'] = 'potential';
$table = new html_table();
$table->attributes['class'] = 'subscribertable boxaligncenter';
$table->data = array(new html_table_row(array($existingcell, $actioncell, $potentialcell)));
$output .= html_writer::table($table);
$output .= html_writer::end_tag('form');
return $output;
}
/**
* This function generates HTML to display a subscriber overview, primarily used on
* the subscribers page if editing was turned off
*
* @param array $users
* @param object $cybrary
* @param object $course
* @return string
*/
public function subscriber_overview($users, $cybrary , $course) {
$output = '';
$modinfo = get_fast_modinfo($course);
if (!$users || !is_array($users) || count($users)===0) {
$output .= $this->output->heading(get_string("nosubscribers", "cybrary"));
} else if (!isset($modinfo->instances['cybrary'][$cybrary->id])) {
$output .= $this->output->heading(get_string("invalidmodule", "error"));
} else {
$cm = $modinfo->instances['cybrary'][$cybrary->id];
$canviewemail = in_array('email', get_extra_user_fields(context_module::instance($cm->id)));
$strparams = new stdclass();
$strparams->name = format_string($cybrary->name);
$strparams->count = count($users);
$output .= $this->output->heading(get_string("subscriberstowithcount", "cybrary", $strparams));
$table = new html_table();
$table->cellpadding = 5;
$table->cellspacing = 5;
$table->tablealign = 'center';
$table->data = array();
foreach ($users as $user) {
$info = array($this->output->user_picture($user, array('courseid'=>$course->id)), fullname($user));
if ($canviewemail) {
array_push($info, $user->email);
}
$table->data[] = $info;
}
$output .= html_writer::table($table);
}
return $output;
}
/**
* This is used to display a control containing all of the subscribed users so that
* it can be searched
*
* @param user_selector_base $existingusers
* @return string
*/
public function subscribed_users(user_selector_base $existingusers) {
$output = $this->output->box_start('subscriberdiv boxaligncenter');
$output .= html_writer::tag('p', get_string('forcesubscribed', 'cybrary'));
$output .= $existingusers->display(true);
$output .= $this->output->box_end();
return $output;
}
/**
* Generate the HTML for an icon to be displayed beside the subject of a timed discussion.
*
* @param object $discussion
* @param bool $visiblenow Indicicates that the discussion is currently
* visible to all users.
* @return string
*/
public function timed_discussion_tooltip($discussion, $visiblenow) {
$dates = array();
if ($discussion->timestart) {
$dates[] = get_string('displaystart', 'mod_cybrary').': '.userdate($discussion->timestart);
}
if ($discussion->timeend) {
$dates[] = get_string('displayend', 'mod_cybrary').': '.userdate($discussion->timeend);
}
$str = $visiblenow ? 'timedvisible' : 'timedhidden';
$dates[] = get_string($str, 'mod_cybrary');
$tooltip = implode("\n", $dates);
return $this->pix_icon('i/calendar', $tooltip, 'moodle', array('class' => 'smallicon timedpost'));
}
/**
* Display a cybrary post in the relevant context.
*
* @param \mod_cybrary\output\cybrary_post $post The post to display.
* @return string
*/
public function render_cybrary_post_email(\mod_cybrary\output\cybrary_post_email $post) {
$data = $post->export_for_template($this, $this->target === RENDERER_TARGET_TEXTEMAIL);
return $this->render_from_template('mod_cybrary/' . $this->cybrary_post_template(), $data);
}
/**
* The template name for this renderer.
*
* @return string
*/
public function cybrary_post_template() {
return 'cybrary_post';
}
}