-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlib.php
135 lines (114 loc) · 5.51 KB
/
lib.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
<?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/>.
/**
* The plugin's external API is defined here
*
* @package local_dev
* @copyright 2012 David Mudrak <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Custom URL handling class that supports the plugin appearing outside its real location
*/
class local_dev_url extends moodle_url {
/**
* Given the real location if the script like '/local/dev/file.php' this method
* actually creates URL to '/dev/file.php'
*/
public function __construct($url, array $params = null) {
if (is_string($url) and preg_match("~^/local/dev(/?)(.*)$~", $url, $matches)) {
$url = '/dev/'.$matches[2];
}
parent::__construct($url, $params);
}
}
/**
* Puts AMOS into the global navigation tree.
*
* @param global_navigation $navigation the navigation tree instance
* @category navigation
*/
function local_dev_extend_navigation(global_navigation $navigation) {
global $CFG;
if (!empty($CFG->hidelocaldevfromnavigation)) {
return;
}
if (!defined('LOCAL_DEV_LOCALLIB_LOADED')) {
return;
}
$devnode = $navigation->add(get_string('pluginname', 'local_dev'), null, navigation_node::TYPE_CUSTOM, null, 'local_dev-root');
$devnode->add(get_string('developers', 'local_dev'), new local_dev_url('/local/dev/index.php'), navigation_node::TYPE_CUSTOM, null, 'local_dev-developers');
$devnode->add(get_string('contributions', 'local_dev'), new local_dev_url('/local/dev/contributions.php'), navigation_node::TYPE_CUSTOM, null, 'local_dev-contributions');
if (has_capability('local/dev:manage', context_system::instance())) {
$admin = $devnode->add(get_string('administration'));
$admin->add(get_string('adminoverview', 'local_dev'), new local_dev_url('/local/dev/admin/index.php'));
$admin->add(get_string('gitaliases', 'local_dev'), new local_dev_url('/local/dev/admin/git-aliases.php'));
}
}
/**
* Adds information about contributions into the user profile pages.
*
* @param \core_user\output\myprofile\tree $tree Profile tree
* @param stdClass $user
* @param bool $iscurrentuser
* @param stdClass $course
*
* @return bool
*/
function local_dev_myprofile_navigation(\core_user\output\myprofile\tree $tree, $user, $iscurrentuser, $course) {
global $DB, $OUTPUT;
$params = ['userid' => $user->id];
$sql = "SELECT da.userid, da.gitcommits, da.gitmerges, MIN(dgc.authordate) AS firstcommit, MAX(dgc.authordate) AS lastcommit
FROM {dev_activity} da
JOIN {dev_git_commits} dgc ON da.userid = dgc.userid
WHERE da.version = 'x.x.x' AND da.userid = :userid";
$data = $DB->get_record_sql($sql, ['userid' => $user->id]);
if (empty($data->userid)) {
return;
}
$category = new core_user\output\myprofile\category('moodlecore',
get_string('myprofilecattitle', 'local_dev'), 'contact');
$tree->add_category($category);
if ($data->gitcommits) {
$url = new local_dev_url('/local/dev/gitcommits.php', ['version' => 'x.x.x', 'userid' => $user->id, 'merges' => 0]);
$numberofcommits = '<span class="badge">'.$data->gitcommits.'</span>';
$link = html_writer::link($url, get_string('gitcommits', 'local_dev'));
$tree->add_node(new core_user\output\myprofile\node('moodlecore', 'gitcommits', $link.' '.$numberofcommits));
}
if ($data->gitmerges) {
$url = new local_dev_url('/local/dev/gitcommits.php', ['version' => 'x.x.x', 'userid' => $user->id, 'merges' => 1]);
$numberofcommits = '<span class="badge">'.$data->gitmerges.'</span>';
$link = html_writer::link($url, get_string('gitmerges', 'local_dev'));
$tree->add_node(new core_user\output\myprofile\node('moodlecore', 'gitmerges', $link.' '.$numberofcommits));
}
if (($data->gitcommits + $data->gitmerges > 1) and $data->firstcommit) {
$date = userdate($data->firstcommit, '', core_date::get_user_timezone());
$date .= ' <small>('.format_time(time() - $data->firstcommit).')</small>';
$tree->add_node(new core_user\output\myprofile\node('moodlecore', 'firstcommit',
get_string('myprofilefirstcommit', 'local_dev'), null, null, $date));
}
if ($data->lastcommit) {
$date = userdate($data->lastcommit, '', core_date::get_user_timezone());
$date .= ' <small>('.format_time(time() - $data->lastcommit).')</small>';
$tree->add_node(new core_user\output\myprofile\node('moodlecore', 'lastcommit',
get_string('myprofilelastcommit', 'local_dev'), null, null, $date));
}
$creditslink = (new local_dev_url('/local/dev/'))->out();
$node = new core_user\output\myprofile\node('moodlecore', 'creditslink', get_string('pluginname', 'local_dev'),
null, $creditslink, null, null, 'viewmore');
$tree->add_node($node);
}