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
 * Course overview report
19
 *
20
 * @package    report
21
 * @subpackage courseoverview
22
 * @copyright  1999 onwards Martin Dougiamas  {@link http://moodle.com}
23
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
 
26
require_once('../../config.php');
27
require_once($CFG->dirroot.'/lib/statslib.php');
28
require_once($CFG->libdir.'/adminlib.php');
29
require_once($CFG->dirroot.'/report/courseoverview/locallib.php');
30
 
31
$report     = optional_param('report', STATS_REPORT_ACTIVE_COURSES, PARAM_INT);
32
$time       = optional_param('time', 0, PARAM_INT);
33
$numcourses = optional_param('numcourses', 20, PARAM_INT);
34
$systemcontext = context_system::instance();
35
 
36
if (empty($CFG->enablestats)) {
37
    if (has_capability('moodle/site:config', $systemcontext)) {
38
        redirect("$CFG->wwwroot/$CFG->admin/search.php?query=enablestats", get_string('mustenablestats', 'admin'), 3);
39
    } else {
40
        throw new \moodle_exception('statsdisable');
41
    }
42
}
43
 
44
admin_externalpage_setup('reportcourseoverview', '', null, '', array('pagelayout'=>'report'));
45
echo $OUTPUT->header();
46
 
47
$course = get_site();
48
stats_check_uptodate($course->id);
49
 
50
$strreports = get_string('reports');
51
$strcourseoverview = get_string('courseoverview');
52
 
53
$reportoptions = stats_get_report_options($course->id,STATS_MODE_RANKED);
54
 
55
$earliestday = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_daily}');
56
$earliestweek = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_weekly}');
57
$earliestmonth = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_monthly}');
58
 
59
if (empty($earliestday)) $earliestday = time();
60
if (empty($earliestweek)) $earliestweek = time();
61
if (empty($earliestmonth)) $earliestmonth = time();
62
 
63
$now = stats_get_base_daily();
64
$lastweekend = stats_get_base_weekly();
65
$lastmonthend = stats_get_base_monthly();
66
 
67
$timeoptions = stats_get_time_options($now,$lastweekend,$lastmonthend,$earliestday,$earliestweek,$earliestmonth);
68
 
69
if (empty($timeoptions)) {
70
    throw new \moodle_exception('nostatstodisplay', 'error', $CFG->wwwroot.'/course/view.php?id='.$course->id);
71
}
72
 
73
echo html_writer::start_tag('form', ['action' => 'index.php', 'method' => 'post',
74
    'class' => 'd-flex flex-wrap align-items-center']);
75
echo html_writer::start_tag('div');
76
 
77
$table = new html_table();
78
$table->width = '*';
79
$table->align = array('left','left','left','left','left','left');
80
 
81
$reporttypemenu = html_writer::label(get_string('statsreporttype'), 'menureport', false, array('class' => 'accesshide'));
82
$reporttypemenu .= html_writer::select($reportoptions,'report',$report, false);
83
$timeoptionsmenu = html_writer::label(get_string('time'), 'menutime', false, array('class' => 'accesshide'));
84
$timeoptionsmenu .= html_writer::select($timeoptions,'time',$time, false);
85
 
86
$table->data[] = array(get_string('statsreporttype'),$reporttypemenu,
87
                       get_string('statstimeperiod'),$timeoptionsmenu,
88
                       html_writer::label(get_string('numberofcourses'), 'numcourses', false, array('class' => 'accesshide')) .
89
                       html_writer::empty_tag('input', array('type' => 'text', 'class' => 'form-control',
90
                           'id' => 'numcourses', 'name' => 'numcourses', 'size' => '3', 'maxlength' => '2',
91
                           'value' => $numcourses)),
92
                       html_writer::empty_tag('input', array('type' => 'submit', 'class' => 'btn btn-secondary',
93
                           'value' => get_string('view'))));
94
 
95
echo html_writer::table($table);
96
echo html_writer::end_tag('div');
97
echo html_writer::end_tag('form');
98
 
99
echo $OUTPUT->heading($reportoptions[$report]);
100
 
101
 
102
if (!empty($report) && !empty($time)) {
103
    $param = stats_get_parameters($time,$report,SITEID,STATS_MODE_RANKED);
104
    if (!empty($param->sql)) {
105
        $sql = $param->sql;
106
    } else {
107
        $sql = "SELECT courseid,".$param->fields."
108
                  FROM {".'stats_'.$param->table."}
109
                 WHERE timeend >= $param->timeafter AND stattype = 'activity' AND roleid = 0
110
              GROUP BY courseid
111
                       $param->extras
112
              ORDER BY $param->orderby";
113
    }
114
 
115
    $courses = $DB->get_records_sql($sql, $param->params, 0, $numcourses);
116
 
117
    if (empty($courses)) {
118
        echo $OUTPUT->notification(get_string('statsnodata'));
119
        echo '</td></tr></table>';
120
 
121
    } else {
122
        require_capability('report/courseoverview:view', $systemcontext);
123
        echo html_writer::start_div();
124
        report_courseoverview_print_chart($report, $time, $numcourses);
125
        echo html_writer::end_div();
126
 
127
        $table = new html_table();
128
        $table->align = array('left','center','center','center');
129
        $table->head = array(get_string('course'),$param->line1);
130
        if (!empty($param->line2)) {
131
            $table->head[] = $param->line2;
132
        }
133
        if (!empty($param->line3)) {
134
            $table->head[] = $param->line3;
135
        }
136
 
137
        foreach  ($courses as $c) {
138
            $a = array();
139
            $a[] = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$c->courseid.'">'.$DB->get_field('course', 'shortname', array('id'=>$c->courseid)).'</a>';
140
 
141
            $a[] = $c->line1;
142
            if (isset($c->line2)) {
143
                $a[] = $c->line2;
144
            }
145
            if (isset($c->line3)) {
146
                $a[] = round($c->line3,2);
147
            }
148
            $table->data[] = $a;
149
        }
150
        echo html_writer::table($table);
151
    }
152
}
153
echo $OUTPUT->footer();