Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402] [Versions 400 and 402] [Versions 401 and 402]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 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. 8 // 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. 13 // 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/>. 16 17 /** 18 * A table of check results 19 * 20 * @package core 21 * @category check 22 * @copyright 2020 Brendan Heywood <brendan@catalyst-au.net> 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 namespace core\check; 26 27 defined('MOODLE_INTERNAL') || die(); 28 29 /** 30 * A table of check results 31 * 32 * @copyright 2020 Brendan Heywood <brendan@catalyst-au.net> 33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 34 */ 35 class table implements \renderable { 36 37 /** 38 * @var \moodle_url $url 39 */ 40 protected $url = ''; 41 42 /** 43 * @var string $type What type of checks 44 */ 45 protected $type = ''; 46 47 /** 48 * @var check $detail a specific check to focus on 49 */ 50 public $detail = ''; 51 52 /** 53 * @var array $checks shown in this table 54 */ 55 public $checks = []; 56 57 /** 58 * Constructor 59 * 60 * @param string $type of check 61 * @param string $url of report 62 * @param string $detail check to focus on 63 */ 64 public function __construct($type, $url, $detail = '') { 65 66 // We may need a bit more memory and this may take a long time to process. 67 \raise_memory_limit(MEMORY_EXTRA); 68 \core_php_time_limit::raise(); 69 70 $this->type = $type; 71 $this->url = $url; 72 $this->checks = \core\check\manager::get_checks($type); 73 74 if ($detail) { 75 $this->checks = array_filter($this->checks, function($check) use ($detail) { 76 return $detail == $check->get_ref(); 77 }); 78 if (!empty($this->checks)) { 79 $this->detail = reset($this->checks); 80 } 81 } 82 } 83 84 /** 85 * Render a table of checks 86 * 87 * @param renderer $output to use 88 * @return string html output 89 */ 90 public function render($output) { 91 92 $table = new \html_table(); 93 $table->data = []; 94 $table->head = [ 95 get_string('status'), 96 get_string('check'), 97 get_string('summary'), 98 get_string('action'), 99 ]; 100 $table->colclasses = [ 101 'rightalign status', 102 'leftalign check', 103 'leftalign summary', 104 'leftalign action', 105 ]; 106 $table->id = $this->type . 'reporttable'; 107 $table->attributes = ['class' => 'admintable ' . $this->type . 'report generaltable']; 108 109 foreach ($this->checks as $check) { 110 $ref = $check->get_ref(); 111 $result = $check->get_result(); 112 $component = $check->get_component(); 113 $actionlink = $check->get_action_link(); 114 115 $link = new \moodle_url($this->url, ['detail' => $ref]); 116 117 $row = []; 118 $row[] = $output->check_result($result); 119 $row[] = $output->action_link($link, $check->get_name()); 120 121 $row[] = $result->get_summary() 122 . '<br>' 123 . \html_writer::start_tag('small') 124 . $output->action_link($link, get_string('moreinfo')) 125 . \html_writer::end_tag('small'); 126 if ($actionlink) { 127 $row[] = $output->render($actionlink); 128 } else { 129 $row[] = ''; 130 } 131 132 $table->data[] = $row; 133 } 134 $html = \html_writer::table($table); 135 136 if ($this->detail && $result) { 137 $html .= $output->heading(get_string('details'), 3); 138 $html .= $output->box($result->get_details(), 'generalbox boxwidthnormal boxaligncenter'); 139 $html .= $output->continue_button($this->url); 140 } 141 142 return $html; 143 } 144 } 145
title
Description
Body
title
Description
Body
title
Description
Body
title
Body