mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-47271 check: Refactor check table into a renderable
This commit is contained in:
parent
20167daf89
commit
e8e2bd28ec
4 changed files with 159 additions and 143 deletions
|
@ -509,6 +509,7 @@ $string['description'] = 'Description';
|
||||||
$string['descriptiona'] = 'Description: {$a}';
|
$string['descriptiona'] = 'Description: {$a}';
|
||||||
$string['deselectall'] = 'Deselect all';
|
$string['deselectall'] = 'Deselect all';
|
||||||
$string['deselectnos'] = 'Deselect all \'No\'';
|
$string['deselectnos'] = 'Deselect all \'No\'';
|
||||||
|
$string['details'] = 'Details';
|
||||||
$string['detailedless'] = 'Less detailed';
|
$string['detailedless'] = 'Less detailed';
|
||||||
$string['detailedmore'] = 'More detailed';
|
$string['detailedmore'] = 'More detailed';
|
||||||
$string['digitalminor'] = 'Digital minor';
|
$string['digitalminor'] = 'Digital minor';
|
||||||
|
|
141
lib/classes/check/table.php
Normal file
141
lib/classes/check/table.php
Normal file
|
@ -0,0 +1,141 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A table of check results
|
||||||
|
*
|
||||||
|
* @package core
|
||||||
|
* @category check
|
||||||
|
* @copyright 2020 Brendan Heywood <brendan@catalyst-au.net>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
namespace core\check;
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A table of check results
|
||||||
|
*
|
||||||
|
* @copyright 2020 Brendan Heywood <brendan@catalyst-au.net>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class table implements \renderable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var moodle_url $url
|
||||||
|
*/
|
||||||
|
protected $url = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string $type What type of checks
|
||||||
|
*/
|
||||||
|
protected $type = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var check $detail a specific check to focus on
|
||||||
|
*/
|
||||||
|
public $detail = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array $checks shown in this table
|
||||||
|
*/
|
||||||
|
public $checks = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param string $type of check
|
||||||
|
* @param string $url of report
|
||||||
|
* @param string $detail check to focus on
|
||||||
|
*/
|
||||||
|
public function __construct($type, $url, $detail = '') {
|
||||||
|
|
||||||
|
// We may need a bit more memory and this may take a long time to process.
|
||||||
|
\raise_memory_limit(MEMORY_EXTRA);
|
||||||
|
\core_php_time_limit::raise();
|
||||||
|
|
||||||
|
$this->type = $type;
|
||||||
|
$this->url = $url;
|
||||||
|
$this->checks = \core\check\manager::get_checks($type);
|
||||||
|
|
||||||
|
if ($detail) {
|
||||||
|
$this->checks = array_filter($this->checks, function($check) use ($detail) {
|
||||||
|
return $detail == $check->get_ref();
|
||||||
|
});
|
||||||
|
if (!empty($this->checks)) {
|
||||||
|
$this->detail = reset($this->checks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render a table of checks
|
||||||
|
*
|
||||||
|
* @param renderer $output to use
|
||||||
|
* @return string html output
|
||||||
|
*/
|
||||||
|
public function render($output) {
|
||||||
|
|
||||||
|
$table = new \html_table();
|
||||||
|
$table->data = [];
|
||||||
|
$table->head = [
|
||||||
|
get_string('status'),
|
||||||
|
get_string('check'),
|
||||||
|
get_string('summary'),
|
||||||
|
get_string('action'),
|
||||||
|
];
|
||||||
|
$table->colclasses = [
|
||||||
|
'rightalign status',
|
||||||
|
'leftalign check',
|
||||||
|
'leftalign summary',
|
||||||
|
'leftalign action',
|
||||||
|
];
|
||||||
|
$table->id = $this->type . 'reporttable';
|
||||||
|
$table->attributes = ['class' => 'admintable ' . $this->type . 'report generaltable'];
|
||||||
|
|
||||||
|
foreach ($this->checks as $check) {
|
||||||
|
$ref = $check->get_ref();
|
||||||
|
$result = $check->get_result();
|
||||||
|
$component = $check->get_component();
|
||||||
|
$actionlink = $check->get_action_link();
|
||||||
|
|
||||||
|
$link = new \moodle_url($this->url, ['detail' => $ref]);
|
||||||
|
|
||||||
|
$row = [];
|
||||||
|
$row[] = $output->check_result($result);
|
||||||
|
$row[] = $output->action_link($link, $check->get_name());
|
||||||
|
|
||||||
|
$row[] = $result->get_summary();
|
||||||
|
if ($actionlink) {
|
||||||
|
$row[] = $output->render($actionlink);
|
||||||
|
} else {
|
||||||
|
$row[] = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$table->data[] = $row;
|
||||||
|
}
|
||||||
|
$html = \html_writer::table($table);
|
||||||
|
|
||||||
|
if ($this->detail && $result) {
|
||||||
|
$html .= $output->heading(get_string('details'), 3);
|
||||||
|
$html .= $output->box($result->get_details(), 'generalbox boxwidthnormal boxaligncenter');
|
||||||
|
$html .= $output->continue_button($this->url);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -27,87 +27,23 @@ define('NO_OUTPUT_BUFFERING', true);
|
||||||
require('../../config.php');
|
require('../../config.php');
|
||||||
require_once($CFG->libdir.'/adminlib.php');
|
require_once($CFG->libdir.'/adminlib.php');
|
||||||
|
|
||||||
use core\check\check;
|
|
||||||
use core\check\result;
|
|
||||||
|
|
||||||
// Print the header.
|
|
||||||
admin_externalpage_setup('reportsecurity', '', null, '', ['pagelayout' => 'report']);
|
admin_externalpage_setup('reportsecurity', '', null, '', ['pagelayout' => 'report']);
|
||||||
|
|
||||||
// We may need a bit more memory and this may take a long time to process.
|
|
||||||
raise_memory_limit(MEMORY_EXTRA);
|
|
||||||
core_php_time_limit::raise();
|
|
||||||
|
|
||||||
$checks = \core\check\manager::get_security_checks();
|
|
||||||
|
|
||||||
$detail = optional_param('detail', '', PARAM_TEXT); // Show detailed info about one check only.
|
$detail = optional_param('detail', '', PARAM_TEXT); // Show detailed info about one check only.
|
||||||
if ($detail) {
|
|
||||||
$checks = array_filter($checks, function($check) use ($detail) {
|
$url = '/report/security/index.php';
|
||||||
return $detail == $check->get_ref();
|
$table = new core\check\table('security', $url, $detail);
|
||||||
});
|
|
||||||
$checks = array_values($checks);
|
if (!empty($table->detail)) {
|
||||||
if (!empty($checks)) {
|
$PAGE->set_docs_path($url . '?detail=' . $detail);
|
||||||
$PAGE->set_docs_path('report/security/index.php?detail=' . $detail);
|
$PAGE->navbar->add($table->detail->get_name());
|
||||||
$PAGE->navbar->add($checks[0]->get_name());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
echo $OUTPUT->header();
|
echo $OUTPUT->header();
|
||||||
echo $OUTPUT->heading(get_string('pluginname', 'report_security'));
|
echo $OUTPUT->heading(get_string('pluginname', 'report_security'));
|
||||||
|
echo $table->render($OUTPUT);
|
||||||
echo '<div id="timewarning">' . get_string('timewarning', 'report_security') . '</div>';
|
|
||||||
|
|
||||||
$url = "$CFG->wwwroot/report/security/index.php";
|
|
||||||
|
|
||||||
$PAGE->requires->js_init_code("Y.one('#timewarning').addClass('timewarninghidden')");
|
|
||||||
$table = new html_table();
|
|
||||||
$table->data = [];
|
|
||||||
$table->head = [
|
|
||||||
get_string('status'),
|
|
||||||
get_string('check'),
|
|
||||||
get_string('summary'),
|
|
||||||
get_string('action'),
|
|
||||||
];
|
|
||||||
$table->colclasses = [
|
|
||||||
'rightalign status',
|
|
||||||
'leftalign check',
|
|
||||||
'leftalign summary',
|
|
||||||
'leftalign action',
|
|
||||||
];
|
|
||||||
$table->id = 'securityreporttable';
|
|
||||||
$table->attributes = ['class' => 'admintable securityreport generaltable'];
|
|
||||||
|
|
||||||
$manager = core_plugin_manager::instance();
|
|
||||||
|
|
||||||
foreach ($checks as $check) {
|
|
||||||
$ref = $check->get_ref();
|
|
||||||
$result = $check->get_result();
|
|
||||||
$component = $check->get_component();
|
|
||||||
$actionlink = $check->get_action_link();
|
|
||||||
|
|
||||||
$link = new \moodle_url('/report/security/index.php', ['detail' => $ref]);
|
|
||||||
|
|
||||||
$row = [];
|
|
||||||
$row[] = $OUTPUT->check_result($result);
|
|
||||||
$row[] = $OUTPUT->action_link($link, $check->get_name());
|
|
||||||
|
|
||||||
$row[] = $result->get_summary();
|
|
||||||
if ($actionlink) {
|
|
||||||
$row[] = $OUTPUT->render($actionlink);
|
|
||||||
} else {
|
|
||||||
$row[] = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
$table->data[] = $row;
|
|
||||||
}
|
|
||||||
echo html_writer::table($table);
|
|
||||||
|
|
||||||
if ($detail && $result) {
|
|
||||||
echo $OUTPUT->heading(get_string('description'), 3);
|
|
||||||
echo $OUTPUT->box($result->get_details(), 'generalbox boxwidthnormal boxaligncenter');
|
|
||||||
echo $OUTPUT->continue_button($url);
|
|
||||||
}
|
|
||||||
|
|
||||||
echo $OUTPUT->footer();
|
echo $OUTPUT->footer();
|
||||||
|
|
||||||
$event = \report_security\event\report_viewed::create(['context' => context_system::instance()]);
|
$event = \report_security\event\report_viewed::create(['context' => context_system::instance()]);
|
||||||
$event->trigger();
|
$event->trigger();
|
||||||
|
|
||||||
|
|
|
@ -27,82 +27,20 @@ define('NO_OUTPUT_BUFFERING', true);
|
||||||
require('../../config.php');
|
require('../../config.php');
|
||||||
require_once($CFG->libdir.'/adminlib.php');
|
require_once($CFG->libdir.'/adminlib.php');
|
||||||
|
|
||||||
use core\check\check;
|
|
||||||
use core\check\result;
|
|
||||||
|
|
||||||
// Print the header.
|
|
||||||
admin_externalpage_setup('reportstatus', '', null, '', ['pagelayout' => 'report']);
|
admin_externalpage_setup('reportstatus', '', null, '', ['pagelayout' => 'report']);
|
||||||
|
|
||||||
// We may need a bit more memory and this may take a long time to process.
|
|
||||||
raise_memory_limit(MEMORY_EXTRA);
|
|
||||||
core_php_time_limit::raise();
|
|
||||||
|
|
||||||
$checks = \core\check\manager::get_checks('status');
|
|
||||||
|
|
||||||
$detail = optional_param('detail', '', PARAM_TEXT); // Show detailed info about one check only.
|
$detail = optional_param('detail', '', PARAM_TEXT); // Show detailed info about one check only.
|
||||||
if ($detail) {
|
|
||||||
$checks = array_filter($checks, function($check) use ($detail) {
|
$url = '/report/status/index.php';
|
||||||
return $detail == $check->get_ref();
|
$table = new core\check\table('status', $url, $detail);
|
||||||
});
|
|
||||||
$checks = array_values($checks);
|
if (!empty($table->detail)) {
|
||||||
if (!empty($checks)) {
|
$PAGE->set_docs_path($url . '?detail=' . $detail);
|
||||||
$PAGE->set_docs_path('report/status/index.php?detail=' . $detail);
|
$PAGE->navbar->add($table->detail->get_name());
|
||||||
$PAGE->navbar->add($checks[0]->get_name());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
echo $OUTPUT->header();
|
echo $OUTPUT->header();
|
||||||
echo $OUTPUT->heading(get_string('pluginname', 'report_status'));
|
echo $OUTPUT->heading(get_string('pluginname', 'report_status'));
|
||||||
|
echo $table->render($OUTPUT);
|
||||||
$url = "$CFG->wwwroot/report/status/index.php";
|
|
||||||
|
|
||||||
$table = new html_table();
|
|
||||||
$table->data = [];
|
|
||||||
$table->head = [
|
|
||||||
get_string('status'),
|
|
||||||
get_string('check'),
|
|
||||||
get_string('summary'),
|
|
||||||
get_string('action'),
|
|
||||||
];
|
|
||||||
$table->colclasses = [
|
|
||||||
'rightalign status',
|
|
||||||
'leftalign check',
|
|
||||||
'leftalign summary',
|
|
||||||
'leftalign action',
|
|
||||||
];
|
|
||||||
$table->id = 'statusreporttable';
|
|
||||||
$table->attributes = ['class' => 'admintable statusreport generaltable'];
|
|
||||||
|
|
||||||
$manager = core_plugin_manager::instance();
|
|
||||||
|
|
||||||
foreach ($checks as $check) {
|
|
||||||
$ref = $check->get_ref();
|
|
||||||
$result = $check->get_result();
|
|
||||||
$component = $check->get_component();
|
|
||||||
$actionlink = $check->get_action_link();
|
|
||||||
|
|
||||||
$link = new \moodle_url('/report/status/index.php', ['detail' => $ref]);
|
|
||||||
|
|
||||||
$row = [];
|
|
||||||
$row[] = $OUTPUT->result($result);
|
|
||||||
$row[] = $OUTPUT->action_link($link, $check->get_name());
|
|
||||||
|
|
||||||
$row[] = $result->get_summary();
|
|
||||||
if ($actionlink) {
|
|
||||||
$row[] = $OUTPUT->render($actionlink);
|
|
||||||
} else {
|
|
||||||
$row[] = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
$table->data[] = $row;
|
|
||||||
}
|
|
||||||
echo html_writer::table($table);
|
|
||||||
|
|
||||||
if ($detail && $result) {
|
|
||||||
echo $OUTPUT->heading(get_string('description'), 3);
|
|
||||||
echo $OUTPUT->box($result->get_details(), 'generalbox boxwidthnormal boxaligncenter');
|
|
||||||
echo $OUTPUT->continue_button($url);
|
|
||||||
}
|
|
||||||
|
|
||||||
echo $OUTPUT->footer();
|
echo $OUTPUT->footer();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue