navigation MDL-14632 Added and implemented course report callback function

This commit is contained in:
samhemelryk
2009-09-21 07:22:57 +00:00
parent 9c8c6c29f0
commit dfab77a26e
10 changed files with 274 additions and 59 deletions
+1 -1
View File
@@ -16,7 +16,7 @@
$strreports = get_string('reports');
$PAGE->navbar->add($strreports);
$PAGE->set_url(new moodle_url($CFG->wwwroot.'/course/report.php', array('id'=>$id)));
$PAGE->set_title($course->fullname.': '.$strreports);
$PAGE->set_heading($course->fullname.': '.$strreports);
echo $OUTPUT->header();
+2 -2
View File
@@ -33,6 +33,8 @@
$chooselog = optional_param('chooselog', 0, PARAM_INT);
$logformat = optional_param('logformat', 'showashtml', PARAM_ALPHA);
$PAGE->set_url(new moodle_url($FULLME));
if ($hostid == $CFG->mnet_localhost_id) {
if (!$course = $DB->get_record('course', array('id'=>$id))) {
print_error('That\'s an invalid course id'.$id);
@@ -131,8 +133,6 @@
} else {
$PAGE->set_title($course->shortname .': '. $strlogs);
$PAGE->set_heading($course->fullname);
$PAGE->navbar->add($strreports, new moodle_url($CFG->wwwroot.'/course/report.php', array('id'=>$course->id)));
$PAGE->navbar->add($strlogs);
echo $OUTPUT->header();
}
+44 -2
View File
@@ -1,4 +1,27 @@
<?php // $Id$
<?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/>.
/**
* This file contains functions used by the log reports
*
* @package course-report
* @copyright 1999 onwards Martin Dougiamas http://moodle.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
function print_mnet_log_selector_form($hostid, $course, $selecteduser=0, $selecteddate='today',
$modname="", $modid=0, $modaction='', $selectedgroup=-1, $showcourses=0, $showusers=0, $logformat='showashtml') {
@@ -504,4 +527,23 @@ function print_log_selector_form($course, $selecteduser=0, $selecteddate='today'
echo '</form>';
}
?>
/**
* This function extends the navigation with the report items
*
* @param navigation_node $navigation The navigation node to extend
* @param stdClass $course The course to object for the report
* @param stdClass $context The context of the course
*/
function log_report_extend_navigation($navigation, $course, $context) {
global $CFG, $OUTPUT;
if (has_capability('coursereport/log:view', $context)) {
$url = new moodle_url($CFG->wwwroot.'/course/report/log/index.php', array('id'=>$course->id));
$navigation->add(get_string('log:view', 'coursereport_log'), $url, navigation_node::TYPE_SETTING, null, null, $OUTPUT->old_icon_url('i/report'));
}
if (has_capability('coursereport/log:viewlive', $context)) {
$livelogs = get_string('livelogs');
$link = html_link::make('/course/report/log/live.php?id='. $course->id, $livelogs);
$link->add_action(new popup_action('click', $link->url, 'livelog', array('height' => 500, 'width' => 800)));
$navigation->add($livelogs, $link, navigation_node::TYPE_SETTING, null, null, $OUTPUT->old_icon_url('i/report'));
}
}
+2
View File
@@ -11,6 +11,8 @@
print_error('invalidcourseid');
}
$PAGE->set_url(new moodle_url($FULLME));
require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
require_capability('coursereport/outline:view', $context);
+40
View File
@@ -0,0 +1,40 @@
<?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/>.
/**
* This file contains functions used by the outline report
*
* @since 2.0
* @package course-report
* @copyright 2009 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* This function extends the navigation with the report items
*
* @param navigation_node $navigation The navigation node to extend
* @param stdClass $course The course to object for the report
* @param stdClass $context The context of the course
*/
function outline_report_extend_navigation($navigation, $course, $context) {
global $CFG, $OUTPUT;
if (has_capability('coursereport/outline:view', $context)) {
$url = new moodle_url($CFG->wwwroot.'/course/report/outline/index.php', array('id'=>$course->id));
$navigation->add(get_string( 'activityreport' ), $url, navigation_node::TYPE_SETTING, null, null, $OUTPUT->old_icon_url('i/report'));
}
}
+40
View File
@@ -0,0 +1,40 @@
<?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/>.
/**
* This file contains functions used by the participation report
*
* @since 2.0
* @package course-report
* @copyright 2009 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* This function extends the navigation with the report items
*
* @param navigation_node $navigation The navigation node to extend
* @param stdClass $course The course to object for the report
* @param stdClass $context The context of the course
*/
function participation_report_extend_navigation($navigation, $course, $context) {
global $CFG, $OUTPUT;
if (has_capability('coursereport/participation:view', $context)) {
$url = new moodle_url($CFG->wwwroot.'/course/report/participation/index.php', array('id'=>$course->id));
$navigation->add(get_string('participationreport'), $url, navigation_node::TYPE_SETTING, null, null, $OUTPUT->old_icon_url('i/report'));
}
}
+14 -1
View File
@@ -5,7 +5,8 @@ require_once($CFG->libdir . '/completionlib.php');
define('COMPLETION_REPORT_PAGE',50);
// Get course
$course=$DB->get_record('course',array('id'=>required_param('course',PARAM_INT)));
$id = required_param('course',PARAM_INT);
$course=$DB->get_record('course',array('id'=>$id));
if(!$course) {
print_error('invalidcourseid');
}
@@ -38,6 +39,18 @@ function csv_quote($value) {
}
}
$url = new moodle_url($CFG->wwwroot.'/course/report/progress/index.php', array('course'=>$id));
if ($sort !== '') {
$url->param('sort', $sort);
}
if ($format !== '') {
$url->param('format', $format);
}
if ($start !== '') {
$url->param('start', $start);
}
$PAGE->set_url($url);
require_login($course);
// Check basic permission
+40
View File
@@ -0,0 +1,40 @@
<?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/>.
/**
* This file contains functions used by the progress report
*
* @since 2.0
* @package course-report
* @copyright 2009 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* This function extends the navigation with the report items
*
* @param navigation_node $navigation The navigation node to extend
* @param stdClass $course The course to object for the report
* @param stdClass $context The context of the course
*/
function progress_report_extend_navigation($navigation, $course, $context) {
global $CFG, $OUTPUT;
if (has_capability('coursereport/progress:view', $context)) {
$url = new moodle_url($CFG->wwwroot.'/course/report/progress/index.php', array('course'=>$course->id));
$navigation->add(get_string('completionreport','completion'), $url, navigation_node::TYPE_SETTING, null, null, $OUTPUT->old_icon_url('i/report'));
}
}
+83 -49
View File
@@ -1,59 +1,93 @@
<?php
/**
* This file is also required by /admin/reports/stats/index.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/>.
/**
* This file contains functions used by the log reports
*
* This file is also required by /admin/reports/stats/index.php.
*
* @package course-report
* @copyright 1999 onwards Martin Dougiamas http://moodle.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once($CFG->dirroot.'/lib/statslib.php');
function report_stats_mode_menu($course, $mode, $time, $url) {
global $CFG, $OUTPUT;
/*
$reportoptions = stats_get_report_options($course->id, $mode);
$timeoptions = report_stats_timeoptions($mode);
if (empty($timeoptions)) {
print_error('nostatstodisplay', '', $CFG->wwwroot.'/course/view.php?id='.$course->id);
}
*/
require_once($CFG->dirroot.'/lib/statslib.php');
$options = array();
$options[STATS_MODE_GENERAL] = get_string('statsmodegeneral');
$options[STATS_MODE_DETAILED] = get_string('statsmodedetailed');
if (has_capability('coursereport/stats:view', get_context_instance(CONTEXT_SYSTEM))) {
$options[STATS_MODE_RANKED] = get_string('reports');
}
$popupurl = $url."?course=$course->id&time=$time";
$select = html_select::make_popup_form($popupurl, 'mode', $options, 'switchmode', $mode);
$select->nothinglabel = false;
return $OUTPUT->select($select);
}
function report_stats_mode_menu($course, $mode, $time, $url) {
global $CFG, $OUTPUT;
/*
$reportoptions = stats_get_report_options($course->id, $mode);
$timeoptions = report_stats_timeoptions($mode);
if (empty($timeoptions)) {
print_error('nostatstodisplay', '', $CFG->wwwroot.'/course/view.php?id='.$course->id);
}
*/
function report_stats_timeoptions($mode) {
global $CFG, $DB;
$options = array();
$options[STATS_MODE_GENERAL] = get_string('statsmodegeneral');
$options[STATS_MODE_DETAILED] = get_string('statsmodedetailed');
if (has_capability('coursereport/stats:view', get_context_instance(CONTEXT_SYSTEM))) {
$options[STATS_MODE_RANKED] = get_string('reports');
}
$popupurl = $url."?course=$course->id&time=$time";
$select = html_select::make_popup_form($popupurl, 'mode', $options, 'switchmode', $mode);
$select->nothinglabel = false;
return $OUTPUT->select($select);
if ($mode == STATS_MODE_DETAILED) {
$earliestday = $DB->get_field_sql('SELECT timeend FROM {stats_user_daily} ORDER BY timeend');
$earliestweek = $DB->get_field_sql('SELECT timeend FROM {stats_user_weekly} ORDER BY timeend');
$earliestmonth = $DB->get_field_sql('SELECT timeend FROM {stats_user_monthly} ORDER BY timeend');
} else {
$earliestday = $DB->get_field_sql('SELECT timeend FROM {stats_daily} ORDER BY timeend');
$earliestweek = $DB->get_field_sql('SELECT timeend FROM {stats_weekly} ORDER BY timeend');
$earliestmonth = $DB->get_field_sql('SELECT timeend FROM {stats_monthly} ORDER BY timeend');
}
function report_stats_timeoptions($mode) {
global $CFG, $DB;
if ($mode == STATS_MODE_DETAILED) {
$earliestday = $DB->get_field_sql('SELECT timeend FROM {stats_user_daily} ORDER BY timeend');
$earliestweek = $DB->get_field_sql('SELECT timeend FROM {stats_user_weekly} ORDER BY timeend');
$earliestmonth = $DB->get_field_sql('SELECT timeend FROM {stats_user_monthly} ORDER BY timeend');
} else {
$earliestday = $DB->get_field_sql('SELECT timeend FROM {stats_daily} ORDER BY timeend');
$earliestweek = $DB->get_field_sql('SELECT timeend FROM {stats_weekly} ORDER BY timeend');
$earliestmonth = $DB->get_field_sql('SELECT timeend FROM {stats_monthly} ORDER BY timeend');
if (empty($earliestday)) $earliestday = time();
if (empty($earliestweek)) $earliestweek = time();
if (empty($earliestmonth)) $earliestmonth = time();
$now = stats_get_base_daily();
$lastweekend = stats_get_base_weekly();
$lastmonthend = stats_get_base_monthly();
return stats_get_time_options($now,$lastweekend,$lastmonthend,$earliestday,$earliestweek,$earliestmonth);
}
/**
* This function extends the navigation with the report items
*
* @param navigation_node $navigation The navigation node to extend
* @param stdClass $course The course to object for the report
* @param stdClass $context The context of the course
*/
function stats_report_extend_navigation($navigation, $course, $context) {
global $CFG, $OUTPUT;
if (has_capability('coursereport/stats:view', $context)) {
if (!empty($CFG->enablestats)) {
$url = new moodle_url($CFG->wwwroot.'/course/report/stats/index.php', array('id'=>$course->id));
$navigation->add(get_string('stats'), $url, navigation_node::TYPE_SETTING, null, null, $OUTPUT->old_icon_url('i/report'));
}
if (empty($earliestday)) $earliestday = time();
if (empty($earliestweek)) $earliestweek = time();
if (empty($earliestmonth)) $earliestmonth = time();
$now = stats_get_base_daily();
$lastweekend = stats_get_base_weekly();
$lastmonthend = stats_get_base_monthly();
return stats_get_time_options($now,$lastweekend,$lastmonthend,$earliestday,$earliestweek,$earliestmonth);
}
?>
}
+8 -4
View File
@@ -1276,14 +1276,18 @@ class global_navigation extends navigation_node {
// View course reports
if (has_capability('moodle/site:viewreports', $this->context)) { // basic capability for listing of reports
$reportkey = $currentcourse->add(get_string('reports'), self::TYPE_SETTING, null, null, $OUTPUT->old_icon_url('i/stats'));
$reportkey = $currentcourse->add(get_string('reports'), new moodle_url($CFG->wwwroot.'/course/report.php', array('id'=>$course->id)), self::TYPE_SETTING, null, null, $OUTPUT->old_icon_url('i/stats'));
$reportnav = $currentcourse->get($reportkey);
if ($reportnav) {
$coursereports = get_plugin_list('coursereport');
foreach ($coursereports as $report=>$dir) {
if (has_capability('coursereport/'.$report.':view', $this->context)) {
$url = new moodle_url($CFG->wwwroot.'/course/report/'.$report.'/view/index.php', array('id'=>$course->id));
$reportnav->add(get_string($report.':view', 'coursereport_'.$report), $url, navigation_node::TYPE_SETTING, null, null, $OUTPUT->old_icon_url('i/report'));
$libfile = $CFG->dirroot.'/course/report/'.$report.'/lib.php';
if (file_exists($libfile)) {
require_once($libfile);
$reportfunction = $report.'_report_extend_navigation';
if (function_exists($report.'_report_extend_navigation')) {
$reportfunction($reportnav, $course, $this->context);
}
}
}
}