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 * Contains the default activity icon. 19 * 20 * @package core_courseformat 21 * @copyright 2023 Mikel Martin <mikel@moodle.com> 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 namespace core_courseformat\output\local\content\cm; 26 27 use cm_info; 28 use core\output\named_templatable; 29 use core_courseformat\base as course_format; 30 use core_courseformat\output\local\courseformat_named_templatable; 31 use renderable; 32 use stdClass; 33 34 /** 35 * Base class to render a course module icon. 36 * 37 * @package core_courseformat 38 * @copyright 2023 Mikel Martin <mikel@moodle.com> 39 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 40 */ 41 class cmicon implements named_templatable, renderable { 42 43 use courseformat_named_templatable; 44 45 /** @var course_format the course format */ 46 protected $format; 47 48 /** @var cm_info the course module instance */ 49 protected $mod; 50 51 /** 52 * Constructor. 53 * 54 * @param course_format $format the course format 55 * @param cm_info $mod the course module ionfo 56 */ 57 public function __construct( 58 course_format $format, 59 cm_info $mod, 60 ) { 61 $this->format = $format; 62 $this->mod = $mod; 63 } 64 65 /** 66 * Export this data so it can be used as the context for a mustache template. 67 * 68 * @param \renderer_base $output typically, the renderer that's calling this function 69 * @return stdClass data context for a mustache template 70 */ 71 public function export_for_template(\renderer_base $output): array { 72 $mod = $this->mod; 73 74 if (!$this->is_icon_visible()) { 75 // Nothing to be displayed to the user. 76 return []; 77 } 78 79 $iconurl = $mod->get_icon_url(); 80 $iconclass = $iconurl->get_param('filtericon') ? '' : 'nofilter'; 81 $data = [ 82 'uservisible' => $mod->uservisible, 83 'url' => $mod->url, 84 'icon' => $iconurl, 85 'iconclass' => $iconclass, 86 'modname' => $mod->modname, 87 'pluginname' => get_string('pluginname', 'mod_' . $mod->modname), 88 'showtooltip' => $this->format->show_editor(), 89 'purpose' => plugin_supports('mod', $mod->modname, FEATURE_MOD_PURPOSE, MOD_PURPOSE_OTHER), 90 ]; 91 92 return $data; 93 } 94 95 /** 96 * Return if the activity has a visible icon. 97 * 98 * @return bool if the icon should be shown. 99 */ 100 public function is_icon_visible(): bool { 101 return $this->mod->is_visible_on_course_page() && $this->mod->url; 102 } 103 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body