-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcredits.php
143 lines (114 loc) · 4.62 KB
/
credits.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
<?php
// This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>.
/**
* Displays maintainers and contributors per language.
*
* @package local_amos
* @copyright 2013 David Mudrak <[email protected]>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// phpcs:ignore moodle.Files.RequireLogin
require(__DIR__ . '/../../config.php');
require_once($CFG->dirroot . '/local/amos/locallib.php');
require_once($CFG->dirroot . '/local/amos/mlanglib.php');
require_once($CFG->dirroot . '/local/amos/renderer.php');
$editmode = optional_param('editmode', false, PARAM_BOOL);
$canedit = has_capability('local/amos:manage', context_system::instance());
if (!$canedit) {
$editmode = false;
} else if (!$editmode) {
$editmode = null;
} else {
$editmode = true;
}
$PAGE->set_context(context_system::instance());
$PAGE->set_pagelayout('standard');
$PAGE->set_url('/local/amos/credits.php');
$PAGE->set_title(get_string('creditstitleshort', 'local_amos'));
$PAGE->set_heading(get_string('creditstitlelong', 'local_amos'));
if ($canedit and $editmode) {
$PAGE->set_button($OUTPUT->single_button(new moodle_url($PAGE->url, ['editmode' => 0]), get_string('turneditingoff'), 'get'));
$PAGE->set_url(new moodle_url($PAGE->url, ['editmode' => 1]));
} else if ($canedit and !$editmode) {
$PAGE->set_button($OUTPUT->single_button(new moodle_url($PAGE->url, ['editmode' => 1]), get_string('turneditingon'), 'get'));
}
$languages = mlang_tools::list_languages(false, true, false);
// Get the list of known languages.
foreach ($languages as $langcode => $langname) {
$list[$langcode] = (object)['langname' => $langname, 'maintainers' => [], 'contributors' => []];
}
// Get the list of maintainers, explicitly assigned contributors and
// other contributors based on submitted contributions.
$userfields = \core_user\fields::for_userpic()->get_sql('u')->selects;
list($sortsql, $sortparams) = users_order_by_sql();
$sql = "SELECT t.lang AS amoslang, t.status AS contribstatus, 1 AS iseditable {$userfields}
FROM {amos_translators} t
JOIN {user} u ON t.userid = u.id
WHERE t.lang <> 'X' AND t.lang <> 'en'
UNION
SELECT c.lang AS amoslang, ".AMOS_USER_CONTRIBUTOR." AS contribstatus, 0 AS iseditable {$userfields}
FROM {amos_contributions} c
JOIN {user} u ON c.authorid = u.id
WHERE c.status = :status
GROUP BY c.lang {$userfields}
HAVING COUNT(*) >= 3
ORDER BY amoslang, contribstatus, {$sortsql}, iseditable";
$rs = $DB->get_recordset_sql($sql, array_merge($sortparams, ['status' => local_amos_contribution::STATE_ACCEPTED]));
// Track credits with unexpected data.
$issues = [];
foreach ($rs as $user) {
$lang = $user->amoslang;
if (empty($lang)) {
$issues[] = (object)[
'problem' => 'Empty contribution language',
'record' => $user,
];
continue;
}
unset($user->amoslang);
$status = $user->contribstatus;
unset($user->contribstatus);
if (empty($list[$lang])) {
$issues[] = (object)[
'problem' => 'Unknown language',
'record' => $user,
];
continue;
}
if ($status == AMOS_USER_MAINTAINER) {
if (!isset($list[$lang]->maintainers[$user->id])) {
$list[$lang]->maintainers[$user->id] = $user;
}
} else if ($status == AMOS_USER_CONTRIBUTOR) {
if (!isset($list[$lang]->maintainers[$user->id]) and !isset($list[$lang]->contributors[$user->id])) {
$list[$lang]->contributors[$user->id] = $user;
}
} else {
$issues[] = (object)[
'problem' => 'Unknown credit status',
'record' => $user,
];
continue;
}
}
$rs->close();
echo $OUTPUT->header();
$output = $PAGE->get_renderer('local_amos');
echo $output->page_credits($list, current_language(), $editmode);
if (!empty($issues) and has_capability('local/amos:manage', $PAGE->context)) {
echo $output->page_credits_issues($issues);
}
echo $OUTPUT->footer();