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

ewallah / moodle-report_growth / 10517235238

22 Aug 2024 11:35PM UTC coverage: 90.184% (-5.7%) from 95.918%
10517235238

push

github

rdebleu
Help

11 of 11 new or added lines in 1 file covered. (100.0%)

29 existing lines in 4 files now uncovered.

294 of 326 relevant lines covered (90.18%)

106.7 hits per line

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

93.62
/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, $p = 1) {
55
        global $CFG;
56
        $this->courseid = $context->instanceid;
140✔
57
        $this->context = $context;
140✔
58
        $txt = get_strings(['activities', 'lastaccess', 'coursecompletions', 'defaultcourseteachers']);
140✔
59
        $rows = [
140✔
60
            'enrolments' => get_string('enrolments', 'enrol'),
140✔
61
            'lastaccess' => $txt->lastaccess,
140✔
62
            'activities' => $txt->activities,
140✔
63
            'teachers' => $txt->defaultcourseteachers, ];
140✔
64
        if (!empty($CFG->enablecompletion)) {
140✔
65
            $rows['activitiescompleted'] = get_string('activitiescompleted', 'completion');
140✔
66
            $rows['coursecompletions'] = $txt->coursecompletions;
140✔
67
        }
68
        $rows = array_merge($rows, $this->certificate_tabs());
140✔
69
        $rows['countries'] = get_string('countries', 'report_growth');
140✔
70
        // Trigger a report viewed event.
71
        $this->trigger_page($p);
140✔
72
        return $this->render_page($rows, $p);
140✔
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');
91✔
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);
7✔
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);
14✔
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');
7✔
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);
7✔
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');
7✔
133
    }
134

135
    /**
136
     * Table certificates.
137
     *
138
     * @param string $title Title
139
     * @return string
140
     */
141
    public function table_certificates($title = ''): string {
UNCOV
142
        return $this->collect_course_table($title, 'certificate', 'certificate_issues', 'course', 'certificateid', 'timecreated');
×
143
    }
144

145
    /**
146
     * Table teacher logs.
147
     *
148
     * @param string $title Title
149
     * @return string
150
     */
151
    public function table_teachers($title = ''): string {
152
        global $DB;
153
        $roleid = $DB->get_field('role', 'id', ['shortname' => 'editingteacher']);
14✔
154
        $out = get_string('nostudentsfound', 'moodle', $title);
14✔
155
        $teachers = get_role_users($roleid, $this->context, true, 'u.id', 'u.id');
14✔
156
        if ($teachers && count($teachers) > 0) {
14✔
157
            [$insql, $inparams] = $DB->get_in_or_equal(array_keys($teachers));
7✔
158
            $insql .= ' AND courseid = ? AND contextlevel = ? AND contextinstanceid = ?';
7✔
159
            $inparams[] = $this->courseid;
7✔
160
            $inparams[] = $this->context->contextlevel;
7✔
161
            $inparams[] = $this->context->instanceid;
7✔
162
            $out = $this->create_charts('logstore_standard_log', $title, 'timecreated', 'userid ' . $insql, $inparams);
7✔
163
        }
164
        return $out;
14✔
165
    }
166

167
    /**
168
     * Table custom certificates.
169
     *
170
     * @param string $title Title
171
     * @return string
172
     */
173
    public function table_customcerts($title = ''): string {
UNCOV
174
        return $this->collect_course_table($title, 'customcert', 'customcert_issues', 'course', 'customcertid', 'timecreated');
×
175
    }
176

177
    /**
178
     * Table course certificates.
179
     *
180
     * @param string $title Title
181
     * @return string
182
     */
183
    public function table_coursecertificates($title = ''): string {
UNCOV
184
        return $this->create_charts('tool_certificate_issues', $title, 'timecreated', 'courseid = ' . $this->courseid);
×
185
    }
186

187
    /**
188
     * Table country.
189
     *
190
     * @param string $title Title
191
     * @return string
192
     */
193
    public function table_countries($title = ''): string {
194
        global $DB;
195
        $title = get_string('users');
21✔
196
        $out = get_string('nostudentsfound', 'moodle', $title);
21✔
197
        $ids = $DB->get_fieldset_select('enrol', 'id', 'courseid = :courseid', ['courseid' => $this->context->instanceid]);
21✔
198
        if (count($ids) > 0) {
21✔
199
            [$insql, $inparams] = $this->insql($ids, 'enrolid', 'enrolid');
21✔
200
            $userids = $DB->get_fieldset_select('user_enrolments', 'userid', $insql, $inparams);
21✔
201
            if (count($userids) > 0) {
21✔
202
                [$insql, $inparams] = $this->insql($userids, 'id', 'id');
7✔
203
                $sql = "SELECT country, COUNT(country) AS newusers FROM {user} WHERE $insql GROUP BY country ORDER BY country";
7✔
204
                $rows = $DB->get_records_sql($sql, $inparams);
7✔
205
                $out = $this->create_countries($rows, $title);
7✔
206
            }
207
        }
208
        return $out;
21✔
209
    }
210
}
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