| 1 | efrain | 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 section header format output class.
 | 
        
           |  |  | 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 core\output\named_templatable;
 | 
        
           |  |  | 28 | use core_courseformat\base as course_format;
 | 
        
           |  |  | 29 | use core_courseformat\output\local\courseformat_named_templatable;
 | 
        
           |  |  | 30 | use renderable;
 | 
        
           |  |  | 31 | use section_info;
 | 
        
           |  |  | 32 | use stdClass;
 | 
        
           |  |  | 33 |   | 
        
           |  |  | 34 | /**
 | 
        
           |  |  | 35 |  * Base class to render a section header.
 | 
        
           |  |  | 36 |  *
 | 
        
           |  |  | 37 |  * @package   core_courseformat
 | 
        
           |  |  | 38 |  * @copyright 2020 Ferran Recio <ferran@moodle.com>
 | 
        
           |  |  | 39 |  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 | 
        
           |  |  | 40 |  */
 | 
        
           |  |  | 41 | class header implements named_templatable, renderable {
 | 
        
           |  |  | 42 |   | 
        
           |  |  | 43 |     use courseformat_named_templatable;
 | 
        
           |  |  | 44 |   | 
        
           |  |  | 45 |     /** @var course_format the course format class */
 | 
        
           |  |  | 46 |     protected $format;
 | 
        
           |  |  | 47 |   | 
        
           |  |  | 48 |     /** @var section_info the course section class */
 | 
        
           |  |  | 49 |     protected $section;
 | 
        
           |  |  | 50 |   | 
        
           |  |  | 51 |     /**
 | 
        
           |  |  | 52 |      * Constructor.
 | 
        
           |  |  | 53 |      *
 | 
        
           |  |  | 54 |      * @param course_format $format the course format
 | 
        
           |  |  | 55 |      * @param section_info $section the section info
 | 
        
           |  |  | 56 |      */
 | 
        
           |  |  | 57 |     public function __construct(course_format $format, section_info $section) {
 | 
        
           |  |  | 58 |         $this->format = $format;
 | 
        
           |  |  | 59 |         $this->section = $section;
 | 
        
           |  |  | 60 |     }
 | 
        
           |  |  | 61 |   | 
        
           |  |  | 62 |     /**
 | 
        
           |  |  | 63 |      * Export this data so it can be used as the context for a mustache template.
 | 
        
           |  |  | 64 |      *
 | 
        
           |  |  | 65 |      * @param renderer_base $output typically, the renderer that's calling this function
 | 
        
           |  |  | 66 |      * @return array data context for a mustache template
 | 
        
           |  |  | 67 |      */
 | 
        
           |  |  | 68 |     public function export_for_template(\renderer_base $output): stdClass {
 | 
        
           |  |  | 69 |   | 
        
           |  |  | 70 |         $format = $this->format;
 | 
        
           |  |  | 71 |         $section = $this->section;
 | 
        
           |  |  | 72 |         $course = $format->get_course();
 | 
        
           |  |  | 73 |   | 
        
           |  |  | 74 |         $data = (object)[
 | 
        
           |  |  | 75 |             'num' => $section->section,
 | 
        
           |  |  | 76 |             'id' => $section->id,
 | 
        
           |  |  | 77 |         ];
 | 
        
           |  |  | 78 |   | 
        
           |  |  | 79 |         $data->editing = $format->show_editor();
 | 
        
           |  |  | 80 |   | 
        
           |  |  | 81 |         if ($course->id == SITEID) {
 | 
        
           |  |  | 82 |             $data->title = $output->section_title_without_link($section, $course);
 | 
        
           |  |  | 83 |             $data->sitehome = true;
 | 
        
           |  |  | 84 |         } else {
 | 
        
           | 1441 | ariadna | 85 |             if (is_null($format->get_sectionid()) || $format->get_sectionid() != $section->id) {
 | 
        
           | 1 | efrain | 86 |                 // All sections are displayed.
 | 
        
           |  |  | 87 |                 if (!$data->editing) {
 | 
        
           |  |  | 88 |                     $data->title = $output->section_title($section, $course);
 | 
        
           |  |  | 89 |                 } else {
 | 
        
           |  |  | 90 |                     $data->title = $output->section_title_without_link($section, $course);
 | 
        
           |  |  | 91 |                 }
 | 
        
           |  |  | 92 |             } else {
 | 
        
           |  |  | 93 |                 // Only one section is displayed.
 | 
        
           |  |  | 94 |                 $data->displayonesection = true;
 | 
        
           |  |  | 95 |                 $data->title = $output->section_title_without_link($section, $course);
 | 
        
           |  |  | 96 |             }
 | 
        
           |  |  | 97 |         }
 | 
        
           |  |  | 98 |   | 
        
           |  |  | 99 |         $coursedisplay = $format->get_course_display();
 | 
        
           |  |  | 100 |         $data->headerdisplaymultipage = ($coursedisplay == COURSE_DISPLAY_MULTIPAGE);
 | 
        
           |  |  | 101 |   | 
        
           |  |  | 102 |         if ($section->section > $format->get_last_section_number()) {
 | 
        
           |  |  | 103 |             // Stealth sections (orphaned) has special title.
 | 
        
           |  |  | 104 |             $data->title = get_string('orphanedactivitiesinsectionno', '', $section->section);
 | 
        
           |  |  | 105 |         }
 | 
        
           |  |  | 106 |   | 
        
           |  |  | 107 |         if (!$section->visible) {
 | 
        
           |  |  | 108 |             $data->ishidden = true;
 | 
        
           |  |  | 109 |         }
 | 
        
           |  |  | 110 |   | 
        
           |  |  | 111 |         if (!$data->editing && $section->uservisible) {
 | 
        
           |  |  | 112 |             $data->url = course_get_url($course, $section->section, ['navigation' => true]);
 | 
        
           |  |  | 113 |         }
 | 
        
           |  |  | 114 |         $data->name = get_section_name($course, $section);
 | 
        
           |  |  | 115 |         $data->selecttext = $format->get_format_string('selectsection', $data->name);
 | 
        
           |  |  | 116 |   | 
        
           | 1441 | ariadna | 117 |         if (!$format->get_sectionnum() && !$section->is_delegated()) {
 | 
        
           | 1 | efrain | 118 |             $data->sectionbulk = true;
 | 
        
           |  |  | 119 |         }
 | 
        
           |  |  | 120 |   | 
        
           | 1441 | ariadna | 121 |         // Delegated sections in main course page need to have h4 tag, h3 otherwise.
 | 
        
           |  |  | 122 |         $data->headinglevel = ($section->get_component_instance() && is_null($format->get_sectionid())) ? 4 : 3;
 | 
        
           |  |  | 123 |   | 
        
           | 1 | efrain | 124 |         return $data;
 | 
        
           |  |  | 125 |     }
 | 
        
           |  |  | 126 | }
 |