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
 * Strings for component 'report_coursestats', language 'en'
19
 *
20
 * @package   	report
21
 * @subpackage 	coursestats
22
 * @copyright 	2017 Paulo Jr.
23
 * @license   	http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
 
26
require(dirname(__FILE__).'/../../config.php');
27
require_once($CFG->libdir.'/adminlib.php');
28
require(__DIR__. '/constants.php');
29
 
30
$type = optional_param('type', CREATED_COURSES, PARAM_ALPHA);    // usage type
31
$category = optional_param('category', ALL_CATEGORIES, PARAM_INT);
32
 
33
admin_externalpage_setup('reportcoursestats', '', null, '', array('pagelayout'=>'report'));
34
 
35
$url = new moodle_url($CFG->wwwroot . '/report/coursestats/index.php');
36
$link = html_writer::link($url, get_string('link_back', 'report_coursestats'));
37
 
38
echo $OUTPUT->header();
39
 
40
if ($type == CREATED_COURSES && $category == ALL_CATEGORIES) {
41
    $catname = get_string('lb_all_categories', 'report_coursestats');
42
	$rs = $DB->get_recordset_sql('SELECT co.id, co.shortname, co.fullname FROM {course} co WHERE co.visible = :visible ORDER BY co.shortname',
43
			array('visible'=>'1'));
44
} else if ($type == CREATED_COURSES && $category != ALL_CATEGORIES) {
45
    $cat = $DB->get_record(COURSE_CATEGORIES_TABLE_NAME, array('id'=>$category));
46
	$catname = $cat->name;
47
 
48
	$rs = $DB->get_recordset_sql('SELECT co.id, co.shortname, co.fullname FROM {course} co WHERE co.category = :cat AND co.visible = :visible ORDER BY co.shortname',
49
			array('cat'=>$category, 'visible'=>'1'));
50
} else if ($type == USED_COURSES && $category == ALL_CATEGORIES) {
51
    $catname = get_string('lb_all_categories', 'report_coursestats');
52
	$rs = $DB->get_recordset_sql('SELECT co.id, co.shortname, co.fullname FROM {report_coursestats} cs JOIN {course} co ON co.id = cs.courseid WHERE co.visible = :visible ORDER BY co.shortname',
53
			array('visible'=>'1'));
54
} else if ($type == USED_COURSES && $category != ALL_CATEGORIES) {
55
    $cat = $DB->get_record(COURSE_CATEGORIES_TABLE_NAME, array('id'=>$category));
56
	$catname = $cat->name;
57
 
58
	$rs = $DB->get_recordset_sql('SELECT co.id, co.shortname, co.fullname FROM {report_coursestats} cs JOIN {course} co ON co.id = cs.courseid WHERE co.category = :cat AND co.visible = :visible ORDER BY co.shortname',
59
			array('cat'=>$category, 'visible'=>'1'));
60
} else if ($type == NOTUSED_COURSES && $category == ALL_CATEGORIES) {
61
    $catname = get_string('lb_all_categories', 'report_coursestats');
62
	$rs = $DB->get_recordset_sql('SELECT co.id, co.shortname, co.fullname FROM {course} co LEFT JOIN {report_coursestats} cs ON co.id = cs.courseid WHERE co.visible = :visible AND cs.courseid IS NULL ORDER BY co.shortname',
63
			array('visible'=>'1'));
64
} else { // ($type == NOTUSED_COURSES && $category != ALL_CATEGORIES)
65
    $cat = $DB->get_record(COURSE_CATEGORIES_TABLE_NAME, array('id'=>$category));
66
	$catname = $cat->name;
67
 
68
	$rs = $DB->get_recordset_sql('SELECT co.id, co.shortname, co.fullname FROM {course} co LEFT JOIN {report_coursestats} cs ON co.id = cs.courseid WHERE co.category = :cat AND co.visible = :visible AND cs.courseid IS NULL ORDER BY co.shortname',
69
			array('cat'=>$category, 'visible'=>'1'));
70
}
71
 
72
echo $OUTPUT->heading(get_string('lb_category', 'report_coursestats') . ': ' . $catname . ' - ' . $link);
73
 
74
$table = new html_table();
75
$table->head = array(get_string('lb_course_name', 'report_coursestats'), get_string('lb_course_fullname', 'report_coursestats'));
76
foreach ($rs as $cs) {
77
    $row = array('<a href=' . $CFG->wwwroot . '/course/view.php?id=' . $cs->id . '>' . $cs->shortname . '</a>', $cs->fullname);
78
    $table->data[] = $row;
79
}
80
$rs->close();
81
 
82
echo html_writer::table($table);
83
 
84
 
85
echo $OUTPUT->footer();