Last active
July 22, 2016 01:54
-
-
Save willianmano/9e39bf4c2c8ab8b90022568733f561ac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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/>. | |
/** | |
* Page for general user badges count | |
* | |
* @package core | |
* @subpackage badges | |
* @copyright 2016 onwards Willian Mano {@link http://www.conecti.me/} | |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
* @author Willian Mano <[email protected]> | |
*/ | |
require_once(dirname(dirname(__FILE__)) . '/config.php'); | |
require_once($CFG->libdir . '/badgeslib.php'); | |
require_login(); | |
if (empty($CFG->enablebadges)) { | |
print_error('badgesdisabled', 'badges'); | |
} | |
if (empty($CFG->badges_allowcoursebadges) && ($type == BADGE_TYPE_COURSE)) { | |
print_error('coursebadgesdisabled', 'badges'); | |
} | |
$hdr = 'Quantidade de emblemas por usuário'; | |
$returnurl = new moodle_url('/'); | |
$PAGE->set_url($returnurl); | |
$title = get_string('sitebadges', 'badges'); | |
$PAGE->set_context(context_system::instance()); | |
$PAGE->set_pagelayout('admin'); | |
$PAGE->set_heading($title . ': ' . $hdr); | |
navigation_node::override_active_url(new moodle_url('/badges/index.php', array('type' => BADGE_TYPE_SITE)), true); | |
if (!has_any_capability(array( | |
'moodle/badges:viewawarded', | |
'moodle/badges:createbadge', | |
'moodle/badges:awardbadge', | |
'moodle/badges:configuremessages', | |
'moodle/badges:configuredetails', | |
'moodle/badges:deletebadge'), $PAGE->context)) { | |
redirect($CFG->wwwroot); | |
} | |
$PAGE->set_title($hdr); | |
echo $OUTPUT->header(); | |
echo $OUTPUT->heading($PAGE->heading); | |
echo $OUTPUT->box('', 'notifyproblem hide', 'check_connection'); | |
$sql = "SELECT userid, u.email, u.firstname, u.lastname, count(userid) as qtd | |
FROM {badge_issued} b | |
INNER JOIN {user} u ON u.id = b.userid | |
GROUP BY userid | |
ORDER BY qtd DESC, u.firstname ASC"; | |
$alunos = $DB->get_records_sql($sql); | |
$table = new html_table(); | |
$table->attributes = array("class" => "table table-hover table-condensed table-striped"); | |
$table->head = array( | |
'Nome completo', | |
'Email', | |
'Quantidade de emblemas' | |
); | |
foreach($alunos as $aluno) { | |
$row = new html_table_row(); | |
$row->cells = array( | |
$aluno->firstname . ' ' . $aluno->lastname, | |
$aluno->email, | |
$aluno->qtd | |
); | |
$table->data[] = $row; | |
} | |
echo html_writer::table($table); | |
echo $OUTPUT->footer(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment