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

ewallah / moodle-report_growth / 14518858290

17 Apr 2025 03:09PM UTC coverage: 88.462% (-5.9%) from 94.379%
14518858290

push

github

rdebleu
CoversClass

299 of 338 relevant lines covered (88.46%)

61.4 hits per line

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

83.64
/classes/output/course_renderer.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
 * Growth course report renderer.
19
 *
20
 * @package   report_growth
21
 * @copyright eWallah (www.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 report_growth\output;
27

28
use moodle_url;
29
use html_writer;
30
use plugin_renderer_base;
31
use renderable;
32
use tabobject;
33
use core\{chart_bar, chart_line, chart_series};
34

35
/**
36
 * growth report renderer.
37
 *
38
 * @package   report_growth
39
 * @copyright eWallah (www.eWallah.net)
40
 * @author    Renaat Debleu <info@eWallah.net>
41
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
42
 */
43
class course_renderer extends growth_renderer {
44
    /** @var int courseid. */
45
    private int $courseid;
46

47
    /**
48
     * Create Tabs.
49
     *
50
     * @param \stdClass $context Selected $coursecontext
51
     * @param int $p Selected tab
52
     * @return string
53
     */
54
    public function create_tabtree($context, int $p = 1) {
55
        global $CFG;
56
        $this->courseid = $context->instanceid;
80✔
57
        $this->context = $context;
80✔
58
        $txt = get_strings(['activities', 'lastaccess', 'coursecompletions', 'defaultcourseteachers']);
80✔
59
        $rows = [
80✔
60
            'enrolments' => get_string('enrolments', 'enrol'),
80✔
61
            'lastaccess' => $txt->lastaccess,
80✔
62
            'activities' => $txt->activities,
80✔
63
            'teachers' => $txt->defaultcourseteachers, ];
80✔
64
        if (!empty($CFG->enablecompletion)) {
80✔
65
            $rows['activitiescompleted'] = get_string('activitiescompleted', 'completion');
80✔
66
            $rows['coursecompletions'] = $txt->coursecompletions;
80✔
67
        }
68
        $rows = array_merge($rows, $this->certificate_tabs());
80✔
69
        $rows['countries'] = get_string('countries', 'report_growth');
80✔
70
        // Trigger a report viewed event.
71
        $this->trigger_page($p);
80✔
72
        return $this->render_page($rows, $p);
80✔
73
    }
74

75
    /**
76
     * Table enrolments.
77
     *
78
     * @param string $title Title
79
     * @return string
80
     */
81
    public function table_enrolments($title = ''): string {
82
        return $this->collect_course_table($title, 'enrol', 'user_enrolments', 'courseid', 'enrolid', 'timecreated');
52✔
83
    }
84

85
    /**
86
     * Table last access.
87
     *
88
     * @param string $title Title
89
     * @return string
90
     */
91
    public function table_lastaccess($title = ''): string {
92
        return $this->create_charts('user_lastaccess', $title, 'timeaccess', 'courseid = ' . $this->courseid);
4✔
93
    }
94

95
    /**
96
     * Table activities.
97
     *
98
     * @param string $title Title
99
     * @return string
100
     */
101
    public function table_activities($title = ''): string {
102
        return $this->create_charts('course_modules', $title, 'added', 'course = ' . $this->courseid);
8✔
103
    }
104

105
    /**
106
     * Table Activities completed.
107
     *
108
     * @param string $title Title
109
     * @return string
110
     */
111
    public function table_activitiescompleted($title = ''): string {
112
        return $this->collect_course_table($title, 'course_modules', 'course_modules_completion', 'course', 'coursemoduleid');
4✔
113
    }
114

115
    /**
116
     * Table completions.
117
     *
118
     * @param string $title Title
119
     * @return string
120
     */
121
    public function table_coursecompletions($title = ''): string {
122
        return $this->create_charts('course_completions', $title, 'timecompleted', 'course = ' . $this->courseid);
4✔
123
    }
124

125
    /**
126
     * Table badges.
127
     *
128
     * @param string $title Title
129
     * @return string
130
     */
131
    public function table_badges($title = ''): string {
132
        return $this->collect_course_table($title, 'badge', 'badge_issued', 'courseid', 'badgeid', 'dateissued');
4✔
133
    }
134

135
    /**
136
     * Table teacher logs.
137
     *
138
     * @param string $title Title
139
     * @return string
140
     */
141
    public function table_teachers($title = ''): string {
142
        global $DB;
143
        $out = get_string('nostudentsfound', 'moodle', $title);
8✔
144
        $teachers = get_users_by_capability($this->context, 'moodle/course:viewhiddenactivities', 'u.id', 'u.id');
8✔
145
        if ($teachers && count($teachers) > 0) {
8✔
146
            [$insql, $inparams] = $DB->get_in_or_equal(array_keys($teachers));
4✔
147
            $insql .= ' AND courseid = ? AND contextlevel = ? AND contextinstanceid = ?';
4✔
148
            $inparams[] = $this->courseid;
4✔
149
            $inparams[] = $this->context->contextlevel;
4✔
150
            $inparams[] = $this->context->instanceid;
4✔
151
            $out = $this->create_charts('logstore_standard_log', $title, 'timecreated', 'userid ' . $insql, $inparams);
4✔
152
        }
153
        return $out;
8✔
154
    }
155

156
    /**
157
     * Table certificates.
158
     *
159
     * @param string $title Title
160
     * @return string
161
     */
162
    public function table_certificates($title = ''): string {
163
        global $CFG;
164
        $s = '';
4✔
165
        if (file_exists($CFG->dirroot . '/mod/certificate')) {
4✔
166
            $s = $this->collect_course_table($title, 'certificate', 'certificate_issues', 'course', 'certificateid', 'timecreated');
×
167
        }
168
        return $s;
4✔
169
    }
170

171
    /**
172
     * Table custom certificates.
173
     *
174
     * @param string $title Title
175
     * @return string
176
     */
177
    public function table_customcerts($title = ''): string {
178
        global $CFG;
179
        $s = '';
×
180
        if (file_exists($CFG->dirroot . '/mod/customcert')) {
×
181
            $s = $this->collect_course_table($title, 'customcert', 'customcert_issues', 'course', 'customcertid', 'timecreated');
×
182
        }
183
        return $s;
×
184
    }
185

186
    /**
187
     * Table course certificates.
188
     *
189
     * @param string $title Title
190
     * @return string
191
     */
192
    public function table_coursecertificates($title = ''): string {
193
        global $CFG;
194
        $s = '';
×
195
        if (file_exists($CFG->dirroot . '/mod/coursecertificate')) {
×
196
            $s = $this->create_charts('tool_certificate_issues', $title, 'timecreated', 'courseid = ' . $this->courseid);
×
197
        }
198
        return $s;
×
199
    }
200

201
    /**
202
     * Table country.
203
     *
204
     * @param string $title Title
205
     * @return string
206
     */
207
    public function table_countries($title = ''): string {
208
        global $DB;
209
        $title = get_string('users');
12✔
210
        $out = get_string('nostudentsfound', 'moodle', $title);
12✔
211
        $ids = $DB->get_fieldset_select('enrol', 'id', 'courseid = :courseid', ['courseid' => $this->context->instanceid]);
12✔
212
        if (count($ids) > 0) {
12✔
213
            [$insql, $inparams] = $this->insql($ids, 'enrolid', 'enrolid');
12✔
214
            $userids = $DB->get_fieldset_select('user_enrolments', 'userid', $insql, $inparams);
12✔
215
            if (count($userids) > 0) {
12✔
216
                [$insql, $inparams] = $this->insql($userids, 'id', 'id');
4✔
217
                $sql = "SELECT country, COUNT(country) AS newusers FROM {user} WHERE $insql GROUP BY country ORDER BY country";
4✔
218
                $rows = $DB->get_records_sql($sql, $inparams);
4✔
219
                $out = $this->create_countries($rows, $title);
4✔
220
            }
221
        }
222
        return $out;
12✔
223
    }
224
}
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