forked from justinhunt/moodle-mod_newmodule
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenderer.php
255 lines (207 loc) · 8.21 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<?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/>.
defined('MOODLE_INTERNAL') || die();
/**
* A custom renderer class that extends the plugin_renderer_base.
*
* @package mod_@@newmodule@@
* @copyright COPYRIGHTNOTICE
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_@@newmodule@@_renderer extends plugin_renderer_base {
/**
* Returns the header for the module
*
* @param mod $instance
* @param string $currenttab current tab that is shown.
* @param int $item id of the anything that needs to be displayed.
* @param string $extrapagetitle String to append to the page title.
* @return string
*/
public function header($moduleinstance, $cm, $currenttab = '', $itemid = null, $extrapagetitle = null) {
global $CFG;
$activityname = format_string($moduleinstance->name, true, $moduleinstance->course);
if (empty($extrapagetitle)) {
$title = $this->page->course->shortname.": ".$activityname;
} else {
$title = $this->page->course->shortname.": ".$activityname.": ".$extrapagetitle;
}
// Build the buttons
$context = context_module::instance($cm->id);
/// Header setup
$this->page->set_title($title);
$this->page->set_heading($this->page->course->fullname);
$output = $this->output->header();
if (has_capability('mod/@@newmodule@@:manage', $context)) {
// $output .= $this->output->heading_with_help($activityname, 'overview', MOD_NEWMODULE_LANG);
if (!empty($currenttab)) {
ob_start();
include($CFG->dirroot.'/mod/@@newmodule@@/tabs.php');
$output .= ob_get_contents();
ob_end_clean();
}
} else {
$output .= $this->output->heading($activityname);
}
return $output;
}
/**
* Return HTML to display limited header
*/
public function notabsheader(){
return $this->output->header();
}
/**
*
*/
public function show_something($showtext) {
$ret = $this->output->box_start();
$ret .= $this->output->heading($showtext, 4, 'main');
$ret .= $this->output->box_end();
return $ret;
}
/**
*
*/
public function show_intro($@@newmodule@@,$cm){
$ret = "";
if (trim(strip_tags($@@newmodule@@->intro))) {
$ret .= $this->output->box_start('mod_introbox');
$ret .= format_module_intro('@@newmodule@@', $@@newmodule@@, $cm->id);
$ret .= $this->output->box_end();
}
return $ret;
}
}
class mod_@@newmodule@@_report_renderer extends plugin_renderer_base {
public function render_reportmenu($moduleinstance,$cm) {
$basic = new single_button(
new moodle_url(MOD_NEWMODULE_URL . '/reports.php',array('report'=>'basic','id'=>$cm->id,'n'=>$moduleinstance->id)),
get_string('basicreport',MOD_NEWMODULE_LANG), 'get');
$ret = html_writer::div($this->render($basic) .'<br />' ,MOD_NEWMODULE_CLASS . '_listbuttons');
return $ret;
}
public function render_delete_allattempts($cm){
$deleteallbutton = new single_button(
new moodle_url(MOD_NEWMODULE_URL . '/manageattempts.php',array('id'=>$cm->id,'action'=>'confirmdeleteall')),
get_string('deleteallattempts',MOD_NEWMODULE_LANG), 'get');
$ret = html_writer::div( $this->render($deleteallbutton) ,MOD_NEWMODULE_CLASS . '_actionbuttons');
return $ret;
}
public function render_reporttitle_html($course,$username) {
$ret = $this->output->heading(format_string($course->fullname),2);
$ret .= $this->output->heading(get_string('reporttitle',MOD_NEWMODULE_LANG,$username),3);
return $ret;
}
public function render_empty_section_html($sectiontitle) {
global $CFG;
return $this->output->heading(get_string('nodataavailable',MOD_NEWMODULE_LANG),3);
}
public function render_exportbuttons_html($cm,$formdata,$showreport){
//convert formdata to array
$formdata = (array) $formdata;
$formdata['id']=$cm->id;
$formdata['report']=$showreport;
/*
$formdata['format']='pdf';
$pdf = new single_button(
new moodle_url(MOD_NEWMODULE_URL . '/reports.php',$formdata),
get_string('exportpdf',MOD_NEWMODULE_LANG), 'get');
*/
$formdata['format']='csv';
$excel = new single_button(
new moodle_url(MOD_NEWMODULE_URL . '/reports.php',$formdata),
get_string('exportexcel',MOD_NEWMODULE_LANG), 'get');
return html_writer::div( $this->render($excel),MOD_NEWMODULE_CLASS . '_actionbuttons');
}
public function render_section_csv($sectiontitle, $report, $head, $rows, $fields) {
// Use the sectiontitle as the file name. Clean it and change any non-filename characters to '_'.
$name = clean_param($sectiontitle, PARAM_FILE);
$name = preg_replace("/[^A-Z0-9]+/i", "_", trim($name));
$quote = '"';
$delim= ",";//"\t";
$newline = "\r\n";
header("Content-Disposition: attachment; filename=$name.csv");
header("Content-Type: text/comma-separated-values");
//echo header
$heading="";
foreach($head as $headfield){
$heading .= $quote . $headfield . $quote . $delim ;
}
echo $heading. $newline;
//echo data rows
foreach ($rows as $row) {
$datarow = "";
foreach($fields as $field){
$datarow .= $quote . $row->{$field} . $quote . $delim ;
}
echo $datarow . $newline;
}
exit();
break;
}
public function render_section_html($sectiontitle, $report, $head, $rows, $fields) {
global $CFG;
if(empty($rows)){
return $this->render_empty_section_html($sectiontitle);
}
//set up our table and head attributes
$tableattributes = array('class'=>'generaltable '. MOD_NEWMODULE_CLASS .'_table');
$headrow_attributes = array('class'=>MOD_NEWMODULE_CLASS . '_headrow');
$htmltable = new html_table();
$htmltable->attributes = $tableattributes;
$htr = new html_table_row();
$htr->attributes = $headrow_attributes;
foreach($head as $headcell){
$htr->cells[]=new html_table_cell($headcell);
}
$htmltable->data[]=$htr;
foreach($rows as $row){
$htr = new html_table_row();
//set up descrption cell
$cells = array();
foreach($fields as $field){
$cell = new html_table_cell($row->{$field});
$cell->attributes= array('class'=>MOD_NEWMODULE_CLASS . '_cell_' . $report . '_' . $field);
$htr->cells[] = $cell;
}
$htmltable->data[]=$htr;
}
$html = $this->output->heading($sectiontitle, 4);
$html .= html_writer::table($htmltable);
return $html;
}
/**
* Returns HTML to display a single paging bar to provide access to other pages (usually in a search)
* @param int $totalcount The total number of entries available to be paged through
* @param stdclass $paging an object containting sort/perpage/pageno fields. Created in reports.php and grading.php
* @param string|moodle_url $baseurl url of the current page, the $pagevar parameter is added
* @return string the HTML to output.
*/
function show_paging_bar($totalcount,$paging,$baseurl){
$pagevar="pageno";
//add paging params to url (NOT pageno)
$baseurl->params(array('perpage'=>$paging->perpage,'sort'=>$paging->sort));
return $this->output->paging_bar($totalcount,$paging->pageno,$paging->perpage,$baseurl,$pagevar);
}
function show_reports_footer($moduleinstance,$cm,$formdata,$showreport){
// print's a popup link to your custom page
$link = new moodle_url(MOD_NEWMODULE_URL . '/reports.php',array('report'=>'menu','id'=>$cm->id,'n'=>$moduleinstance->id));
$ret = html_writer::link($link, get_string('returntoreports',MOD_NEWMODULE_LANG));
$ret .= $this->render_exportbuttons_html($cm,$formdata,$showreport);
return $ret;
}
}