Differences Between: [Versions 402 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 item from a section. 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\section; 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 renderer_base; 33 use section_info; 34 use stdClass; 35 36 /** 37 * Base class to render a section activity in the activities list. 38 * 39 * @package core_courseformat 40 * @copyright 2020 Ferran Recio <ferran@moodle.com> 41 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 42 */ 43 class cmitem implements named_templatable, renderable { 44 45 use courseformat_named_templatable; 46 47 /** @var course_format the course format class */ 48 protected $format; 49 50 /** @var section_info the course section class */ 51 protected $section; 52 53 /** @var cm_info the course module to display */ 54 protected $mod; 55 56 /** @var array optional display options */ 57 protected $displayoptions; 58 59 /** @var string the cm output class name */ 60 protected $cmclass; 61 62 /** 63 * Constructor. 64 * 65 * @param course_format $format the course format 66 * @param section_info $section the section info 67 * @param cm_info $mod the course module ionfo 68 * @param array $displayoptions optional extra display options 69 */ 70 public function __construct(course_format $format, section_info $section, cm_info $mod, array $displayoptions = []) { 71 $this->format = $format; 72 $this->section = $section; 73 $this->mod = $mod; 74 $this->displayoptions = $displayoptions; 75 76 // Get the necessary classes. 77 $this->cmclass = $format->get_output_classname('content\\cm'); 78 } 79 80 /** 81 * Export this data so it can be used as the context for a mustache template. 82 * 83 * @param renderer_base $output typically, the renderer that's calling this function 84 * @return stdClass data context for a mustache template 85 */ 86 public function export_for_template(\renderer_base $output): stdClass { 87 $format = $this->format; 88 $course = $format->get_course(); 89 $mod = $this->mod; 90 91 $data = new stdClass(); 92 $data->cms = []; 93 94 $completionenabled = $course->enablecompletion == COMPLETION_ENABLED; 95 $showactivityconditions = $completionenabled && $course->showcompletionconditions == COMPLETION_SHOW_CONDITIONS; 96 $showactivitydates = !empty($course->showactivitydates); 97 98 // This will apply styles to the course homepage when the activity information output component is displayed. 99 $hasinfo = $showactivityconditions || $showactivitydates; 100 101 $item = new $this->cmclass($format, $this->section, $mod, $this->displayoptions); 102 return (object)[ 103 'id' => $mod->id, 104 'anchor' => "module-{$mod->id}", 105 'module' => $mod->modname, 106 'extraclasses' => $mod->extraclasses, 107 'cmformat' => $item->export_for_template($output), 108 'hasinfo' => $hasinfo, 109 'indent' => ($format->uses_indentation()) ? $mod->indent : 0, 110 ]; 111 } 112 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body