2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
20 * This file is part of Moodle's cache API, affectionately called MUC.
24 * @copyright 2012 Sam Hemelryk
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 defined('MOODLE_INTERNAL') ||
die();
31 * The cache renderer (mainly admin interfaces).
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
{
41 * Displays store summaries.
43 * @param array $stores
44 * @param array $plugins
47 public function store_instance_summariers(array $stores, array $plugins) {
48 $table = new html_table();
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(
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);
74 foreach ($store['modes'] as $mode => $enabled) {
76 $modes[] = get_string('mode_'.$mode, 'cache');
81 foreach ($store['supports'] as $support => $enabled) {
83 $supports[] = get_string('supports_'.$support, 'cache');
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(
103 get_string('pluginname', 'cachestore_'.$store['plugin']),
104 ($store['isready'] && $store['requirementsmet']) ?
$this->output
->pix_icon('i/valid', '1') : '',
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');
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(
148 $table->data
= array();
150 foreach ($plugins as $name => $plugin) {
151 $actions = cache_administration_helper
::get_store_plugin_actions($name, $plugin);
154 foreach ($plugin['modes'] as $mode => $enabled) {
156 $modes[] = get_string('mode_'.$mode, 'cache');
161 foreach ($plugin['supports'] as $support => $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(
174 ($plugin['requirementsmet']) ?
$this->output
->pix_icon('i/valid', '1') : '',
175 $plugin['instances'],
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');
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(
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']);
229 $mapping = '<em>'.$none.'</em>';
232 $row = new html_table_row(array(
234 get_string('mode_'.$definition['mode'], 'cache'),
235 $definition['component'],
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');
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(
271 $table->rowclasses
= array(
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');
296 * Display basic information about lock instances.
298 * @todo Add some actions so that people can configure lock instances.
300 * @param array $locks
303 public function lock_summaries(array $locks) {
304 $table = new html_table();
305 $table->colclasses
= array(
309 // Useful later: 'actions'.
311 $table->rowclasses
= array(
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');