-
Notifications
You must be signed in to change notification settings - Fork 4
/
contributions.php
180 lines (155 loc) · 6.46 KB
/
contributions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @package local_dev
* @copyright 2012 David Mudrak <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require(dirname(dirname(dirname(__FILE__))).'/config.php');
require_once($CFG->dirroot.'/local/dev/lib.php');
require_once($CFG->dirroot.'/local/dev/locallib.php');
require_once($CFG->dirroot.'/local/dev/tablelib.php');
$version = optional_param('version', null, PARAM_RAW);
if (empty($version)) {
$version = null;
}
if (!is_null($version)) {
if ($version !== 'x.x.x') {
$version = preg_replace('/[^x0-9\.]/', '', $version);
}
}
$PAGE->set_context(context_system::instance());
$PAGE->set_pagelayout('standard');
$PAGE->set_url(new local_dev_url('/local/dev/contributions.php', array('version' => $version)));
$PAGE->add_body_class('path-local-dev');
$PAGE->set_title(get_string('pluginname', 'local_dev'));
$PAGE->set_heading(get_string('pluginname', 'local_dev'));
$output = $PAGE->get_renderer('local_dev');
// prepare the drop down box with versions
$options = array('x.x.x' => get_string('allversions', 'local_dev'));
$validversion = is_null($version);
$branches = dev_aggregator::get_branches();
foreach ($branches as $branch => $vers) {
if ($version === 'x.x.x') {
$validversion = true;
} else if ($version === $branch) {
$validversion = true;
}
$optgroup = array($branch => get_string('allversionsonbranch', 'local_dev', $branch));
foreach ($vers as $ver) {
$optgroup[$ver] = $ver;
if ($version === $ver) {
$validversion = true;
}
}
$options[] = array(('Moodle '.$branch) => $optgroup);
}
if (empty($CFG->hidelocaldevfromnavigation)) {
$rootnode = $PAGE->navigation->find('local_dev-contributions', navigation_node::TYPE_CUSTOM);
foreach ($options as $key => $val) {
if (is_array($val)) {
$vers = array_keys(reset($val));
$branch = array_shift($vers);
$branchnode = $rootnode->add($branch, new local_dev_url('/local/dev/contributions.php', array('version' => $branch)));
foreach ($vers as $ver) {
$branchnode->add($ver, new local_dev_url('/local/dev/contributions.php', array('version' => $ver)));
}
}
}
}
echo $output->header();
if (empty($branches)) {
echo $output->box('Unable to find any branch, are you sure you have executed cli/aggregate.php?');
echo $output->footer();
die();
}
if (!$validversion) {
// the version has the correct format but is not known, for example 1.8.99
echo $output->heading(get_string('contributionsversioninvalid', 'local_dev', $version));
} else {
if (is_null($version)) {
// version not specified or has invalid format - use 'All versions'
$version = 'x.x.x';
}
if ($version === 'x.x.x') {
echo $output->heading(get_string('contributionsversionall', 'local_dev'));
} else {
echo $output->heading(get_string('contributionsversion', 'local_dev', $version));
}
}
$select = new single_select(new local_dev_url('/local/dev/contributions.php'), 'version', $options, $version);
$select->set_label(get_string('contributionsversionselect', 'local_dev'));
if (!$validversion) {
echo $output->box($output->render($select), array('generalbox versionselector'));
echo $output->footer();
die();
}
$metrics = array('gitcommits', 'gitmerges');
$table = new dev_activity_table_sql('dev-activity-table');
$sqlfields = "a.id, a.version,
COALESCE(u.firstname, a.userfirstname) AS firstname,
COALESCE(u.lastname, a.userlastname) AS lastname,
COALESCE(u.email, a.useremail) AS email" .
\core_user\fields::for_userpic()->including('country', 'institution')->get_sql('u', false, 'realuser', 'realuserid')->selects .
", " . implode(",", $metrics);
$sqlfrom = "{dev_activity} a LEFT JOIN {user} u ON (a.userid = u.id)";
$sqlwheremetrics = array();
foreach ($metrics as $metric) {
$sqlwheremetrics[] = "$metric IS NOT NULL";
}
$sqlwhere = "(" . implode(" OR ", $sqlwheremetrics) . ")";
$sqlwhere .= " AND version = :version";
$sqlparams = array('version' => $version);
$table->set_sql($sqlfields, $sqlfrom, $sqlwhere, $sqlparams);
$statsql = "SELECT COUNT(*) AS devs, COUNT(DISTINCT r.realusercountry) AS countries, SUM(r.gitcommits) AS commits
FROM (SELECT $sqlfields
FROM $sqlfrom
WHERE $sqlwhere) r";
$stats = $DB->get_record_sql($statsql, $sqlparams);
echo $output->container_start('stats');
echo $output->container(get_string('statsdevs', 'local_dev', html_writer::span($stats->devs)), 'devs');
echo $output->container(get_string('statscountries', 'local_dev', html_writer::span($stats->countries)), 'countries');
echo $output->container(get_string('statscommits', 'local_dev', html_writer::span($stats->commits)), 'commits');
echo $output->container_end();
echo $output->box($output->render($select), array('generalbox versionselector'));
$columns = array();
$headers = array();
if (!$table->is_downloading()) {
$columns[] = 'userpic';
$headers[] = '';
$columns[] = 'fullname';
$headers[] = get_string('name');
} else {
$columns[] = 'lastname';
$headers[] = get_string('lastname');
$columns[] = 'firstname';
$headers[] = get_string('firstname');
}
$columns[] = 'realusercountry';
$headers[] = get_string('country');
//$columns[] = 'realuserinstitution'; // removed, see MDLSITE-3080
//$headers[] = get_string('institution');
$columns[] = 'gitcommits';
$headers[] = get_string('gitcommits', 'local_dev');
$columns[] = 'gitmerges';
$headers[] = get_string('gitmerges', 'local_dev');
$table->define_columns($columns);
$table->define_headers($headers);
$table->sortable(true, 'gitcommits', SORT_DESC);
$table->define_baseurl($PAGE->url);
$table->initialbars(true);
$table->out(100, true, true);
echo $output->footer();