1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* Renderer.
|
|
|
19 |
*
|
|
|
20 |
* @package tool_filetypes
|
|
|
21 |
* @copyright 2014 The Open University
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
defined('MOODLE_INTERNAL') || die();
|
|
|
26 |
|
|
|
27 |
/**
|
|
|
28 |
* Class containing the renderer functions for displaying file types.
|
|
|
29 |
*
|
|
|
30 |
* @package tool_filetypes
|
|
|
31 |
* @copyright 2014 The Open University
|
|
|
32 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
33 |
*/
|
|
|
34 |
class tool_filetypes_renderer extends plugin_renderer_base {
|
|
|
35 |
|
|
|
36 |
/**
|
|
|
37 |
* Renderer for displaying the file type edit table.
|
|
|
38 |
*
|
|
|
39 |
* @param array $filetypes An array of file type objects (from get_mimetypes_array)
|
|
|
40 |
* @param array $deleted An array of deleted file types
|
|
|
41 |
* @param bool $restricted If true, cannot be edited because set in config.php.
|
|
|
42 |
* @return string HTML code
|
|
|
43 |
*/
|
|
|
44 |
public function edit_table(array $filetypes, array $deleted, $restricted) {
|
|
|
45 |
// Get combined array of all types, with deleted marker.
|
|
|
46 |
$combined = array_merge($filetypes, $deleted);
|
|
|
47 |
foreach ($deleted as $ext => $value) {
|
|
|
48 |
$combined[$ext]['deleted'] = true;
|
|
|
49 |
}
|
|
|
50 |
ksort($combined);
|
|
|
51 |
|
|
|
52 |
$out = $this->heading(get_string('pluginname', 'tool_filetypes'));
|
|
|
53 |
if ($restricted) {
|
|
|
54 |
$out .= html_writer::div(
|
|
|
55 |
html_writer::div(get_string('configoverride', 'admin'), 'alert alert-info'),
|
|
|
56 |
'', array('id' => 'adminsettings'));
|
|
|
57 |
}
|
|
|
58 |
if (count($combined) > 1) {
|
|
|
59 |
// Display the file type table if any file types exist (other than 'xxx').
|
|
|
60 |
$table = new html_table();
|
|
|
61 |
$headings = new html_table_row();
|
|
|
62 |
$headings->cells = array();
|
|
|
63 |
$headings->cells[] = new html_table_cell(get_string('extension', 'tool_filetypes'));
|
|
|
64 |
if (!$restricted) {
|
|
|
65 |
$headings->cells[] =
|
|
|
66 |
new html_table_cell(html_writer::span(get_string('edit'), 'accesshide'));
|
|
|
67 |
}
|
|
|
68 |
$headings->cells[] = new html_table_cell(get_string('source', 'tool_filetypes'));
|
|
|
69 |
$headings->cells[] = new html_table_cell(get_string('mimetype', 'tool_filetypes'));
|
|
|
70 |
$headings->cells[] = new html_table_cell(get_string('groups', 'tool_filetypes'));
|
|
|
71 |
$headings->cells[] = new html_table_cell(get_string('displaydescription', 'tool_filetypes'));
|
|
|
72 |
foreach ($headings->cells as $cell) {
|
|
|
73 |
$cell->header = true;
|
|
|
74 |
}
|
|
|
75 |
$table->data = array($headings);
|
|
|
76 |
foreach ($combined as $extension => $filetype) {
|
|
|
77 |
if ($extension === 'xxx') {
|
|
|
78 |
continue;
|
|
|
79 |
}
|
|
|
80 |
$row = new html_table_row();
|
|
|
81 |
$row->cells = array();
|
|
|
82 |
|
|
|
83 |
// First cell has icon and extension.
|
|
|
84 |
$icon = $this->pix_icon('f/' . $filetype['icon'], '');
|
|
|
85 |
$iconcell = new html_table_cell($icon . ' ' . html_writer::span(s($extension)));
|
|
|
86 |
$iconcell->attributes['class'] = 'icon-size-5';
|
|
|
87 |
$row->cells[] = $iconcell;
|
|
|
88 |
|
|
|
89 |
// Reset URL and button if needed.
|
|
|
90 |
$reverturl = new \moodle_url('/admin/tool/filetypes/revert.php',
|
|
|
91 |
array('extension' => $extension));
|
|
|
92 |
$revertbutton = html_writer::link($reverturl, $this->pix_icon('t/restore',
|
|
|
93 |
get_string('revert', 'tool_filetypes', s($extension))));
|
|
|
94 |
if ($restricted) {
|
|
|
95 |
$revertbutton = '';
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
// Rest is different for deleted items.
|
|
|
99 |
if (!empty($filetype['deleted'])) {
|
|
|
100 |
// Show deleted standard types differently.
|
|
|
101 |
if (!$restricted) {
|
|
|
102 |
$row->cells[] = new html_table_cell('');
|
|
|
103 |
}
|
|
|
104 |
$source = new html_table_cell(get_string('source_deleted', 'tool_filetypes') .
|
|
|
105 |
' ' . $revertbutton);
|
|
|
106 |
$source->attributes = array('class' => 'nonstandard');
|
|
|
107 |
$row->cells[] = $source;
|
|
|
108 |
|
|
|
109 |
// Other cells are blank.
|
|
|
110 |
$row->cells[] = new html_table_cell('');
|
|
|
111 |
$row->cells[] = new html_table_cell('');
|
|
|
112 |
$row->cells[] = new html_table_cell('');
|
|
|
113 |
$row->attributes = array('class' => 'deleted');
|
|
|
114 |
} else {
|
|
|
115 |
if (!$restricted) {
|
|
|
116 |
// Edit icons. For accessibility, the name of these links should
|
|
|
117 |
// be different for each row, so we have to include the extension.
|
|
|
118 |
$editurl = new \moodle_url('/admin/tool/filetypes/edit.php',
|
|
|
119 |
array('oldextension' => $extension));
|
|
|
120 |
$editbutton = html_writer::link($editurl, $this->pix_icon('t/edit',
|
|
|
121 |
get_string('edita', 'moodle', s($extension))));
|
|
|
122 |
$deleteurl = new \moodle_url('/admin/tool/filetypes/delete.php',
|
|
|
123 |
array('extension' => $extension));
|
|
|
124 |
$deletebutton = html_writer::link($deleteurl, $this->pix_icon('t/delete',
|
|
|
125 |
get_string('deletea', 'tool_filetypes', s($extension))));
|
|
|
126 |
$row->cells[] = new html_table_cell($editbutton . ' ' . $deletebutton);
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
// Source.
|
|
|
130 |
$sourcestring = 'source_';
|
|
|
131 |
if (!empty($filetype['custom'])) {
|
|
|
132 |
$sourcestring .= 'custom';
|
|
|
133 |
} else if (!empty($filetype['modified'])) {
|
|
|
134 |
$sourcestring .= 'modified';
|
|
|
135 |
} else {
|
|
|
136 |
$sourcestring .= 'standard';
|
|
|
137 |
}
|
|
|
138 |
$source = new html_table_cell(get_string($sourcestring, 'tool_filetypes') .
|
|
|
139 |
($sourcestring === 'source_modified' ? ' ' . $revertbutton : ''));
|
|
|
140 |
if ($sourcestring !== 'source_standard') {
|
|
|
141 |
$source->attributes = array('class' => 'nonstandard');
|
|
|
142 |
}
|
|
|
143 |
$row->cells[] = $source;
|
|
|
144 |
|
|
|
145 |
// MIME type.
|
|
|
146 |
$mimetype = html_writer::div(s($filetype['type']), 'mimetype');
|
|
|
147 |
if (!empty($filetype['defaulticon'])) {
|
|
|
148 |
// Include the 'default for MIME type' info in the MIME type cell.
|
|
|
149 |
$mimetype .= html_writer::div(html_writer::tag('i',
|
|
|
150 |
get_string('defaulticon', 'tool_filetypes')));
|
|
|
151 |
}
|
|
|
152 |
$row->cells[] = new html_table_cell($mimetype);
|
|
|
153 |
|
|
|
154 |
// Groups.
|
|
|
155 |
$groups = !empty($filetype['groups']) ? implode(', ', $filetype['groups']) : '';
|
|
|
156 |
$row->cells[] = new html_table_cell(s($groups));
|
|
|
157 |
|
|
|
158 |
// Description.
|
|
|
159 |
$description = get_mimetype_description(array('filename' => 'a.' . $extension));
|
|
|
160 |
// Don't show the description if it's just a copy of the MIME type,
|
|
|
161 |
// it makes the table ugly with the long duplicate text; leave blank instead.
|
|
|
162 |
if ($description === $filetype['type']) {
|
|
|
163 |
$description = '';
|
|
|
164 |
}
|
|
|
165 |
$row->cells[] = new html_table_cell($description);
|
|
|
166 |
}
|
|
|
167 |
|
|
|
168 |
$table->data[] = $row;
|
|
|
169 |
}
|
|
|
170 |
$out .= html_writer::table($table);
|
|
|
171 |
} else {
|
|
|
172 |
$out .= html_writer::tag('div', get_string('emptylist', 'tool_filetypes'));
|
|
|
173 |
}
|
|
|
174 |
// Displaying the 'Add' button.
|
|
|
175 |
if (!$restricted) {
|
|
|
176 |
$out .= $this->single_button(new moodle_url('/admin/tool/filetypes/edit.php',
|
|
|
177 |
array('name' => 'add')), get_string('addfiletypes', 'tool_filetypes'), 'get');
|
|
|
178 |
}
|
|
|
179 |
return $out;
|
|
|
180 |
}
|
|
|
181 |
}
|