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('lockingmeans', 'cache'),
57 get_string('actions', 'cache'),
59 $table->colclasses
= array(
69 $table->data
= array();
71 $defaultstoreactions = get_string('defaultstoreactions', 'cache');
73 foreach ($stores as $name => $store) {
74 $actions = cache_administration_helper
::get_store_instance_actions($name, $store);
76 foreach ($store['modes'] as $mode => $enabled) {
78 $modes[] = get_string('mode_'.$mode, 'cache');
83 foreach ($store['supports'] as $support => $enabled) {
85 $supports[] = get_string('supports_'.$support, 'cache');
90 if (!empty($store['default'])) {
91 $info = $this->output
->pix_icon('i/info', $defaultstoreactions, '', array('class' => 'icon'));
93 $htmlactions = array();
94 foreach ($actions as $action) {
95 $htmlactions[] = $this->output
->action_link($action['url'], $action['text']);
98 $isready = $store['isready'] && $store['requirementsmet'];
99 $readycell = new html_table_cell
;
101 $readycell->text
= $this->output
->pix_icon('i/valid', '1');
104 $storename = $store['name'];
105 if (!empty($store['default'])) {
106 $storename = get_string('store_'.$store['name'], 'cache');
108 if (!$isready && (int)$store['mappings'] > 0) {
109 $readycell->text
= $this->output
->help_icon('storerequiresattention', 'cache');
110 $readycell->attributes
['class'] = 'store-requires-attention';
113 $lock = $store['lock']['name'];
114 if (!empty($store['lock']['default'])) {
115 $lock = get_string($store['lock']['name'], 'cache');
118 $row = new html_table_row(array(
120 get_string('pluginname', 'cachestore_'.$store['plugin']),
124 join(', ', $supports),
126 $info.join(', ', $htmlactions)
128 $row->attributes
['class'] = 'store-'.$name;
129 if ($store['default']) {
130 $row->attributes
['class'] .= ' default-store';
132 $table->data
[] = $row;
135 $html = html_writer
::start_tag('div', array('id' => 'core-cache-store-summaries'));
136 $html .= $this->output
->heading(get_string('storesummaries', 'cache'), 3);
137 $html .= html_writer
::table($table);
138 $html .= html_writer
::end_tag('div');
143 * Displays plugin summaries
145 * @param array $plugins
146 * @return string HTML
148 public function store_plugin_summaries(array $plugins) {
149 $table = new html_table();
150 $table->head
= array(
151 get_string('plugin', 'cache'),
152 get_string('storeready', 'cache'),
153 get_string('stores', 'cache'),
154 get_string('modes', 'cache'),
155 get_string('supports', 'cache'),
156 get_string('actions', 'cache'),
158 $table->colclasses
= array(
166 $table->data
= array();
168 foreach ($plugins as $name => $plugin) {
169 $actions = cache_administration_helper
::get_store_plugin_actions($name, $plugin);
172 foreach ($plugin['modes'] as $mode => $enabled) {
174 $modes[] = get_string('mode_'.$mode, 'cache');
179 foreach ($plugin['supports'] as $support => $enabled) {
181 $supports[] = get_string('supports_'.$support, 'cache');
185 $htmlactions = array();
186 foreach ($actions as $action) {
187 $htmlactions[] = $this->output
->action_link($action['url'], $action['text']);
190 $row = new html_table_row(array(
192 ($plugin['requirementsmet']) ?
$this->output
->pix_icon('i/valid', '1') : '',
193 $plugin['instances'],
195 join(', ', $supports),
196 join(', ', $htmlactions)
199 $row->attributes
['class'] = 'plugin-'.$name;
200 $table->data
[] = $row;
203 $html = html_writer
::start_tag('div', array('id' => 'core-cache-plugin-summaries'));
204 $html .= $this->output
->heading(get_string('pluginsummaries', 'cache'), 3);
205 $html .= html_writer
::table($table);
206 $html .= html_writer
::end_tag('div');
211 * Displays definition summaries
213 * @param array $definitions
214 * @return string HTML
216 public function definition_summaries(array $definitions, context
$context) {
217 $table = new html_table();
218 $table->head
= array(
219 get_string('definition', 'cache'),
220 get_string('mode', 'cache'),
221 get_string('component', 'cache'),
222 get_string('area', 'cache'),
223 get_string('mappings', 'cache'),
224 get_string('sharing', 'cache'),
225 get_string('actions', 'cache'),
227 $table->colclasses
= array(
236 $table->data
= array();
238 $none = new lang_string('none', 'cache');
239 foreach ($definitions as $id => $definition) {
240 $actions = cache_administration_helper
::get_definition_actions($context, $definition);
241 $htmlactions = array();
242 foreach ($actions as $action) {
243 $action['url']->param('definition', $id);
244 $htmlactions[] = $this->output
->action_link($action['url'], $action['text']);
246 if (!empty($definition['mappings'])) {
247 $mapping = join(', ', $definition['mappings']);
249 $mapping = '<em>'.$none.'</em>';
252 $row = new html_table_row(array(
254 get_string('mode_'.$definition['mode'], 'cache'),
255 $definition['component'],
258 join(', ', $definition['selectedsharingoption']),
259 join(', ', $htmlactions)
261 $row->attributes
['class'] = 'definition-'.$definition['component'].'-'.$definition['area'];
262 $table->data
[] = $row;
265 $html = html_writer
::start_tag('div', array('id' => 'core-cache-definition-summaries'));
266 $html .= $this->output
->heading(get_string('definitionsummaries', 'cache'), 3);
267 $html .= html_writer
::table($table);
269 $url = new moodle_url('/cache/admin.php', array('action' => 'rescandefinitions', 'sesskey' => sesskey()));
270 $link = html_writer
::link($url, get_string('rescandefinitions', 'cache'));
271 $html .= html_writer
::tag('div', $link, array('id' => 'core-cache-rescan-definitions'));
273 $html .= html_writer
::end_tag('div');
278 * Displays mode mappings
280 * @param string $applicationstore
281 * @param string $sessionstore
282 * @param string $requeststore
283 * @param moodle_url $editurl
284 * @return string HTML
286 public function mode_mappings($applicationstore, $sessionstore, $requeststore, moodle_url
$editurl) {
287 $table = new html_table();
288 $table->colclasses
= array(
292 $table->rowclasses
= array(
297 $table->head
= array(
298 get_string('mode', 'cache'),
299 get_string('mappings', 'cache'),
301 $table->data
= array(
302 array(get_string('mode_'.cache_store
::MODE_APPLICATION
, 'cache'), $applicationstore),
303 array(get_string('mode_'.cache_store
::MODE_SESSION
, 'cache'), $sessionstore),
304 array(get_string('mode_'.cache_store
::MODE_REQUEST
, 'cache'), $requeststore)
307 $html = html_writer
::start_tag('div', array('id' => 'core-cache-mode-mappings'));
308 $html .= $this->output
->heading(get_string('defaultmappings', 'cache'), 3);
309 $html .= html_writer
::table($table);
310 $link = html_writer
::link($editurl, get_string('editmappings', 'cache'));
311 $html .= html_writer
::tag('div', $link, array('class' => 'edit-link'));
312 $html .= html_writer
::end_tag('div');
317 * Display basic information about lock instances.
319 * @todo Add some actions so that people can configure lock instances.
321 * @param array $locks
324 public function lock_summaries(array $locks) {
325 $table = new html_table();
326 $table->colclasses
= array(
333 $table->rowclasses
= array(
340 $table->head
= array(
341 get_string('lockname', 'cache'),
342 get_string('locktype', 'cache'),
343 get_string('lockdefault', 'cache'),
344 get_string('lockuses', 'cache'),
345 get_string('actions', 'cache')
347 $table->data
= array();
348 $tick = $this->output
->pix_icon('i/valid', '');
349 foreach ($locks as $lock) {
351 if ($lock['uses'] === 0 && !$lock['default']) {
352 $url = new moodle_url('/cache/admin.php', array('lock' => $lock['name'], 'action' => 'deletelock', 'sesskey' => sesskey()));
353 $actions[] = html_writer
::link($url, get_string('delete', 'cache'));
355 $table->data
[] = new html_table_row(array(
356 new html_table_cell($lock['name']),
357 new html_table_cell($lock['type']),
358 new html_table_cell($lock['default'] ?
$tick : ''),
359 new html_table_cell($lock['uses']),
360 new html_table_cell(join(' ', $actions))
364 $url = new moodle_url('/cache/admin.php', array('action' => 'newlockinstance', 'sesskey' => sesskey()));
365 $select = new single_select($url, 'lock', cache_administration_helper
::get_addable_lock_options());
366 $select->label
= get_string('addnewlockinstance', 'cache');
368 $html = html_writer
::start_tag('div', array('id' => 'core-cache-lock-summary'));
369 $html .= $this->output
->heading(get_string('locksummary', 'cache'), 3);
370 $html .= html_writer
::table($table);
371 $html .= html_writer
::tag('div', $this->output
->render($select), array('class' => 'new-instance'));
372 $html .= html_writer
::end_tag('div');