From: samhemelryk Date: Mon, 21 Sep 2009 07:22:57 +0000 (+0000) Subject: navigation MDL-14632 Added and implemented course report callback function X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=dfab77a26e4c35b0c3bda2fa64b0b3e15616e1bd;p=moodle.git navigation MDL-14632 Added and implemented course report callback function --- diff --git a/course/report.php b/course/report.php index 951ae588e2..ad8711bc27 100644 --- a/course/report.php +++ b/course/report.php @@ -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(); diff --git a/course/report/log/index.php b/course/report/log/index.php index 1c24733785..113db54b45 100644 --- a/course/report/log/index.php +++ b/course/report/log/index.php @@ -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(); } diff --git a/course/report/log/lib.php b/course/report/log/lib.php index cf79b1ad4f..a218a60092 100644 --- a/course/report/log/lib.php +++ b/course/report/log/lib.php @@ -1,4 +1,27 @@ -. + +/** + * 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 ''; } -?> +/** + * 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')); + } +} \ No newline at end of file diff --git a/course/report/outline/index.php b/course/report/outline/index.php index 9b4c6d9207..d1d875d828 100644 --- a/course/report/outline/index.php +++ b/course/report/outline/index.php @@ -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); diff --git a/course/report/outline/lib.php b/course/report/outline/lib.php new file mode 100644 index 0000000000..2c6e6c316b --- /dev/null +++ b/course/report/outline/lib.php @@ -0,0 +1,40 @@ +. + +/** + * 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')); + } +} \ No newline at end of file diff --git a/course/report/participation/lib.php b/course/report/participation/lib.php new file mode 100644 index 0000000000..dd00251343 --- /dev/null +++ b/course/report/participation/lib.php @@ -0,0 +1,40 @@ +. + +/** + * 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')); + } +} \ No newline at end of file diff --git a/course/report/progress/index.php b/course/report/progress/index.php index ae295bea95..09286a872e 100644 --- a/course/report/progress/index.php +++ b/course/report/progress/index.php @@ -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 diff --git a/course/report/progress/lib.php b/course/report/progress/lib.php new file mode 100644 index 0000000000..9eef33d2d8 --- /dev/null +++ b/course/report/progress/lib.php @@ -0,0 +1,40 @@ +. + +/** + * 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')); + } +} \ No newline at end of file diff --git a/course/report/stats/lib.php b/course/report/stats/lib.php index 57acc8ae27..b9702d0120 100644 --- a/course/report/stats/lib.php +++ b/course/report/stats/lib.php @@ -1,59 +1,93 @@ . + +/** + * 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'); - - - 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); - } - */ - $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); + $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_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'); - } +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(); + if (empty($earliestday)) $earliestday = time(); + if (empty($earliestweek)) $earliestweek = time(); + if (empty($earliestmonth)) $earliestmonth = time(); - return stats_get_time_options($now,$lastweekend,$lastmonthend,$earliestday,$earliestweek,$earliestmonth); - } + $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')); + } + } +} \ No newline at end of file diff --git a/lib/navigationlib.php b/lib/navigationlib.php index cc0c41cf6d..251903374e 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -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); + } } } }