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 namespace tool_brickfield\local\tool; 18 19 use tool_brickfield\manager; 20 21 /** 22 * Class errors. 23 * 24 * @package tool_brickfield 25 * @copyright 2020 onward: Brickfield Education Labs, www.brickfield.ie 26 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 27 */ 28 class errors extends tool { 29 30 /** 31 * Provide a name for this tool, suitable for display on pages. 32 * @return mixed|string 33 * @throws \coding_exception 34 */ 35 public static function toolname(): string { 36 return get_string('errors:toolname', 'tool_brickfield'); 37 } 38 39 /** 40 * Provide a short name for this tool, suitable for menus and selectors. 41 * @return mixed|string 42 * @throws \coding_exception 43 */ 44 public static function toolshortname(): string { 45 return get_string('errors:toolshortname', 'tool_brickfield'); 46 } 47 48 /** 49 * Provide a lowercase name identifying this plugin. Should really be the same as the directory name. 50 * @return string 51 */ 52 public function pluginname(): string { 53 return 'errors'; 54 } 55 56 /** 57 * Return the data for renderer / template display. 58 * @return \stdClass 59 * @throws \coding_exception 60 * @throws \dml_exception 61 */ 62 protected function fetch_data(): \stdClass { 63 global $DB; 64 65 $filter = $this->get_filter(); 66 if (!$filter->validate_filters()) { 67 return (object)[ 68 'valid' => false, 69 'error' => $filter->get_errormessage(), 70 ]; 71 72 } 73 74 $data = (object)[ 75 'valid' => true, 76 'error' => '', 77 ]; 78 79 list($wheresql, $params) = $filter->get_course_sql(); 80 $sql = 'SELECT err.id as errid, res.id as resid, area.*, 81 res.checkid, err.linenumber as errline, err.htmlcode 82 FROM {' . manager::DB_AREAS . '} area 83 INNER JOIN {' . manager::DB_CONTENT . '} ch ON ch.areaid = area.id AND ch.iscurrent = 1 84 INNER JOIN {' . manager::DB_RESULTS . '} res ON res.contentid = ch.id 85 INNER JOIN {' . manager::DB_ERRORS . '} err ON res.id = err.resultid 86 WHERE 1=1 ' . $wheresql .' 87 ORDER BY area.courseid, area.component ASC'; 88 89 $errordata = $DB->get_records_sql($sql, $params, ($filter->page * $filter->perpage), $filter->perpage); 90 91 // Adding check displaynames and component names from language strings. 92 $checks = $DB->get_records_menu(manager::DB_CHECKS, ['status' => 1], '', 'id, shortname'); 93 foreach ($errordata as $value) { 94 $value->shortname = $checks[$value->checkid]; 95 $value->checkdesc = self::get_check_description($value->shortname); 96 // Truncating HTML with base64 image data, to avoid page overstretching. 97 $base64detected = parent::base64_img_detected($value->htmlcode); 98 if ($base64detected) { 99 $value->htmlcode = parent::truncate_base64($value->htmlcode); 100 } 101 } 102 103 $countsql = 'SELECT COUNT(err.id) 104 FROM {' . manager::DB_AREAS . '} area 105 INNER JOIN {' . manager::DB_CONTENT . '} ch ON ch.areaid = area.id AND ch.iscurrent = 1 106 INNER JOIN {' . manager::DB_RESULTS . '} res ON res.contentid = ch.id 107 INNER JOIN {' . manager::DB_ERRORS . '} err ON res.id = err.resultid 108 WHERE 1=1 ' . $wheresql; 109 110 if (($filter->courseid == 0) 111 && ($filter->categoryid == 0)) { 112 $countsql = 'SELECT COUNT(err.id) 113 FROM {' . manager::DB_CONTENT . '} ch 114 INNER JOIN {' . manager::DB_RESULTS . '} res ON res.contentid = ch.id AND ch.iscurrent = 1 115 INNER JOIN {' . manager::DB_ERRORS . '} err ON res.id = err.resultid 116 WHERE 1=1 ' . $wheresql; 117 } 118 119 $errortotal = $DB->count_records_sql($countsql, $params); 120 121 $data->errordata = $errordata; 122 $data->errortotal = $errortotal; 123 124 if ($filter->categoryid != 0) { 125 $data->countdata = count($filter->courseids); 126 } else { 127 $countsql = 'select count(distinct courseid) from {' . manager::DB_AREAS . '}'; 128 $countdata = $DB->count_records_sql($countsql, []); 129 $data->countdata = $countdata; 130 } 131 132 return $data; 133 } 134 135 /** 136 * Errors needs to use perpage for pages. 137 * 138 * @param int $perpage 139 * @return int 140 */ 141 public function perpage_limits(int $perpage): int { 142 $config = get_config(manager::PLUGINNAME); 143 return $config->perpage; 144 } 145 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body