Differences Between: [Versions 400 and 401] [Versions 400 and 402] [Versions 400 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 /** 18 * Contains the default activity name inplace editable. 19 * 20 * @package core_courseformat 21 * @copyright 2020 Ferran Recio <ferran@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 section_info; 33 use stdClass; 34 35 /** 36 * Base class to render a course module inplace editable header. 37 * 38 * @package core_courseformat 39 * @copyright 2020 Ferran Recio <ferran@moodle.com> 40 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 41 */ 42 class cmname implements named_templatable, renderable { 43 44 use courseformat_named_templatable; 45 46 /** @var course_format the course format */ 47 protected $format; 48 49 /** @var section_info the section object */ 50 private $section; 51 52 /** @var cm_info the course module instance */ 53 protected $mod; 54 55 /** @var array optional display options */ 56 protected $displayoptions; 57 58 /** @var string the activity title output class name */ 59 protected $titleclass; 60 61 /** 62 * Constructor. 63 * 64 * @param course_format $format the course format 65 * @param section_info $section the section info 66 * @param cm_info $mod the course module ionfo 67 * @param bool|null $editable if it is editable (not used) 68 * @param array $displayoptions optional extra display options 69 */ 70 public function __construct( 71 course_format $format, 72 section_info $section, 73 cm_info $mod, 74 ?bool $editable = null, 75 array $displayoptions = [] 76 ) { 77 $this->format = $format; 78 $this->section = $section; 79 $this->mod = $mod; 80 $this->displayoptions = $displayoptions; 81 82 // Get the necessary classes. 83 $this->titleclass = $format->get_output_classname('content\\cm\\title'); 84 } 85 86 /** 87 * Export this data so it can be used as the context for a mustache template. 88 * 89 * @param \renderer_base $output typically, the renderer that's calling this function 90 * @return stdClass data context for a mustache template 91 */ 92 public function export_for_template(\renderer_base $output): array { 93 $mod = $this->mod; 94 $displayoptions = $this->displayoptions; 95 96 if (!$this->has_name()) { 97 // Nothing to be displayed to the user. 98 return []; 99 } 100 101 $iconurl = $mod->get_icon_url(); 102 $iconclass = $iconurl->get_param('filtericon') ? '' : 'nofilter'; 103 $data = [ 104 'url' => $mod->url, 105 'icon' => $iconurl, 106 'iconclass' => $iconclass, 107 'modname' => $mod->modname, 108 'textclasses' => $displayoptions['textclasses'] ?? '', 109 'purpose' => plugin_supports('mod', $mod->modname, FEATURE_MOD_PURPOSE, MOD_PURPOSE_OTHER), 110 'activityname' => $this->get_title_data($output), 111 ]; 112 113 if ($this->format->show_editor()) { 114 $data['pluginname'] = get_string('pluginname', 'mod_' . $mod->modname); 115 } 116 117 return $data; 118 } 119 120 /** 121 * Get the title data. 122 * 123 * @param \renderer_base $output typically, the renderer that's calling this function 124 * @return array data context for a mustache template 125 */ 126 protected function get_title_data(\renderer_base $output): array { 127 $title = new $this->titleclass( 128 $this->format, 129 $this->section, 130 $this->mod, 131 $this->displayoptions 132 ); 133 return (array) $title->export_for_template($output); 134 } 135 136 /** 137 * Return if the activity has a visible name. 138 * 139 * @return bool if the title is visible. 140 */ 141 public function has_name(): bool { 142 return $this->mod->is_visible_on_course_page() && $this->mod->url; 143 } 144 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body