-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.php
96 lines (84 loc) · 3.46 KB
/
index.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
<?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/>.
/**
* Displays the cloud of developer names
*
* @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');
$PAGE->set_context(context_system::instance());
$PAGE->set_pagelayout('standard');
$PAGE->set_url(new local_dev_url('/local/dev/index.php'));
$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');
echo $output->header();
echo $output->heading(get_string('developers', 'local_dev'));
echo $output->box(get_string('developersinfo', 'local_dev', (new local_dev_url('/local/dev/contributions.php'))->out()));
$devs = array();
$cache = cache::make('local_dev', 'gitcommits');
// List of developers from the {dev_git_commits} table.
$devs = $cache->get('devs');
// The maximum number of commits by a single developer (used for font-size
// calculation in the names tag cloud).
$max = $cache->get('maxcommits');
if ($devs === false or $max === false) {
$devs = [];
$max = 1;
$sql = "SELECT c.userid,
COALESCE(".$DB->sql_concat("u.firstname", "' '", "u.lastname").", c.authorname) AS xname,
COALESCE(u.email, c.authorname) AS xemail,
COUNT(c.commithash) AS xcommits
FROM {dev_git_commits} c
LEFT JOIN {user} u ON (c.userid = u.id)
GROUP BY userid, xname, xemail";
$rs = $DB->get_recordset_sql($sql);
foreach ($rs as $record) {
$dev = new stdClass();
$fullname = s(trim($record->xname));
$fullname = html_writer::tag('span', $fullname, array('class' => 'cx' . $record->xcommits));
if (is_null($record->userid)) {
$dev->name = $fullname;
} else {
$dev->name = html_writer::link(new moodle_url('/user/profile.php', array('id' => $record->userid)), $fullname);
}
$dev->commits = $record->xcommits;
$max = $dev->commits > $max ? $dev->commits : $max;
$devs[] = $dev;
}
$rs->close();
$cache->set('devs', $devs);
$cache->set('maxcommits', $max);
}
shuffle($devs);
echo $output->box_start(array('devscloud'));
foreach ($devs as $dev) {
if ($dev->commits <= 1 or $max == 0) {
$rel = 0;
} else {
$rel = round(log($dev->commits) / log($max) * 100);
}
$rel = 3 * max($rel, 25);
echo html_writer::tag('span', ' '.$dev->name.' ', array('style' => sprintf('font-size:%d%%', $rel)));
}
echo $output->box_end();
echo $output->footer();