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 breakdown.
19
 *
20
 * @package    report_coursesize
21
 * @copyright  2017 Catalyst IT {@link http://www.catalyst.net.nz}
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
require_once('../../config.php');
26
require_once($CFG->libdir.'/adminlib.php');
27
 
28
$courseid = required_param('id', PARAM_INT);
29
 
30
admin_externalpage_setup('reportcoursesize');
31
 
32
$course = $DB->get_record('course', array('id' => $courseid));
33
 
34
$context = context_course::instance($course->id);
35
$contextcheck = $context->path . '/%';
36
 
37
$sizesql = "SELECT a.component, a.filearea, SUM(a.filesize) as filesize
38
              FROM (SELECT DISTINCT f.contenthash, f.component, f.filesize, f.filearea
39
                    FROM {files} f
40
                    JOIN {context} ctx ON f.contextid = ctx.id
41
                    WHERE ".$DB->sql_concat('ctx.path', "'/'")." LIKE ?
42
                       AND f.filename != '.') a
43
             GROUP BY a.component, a.filearea";
44
 
45
$cxsizes = $DB->get_recordset_sql($sizesql, array($contextcheck));
46
 
47
$coursetable = new html_table();
48
$coursetable->align = array('right', 'right', 'right');
49
$coursetable->head = array(get_string('plugin'), get_string('filearea', 'report_coursesize'), get_string('size'));
50
$coursetable->data = array();
51
 
52
foreach ($cxsizes as $cxdata) {
53
    $row = array();
54
    $row[] = $cxdata->component;
55
    $row[] = $cxdata->filearea;
56
    $row[] = display_size($cxdata->filesize);
57
 
58
    $coursetable->data[] = $row;
59
}
60
$cxsizes->close();
61
 
62
// Calculate filesize shared with other courses.
63
$sizesql = "SELECT SUM(filesize) FROM (SELECT DISTINCT contenthash, filesize
64
            FROM {files} f
65
            JOIN {context} ctx ON f.contextid = ctx.id
66
            WHERE ".$DB->sql_concat('ctx.path', "'/'")." NOT LIKE ?
67
                AND f.contenthash IN (SELECT DISTINCT f.contenthash
68
                                      FROM {files} f
69
                                      JOIN {context} ctx ON f.contextid = ctx.id
70
                                     WHERE ".$DB->sql_concat('ctx.path', "'/'")." LIKE ?
71
                                       AND f.filename != '.')) b";
72
$size = $DB->get_field_sql($sizesql, array($contextcheck, $contextcheck));
73
if (!empty($size)) {
74
    $size = display_size($size);
75
}
76
 
77
 
78
// All the processing done, the rest is just output stuff.
79
 
80
print $OUTPUT->header();
81
 
82
print $OUTPUT->heading(get_string('coursesize', 'report_coursesize'). " - ". format_string($course->fullname));
83
print $OUTPUT->box(get_string('coursereport', 'report_coursesize'));
84
if (!empty($size)) {
85
    print $OUTPUT->box(get_string('sharedusagecourse', 'report_coursesize', $size));
86
}
87
 
88
print html_writer::table($coursetable);
89
print $OUTPUT->footer();