MDL-26784 Improved plugins check screen and the new plugins management screen
[moodle.git] / admin / renderer.php
CommitLineData
b9934a17
DM
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 for core_admin subsystem
19 *
20 * @package core
21 * @subpackage admin
22 * @copyright 2011 David Mudrak <david@moodle.com>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
26defined('MOODLE_INTERNAL') || die();
27
28require_once($CFG->libdir . '/pluginlib.php');
29
30/**
31 * Standard HTML output renderer for core_admin subsystem
32 */
33class core_admin_renderer extends plugin_renderer_base {
34
35 /**
36 * Displays all known plugins and information about their installation or upgrade
37 *
38 * This default implementation renders all plugins into one big table. The rendering
39 * options support:
40 * (bool)full = false: whether to display up-to-date plugins, too
41 *
42 * @param array $plugininfo as returned by {@see plugin_manager::get_plugins()}
43 * @param array $options rendering options
44 * @return string HTML code
45 */
46 public function plugins_check(array $plugininfo, array $options = null) {
47
48 if (empty($plugininfo)) {
49 return '';
50 }
51
52 if (empty($options)) {
53 $options = array(
54 'full' => false,
55 );
56 }
57
58 $pluginman = plugin_manager::instance();
59
60 $table = new html_table();
61 $table->id = 'plugins-check';
62 $table->head = array(
63 get_string('displayname', 'core_plugin'),
64 get_string('rootdir', 'core_plugin'),
65 get_string('source', 'core_plugin'),
66 get_string('versiondb', 'core_plugin'),
67 get_string('versiondisk', 'core_plugin'),
68 get_string('status', 'core_plugin'),
69 );
70 $table->colclasses = array(
71 'displayname', 'rootdir', 'source', 'versiondb', 'versiondisk', 'status',
72 );
73 $table->data = array();
74
75 $numofhighlighted = array(); // number of highlighted rows per this subsection
76
77 foreach ($plugininfo as $type => $plugins) {
78
79 $header = new html_table_cell($pluginman->plugintype_name_plural($type));
80 $header->header = true;
81 $header->colspan = count($table->head);
82 $header = new html_table_row(array($header));
83 $header->attributes['class'] = 'plugintypeheader type-' . $type;
84
85 $numofhighlighted[$type] = 0;
86
87 if (empty($plugins) and $options['full']) {
88 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
89 $msg->colspan = count($table->head);
90 $row = new html_table_row(array($msg));
91 $row->attributes['class'] .= 'msg msg-noneinstalled';
92 $table->data[] = $header;
93 $table->data[] = $row;
94 continue;
95 }
96
97 $plugintyperows = array();
98
99 foreach ($plugins as $name => $plugin) {
100 $row = new html_table_row();
101 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
102
103 if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name)) {
104 $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon'));
105 } else {
106 $icon = $this->output->pix_icon('spacer', '', 'moodle', array('class' => 'smallicon pluginicon noicon'));
107 }
108 $displayname = $icon . ' ' . $plugin->displayname;
109 $displayname = new html_table_cell($displayname);
110
111 $rootdir = new html_table_cell($plugin->get_dir());
112
113 if ($isstandard = $plugin->is_standard()) {
114 $row->attributes['class'] .= ' standard';
115 $source = new html_table_cell(get_string('sourcestd', 'core_plugin'));
116 } else {
117 $row->attributes['class'] .= ' extension';
118 $source = new html_table_cell(get_string('sourceext', 'core_plugin'));
119 }
120
121 $versiondb = new html_table_cell($plugin->versiondb);
122 $versiondisk = new html_table_cell($plugin->versiondisk);
123
124 $statuscode = $plugin->get_status();
125 $row->attributes['class'] .= ' status-' . $statuscode;
126
127 $status = new html_table_cell(get_string('status_' . $statuscode, 'core_plugin'));
128
129 if ($isstandard and in_array($statuscode, array(plugin_manager::PLUGIN_STATUS_NODB, plugin_manager::PLUGIN_STATUS_UPTODATE))) {
130 if (empty($options['full'])) {
131 continue;
132 }
133 } else {
134 $numofhighlighted[$type]++;
135 }
136
137 $row->cells = array($displayname, $rootdir, $source, $versiondb, $versiondisk, $status);
138 $plugintyperows[] = $row;
139 }
140
141 if (empty($numofhighlighted[$type]) and empty($options['full'])) {
142 continue;
143 }
144
145 $table->data[] = $header;
146 $table->data = array_merge($table->data, $plugintyperows);
147 }
148
149 $sumofhighlighted = array_sum($numofhighlighted);
150
151 if ($sumofhighlighted == 0) {
152 $out = $this->output->container_start('nonehighlighted', 'plugins-check-info');
153 $out .= $this->output->heading(get_string('nonehighlighted', 'core_plugin'));
154 if (empty($options['full'])) {
155 $out .= html_writer::link(new moodle_url('/admin/index.php',
156 array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1)),
157 get_string('nonehighlightedinfo', 'core_plugin'));
158 }
159 $out .= $this->output->container_end();
160
161 } else {
162 $out = $this->output->container_start('somehighlighted', 'plugins-check-info');
163 $out .= $this->output->heading(get_string('somehighlighted', 'core_plugin', $sumofhighlighted));
164 if (empty($options['full'])) {
165 $out .= html_writer::link(new moodle_url('/admin/index.php',
166 array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1)),
167 get_string('somehighlightedinfo', 'core_plugin'));
168 }
169 $out .= $this->output->container_end();
170 }
171
172 if ($sumofhighlighted > 0 or $options['full']) {
173 $out .= html_writer::table($table);
174 }
175
176 return $out;
177 }
178
179 /**
180 * Displays all known plugins and links to manage them
181 *
182 * This default implementation renders all plugins into one big table.
183 *
184 * @param array $plugininfo as returned by {@see plugin_manager::get_plugins()}
185 * @return string HTML code
186 */
187 public function plugins_control_panel(array $plugininfo) {
188
189 if (empty($plugininfo)) {
190 return '';
191 }
192
193 $pluginman = plugin_manager::instance();
194
195 $table = new html_table();
196 $table->id = 'plugins-control-panel';
197 $table->head = array(
198 get_string('displayname', 'core_plugin'),
199 get_string('systemname', 'core_plugin'),
200 get_string('source', 'core_plugin'),
201 get_string('version', 'core_plugin'),
202 get_string('availability', 'core_plugin'),
203 get_string('settings', 'core_plugin'),
204 get_string('uninstall','core_plugin'),
205 );
206 $table->colclasses = array(
207 'displayname', 'systemname', 'source', 'version', 'availability', 'settings', 'uninstall',
208 );
209
210 foreach ($plugininfo as $type => $plugins) {
211
212 $header = new html_table_cell($pluginman->plugintype_name_plural($type));
213 $header->header = true;
214 $header->colspan = count($table->head);
215 $header = new html_table_row(array($header));
216 $header->attributes['class'] = 'plugintypeheader type-' . $type;
217 $table->data[] = $header;
218
219 if (empty($plugins)) {
220 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
221 $msg->colspan = count($table->head);
222 $row = new html_table_row(array($msg));
223 $row->attributes['class'] .= 'msg msg-noneinstalled';
224 $table->data[] = $row;
225 continue;
226 }
227
228 foreach ($plugins as $name => $plugin) {
229 $row = new html_table_row();
230 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
231
232 if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name)) {
233 $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon'));
234 } else {
235 $icon = $this->output->pix_icon('spacer', '', 'moodle', array('class' => 'smallicon pluginicon noicon'));
236 }
237 if ($plugin->get_status() === plugin_manager::PLUGIN_STATUS_MISSING) {
238 $msg = html_writer::tag('span', get_string('status_missing', 'core_plugin'), array('class' => 'notifyproblem'));
239 $row->attributes['class'] .= ' missingfromdisk';
240 } else {
241 $msg = '';
242 }
243 $displayname = $icon . ' ' . $plugin->displayname . ' ' . $msg;
244 $displayname = new html_table_cell($displayname);
245
246 $systemname = new html_table_cell($plugin->type . '_' . $plugin->name);
247
248 if ($plugin->is_standard()) {
249 $row->attributes['class'] .= ' standard';
250 $source = new html_table_cell(get_string('sourcestd', 'core_plugin'));
251 } else {
252 $row->attributes['class'] .= ' extension';
253 $source = new html_table_cell(get_string('sourceext', 'core_plugin'));
254 }
255
256 $version = new html_table_cell($plugin->versiondb);
257
258 $isenabled = $plugin->is_enabled();
259 if (is_null($isenabled)) {
260 $availability = new html_table_cell('');
261 } else if ($isenabled) {
262 $row->attributes['class'] .= ' enabled';
263 $icon = $this->output->pix_icon('i/hide', get_string('pluginenabled', 'core_plugin'));
264 $availability = new html_table_cell($icon . ' ' . get_string('pluginenabled', 'core_plugin'));
265 } else {
266 $row->attributes['class'] .= ' disabled';
267 $icon = $this->output->pix_icon('i/show', get_string('plugindisabled', 'core_plugin'));
268 $availability = new html_table_cell($icon . ' ' . get_string('plugindisabled', 'core_plugin'));
269 }
270
271 $settingsurl = $plugin->get_settings_url();
272 if (is_null($settingsurl)) {
273 $settings = new html_table_cell('');
274 } else {
275 $settings = html_writer::link($settingsurl, get_string('settings', 'core_plugin'));
276 $settings = new html_table_cell($settings);
277 }
278
279 $uninstallurl = $plugin->get_uninstall_url();
280 if (is_null($uninstallurl)) {
281 $uninstall = new html_table_cell('');
282 } else {
283 $uninstall = html_writer::link($uninstallurl, get_string('uninstall', 'core_plugin'));
284 $uninstall = new html_table_cell($uninstall);
285 }
286
287 $row->cells = array(
288 $displayname, $systemname, $source, $version, $availability, $settings, $uninstall
289 );
290 $table->data[] = $row;
291 }
292 }
293
294 return html_writer::table($table);
295 }
296}