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
admin_externalpage_setup('reportcoursestats', '', null, '', array('pagelayout'=>'report'));
31
 
32
function get_amount_created_courses($category) {
33
	global $DB;
34
 
35
	if ($category == ALL_CATEGORIES) {
36
		return ($DB->count_records(COURSE_TABLE_NAME,
37
			array('visible'=>'1')) - 1);
38
	} else {
39
		return $DB->count_records(COURSE_TABLE_NAME,
40
			array('visible'=>'1', 'category'=>$category));
41
	}
42
}
43
function get_amount_used_courses($category) {
44
	global $DB;
45
 
46
	if ($category == ALL_CATEGORIES) {
47
		return $DB->count_records_sql('SELECT COUNT(*) FROM {report_coursestats} cs JOIN {course} co ON co.id = cs.courseid WHERE co.visible = :visible',
48
			array('visible'=>'1'));
49
	} else {
50
		return $DB->count_records_sql('SELECT COUNT(*) FROM {report_coursestats} cs JOIN {course} co ON co.id = cs.courseid WHERE co.category = :cat AND co.visible = :visible',
51
			array('cat'=>$category, 'visible'=>'1'));
52
	}
53
}
54
 
55
echo $OUTPUT->header();
56
 
57
$result = $DB->get_records(COURSE_CATEGORIES_TABLE_NAME, null, 'name');
58
 
59
$table = new html_table();
60
$table->size = array( '60%', '10%', '10%', '10%', '10%');
61
$table->head = array(get_string('lb_category', 'report_coursestats'), get_string('lb_courses_created_amount', 'report_coursestats'),
62
	get_string('lb_used_courses', 'report_coursestats'), get_string('lb_not_used_courses', 'report_coursestats'), get_string('lb_percent_of_used_courses', 'report_coursestats'));
63
 
64
// All categories
65
$link = '<a href=' . $CFG->wwwroot . '/report/coursestats/main.php?category=' . ALL_CATEGORIES . '>' .
66
	get_string('lb_all_categories', 'report_coursestats') . '</a>';
67
$co_created = get_amount_created_courses(ALL_CATEGORIES);
68
$co_used = get_amount_used_courses(ALL_CATEGORIES);
69
if ($co_created > 0) {
70
	$co_percent = number_format(($co_used / $co_created) * 100, 2) . '%';
71
} else {
72
	$co_percent = '-';
73
}
74
 
75
$link_co_created = '<a href=' . $CFG->wwwroot . '/report/coursestats/courses.php?type=' . CREATED_COURSES . '&category=' . ALL_CATEGORIES . '>' .
76
	$co_created . '</a>';
77
 
78
$link_co_used = '<a href=' . $CFG->wwwroot . '/report/coursestats/courses.php?type=' . USED_COURSES . '&category=' . ALL_CATEGORIES . '>' .
79
	$co_used . '</a>';
80
 
81
$link_co_notused = '<a href=' . $CFG->wwwroot . '/report/coursestats/courses.php?type=' . NOTUSED_COURSES . '&category=' . ALL_CATEGORIES . '>' .
82
	($co_created - $co_used) . '</a>';
83
 
84
$table->data[] = array($link, $link_co_created, $link_co_used, $link_co_notused, $co_percent);
85
 
86
// Each category
87
$cat_array = array();
88
$created_courses_array = array();
89
$used_courses_array = array();
90
$percentage_used_courses_array = array();
91
 
92
foreach ($result as $cs) {
93
	$co_created = get_amount_created_courses($cs->id);
94
	$co_used = get_amount_used_courses($cs->id);
95
 
96
    $cat_array[] = $cs->name;
97
    $created_courses_array[] = $co_created;
98
	$used_courses_array[] = $co_used;
99
 
100
    if ($co_created > 0) {
101
		$co_percent = number_format(($co_used / $co_created) * 100, 2) . '%';
102
		$percentage_used_courses_array[] = number_format(($co_used / $co_created) * 100, 2);
103
	} else {
104
		$co_percent = '-';
105
		$percentage_used_courses_array[] = 0;
106
	}
107
 
108
	$catfullname = $cs->name;
109
	// check if category has parent
110
	if ($cs->depth == 2) {
111
		$parents = explode("/", $cs->path);
112
		$id = $parents[count($parents) - 2];
113
		$temp = $DB->get_record(COURSE_CATEGORIES_TABLE_NAME, ['id' => $id]);
114
		$catfullname = $temp->name . ' -> ' . $catfullname;
115
	}
116
 
117
    $link = '<a href=' . $CFG->wwwroot . '/report/coursestats/main.php?category=' . $cs->id . '>' . $catfullname . '</a>';
118
 
119
	$link_co_created = '<a href=' . $CFG->wwwroot . '/report/coursestats/courses.php?type=' . CREATED_COURSES . '&category=' . $cs->id . '>' .
120
		$co_created . '</a>';
121
 
122
	$link_co_used = '<a href=' . $CFG->wwwroot . '/report/coursestats/courses.php?type=' . USED_COURSES . '&category=' . $cs->id . '>' .
123
		$co_used . '</a>';
124
 
125
	$link_co_notused = '<a href=' . $CFG->wwwroot . '/report/coursestats/courses.php?type=' . NOTUSED_COURSES . '&category=' . $cs->id . '>' .
126
		($co_created - $co_used) . '</a>';
127
 
128
	$row = array($link, $link_co_created, $link_co_used, $link_co_notused, $co_percent);
129
	$table->data[] = $row;
130
}
131
 
132
if (class_exists('core\chart_bar')) {
133
	$chart_stacked = new core\chart_bar();
134
 
135
	$created_courses_serie = new core\chart_series(get_string('lb_courses_created_amount', 'report_coursestats'), $created_courses_array);
136
	$used_courses_serie = new core\chart_series(get_string('lb_used_courses', 'report_coursestats'), $used_courses_array);
137
	$percentage_used_courses_serie = new core\chart_series(get_string('lb_percent_of_used_courses', 'report_coursestats'), $percentage_used_courses_array);
138
	$percentage_used_courses_serie->set_type(\core\chart_series::TYPE_LINE);
139
 
140
	$chart_stacked->add_series($percentage_used_courses_serie);
141
	$chart_stacked->add_series($created_courses_serie);
142
	$chart_stacked->add_series($used_courses_serie);
143
	$chart_stacked->set_labels($cat_array);
144
 
145
	echo $OUTPUT->render_chart($chart_stacked, false);
146
}
147
 
148
$url_csv = new moodle_url($CFG->wwwroot . '/report/coursestats/csvgen.php');
149
$link_csv = html_writer::link($url_csv, get_string('link_csv', 'report_coursestats'));
150
echo '<p align="center">' . $link_csv . '</p>';
151
 
152
echo html_writer::table($table);
153
 
154
echo $OUTPUT->footer();
155