Differences Between: [Versions 311 and 403] [Versions 400 and 403] [Versions 401 and 403]
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\output; 18 19 use tool_brickfield\accessibility; 20 use plugin_renderer_base; 21 use moodle_url; 22 use tabobject; 23 use tabtree; 24 use html_writer; 25 use tool_brickfield\analysis; 26 use tool_brickfield\local\tool\filter; 27 use tool_brickfield\local\tool\tool; 28 use tool_brickfield\manager; 29 use tool_brickfield\scheduler; 30 31 /** 32 * tool_brickfield renderer 33 * 34 * @package tool_brickfield 35 * @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie 36 * @author Bas Brands 37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 38 */ 39 class renderer extends plugin_renderer_base { 40 41 /** 42 * Render the page containing the tool report. 43 * 44 * @param \stdClass $data Report data. 45 * @param filter $filter Display filters. 46 * @return String HTML showing charts. 47 */ 48 public function display(\stdClass $data, filter $filter): string { 49 $component = 'tool_brickfield'; 50 $subtype = $filter->tab; 51 $toolrenderer = $this->page->get_renderer($component, $subtype); 52 if (!empty($toolrenderer)) { 53 return $toolrenderer->display($data, $filter); 54 } 55 } 56 57 /** 58 * Render the valid tabs. 59 * 60 * @param filter $filter 61 * @param array $tools 62 * @return string 63 * @throws \moodle_exception 64 */ 65 public function tabs(filter $filter, array $tools): string { 66 $idprefix = 'tab_'; 67 $tabs = []; 68 foreach ($tools as $toolname => $tool) { 69 $link = new moodle_url( 70 accessibility::get_plugin_url(), 71 array_merge(['tab' => $toolname, ], $tool->toplevel_arguments($filter)) 72 ); 73 if (isset($altlabel[$toolname])) { 74 $label = $altlabel[$toolname]; 75 } else { 76 $label = $tool->get_toolshortname(); 77 } 78 $tab = new tabobject($idprefix . $toolname, $link, $label); 79 $tabs[] = $tab; 80 } 81 return $this->render(new tabtree($tabs, $idprefix . $filter->tab)); 82 } 83 84 /** 85 * Renders tabtree 86 * 87 * @param tabtree $tabtree 88 * @return string 89 * @throws \moodle_exception 90 */ 91 protected function render_tabtree(tabtree $tabtree): string { 92 if (empty($tabtree->subtree)) { 93 return ''; 94 } 95 $data = $tabtree->export_for_template($this); 96 foreach ($data->tabs as $idx => $tab) { 97 if (isset($tabtree->subtree[$idx]->extraclass)) { 98 $data->tabs[$idx]->extraclass = $tabtree->subtree[$idx]->extraclass; 99 } 100 } 101 return $this->render_from_template(manager::PLUGINNAME . '/tabtree', $data); 102 } 103 104 /** 105 * Render the cache alert message. 106 * 107 * @return string 108 * @throws \coding_exception 109 * @throws \dml_exception 110 */ 111 public function cachealert(): string { 112 $html = ''; 113 if (!analysis::is_enabled()) { 114 $html = \html_writer::div(get_string('analysistypedisabled', manager::PLUGINNAME), 115 '', ['class' => 'alert alert-primary']); 116 } 117 return $html; 118 } 119 120 /** 121 * This function assumes that 'scheduler::is_analysed' has already failed. 122 * @param int $courseid 123 * @return string 124 * @throws \coding_exception 125 * @throws \moodle_exception 126 */ 127 public function analysisalert(int $courseid): string { 128 $siteorcourse = ($courseid == SITEID) ? 'site' : ''; 129 if (scheduler::is_course_in_schedule($courseid)) { 130 $html = \html_writer::div(get_string('schedule:' . $siteorcourse . 'scheduled', manager::PLUGINNAME), 131 '', ['class' => 'alert alert-primary']); 132 } else { 133 $html = \html_writer::div( 134 get_string('schedule:' . $siteorcourse . 'notscheduled', manager::PLUGINNAME, manager::get_helpurl()), 135 '', ['class' => 'alert alert-primary'] 136 ); 137 $html .= $this->analysisbutton($courseid); 138 } 139 return $html; 140 } 141 142 /** 143 * Render the "not validated" alert message. 144 * 145 * @return string 146 * @throws \coding_exception 147 */ 148 public function notvalidatedalert(): string { 149 return \html_writer::div(get_string('notvalidated', manager::PLUGINNAME), '', ['class' => 'alert alert-primary']); 150 } 151 152 /** 153 * Render the analysis request button. 154 * 155 * @param int $courseid 156 * @return string 157 * @throws \coding_exception 158 * @throws \moodle_exception 159 */ 160 public function analysisbutton(int $courseid) : string { 161 $link = new moodle_url(accessibility::get_plugin_url(), [ 162 'action' => 'requestanalysis', 163 'courseid' => $courseid 164 ]); 165 166 $classname = manager::PLUGINNAME . '_analysisbutton'; 167 168 $button = new \single_button( 169 $link, 170 get_string('schedule:requestanalysis', manager::PLUGINNAME), 171 'post', 172 \single_button::BUTTON_PRIMARY, 173 ['class' => $classname] 174 ); 175 176 return html_writer::tag('div', $this->render($button), ['class' => $classname]); 177 } 178 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body