Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * Report of the users' preferred languages
19
 *
20
 * @package     report_overviewstats
21
 * @copyright   2013 David Mudrak <david@moodle.com>
22
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
defined('MOODLE_INTERNAL') || die();
26
 
27
/**
28
 * Reports the number of users preferring a language for Moodle UI
29
 */
30
class report_overviewstats_chart_langs extends report_overviewstats_chart {
31
 
32
    /**
33
     * @return string
34
     */
35
    public function get_content() {
36
 
37
        $this->prepare_data();
38
 
39
        $title = get_string('chart-langs', 'report_overviewstats');
40
        $info = html_writer::div(get_string('chart-langs-info', 'report_overviewstats', count($this->data)), 'chartinfo');
41
        $chart = html_writer::tag('div', '', array(
42
            'id' => 'chart_langs',
43
            'class' => 'chartplaceholder',
44
            'style' => 'min-height: '.max(66, (count($this->data) * 20)).'px;'
45
        ));
46
 
47
        return array($title => $info . $chart);
48
    }
49
 
50
    /**
51
     * @see parent
52
     */
53
    public function inject_page_requirements(moodle_page $page) {
54
 
55
        $this->prepare_data();
56
 
57
        $page->requires->yui_module(
58
            'moodle-report_overviewstats-charts',
59
            'M.report_overviewstats.charts.langs.init',
60
            array($this->data)
61
        );
62
    }
63
 
64
    /**
65
     * Prepares data to report
66
     */
67
    protected function prepare_data() {
68
        global $DB;
69
 
70
        if (!is_null($this->data)) {
71
            return;
72
        }
73
 
74
        $sql = "SELECT lang, COUNT(*)
75
                  FROM {user}
76
                 WHERE deleted = 0 AND confirmed = 1
77
              GROUP BY lang
78
              ORDER BY COUNT(*) DESC";
79
 
80
        $data = array();
81
        foreach ($DB->get_records_sql_menu($sql) as $lang => $count) {
82
            if (get_string_manager()->translation_exists($lang)) {
83
                $langname = get_string_manager()->get_string('thislanguageint', 'core_langconfig', null, $lang);
84
            } else {
85
                $langname = $lang;
86
            }
87
            $data[] = array(
88
                'language' => $langname,
89
                'count' => $count
90
            );
91
        }
92
 
93
        $this->data = $data;
94
    }
95
}