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

ewallah / moodle-format_masonry / 20407412395

21 Dec 2025 08:52AM UTC coverage: 49.573% (-49.2%) from 98.75%
20407412395

push

github

rdebleu
rector

3 of 6 new or added lines in 3 files covered. (50.0%)

40 existing lines in 2 files now uncovered.

116 of 234 relevant lines covered (49.57%)

4.36 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;
10✔
57
        $course = $format->get_course();
10✔
58
        $section = $this->section;
10✔
59
        $context = context_course::instance($course->id);
10✔
60

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

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

77
        $haspartials = [];
10✔
78
        $haspartials['availability'] = $this->add_availability_data($data, $output);
10✔
79
        $haspartials['visibility'] = $this->add_visibility_data($data, $output);
10✔
80
        $haspartials['editor'] = $this->add_editor_data($data, $output);
10✔
81
        $haspartials['header'] = $this->add_header_data($data, $output);
10✔
82
        $haspartials['cm'] = $this->add_cm_data($data, $output);
10✔
83
        $this->add_format_data($data, $haspartials, $output);
10✔
84
        return $data;
10✔
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);
10✔
96
        $data->header = $header->export_for_template($output);
10✔
97
        return true;
10✔
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;
10✔
109
        $section = $this->section;
10✔
110
        if ($section->uservisible) {
10✔
111
            $cmlist = new $this->cmlistclass($this->format, $section);
10✔
112
            $data->cmlist = $cmlist->export_for_template($output);
10✔
113
            $result = true;
10✔
114
        }
115

116
        return $result;
10✔
117
    }
118

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

140
        if ($this->isstealth) {
10✔
UNCOV
141
            $data->uservisible = false;
×
142
        }
143

144
        if (has_capability('moodle/course:sectionvisibility', $coursecontext)) {
10✔
145
            $data->uservisible = true;
10✔
146
        }
147

148
        $data->contentcollapsed = false;
10✔
149
        return true;
10✔
150
    }
151

152
    /**
153
     * Returns true if the current section should be shown collapsed.
154
     */
155
    protected function is_section_collapsed(): bool {
UNCOV
156
        return false;
×
157
    }
158
}
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