Make changes in functionality, originally implemented by Petr to make
[moodle.git] / admin / renderer.php
blob08b81e3b03b80102217dedc4f55e631d1b6ea9c6
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.
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/>.
17 /**
18 * Renderer for core_admin subsystem
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
26 defined('MOODLE_INTERNAL') || die();
28 require_once($CFG->libdir . '/pluginlib.php');
30 /**
31 * Standard HTML output renderer for core_admin subsystem
33 class core_admin_renderer extends plugin_renderer_base {
35 /**
36 * Displays all known plugins and information about their installation or upgrade
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
42 * @param array $plugininfo as returned by {@see plugin_manager::get_plugins()}
43 * @param array $options rendering options
44 * @return string HTML code
46 public function plugins_check(array $plugininfo, array $options = null) {
48 if (empty($plugininfo)) {
49 return '';
52 if (empty($options)) {
53 $options = array(
54 'full' => false,
58 $pluginman = plugin_manager::instance();
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'),
70 $table->colclasses = array(
71 'displayname', 'rootdir', 'source', 'versiondb', 'versiondisk', 'status',
73 $table->data = array();
75 $numofhighlighted = array(); // number of highlighted rows per this subsection
77 foreach ($plugininfo as $type => $plugins) {
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;
85 $numofhighlighted[$type] = 0;
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;
97 $plugintyperows = array();
99 foreach ($plugins as $name => $plugin) {
100 $row = new html_table_row();
101 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
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'));
108 $displayname = $icon . ' ' . $plugin->displayname;
109 $displayname = new html_table_cell($displayname);
111 $rootdir = new html_table_cell($plugin->get_dir());
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'));
121 $versiondb = new html_table_cell($plugin->versiondb);
122 $versiondisk = new html_table_cell($plugin->versiondisk);
124 $statuscode = $plugin->get_status();
125 $row->attributes['class'] .= ' status-' . $statuscode;
127 $status = new html_table_cell(get_string('status_' . $statuscode, 'core_plugin'));
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;
133 } else {
134 $numofhighlighted[$type]++;
137 $row->cells = array($displayname, $rootdir, $source, $versiondb, $versiondisk, $status);
138 $plugintyperows[] = $row;
141 if (empty($numofhighlighted[$type]) and empty($options['full'])) {
142 continue;
145 $table->data[] = $header;
146 $table->data = array_merge($table->data, $plugintyperows);
149 $sumofhighlighted = array_sum($numofhighlighted);
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'));
159 $out .= $this->output->container_end();
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'));
169 $out .= $this->output->container_end();
172 if ($sumofhighlighted > 0 or $options['full']) {
173 $out .= html_writer::table($table);
176 return $out;
180 * Displays all known plugins and links to manage them
182 * This default implementation renders all plugins into one big table.
184 * @param array $plugininfo as returned by {@see plugin_manager::get_plugins()}
185 * @return string HTML code
187 public function plugins_control_panel(array $plugininfo) {
189 if (empty($plugininfo)) {
190 return '';
193 $pluginman = plugin_manager::instance();
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'),
206 $table->colclasses = array(
207 'displayname', 'systemname', 'source', 'version', 'availability', 'settings', 'uninstall',
210 foreach ($plugininfo as $type => $plugins) {
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;
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;
228 foreach ($plugins as $name => $plugin) {
229 $row = new html_table_row();
230 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
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'));
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 = '';
243 $displayname = $icon . ' ' . $plugin->displayname . ' ' . $msg;
244 $displayname = new html_table_cell($displayname);
246 $systemname = new html_table_cell($plugin->type . '_' . $plugin->name);
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'));
256 $version = new html_table_cell($plugin->versiondb);
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'));
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);
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);
287 $row->cells = array(
288 $displayname, $systemname, $source, $version, $availability, $settings, $uninstall
290 $table->data[] = $row;
294 return html_writer::table($table);