Skip to content

Commit

Permalink
Add status_table.php
Browse files Browse the repository at this point in the history
  • Loading branch information
Owen Herbert committed Dec 7, 2023
1 parent 3e9e109 commit f0fec86
Showing 1 changed file with 99 additions and 0 deletions.
99 changes: 99 additions & 0 deletions classes/table/status_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?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 2023 Owen Herbert <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace tool_heartbeat\table;

use core\check\table;
use html_writer;
use renderer;
use tool_heartbeat\object\override;

defined('MOODLE_INTERNAL') || die();

/**
* A table of check results
*
* @copyright 2020 Brendan Heywood <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class status_table extends table {

/**
* Render a table of checks
*
* @param renderer $output to use
* @return string html output
*/
public function render($output) {

$html = '';

// create new override button
$link = new \moodle_url('/admin/tool/heartbeat/override.php');
$html .= html_writer::link($link, get_string('buttoncreate', 'tool_heartbeat'), ['class' => 'btn btn-primary mb-2']);

$table = new \html_table();
$table->data = [];
$table->head = [
get_string('status'),
get_string('check'),
get_string('summary'),
get_string('headeroverride', 'tool_heartbeat'),
];
$table->colclasses = [
'rightalign status',
'leftalign check',
'leftalign summary',
'leftalign exemption',
'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();
$report_link = new \moodle_url('/report/status/index.php', ['detail' => $ref]);
$display_link = strpos($ref, 'failingtaskcheck') !== false;
$override_link = new \moodle_url('/admin/tool/heartbeat/status.php', ['ref' => $ref]);

$row = [];
$row[] = $output->check_result($result);
$row[] = $output->action_link($report_link, $check->get_name());

$row[] = $result->get_summary()
. '<br>'
. \html_writer::start_tag('small')
. $output->action_link($report_link, get_string('moreinfo'))
. \html_writer::end_tag('small');

$row[] = $display_link ? html_writer::link($override_link, get_string('buttonmanage', 'tool_heartbeat'), ['class' => 'btn btn-primary']) : '';
$table->data[] = $row;
}
$html .= \html_writer::table($table);

return $html;
}
}

0 comments on commit f0fec86

Please sign in to comment.