Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 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 use tool_brickfield\accessibility; 18 use tool_brickfield\analysis; 19 use tool_brickfield\area_base; 20 use tool_brickfield\local\tool\filter; 21 use tool_brickfield\manager; 22 use tool_brickfield\registration; 23 use tool_brickfield\scheduler; 24 use tool_brickfield\sitedata; 25 26 /** 27 * Definition of the accessreview block. 28 * 29 * @package block_accessreview 30 * @copyright 2019 Karen Holland LTS.ie 31 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 32 */ 33 class block_accessreview extends block_base { 34 /** 35 * Sets the block title. 36 */ 37 public function init(): void { 38 $this->title = get_string('errorssummary', 'block_accessreview'); 39 } 40 41 /** 42 * Defines where the block can be added. 43 * 44 * @return array 45 */ 46 public function applicable_formats(): array { 47 return [ 48 'course-view' => true, 49 'site' => true, 50 'mod' => false, 51 'my' => false, 52 ]; 53 } 54 55 /** 56 * Controls global configurability of block. 57 * 58 * @return bool 59 */ 60 public function has_config(): bool { 61 return true; 62 } 63 64 /** 65 * Controls whether multiple block instances are allowed. 66 * 67 * @return bool 68 */ 69 public function instance_allow_multiple(): bool { 70 return false; 71 } 72 73 /** 74 * Creates the block's main content 75 * 76 * @return string|stdClass 77 */ 78 public function get_content() { 79 global $COURSE, $OUTPUT; 80 81 // If Brickfield accessibility toolkit has been disabled, do nothing. 82 if (!accessibility::is_accessibility_enabled()) { 83 return ''; 84 } 85 86 if (isset($this->content)) { 87 return $this->content; 88 } 89 90 $this->content = new stdClass; 91 $this->content->text = ''; 92 93 // Check to see user can view/use the accessmap. 94 $context = context_course::instance($COURSE->id); 95 if (!isloggedin() || isguestuser() || !has_capability('block/accessreview:view', $context)) { 96 return $this->content; 97 } 98 99 // Check for valid registration. 100 if (!(new registration())->toolkit_is_active()) { 101 $this->content->text = manager::registration_message(); 102 } else if (scheduler::is_course_analyzed($COURSE->id)) { 103 // Build error data table. 104 $table = new html_table(); 105 $table->head = [ 106 get_string('checktypes', 'block_accessreview'), get_string('errors', 'block_accessreview') 107 ]; 108 $table->align = ['left', 'center']; 109 $tabledata = $this->get_table_data($COURSE->id); 110 // Handling no data. 111 if ($tabledata === null) { 112 $this->content->text = get_string('nodata', 'block_accessreview'); 113 return $this->content; 114 } 115 $table->data = $tabledata; 116 $table->attributes['class'] = 'generaltable table-sm block_accessreview_table'; 117 $this->content->text .= html_writer::table($table, true); 118 119 // Check for compatible course formats for highlighting. 120 $showhighlighting = false; 121 switch ($COURSE->format) { 122 case accessibility::TOOL_BRICKFIELD_FORMAT_TOPIC: 123 case accessibility::TOOL_BRICKFIELD_FORMAT_WEEKLY: 124 $showhighlighting = true; 125 break; 126 } 127 128 // Toggle overlay link. 129 $toggle = ($showhighlighting) ? $this->get_toggle_link() : ''; 130 // Report download link. 131 $download = $this->get_download_link($context); 132 // Report view link. 133 $view = $this->get_report_link($context); 134 135 $this->content->text .= html_writer::tag('div', $toggle . $view . $download, [ 136 'class' => 'block_accessreview_links' 137 ] 138 ); 139 140 if ($showhighlighting) { 141 // Setting up AMD module. 142 $whattoshow = get_config('block_accessreview', 'whattoshow'); 143 $toggled = get_user_preferences('block_accessreviewtogglestate', true); 144 $arguments = [$toggled, $whattoshow, $COURSE->id]; 145 $this->page->requires->js_call_amd('block_accessreview/module', 'init', $arguments); 146 } 147 } else if (scheduler::is_course_in_schedule($COURSE->id)) { 148 // Display a message that the course is awaiting analysis. 149 $this->content->text = get_string('schedule:scheduled', manager::PLUGINNAME); 150 } else if (!analysis::is_enabled()) { 151 $this->content->text = get_string('analysistypedisabled', manager::PLUGINNAME); 152 } else { 153 // Display a button to request analysis. 154 $this->content->text = get_string('schedule:blocknotscheduled', manager::PLUGINNAME, manager::get_helpurl()); 155 156 $button = new single_button( 157 new moodle_url(accessibility::get_plugin_url(), ['action' => 'requestanalysis', 'courseid' => $COURSE->id]), 158 get_string('schedule:requestanalysis', manager::PLUGINNAME), 'post', true, 159 ['class' => 'block_accessreview_analysisbutton']); 160 $this->content->text .= html_writer::tag('div', $OUTPUT->render($button), 161 ['class' => 'block_accessreview_analysisbutton']); 162 } 163 164 return $this->content; 165 } 166 167 /** 168 * Fetches and groups the relevent error data for the table to display. 169 * @param int $courseid The ID of the course. 170 * @return array The data required by the table. 171 * @throws coding_exception 172 * @throws moodle_exception 173 */ 174 protected function get_table_data($courseid): array { 175 global $OUTPUT; 176 $datafilters = new filter($courseid, 0); 177 $errordisplay = get_config('block_accessreview', 'errordisplay'); 178 $summarydata = (new sitedata())->get_checkgroup_data($datafilters); 179 $data = []; 180 $count = 0; 181 for ($i = 1; $count < $summarydata[0]->groupcount; $i++) { 182 if (isset($summarydata[0]->{'componentlabel' . $i})) { 183 $data[$i] = $summarydata[0]->{'errorsvalue' . $i}; 184 $count++; 185 } 186 } 187 $files = [ 188 'form' => '', 189 'image' => '231/', 190 'layout' => '234/', 191 'link' => '237/', 192 'media' => '240/', 193 'table' => '243/', 194 'text' => '246/', 195 ]; 196 // Populating table data. 197 $tabledata = []; 198 foreach ($data as $key => $total) { 199 // If the total is empty it means there is no results yet in the table. 200 if ($total === null) { 201 continue; 202 } 203 $type = area_base::checkgroup_name($key); 204 // Error display data. 205 $display = $total; 206 // Icons. 207 $typeicon = $OUTPUT->pix_icon('f/' . $type, '', 'block_accessreview'); 208 if ($errordisplay == 'showicon') { 209 $thistype = $total == 0 ? 'smile' : 'frown'; 210 $display = $OUTPUT->pix_icon($thistype, 211 get_string($thistype, 'block_accessreview'), 'block_accessreview' 212 ); 213 } else if ($errordisplay == 'showpercent') { 214 $display = round(($total), 1) . '%'; 215 } 216 $tabledata[] = [$typeicon . get_string('checktype:' . $type, manager::PLUGINNAME), $display]; 217 } 218 return $tabledata; 219 } 220 221 /** 222 * Get the link to toggle the heatmap. 223 * 224 * @return string 225 * @throws coding_exception 226 */ 227 protected function get_toggle_link(): string { 228 global $OUTPUT; 229 230 if (get_user_preferences('block_accessreviewtogglestate')) { 231 $icon = 't/hide'; 232 } else { 233 $icon = 't/show'; 234 } 235 236 // Toggle overlay link. 237 return html_writer::link( 238 '#', 239 $OUTPUT->pix_icon($icon, get_string('togglealt', 'block_accessreview'), 'moodle', ['class' => 'icon-accessmap']), 240 [ 241 'title' => get_string('togglealt', 'block_accessreview'), 242 'style' => 'cursor: pointer;', 243 'id' => 'toggle-accessmap', 244 'class' => 'block_accessreview_link', 245 ] 246 ); 247 } 248 249 /** 250 * Get the link to download a report for the specified context. 251 * 252 * @param context $context 253 * @return string 254 * @throws coding_exception 255 * @throws moodle_exception 256 */ 257 protected function get_download_link(context $context): string { 258 global $OUTPUT, $COURSE; 259 260 if (has_capability(accessibility::get_capability_name('viewcoursetools'), $context)) { 261 return html_writer::link( 262 new moodle_url(accessibility::get_plugin_url(), 263 [ 264 'courseid' => $COURSE->id, 265 'tab' => 'printable', 266 'target' => 'pdf', 267 ] 268 ), 269 $OUTPUT->pix_icon('a/download_all', get_string('downloadreportalt', 'block_accessreview')), 270 [ 271 'title' => get_string('downloadreportalt', 'block_accessreview'), 272 'class' => 'block_accessreview_link download-accessmap', 273 ] 274 ); 275 } else { 276 return ''; 277 } 278 } 279 280 /** 281 * Get the report link for the specified context. 282 * 283 * @param context $context 284 * @return string 285 * @throws coding_exception 286 * @throws dml_exception 287 * @throws moodle_exception 288 */ 289 protected function get_report_link(context $context): string { 290 global $OUTPUT, $COURSE; 291 292 if (has_capability(accessibility::get_capability_name('viewcoursetools'), $context)) { 293 return html_writer::link( 294 new moodle_url(accessibility::get_plugin_url(), 295 [ 296 'courseid' => $COURSE->id, 297 'tab' => get_config('block_accessreview', 'toolpage'), 298 ] 299 ), 300 $OUTPUT->pix_icon('f/find', get_string('viewreportalt', 'block_accessreview'), 'block_accessreview'), 301 [ 302 'title' => get_string('viewreportalt', 'block_accessreview'), 303 'class' => 'block_accessreview_link report-accessmap', 304 ] 305 ); 306 } else { 307 return ''; 308 } 309 } 310 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body