Skip to content

Commit

Permalink
MDL-29030 standardise report_courseoverview
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Nov 6, 2011
1 parent c3a18ed commit fd2af3f
Show file tree
Hide file tree
Showing 6 changed files with 258 additions and 186 deletions.
44 changes: 22 additions & 22 deletions report/courseoverview/db/access.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.com //
// //
// Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details: //
// //
// http://www.gnu.org/copyleft/gpl.html //
// //
///////////////////////////////////////////////////////////////////////////
/**
* Report capabilities
*
* @package report
* @subpackage courseoverview
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

$capabilities = array(

Expand Down
207 changes: 115 additions & 92 deletions report/courseoverview/index.php
Original file line number Diff line number Diff line change
@@ -1,122 +1,145 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Course overview report
*
* @package report
* @subpackage courseoverview
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

require_once('../../config.php');
require_once($CFG->dirroot.'/lib/statslib.php');
require_once($CFG->libdir.'/adminlib.php');

$report = optional_param('report', STATS_REPORT_ACTIVE_COURSES, PARAM_INT);
$time = optional_param('time', 0, PARAM_INT);
$numcourses = optional_param('numcourses', 20, PARAM_INT);

if (empty($CFG->enablestats)) {
if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=stats", get_string('mustenablestats', 'admin'), 3);
} else {
print_error('statsdisable');
}
}

require_once('../../config.php');
require_once($CFG->dirroot.'/lib/statslib.php');
require_once($CFG->libdir.'/adminlib.php');
admin_externalpage_setup('reportcourseoverview');
echo $OUTPUT->header();

$report = optional_param('report', STATS_REPORT_ACTIVE_COURSES, PARAM_INT);
$time = optional_param('time', 0, PARAM_INT);
$numcourses = optional_param('numcourses', 20, PARAM_INT);
$course = get_site();
stats_check_uptodate($course->id);

if (empty($CFG->enablestats)) {
if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=stats", get_string('mustenablestats', 'admin'), 3);
} else {
print_error('statsdisable');
}
}
$strreports = get_string('reports');
$strcourseoverview = get_string('courseoverview');

admin_externalpage_setup('reportcourseoverview');
echo $OUTPUT->header();
$reportoptions = stats_get_report_options($course->id,STATS_MODE_RANKED);

$course = get_site();
stats_check_uptodate($course->id);
$earliestday = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_daily}');
$earliestweek = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_weekly}');
$earliestmonth = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_monthly}');

$strreports = get_string('reports');
$strcourseoverview = get_string('courseoverview');
if (empty($earliestday)) $earliestday = time();
if (empty($earliestweek)) $earliestweek = time();
if (empty($earliestmonth)) $earliestmonth = time();

$reportoptions = stats_get_report_options($course->id,STATS_MODE_RANKED);
$now = stats_get_base_daily();
$lastweekend = stats_get_base_weekly();
$lastmonthend = stats_get_base_monthly();

$earliestday = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_daily}');
$earliestweek = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_weekly}');
$earliestmonth = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_monthly}');
$timeoptions = stats_get_time_options($now,$lastweekend,$lastmonthend,$earliestday,$earliestweek,$earliestmonth);

if (empty($earliestday)) $earliestday = time();
if (empty($earliestweek)) $earliestweek = time();
if (empty($earliestmonth)) $earliestmonth = time();
if (empty($timeoptions)) {
print_error('nostatstodisplay', 'error', $CFG->wwwroot.'/course/view.php?id='.$course->id);
}

$now = stats_get_base_daily();
$lastweekend = stats_get_base_weekly();
$lastmonthend = stats_get_base_monthly();
echo '<form action="index.php" method="post">'."\n";
echo '<div>';

$timeoptions = stats_get_time_options($now,$lastweekend,$lastmonthend,$earliestday,$earliestweek,$earliestmonth);
$table = new html_table();
$table->width = '*';
$table->align = array('left','left','left','left','left','left');

if (empty($timeoptions)) {
print_error('nostatstodisplay', 'error', $CFG->wwwroot.'/course/view.php?id='.$course->id);
}
$reporttypemenu = html_writer::select($reportoptions,'report',$report, false);
$timeoptionsmenu = html_writer::select($timeoptions,'time',$time, false);

echo '<form action="index.php" method="post">'."\n";
echo '<div>';
$table->data[] = array(get_string('statsreporttype'),$reporttypemenu,
get_string('statstimeperiod'),$timeoptionsmenu,
'<input type="text" name="numcourses" size="3" maxlength="2" value="'.$numcourses.'" />',
'<input type="submit" value="'.get_string('view').'" />') ;

$table = new html_table();
$table->width = '*';
$table->align = array('left','left','left','left','left','left');
echo html_writer::table($table);
echo '</div>';
echo '</form>';

$reporttypemenu = html_writer::select($reportoptions,'report',$report, false);
$timeoptionsmenu = html_writer::select($timeoptions,'time',$time, false);
echo $OUTPUT->heading($reportoptions[$report]);

$table->data[] = array(get_string('statsreporttype'),$reporttypemenu,
get_string('statstimeperiod'),$timeoptionsmenu,
'<input type="text" name="numcourses" size="3" maxlength="2" value="'.$numcourses.'" />',
'<input type="submit" value="'.get_string('view').'" />') ;

echo html_writer::table($table);
echo '</div>';
echo '</form>';
if (!empty($report) && !empty($time)) {
$param = stats_get_parameters($time,$report,SITEID,STATS_MODE_RANKED);
if (!empty($param->sql)) {
$sql = $param->sql;
} else {
$sql = "SELECT courseid,".$param->fields."
FROM {".'stats_'.$param->table."}
WHERE timeend >= $param->timeafter AND stattype = 'activity' AND roleid = 0
GROUP BY courseid
$param->extras
ORDER BY $param->orderby";
}

echo $OUTPUT->heading($reportoptions[$report]);
$courses = $DB->get_records_sql($sql, $param->params, 0, $numcourses);

if (empty($courses)) {
echo $OUTPUT->notification(get_string('statsnodata'));
echo '</td></tr></table>';

if (!empty($report) && !empty($time)) {
$param = stats_get_parameters($time,$report,SITEID,STATS_MODE_RANKED);
if (!empty($param->sql)) {
$sql = $param->sql;
} else {
if (empty($CFG->gdversion)) {
echo '<div class="graph">(' . get_string("gdneed") .')</div>';
} else {
$sql = "SELECT courseid,".$param->fields."
FROM {".'stats_'.$param->table."}
WHERE timeend >= $param->timeafter AND stattype = 'activity' AND roleid = 0
GROUP BY courseid
$param->extras
ORDER BY $param->orderby";
echo '<div class="graph"><img alt="'.get_string('courseoverviewgraph').'" src="'.$CFG->wwwroot.'/report/courseoverview/reportsgraph.php?time='.$time.'&report='.$report.'&numcourses='.$numcourses.'" /></div>';
}

$courses = $DB->get_records_sql($sql, $param->params, 0, $numcourses);

if (empty($courses)) {
echo $OUTPUT->notification(get_string('statsnodata'));
echo '</td></tr></table>';
$table = new html_table();
$table->align = array('left','center','center','center');
$table->head = array(get_string('course'),$param->line1);
if (!empty($param->line2)) {
$table->head[] = $param->line2;
}
if (!empty($param->line3)) {
$table->head[] = $param->line3;
}

} else {
if (empty($CFG->gdversion)) {
echo '<div class="graph">(' . get_string("gdneed") .')</div>';
} else {
echo '<div class="graph"><img alt="'.get_string('courseoverviewgraph').'" src="'.$CFG->wwwroot.'/report/courseoverview/reportsgraph.php?time='.$time.'&report='.$report.'&numcourses='.$numcourses.'" /></div>';
}
foreach ($courses as $c) {
$a = array();
$a[] = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$c->courseid.'">'.$DB->get_field('course', 'shortname', array('id'=>$c->courseid)).'</a>';

$table = new html_table();
$table->align = array('left','center','center','center');
$table->head = array(get_string('course'),$param->line1);
if (!empty($param->line2)) {
$table->head[] = $param->line2;
}
if (!empty($param->line3)) {
$table->head[] = $param->line3;
$a[] = $c->line1;
if (isset($c->line2)) {
$a[] = $c->line2;
}

foreach ($courses as $c) {
$a = array();
$a[] = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$c->courseid.'">'.$DB->get_field('course', 'shortname', array('id'=>$c->courseid)).'</a>';

$a[] = $c->line1;
if (isset($c->line2)) {
$a[] = $c->line2;
}
if (isset($c->line3)) {
$a[] = round($c->line3,2);
}
$table->data[] = $a;
if (isset($c->line3)) {
$a[] = round($c->line3,2);
}
echo html_writer::table($table);
$table->data[] = $a;
}
echo html_writer::table($table);
}
echo $OUTPUT->footer();
}
echo $OUTPUT->footer();
10 changes: 5 additions & 5 deletions report/courseoverview/lang/en/report_courseoverview.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
Expand All @@ -16,11 +15,12 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Strings for component 'report_courseoverview', language 'en', branch 'MOODLE_20_STABLE'
* Strings for component 'report_courseoverview'.
*
* @package report_courseoverview
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package report
* @subpackage courseoverview
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

$string['courseoverview:view'] = 'View course overview report';
Expand Down
Loading

0 comments on commit fd2af3f

Please sign in to comment.