-
Notifications
You must be signed in to change notification settings - Fork 7
/
renderer.php
152 lines (136 loc) · 6.5 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
<?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/>.
/**
* A custmom renderer class that extends the plugin_renderer_base and is used by the hotquestion module
*
* @package mod_hotquestion
* @copyright 2012 Zhang Anzhen
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
class mod_hotquestion_renderer extends plugin_renderer_base {
private $hotquestion;
/**
* Initialise internal objects.
*
* @param object $hotquestion
*/
public function init($hotquestion) {
$this->hotquestion = $hotquestion;
}
/**
* Return introduction
*/
public function introduction() {
$output = '';
if (trim($this->hotquestion->instance->intro)) {
$output .= $this->box_start('generalbox boxaligncenter', 'intro');
$output .= format_module_intro('hotquestion', $this->hotquestion->instance, $this->hotquestion->cm->id);
$output .= $this->box_end();
}
return $output;
}
/**
* Return the toolbar
*
* @param bool $show_new whether show "New round" button
* return alist of links
*/
public function toolbar($show_new = true) {
$output = '';
$toolbuttons = array();
// Print next/prev round bar
if ($this->hotquestion->get_prev_round() != null) {
$url = new moodle_url('/mod/hotquestion/view.php', array('id'=>$this->hotquestion->cm->id, 'round'=>$this->hotquestion->get_prev_round()->id));
$toolbuttons[] = html_writer::link($url, $this->pix_icon('t/collapsed_rtl', get_string('previousround', 'hotquestion')), array('class' => 'toolbutton'));
} else {
$toolbuttons[] = html_writer::tag('span', $this->pix_icon('t/collapsed_empty_rtl', ''), array('class' => 'dis_toolbutton'));
}
if ($this->hotquestion->get_next_round() != null) {
$url = new moodle_url('/mod/hotquestion/view.php', array('id'=>$this->hotquestion->cm->id, 'round'=>$this->hotquestion->get_next_round()->id));
$toolbuttons[] = html_writer::link($url, $this->pix_icon('t/collapsed', get_string('nextround', 'hotquestion')), array('class' => 'toolbutton'));
} else {
$toolbuttons[] = html_writer::tag('span', $this->pix_icon('t/collapsed_empty', ''), array('class' => 'dis_toolbutton'));
}
// Print new round bar
if ($show_new) {
$options = array();
$options['id'] = $this->hotquestion->cm->id;
$options['action'] = 'newround';
$url = new moodle_url('/mod/hotquestion/view.php', $options);
$toolbuttons[] = html_writer::link($url, $this->pix_icon('t/add', get_string('newround', 'hotquestion')), array('class' => 'toolbutton'));
}
// Print refresh button
$url = new moodle_url('/mod/hotquestion/view.php', array('id'=>$this->hotquestion->cm->id));
$toolbuttons[] = html_writer::link($url, $this->pix_icon('t/reload', get_string('reload')), array('class' => 'toolbutton'));
// return all available toolbuttons
$output .= html_writer::alist($toolbuttons, array('id' => 'toolbar'));
return $output;
}
/**
* Return all questions in current list
*
* Return question list, which includes the content, the author, the time
* and the heat. If $can_vote is true, will display a icon of vote
*
* @global object
* @global object
* @global object
* @param bool $allow_vote whether current user has vote cap
* return table of questionlist
*/
public function questions($allow_vote = true) {
global $DB, $CFG, $USER;
$output = '';
// Search questions in current round
$questions = $this->hotquestion->get_questions();
if ($questions) {
$table = new html_table();
$table->cellpadding = 10;
$table->class = 'generaltable';
$table->width = '100%';
$table->align = array ('left', 'center');
$table->head = array(get_string('question', 'hotquestion'), get_string('heat', 'hotquestion'));
foreach ($questions as $question) {
$line = array();
$formatoptions->para = false;
$content = format_text($question->content, FORMAT_MOODLE, $formatoptions);
$user = $DB->get_record('user', array('id'=>$question->userid));
if ($question->anonymous) {
$a->user = get_string('anonymous', 'hotquestion');
} else {
$a->user = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $user->id . '&course=' . $this->hotquestion->course->id . '">' . fullname($user) . '</a>';
}
$a->time = userdate($question->time).' ('.get_string('early', 'assignment', format_time(time() - $question->time)) . ')';
$info = '<div class="author">'.get_string('authorinfo', 'hotquestion', $a).'</div>';
$line[] = $content.$info;
$heat = $question->votecount;
// Print the vote cron
if ($allow_vote && $this->hotquestion->can_vote_on($question)){
if (!$this->hotquestion->has_voted($question->id)){
$heat .= ' <a href="view.php?id='.$this->hotquestion->cm->id.'&action=vote&q='.$question->id.'" class="hotquestion_vote" id="question_'.$question->id.'"><img src="'.$this->pix_url('s/yes').'" title="'.get_string('vote', 'hotquestion') .'" alt="'. get_string('vote', 'hotquestion') .'"/></a>';
}
}
$line[] = $heat;
$table->data[] = $line;
}
$output .= html_writer::table($table);
} else {
$output .= $this->box(get_string('noquestions', 'hotquestion'), 'center', '70%');
}
return $output;
}
}