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

ewallah / moodle-report_growth / 14516408145

17 Apr 2025 01:08PM UTC coverage: 89.941% (-3.8%) from 93.787%
14516408145

push

github

rdebleu
CoversClass

304 of 338 relevant lines covered (89.94%)

30.44 hits per line

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

93.85
/classes/output/global_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 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
namespace report_growth\output;
26

27
use plugin_renderer_base;
28
use renderable;
29
use core\{chart_bar, chart_line, chart_series};
30

31
/**
32
 * growth report renderer.
33
 *
34
 * @package   report_growth
35
 * @copyright eWallah (www.eWallah.net)
36
 * @author    Renaat Debleu <info@eWallah.net>
37
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38
 */
39
class global_renderer extends growth_renderer {
40
    /**
41
     * Create Tabs.
42
     *
43
     * @param \stdClass $context Selected $coursecontext
44
     * @param int $p Selected tab
45
     */
46
    public function create_tabtree($context, $p = 1) {
47
        global $CFG;
48
        $this->context = $context;
52✔
49
        $txt = get_strings(['summary', 'courses', 'users', 'activities', 'lastaccess', 'coursecompletions', 'files', 'payments']);
52✔
50
        $rows = ['summary' => $txt->summary, 'courses' => $txt->courses, 'users' => $txt->users, 'lastaccess' => $txt->lastaccess];
52✔
51
        $rows['enrolments'] = get_string('enrolments', 'enrol');
52✔
52
        $rows['logguests'] = get_string('policydocaudience2', 'tool_policy');
52✔
53
        $rows['activities'] = $txt->activities;
52✔
54
        if (!empty($CFG->enablecompletion)) {
52✔
55
            $rows['activitiescompleted'] = get_string('activitiescompleted', 'completion');
52✔
56
            $rows['coursecompletions'] = $txt->coursecompletions;
52✔
57
        }
58
        if (!empty($CFG->enablemobilewebservice)) {
52✔
59
            $rows['mobiles'] = get_string('mobile', 'report_growth');
52✔
60
        }
61
        $rows = array_merge($rows, $this->certificate_tabs());
52✔
62
        $rows['payments'] = $txt->payments;
52✔
63
        $rows['questions'] = get_string('questions', 'question');
52✔
64
        $rows['files'] = $txt->files;
52✔
65
        $rows['messages'] = get_string('messages', 'message');
52✔
66
        $rows['countries'] = get_string('countries', 'report_growth');
52✔
67
        // Trigger a report viewed event.
68
        $this->trigger_page($p);
52✔
69
        return $this->render_page($rows, $p);
52✔
70
    }
71

72
    /**
73
     * Table summary.
74
     *
75
     * @param string $title Title
76
     * @return string
77
     */
78
    public function table_summary($title = ''): string {
79
        $siteinfo = \core\hub\registration::get_site_info([]);
18✔
80
        $lis = strip_tags(\core\hub\registration::get_stats_summary($siteinfo), '<ul><li>');
18✔
81
        return \html_writer::tag('h3', $title) . str_replace(get_string('sendfollowinginfo_help', 'hub'), '', $lis);
18✔
82
    }
83

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

94
    /**
95
     * Table users.
96
     *
97
     * @param string $title Title
98
     * @return string
99
     */
100
    public function table_users($title = ''): string {
101
        global $DB;
102
        $arr = [
6✔
103
           [get_string('deleted'), $DB->count_records('user', ['deleted' => 1])],
6✔
104
           [get_string('suspended'), $DB->count_records('user', ['suspended' => 1])],
6✔
105
           [get_string('confirmed', 'admin'), $DB->count_records('user', ['confirmed' => 1]) - 1],
6✔
106
           [get_string('activeusers'), $DB->count_records_select('user', 'lastip <> ?', [''])], ];
6✔
107
        return $this->create_intro($arr, $title) . $this->create_charts('user', $title);
6✔
108
    }
109

110
    /**
111
     * Table courses.
112
     *
113
     * @param string $title Title
114
     * @return string
115
     */
116
    public function table_courses($title = ''): string {
117
        global $DB;
118
        $arr = [[get_string('categories'), $DB->count_records('course_categories', [])]];
6✔
119
        return $this->create_intro($arr, $title) . $this->create_charts('course', $title, 'timecreated', 'id > 1');
6✔
120
    }
121

122
    /**
123
     * Table enrolments.
124
     *
125
     * @param string $title Title
126
     * @return string
127
     */
128
    public function table_enrolments($title = ''): string {
129
        global $DB;
130
        $enabled = array_keys(enrol_get_plugins(true));
10✔
131
        $arr = [];
10✔
132
        foreach ($enabled as $key) {
10✔
133
            $ids = $DB->get_fieldset_select('enrol', 'id', "enrol = '$key'");
10✔
134
            if (count($ids) > 0) {
10✔
135
                [$insql, $inparams] = $DB->get_in_or_equal($ids);
6✔
136
                $cnt = $DB->count_records_sql("SELECT COUNT('x') FROM {user_enrolments} WHERE enrolid {$insql}", $inparams);
6✔
137
                $arr[] = [get_string('pluginname', 'enrol_' . $key), $cnt];
6✔
138
            }
139
        }
140
        return $this->create_intro($arr, $title) . $this->create_charts('user_enrolments', $title);
10✔
141
    }
142

143
    /**
144
     * Table payments.
145
     *
146
     * @param string $title Title
147
     * @return string
148
     */
149
    public function table_payments($title = ''): string {
150
        return $this->create_charts('payments', $title);
6✔
151
    }
152

153
    /**
154
     * Table mobile.
155
     *
156
     * @param string $title Title
157
     * @return string
158
     */
159
    public function table_mobiles($title = ''): string {
160
        return $this->create_charts('user_devices', $title);
6✔
161
    }
162

163
    /**
164
     * Table badges.
165
     *
166
     * @param string $title Title
167
     * @return string
168
     */
169
    public function table_badges($title = ''): string {
170
        return $this->create_charts('badge_issued', $title, 'dateissued');
2✔
171
    }
172

173
    /**
174
     * Table activities.
175
     *
176
     * @param string $title Title
177
     * @return string
178
     */
179
    public function table_activities($title = ''): string {
180
        return $this->create_charts('course_modules', $title, 'added');
2✔
181
    }
182

183
    /**
184
     * Table Activities completed.
185
     *
186
     * @param string $title Title
187
     * @return string
188
     */
189
    public function table_activitiescompleted($title = ''): string {
190
        return $this->create_charts('course_modules_completion', $title, 'timemodified');
2✔
191
    }
192

193
    /**
194
     * Table completions.
195
     *
196
     * @param string $title Title
197
     * @return string
198
     */
199
    public function table_coursecompletions($title = ''): string {
200
        return $this->create_charts('course_completions', $title, 'timecompleted');
4✔
201
    }
202

203
    /**
204
     * Table questions.
205
     *
206
     * @param string $title Title
207
     * @return string
208
     */
209
    public function table_questions($title = ''): string {
210
        return $this->create_charts('question', $title);
2✔
211
    }
212

213
    /**
214
     * Table guests.
215
     *
216
     * @param string $title Title
217
     * @return string
218
     */
219
    public function table_logguests($title = ''): string {
220
        return $this->create_charts('logstore_standard_log', $title, 'timecreated', 'userid = 1');
2✔
221
    }
222

223
    /**
224
     * Table certificates.
225
     *
226
     * @param string $title Title
227
     * @return string
228
     */
229
    public function table_certificates($title = ''): string {
230
        global $CFG;
231
        $s = '';
6✔
232
        if (file_exists($CFG->dirroot . '/mod/certificate')) {
6✔
233
            $s = $this->create_charts('certificate_issues', $title);
6✔
234
        }
235
        return $s;
6✔
236
    }
237

238
    /**
239
     * Table custom certificates.
240
     *
241
     * @param string $title Title
242
     * @return string
243
     */
244
    public function table_customcerts($title = ''): string {
245
        global $CFG;
246
        $s = '';
×
247
        if (file_exists($CFG->dirroot . '/mod/customcert')) {
×
248
            $s = $this->create_charts('customcert_issues', $title);
×
249
        }
250
        return $s;
×
251
    }
252

253
    /**
254
     * Table course certificates.
255
     *
256
     * @param string $title Title
257
     * @return string
258
     */
259
    public function table_coursecertificates($title = ''): string {
260
        global $CFG;
261
        $s = '';
2✔
262
        if (file_exists($CFG->dirroot . '/mod/coursecertificate')) {
2✔
263
            $s = $this->create_charts('tool_certificate_issues', $title);
2✔
264
        }
265
        return $s;
2✔
266
    }
267

268
    /**
269
     * Table files.
270
     *
271
     * @param string $title Title
272
     * @return string
273
     */
274
    public function table_files($title = ''): string {
275
        return $this->create_charts('files', $title);
2✔
276
    }
277

278
    /**
279
     * Table messages.
280
     *
281
     * @param string $title Title
282
     * @return string
283
     */
284
    public function table_messages($title = ''): string {
285
        return $this->create_charts('messages', $title);
2✔
286
    }
287

288
    /**
289
     * Table country.
290
     *
291
     * @param string $title Title
292
     * @return string
293
     */
294
    public function table_countries($title = ''): string {
295
        global $DB;
296
        $sql = "SELECT country, COUNT(country) AS newusers FROM {user} GROUP BY country ORDER BY country";
6✔
297
        $rows = $DB->get_records_sql($sql);
6✔
298
        return $this->create_countries($rows, $title);
6✔
299
    }
300
}
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