forked from drachels/moodle-mod_diary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenderer.php
166 lines (152 loc) · 5.94 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
<?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 renderer for various parts of the Diary module.
*
* @package mod_diary
* @copyright 2019 onwards AL Rachels [email protected]
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die(); // @codingStandardsIgnoreLine
/**
* A custom renderer class that extends the plugin_renderer_base and is used by the diary module.
*
* @package mod_diary
* @copyright 2019 onwards AL Rachels [email protected]
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_diary_renderer extends plugin_renderer_base {
/**
* Rendering diary files.
*
* @var int $diary
*/
private $diary;
/**
* Return introduction box and content for the page generated by view.php file.
*
* @param int $diary Diary activity this description is for.
* @param int $cm Course module this description is for.
* @return $output Return a box with the description in it.
*/
public function introduction($diary, $cm) {
$output = '';
if (trim($diary->intro)) {
$output .= $this->box_start('generalbox boxaligncenter', 'intro');
$output .= format_module_intro('diary', $diary, $cm->id);
$output .= $this->box_end();
}
return $output;
}
/**
* Print the toolbar above the entries on the page generated by view.php.
*
* @param int $firstkey Id of the entry for the current sort order.
* @return $output Return all the buttons that are part of the toolbar.
*/
public function toolbar($firstkey, $cm) {
// 20201003 Changed toolbar code to $output instead of html_writer::alist.
$options = [];
$options['id'] = $cm->id;
$output = ' ';
// Print export to .csv file toolbutton.
$options['action'] = 'download';
$url = new moodle_url('/mod/diary/view.php', $options);
$output .= html_writer::link($url, $this->pix_icon('i/export', get_string('csvexport', 'diary')),
[
'class' => 'toolbutton',
]
);
// Print reload toolbutton.
$options['action'] = 'reload';
$url = new moodle_url('/mod/diary/view.php', $options);
$output .= html_writer::link($url, $this->pix_icon('t/reload', get_string('reload', 'diary')),
[
'class' => 'toolbutton',
]
);
// Print edit entry toolbutton.
$options['action'] = 'editentry';
$options['firstkey'] = $firstkey;
$url = new moodle_url('/mod/diary/edit.php', $options);
$output .= html_writer::link($url, $this->pix_icon('i/edit', get_string('edittopoflist', 'diary')),
[
'class' => 'toolbutton',
]
);
// Print sort to first entry toolbutton.
$options['action'] = 'sortfirstentry';
$options['firstkey'] = $firstkey;
$url = new moodle_url('/mod/diary/view.php', $options);
$output .= html_writer::link($url, $this->pix_icon('t/left', get_string('sortfirstentry', 'diary')),
[
'class' => 'toolbutton',
]
);
// Print lowest grade entry toolbutton.
$options['action'] = 'lowestgradeentry';
$options['firstkey'] = $firstkey;
$url = new moodle_url('/mod/diary/view.php', $options);
$output .= html_writer::link($url, $this->pix_icon('t/down', get_string('lowestgradeentry', 'diary')),
[
'class' => 'toolbutton',
]
);
// Print highest grade entry toolbutton.
$options['action'] = 'highestgradeentry';
$options['firstkey'] = $firstkey;
$url = new moodle_url('/mod/diary/view.php', $options);
$output .= html_writer::link($url, $this->pix_icon('t/up', get_string('highestgradeentry', 'diary')),
[
'class' => 'toolbutton',
]
);
// Print latest modified entry toolbutton.
$options['action'] = 'latestmodifiedentry';
$options['firstkey'] = $firstkey;
$url = new moodle_url('/mod/diary/view.php', $options);
$output .= html_writer::link($url, $this->pix_icon('t/right', get_string('latestmodifiedentry', 'diary')),
[
'class' => 'toolbutton',
]
);
$firstkey = '';
// Return all available toolbuttons.
return $output;
}
/**
* Returns HTML for a diary inaccessible message.
* Added 20161002
*
* @param string $message
* @return <type>
*/
public function diary_inaccessible($message) {
global $CFG;
$output = $this->output->box_start('generalbox boxaligncenter');
$output .= $this->output->box_start('center');
$output .= (get_string('notavailable', 'diary'));
$output .= $message;
$output .= $this->output->box('<a href="'
.$CFG->wwwroot.'/course/view.php?id='
.$this->page->course->id.'">'
.get_string('returnto', 'diary', format_string($this->page->course->fullname, true))
.'</a>', 'diarybutton standardbutton');
$output .= $this->output->box_end();
$output .= $this->output->box_end();
return $output;
}
}