• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ewallah / moodle-format_masonry / 17801099810

17 Sep 2025 02:32PM UTC coverage: 97.436% (-1.3%) from 98.75%
17801099810

push

github

rdebleu
dev

228 of 234 relevant lines covered (97.44%)

7.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.12
/classes/output/courseformat/content/section.php
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
 * Format masonry section class.
19
 *
20
 * @package    format_masonry
21
 * @copyright  eWallah.net
22
 * @author     Renaat Debleu <info@eWallah.net>
23
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25

26
namespace format_masonry\output\courseformat\content;
27

28
use core_courseformat\output\local\content\section as section_base;
29
use context_course;
30
use core\output\named_templatable;
31
use core_courseformat\base as course_format;
32
use core_courseformat\output\local\courseformat_named_templatable;
33
use renderable;
34
use renderer_base;
35
use section_info;
36
use stdClass;
37

38
/**
39
 * Format masonry section class.
40
 *
41
 * @package    format_masonry
42
 * @copyright  eWallah.net
43
 * @author     Renaat Debleu <info@eWallah.net>
44
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
45
 */
46
class section extends section_base {
47
    /**
48
     * Override export for template data.
49
     *
50
     * @param renderer_base $output typically, the renderer that's calling this function
51
     * @return stdClass data context for a mustache template
52
     */
53
    public function export_for_template(renderer_base $output): stdClass {
54
        global $PAGE;
55

56
        $format = $this->format;
12✔
57
        $course = $format->get_course();
12✔
58
        $section = $this->section;
12✔
59
        $context = context_course::instance($course->id);
12✔
60

61
        $summary = new $this->summaryclass($format, $section);
12✔
62
        $isediting = $PAGE->user_is_editing();
12✔
63

64
        $data = (object)[
12✔
65
            'num' => $section->section ?? 0,
12✔
66
            'id' => $section->id,
12✔
67
            'insertafter' => false,
12✔
68
            'sitehome' => $course->id == SITEID,
12✔
69
            'editing' => $isediting,
12✔
70
            'summary' => $summary->export_for_template($output),
12✔
71
            'displayonesection' => false,
12✔
72
        ];
12✔
73
        if ($this->isstealth && !has_capability('moodle/course:sectionvisibility', $context)) {
12✔
74
            return $data;
×
75
        }
76

77
        $haspartials = [];
12✔
78
        $haspartials['availability'] = $this->add_availability_data($data, $output);
12✔
79
        $haspartials['visibility'] = $this->add_visibility_data($data, $output);
12✔
80
        $haspartials['editor'] = $this->add_editor_data($data, $output);
12✔
81
        $haspartials['header'] = $this->add_header_data($data, $output);
12✔
82
        $haspartials['cm'] = $this->add_cm_data($data, $output);
12✔
83
        $this->add_format_data($data, $haspartials, $output);
12✔
84
        return $data;
12✔
85
    }
86

87
    /**
88
     * Add the section header to the data structure.
89
     *
90
     * @param stdClass $data the current cm data reference
91
     * @param renderer_base $output typically, the renderer that's calling this function
92
     * @return bool if the cm has name data
93
     */
94
    protected function add_header_data(stdClass &$data, renderer_base $output): bool {
95
        $header = new $this->headerclass($this->format, $this->section);
12✔
96
        $data->header = $header->export_for_template($output);
12✔
97
        return true;
12✔
98
    }
99

100
    /**
101
     * Add the section cm list to the data structure.
102
     *
103
     * @param stdClass $data the current cm data reference
104
     * @param renderer_base $output typically, the renderer that's calling this function
105
     * @return bool if the cm has name data
106
     */
107
    protected function add_cm_data(stdClass &$data, renderer_base $output): bool {
108
        $result = false;
12✔
109
        $section = $this->section;
12✔
110
        if ($section->uservisible) {
12✔
111
            $cmlist = new $this->cmlistclass($this->format, $section);
12✔
112
            $data->cmlist = $cmlist->export_for_template($output);
12✔
113
            $result = true;
12✔
114
        }
115
        return $result;
12✔
116
    }
117

118
    /**
119
     * Add the section format attributes to the data structure.
120
     *
121
     * @param stdClass $data the current cm data reference
122
     * @param bool[] $haspartials the result of loading partial data elements
123
     * @param renderer_base $output typically, the renderer that's calling this function
124
     * @return bool if the cm has name data
125
     */
126
    protected function add_format_data(stdClass &$data, array $haspartials, renderer_base $output): bool {
127
        $course = $this->format->get_course();
12✔
128
        $coursecontext = context_course::instance($course->id);
12✔
129
        $data->onlysummary = 0;
12✔
130
        $data->iscoursedisplaymultipage = true;
12✔
131
        $data->sectionbulk = false;
12✔
132
        $data->uservisible = true;
12✔
133
        if ($data->num === 0) {
12✔
134
            if (count($data->cmlist->cms) == 0) {
12✔
135
                $data->uservisible = false;
12✔
136
            }
137
        }
138
        if ($this->isstealth) {
12✔
139
            $data->uservisible = false;
×
140
        }
141
        if (has_capability('moodle/course:sectionvisibility', $coursecontext)) {
12✔
142
            $data->uservisible = true;
12✔
143
        }
144
        $data->contentcollapsed = false;
12✔
145
        return true;
12✔
146
    }
147

148
    /**
149
     * Returns true if the current section should be shown collapsed.
150
     *
151
     * @return bool
152
     */
153
    protected function is_section_collapsed(): bool {
154
        return false;
×
155
    }
156
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc