MDL-37961 webservice: PARAM_BOOL with PARAM_DEFAULT accepts boolean default
[moodle.git] / cache / renderer.php
blob7e55df8bf04febd2d7121389c983a0d163958069
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 * The Cache renderer.
20 * This file is part of Moodle's cache API, affectionately called MUC.
22 * @package core
23 * @category cache
24 * @copyright 2012 Sam Hemelryk
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 defined('MOODLE_INTERNAL') || die();
30 /**
31 * The cache renderer (mainly admin interfaces).
33 * @package core
34 * @category cache
35 * @copyright 2012 Sam Hemelryk
36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38 class core_cache_renderer extends plugin_renderer_base {
40 /**
41 * Displays store summaries.
43 * @param array $stores
44 * @param array $plugins
45 * @return string HTML
47 public function store_instance_summariers(array $stores, array $plugins) {
48 $table = new html_table();
49 $table->head = array(
50 get_string('storename', 'cache'),
51 get_string('plugin', 'cache'),
52 get_string('storeready', 'cache'),
53 get_string('mappings', 'cache'),
54 get_string('modes', 'cache'),
55 get_string('supports', 'cache'),
56 get_string('actions', 'cache'),
58 $table->colclasses = array(
59 'storename',
60 'plugin',
61 'storeready',
62 'mappings',
63 'modes',
64 'supports',
65 'actions'
67 $table->data = array();
69 $defaultstoreactions = get_string('defaultstoreactions', 'cache');
71 foreach ($stores as $name => $store) {
72 $actions = cache_administration_helper::get_store_instance_actions($name, $store);
73 $modes = array();
74 foreach ($store['modes'] as $mode => $enabled) {
75 if ($enabled) {
76 $modes[] = get_string('mode_'.$mode, 'cache');
80 $supports = array();
81 foreach ($store['supports'] as $support => $enabled) {
82 if ($enabled) {
83 $supports[] = get_string('supports_'.$support, 'cache');
87 $info = '';
88 if (!empty($store['default'])) {
89 $info = $this->output->pix_icon('i/info', $defaultstoreactions, '', array('class' => 'icon'));
91 $htmlactions = array();
92 foreach ($actions as $action) {
93 $htmlactions[] = $this->output->action_link($action['url'], $action['text']);
96 $storename = $store['name'];
97 if (!empty($store['default'])) {
98 $storename = get_string('store_'.$store['name'], 'cache');
101 $row = new html_table_row(array(
102 $storename,
103 get_string('pluginname', 'cachestore_'.$store['plugin']),
104 ($store['isready'] && $store['requirementsmet']) ? $this->output->pix_icon('i/valid', '1') : '',
105 $store['mappings'],
106 join(', ', $modes),
107 join(', ', $supports),
108 $info.join(', ', $htmlactions)
110 $row->attributes['class'] = 'store-'.$name;
111 if ($store['default']) {
112 $row->attributes['class'] .= ' default-store';
114 $table->data[] = $row;
117 $html = html_writer::start_tag('div', array('id' => 'core-cache-store-summaries'));
118 $html .= $this->output->heading(get_string('storesummaries', 'cache'), 3);
119 $html .= html_writer::table($table);
120 $html .= html_writer::end_tag('div');
121 return $html;
125 * Displays plugin summaries
127 * @param array $plugins
128 * @return string HTML
130 public function store_plugin_summaries(array $plugins) {
131 $table = new html_table();
132 $table->head = array(
133 get_string('plugin', 'cache'),
134 get_string('storeready', 'cache'),
135 get_string('stores', 'cache'),
136 get_string('modes', 'cache'),
137 get_string('supports', 'cache'),
138 get_string('actions', 'cache'),
140 $table->colclasses = array(
141 'plugin',
142 'storeready',
143 'stores',
144 'modes',
145 'supports',
146 'actions'
148 $table->data = array();
150 foreach ($plugins as $name => $plugin) {
151 $actions = cache_administration_helper::get_store_plugin_actions($name, $plugin);
153 $modes = array();
154 foreach ($plugin['modes'] as $mode => $enabled) {
155 if ($enabled) {
156 $modes[] = get_string('mode_'.$mode, 'cache');
160 $supports = array();
161 foreach ($plugin['supports'] as $support => $enabled) {
162 if ($enabled) {
163 $supports[] = get_string('supports_'.$support, 'cache');
167 $htmlactions = array();
168 foreach ($actions as $action) {
169 $htmlactions[] = $this->output->action_link($action['url'], $action['text']);
172 $row = new html_table_row(array(
173 $plugin['name'],
174 ($plugin['requirementsmet']) ? $this->output->pix_icon('i/valid', '1') : '',
175 $plugin['instances'],
176 join(', ', $modes),
177 join(', ', $supports),
178 join(', ', $htmlactions)
181 $row->attributes['class'] = 'plugin-'.$name;
182 $table->data[] = $row;
185 $html = html_writer::start_tag('div', array('id' => 'core-cache-plugin-summaries'));
186 $html .= $this->output->heading(get_string('pluginsummaries', 'cache'), 3);
187 $html .= html_writer::table($table);
188 $html .= html_writer::end_tag('div');
189 return $html;
193 * Displays definition summaries
195 * @param array $definitions
196 * @param array $actions
197 * @return string HTML
199 public function definition_summaries(array $definitions, array $actions) {
200 $table = new html_table();
201 $table->head = array(
202 get_string('definition', 'cache'),
203 get_string('mode', 'cache'),
204 get_string('component', 'cache'),
205 get_string('area', 'cache'),
206 get_string('mappings', 'cache'),
207 get_string('actions', 'cache'),
209 $table->colclasses = array(
210 'definition',
211 'mode',
212 'component',
213 'area',
214 'mappings',
215 'actions'
217 $table->data = array();
219 $none = new lang_string('none', 'cache');
220 foreach ($definitions as $id => $definition) {
221 $htmlactions = array();
222 foreach ($actions as $action) {
223 $action['url']->param('definition', $id);
224 $htmlactions[] = $this->output->action_link($action['url'], $action['text']);
226 if (!empty($definition['mappings'])) {
227 $mapping = join(', ', $definition['mappings']);
228 } else {
229 $mapping = '<em>'.$none.'</em>';
232 $row = new html_table_row(array(
233 $definition['name'],
234 get_string('mode_'.$definition['mode'], 'cache'),
235 $definition['component'],
236 $definition['area'],
237 $mapping,
238 join(', ', $htmlactions)
240 $row->attributes['class'] = 'definition-'.$definition['component'].'-'.$definition['area'];
241 $table->data[] = $row;
244 $html = html_writer::start_tag('div', array('id' => 'core-cache-definition-summaries'));
245 $html .= $this->output->heading(get_string('definitionsummaries', 'cache'), 3);
246 $html .= html_writer::table($table);
248 $url = new moodle_url('/cache/admin.php', array('action' => 'rescandefinitions', 'sesskey' => sesskey()));
249 $link = html_writer::link($url, get_string('rescandefinitions', 'cache'));
250 $html .= html_writer::tag('div', $link, array('id' => 'core-cache-rescan-definitions'));
252 $html .= html_writer::end_tag('div');
253 return $html;
257 * Displays mode mappings
259 * @param string $applicationstore
260 * @param string $sessionstore
261 * @param string $requeststore
262 * @param moodle_url $editurl
263 * @return string HTML
265 public function mode_mappings($applicationstore, $sessionstore, $requeststore, moodle_url $editurl) {
266 $table = new html_table();
267 $table->colclasses = array(
268 'mode',
269 'mapping',
271 $table->rowclasses = array(
272 'mode_application',
273 'mode_session',
274 'mode_request'
276 $table->head = array(
277 get_string('mode', 'cache'),
278 get_string('mappings', 'cache'),
280 $table->data = array(
281 array(get_string('mode_'.cache_store::MODE_APPLICATION, 'cache'), $applicationstore),
282 array(get_string('mode_'.cache_store::MODE_SESSION, 'cache'), $sessionstore),
283 array(get_string('mode_'.cache_store::MODE_REQUEST, 'cache'), $requeststore)
286 $html = html_writer::start_tag('div', array('id' => 'core-cache-mode-mappings'));
287 $html .= $this->output->heading(get_string('defaultmappings', 'cache'), 3);
288 $html .= html_writer::table($table);
289 $link = html_writer::link($editurl, get_string('editmappings', 'cache'));
290 $html .= html_writer::tag('div', $link, array('class' => 'edit-link'));
291 $html .= html_writer::end_tag('div');
292 return $html;
296 * Display basic information about lock instances.
298 * @todo Add some actions so that people can configure lock instances.
300 * @param array $locks
301 * @return string
303 public function lock_summaries(array $locks) {
304 $table = new html_table();
305 $table->colclasses = array(
306 'name',
307 'default',
308 'uses',
309 // Useful later: 'actions'.
311 $table->rowclasses = array(
312 'lock_name',
313 'lock_default',
314 'lock_uses',
315 // Useful later: 'lock_actions',.
317 $table->head = array(
318 get_string('lockname', 'cache'),
319 get_string('lockdefault', 'cache'),
320 get_string('lockuses', 'cache'),
321 // Useful later: get_string('actions', 'cache').
323 $table->data = array();
324 $tick = $this->output->pix_icon('i/valid', '');
325 foreach ($locks as $lock) {
326 $table->data[] = new html_table_row(array(
327 new html_table_cell($lock['name']),
328 new html_table_cell($lock['default'] ? $tick : ''),
329 new html_table_cell($lock['uses']),
333 $html = html_writer::start_tag('div', array('id' => 'core-cache-lock-summary'));
334 $html .= $this->output->heading(get_string('locksummary', 'cache'), 3);
335 $html .= html_writer::table($table);
336 $html .= html_writer::end_tag('div');
337 return $html;