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 $storeinstancesummaries information about each store instance,
44 * as returned by cache_administration_helper::get_store_instance_summaries().
45 * @param array $storepluginsummaries information about each store plugin as
46 * returned by cache_administration_helper::get_store_plugin_summaries().
49 public function store_instance_summariers(array $storeinstancesummaries, array $storepluginsummaries) {
50 $table = new html_table();
52 get_string('storename', 'cache'),
53 get_string('plugin', 'cache'),
54 get_string('storeready', 'cache'),
55 get_string('mappings', 'cache'),
56 get_string('modes', 'cache'),
57 get_string('supports', 'cache'),
58 get_string('locking', 'cache') . ' ' . $this->output
->help_icon('locking', 'cache'),
59 get_string('actions', 'cache'),
61 $table->colclasses
= array(
71 $table->data
= array();
73 $defaultstoreactions = get_string('defaultstoreactions', 'cache');
75 foreach ($storeinstancesummaries as $name => $storesummary) {
76 $actions = cache_administration_helper
::get_store_instance_actions($name, $storesummary);
78 foreach ($storesummary['modes'] as $mode => $enabled) {
80 $modes[] = get_string('mode_'.$mode, 'cache');
85 foreach ($storesummary['supports'] as $support => $enabled) {
87 $supports[] = get_string('supports_'.$support, 'cache');
92 if (!empty($storesummary['default'])) {
93 $info = $this->output
->pix_icon('i/info', $defaultstoreactions, '', array('class' => 'icon'));
95 $htmlactions = array();
96 foreach ($actions as $action) {
97 $htmlactions[] = $this->output
->action_link($action['url'], $action['text']);
100 $isready = $storesummary['isready'] && $storesummary['requirementsmet'];
101 $readycell = new html_table_cell
;
103 $readycell->text
= $this->output
->pix_icon('i/valid', '1');
106 $storename = $storesummary['name'];
107 if (!empty($storesummary['default'])) {
108 $storename = get_string('store_'.$storesummary['name'], 'cache');
110 if (!$isready && (int)$storesummary['mappings'] > 0) {
111 $readycell->text
= $this->output
->help_icon('storerequiresattention', 'cache');
112 $readycell->attributes
['class'] = 'store-requires-attention';
115 $lock = $storesummary['lock']['name'];
116 if (!empty($storesummary['lock']['default'])) {
117 $lock = get_string($storesummary['lock']['name'], 'cache');
120 $row = new html_table_row(array(
122 get_string('pluginname', 'cachestore_'.$storesummary['plugin']),
124 $storesummary['mappings'],
126 join(', ', $supports),
128 $info.join(', ', $htmlactions)
130 $row->attributes
['class'] = 'store-'.$name;
131 if ($storesummary['default']) {
132 $row->attributes
['class'] .= ' default-store';
134 $table->data
[] = $row;
137 $html = html_writer
::start_tag('div', array('id' => 'core-cache-store-summaries'));
138 $html .= $this->output
->heading(get_string('storesummaries', 'cache'), 3);
139 $html .= html_writer
::table($table);
140 $html .= html_writer
::end_tag('div');
145 * Displays plugin summaries.
147 * @param array $storepluginsummaries information about each store plugin as
148 * returned by cache_administration_helper::get_store_plugin_summaries().
149 * @return string HTML
151 public function store_plugin_summaries(array $storepluginsummaries) {
152 $table = new html_table();
153 $table->head
= array(
154 get_string('plugin', 'cache'),
155 get_string('storeready', 'cache'),
156 get_string('stores', 'cache'),
157 get_string('modes', 'cache'),
158 get_string('supports', 'cache'),
159 get_string('actions', 'cache'),
161 $table->colclasses
= array(
169 $table->data
= array();
171 foreach ($storepluginsummaries as $name => $plugin) {
172 $actions = cache_administration_helper
::get_store_plugin_actions($name, $plugin);
175 foreach ($plugin['modes'] as $mode => $enabled) {
177 $modes[] = get_string('mode_'.$mode, 'cache');
182 foreach ($plugin['supports'] as $support => $enabled) {
184 $supports[] = get_string('supports_'.$support, 'cache');
188 $htmlactions = array();
189 foreach ($actions as $action) {
190 $htmlactions[] = $this->output
->action_link($action['url'], $action['text']);
193 $row = new html_table_row(array(
195 ($plugin['requirementsmet']) ?
$this->output
->pix_icon('i/valid', '1') : '',
196 $plugin['instances'],
198 join(', ', $supports),
199 join(', ', $htmlactions)
202 $row->attributes
['class'] = 'plugin-'.$name;
203 $table->data
[] = $row;
206 $html = html_writer
::start_tag('div', array('id' => 'core-cache-plugin-summaries'));
207 $html .= $this->output
->heading(get_string('pluginsummaries', 'cache'), 3);
208 $html .= html_writer
::table($table);
209 $html .= html_writer
::end_tag('div');
214 * Displays definition summaries.
216 * @param array $definitionsummaries information about each definition, as returned by
217 * cache_administration_helper::get_definition_summaries().
218 * @param context $context the system context.
220 * @return string HTML.
222 public function definition_summaries(array $definitionsummaries, context
$context) {
223 $table = new html_table();
224 $table->head
= array(
225 get_string('definition', 'cache'),
226 get_string('mode', 'cache'),
227 get_string('component', 'cache'),
228 get_string('area', 'cache'),
229 get_string('mappings', 'cache'),
230 get_string('sharing', 'cache'),
231 get_string('canuselocalstore', 'cache'),
232 get_string('actions', 'cache')
234 $table->colclasses
= array(
244 $table->data
= array();
246 core_collator
::asort_array_of_arrays_by_key($definitionsummaries, 'name');
248 $none = new lang_string('none', 'cache');
249 foreach ($definitionsummaries as $id => $definition) {
250 $actions = cache_administration_helper
::get_definition_actions($context, $definition);
251 $htmlactions = array();
252 foreach ($actions as $action) {
253 $action['url']->param('definition', $id);
254 $htmlactions[] = $this->output
->action_link($action['url'], $action['text']);
256 if (!empty($definition['mappings'])) {
257 $mapping = join(', ', $definition['mappings']);
259 $mapping = '<em>'.$none.'</em>';
262 $uselocalcachecol = get_string('no');
263 if ($definition['mode'] != cache_store
::MODE_REQUEST
) {
264 if (isset($definition['canuselocalstore']) && $definition['canuselocalstore']) {
265 $uselocalcachecol = get_string('yes');
269 $row = new html_table_row(array(
271 get_string('mode_'.$definition['mode'], 'cache'),
272 $definition['component'],
275 join(', ', $definition['selectedsharingoption']),
277 join(', ', $htmlactions)
279 $row->attributes
['class'] = 'definition-'.$definition['component'].'-'.$definition['area'];
280 $table->data
[] = $row;
283 $html = html_writer
::start_tag('div', array('id' => 'core-cache-definition-summaries'));
284 $html .= $this->output
->heading(get_string('definitionsummaries', 'cache'), 3);
285 $html .= html_writer
::table($table);
287 $url = new moodle_url('/cache/admin.php', array('action' => 'rescandefinitions', 'sesskey' => sesskey()));
288 $link = html_writer
::link($url, get_string('rescandefinitions', 'cache'));
289 $html .= html_writer
::tag('div', $link, array('id' => 'core-cache-rescan-definitions'));
291 $html .= html_writer
::end_tag('div');
296 * Displays mode mappings
298 * @param string $applicationstore
299 * @param string $sessionstore
300 * @param string $requeststore
301 * @param moodle_url $editurl
302 * @return string HTML
304 public function mode_mappings($applicationstore, $sessionstore, $requeststore, moodle_url
$editurl) {
305 $table = new html_table();
306 $table->colclasses
= array(
310 $table->rowclasses
= array(
315 $table->head
= array(
316 get_string('mode', 'cache'),
317 get_string('mappings', 'cache'),
319 $table->data
= array(
320 array(get_string('mode_'.cache_store
::MODE_APPLICATION
, 'cache'), $applicationstore),
321 array(get_string('mode_'.cache_store
::MODE_SESSION
, 'cache'), $sessionstore),
322 array(get_string('mode_'.cache_store
::MODE_REQUEST
, 'cache'), $requeststore)
325 $html = html_writer
::start_tag('div', array('id' => 'core-cache-mode-mappings'));
326 $html .= $this->output
->heading(get_string('defaultmappings', 'cache'), 3);
327 $html .= html_writer
::table($table);
328 $link = html_writer
::link($editurl, get_string('editmappings', 'cache'));
329 $html .= html_writer
::tag('div', $link, array('class' => 'edit-link'));
330 $html .= html_writer
::end_tag('div');
335 * Display basic information about lock instances.
337 * @todo Add some actions so that people can configure lock instances.
339 * @param array $locks
342 public function lock_summaries(array $locks) {
343 $table = new html_table();
344 $table->colclasses
= array(
351 $table->rowclasses
= array(
358 $table->head
= array(
359 get_string('lockname', 'cache'),
360 get_string('locktype', 'cache'),
361 get_string('lockdefault', 'cache'),
362 get_string('lockuses', 'cache'),
363 get_string('actions', 'cache')
365 $table->data
= array();
366 $tick = $this->output
->pix_icon('i/valid', '');
367 foreach ($locks as $lock) {
369 if ($lock['uses'] === 0 && !$lock['default']) {
370 $url = new moodle_url('/cache/admin.php', array('lock' => $lock['name'], 'action' => 'deletelock', 'sesskey' => sesskey()));
371 $actions[] = html_writer
::link($url, get_string('delete', 'cache'));
373 $table->data
[] = new html_table_row(array(
374 new html_table_cell($lock['name']),
375 new html_table_cell($lock['type']),
376 new html_table_cell($lock['default'] ?
$tick : ''),
377 new html_table_cell($lock['uses']),
378 new html_table_cell(join(' ', $actions))
382 $url = new moodle_url('/cache/admin.php', array('action' => 'newlockinstance', 'sesskey' => sesskey()));
383 $select = new single_select($url, 'lock', cache_administration_helper
::get_addable_lock_options());
384 $select->label
= get_string('addnewlockinstance', 'cache');
386 $html = html_writer
::start_tag('div', array('id' => 'core-cache-lock-summary'));
387 $html .= $this->output
->heading(get_string('locksummary', 'cache'), 3);
388 $html .= html_writer
::table($table);
389 $html .= html_writer
::tag('div', $this->output
->render($select), array('class' => 'new-instance'));
390 $html .= html_writer
::end_tag('div');
395 * Renders an array of notifications for the cache configuration screen.
397 * Takes an array of notifications with the form:
398 * $notifications = array(
399 * array('This is a success message', true),
400 * array('This is a failure message', false),
403 * @param array $notifications
406 public function notifications(array $notifications = array()) {
407 if (count($notifications) === 0) {
408 // There are no notifications to render.
411 $html = html_writer
::start_div('notifications');
412 foreach ($notifications as $notification) {
413 list($message, $notifysuccess) = $notification;
414 $html .= $this->notification($message, ($notifysuccess) ?
'notifysuccess' : 'notifyproblem');
416 $html .= html_writer
::end_div();