mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-57892 report_outline: add date filter
This commit is contained in:
parent
3fa531ea2c
commit
eadd195151
2 changed files with 127 additions and 6 deletions
74
report/outline/classes/filter_form.php
Normal file
74
report/outline/classes/filter_form.php
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
<?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/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Form to filter the outline report
|
||||||
|
*
|
||||||
|
* @package report_outline
|
||||||
|
* @copyright 2017 Davo Smith, Synergy Learning
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace report_outline;
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
global $CFG;
|
||||||
|
require_once($CFG->libdir.'/formslib.php');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class filter_form form to filter the results by date
|
||||||
|
* @package report_outline
|
||||||
|
*/
|
||||||
|
class filter_form extends \moodleform {
|
||||||
|
/**
|
||||||
|
* Form definition
|
||||||
|
* @throws \HTML_QuickForm_Error
|
||||||
|
* @throws \coding_exception
|
||||||
|
*/
|
||||||
|
protected function definition() {
|
||||||
|
$mform = $this->_form;
|
||||||
|
|
||||||
|
$mform->addElement('hidden', 'id');
|
||||||
|
$mform->setType('id', PARAM_INT);
|
||||||
|
|
||||||
|
$mform->addElement('header', 'filterheader', get_string('filter'));
|
||||||
|
$opts = ['optional' => true];
|
||||||
|
$mform->addElement('date_selector', 'filterstartdate', get_string('from'), $opts);
|
||||||
|
$mform->addElement('date_selector', 'filterenddate', get_string('to'), $opts);
|
||||||
|
|
||||||
|
$mform->setExpanded('filterheader', false);
|
||||||
|
|
||||||
|
// Add the filter/cancel buttons (without 'closeHeaderBefore', so they collapse with the filter).
|
||||||
|
$buttonarray = [
|
||||||
|
$mform->createElement('submit', 'submitbutton', get_string('filter')),
|
||||||
|
$mform->createElement('cancel'),
|
||||||
|
];
|
||||||
|
$mform->addGroup($buttonarray, 'buttonar', '', [' '], false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expand the form contents if the filter is in use.
|
||||||
|
* @throws \HTML_QuickForm_Error
|
||||||
|
*/
|
||||||
|
public function definition_after_data() {
|
||||||
|
$mform = $this->_form;
|
||||||
|
$filterstartdate = $mform->getElement('filterstartdate')->getValue();
|
||||||
|
$filterenddate = $mform->getElement('filterenddate')->getValue();
|
||||||
|
if (!empty($filterstartdate['enabled']) || !empty($filterenddate['enabled'])) {
|
||||||
|
$mform->setExpanded('filterheader', true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,16 +27,45 @@ require('../../config.php');
|
||||||
require_once($CFG->dirroot.'/report/outline/locallib.php');
|
require_once($CFG->dirroot.'/report/outline/locallib.php');
|
||||||
|
|
||||||
$id = required_param('id',PARAM_INT); // course id
|
$id = required_param('id',PARAM_INT); // course id
|
||||||
|
$startdate = optional_param('startdate', null, PARAM_INT);
|
||||||
|
$enddate = optional_param('enddate', null, PARAM_INT);
|
||||||
|
|
||||||
$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
|
$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
|
||||||
|
|
||||||
$PAGE->set_url('/report/outline/index.php', array('id'=>$id));
|
$pageparams = array('id' => $id);
|
||||||
|
if ($startdate) {
|
||||||
|
$pageparams['startdate'] = $startdate;
|
||||||
|
}
|
||||||
|
if ($enddate) {
|
||||||
|
$pageparams['enddate'] = $enddate;
|
||||||
|
}
|
||||||
|
|
||||||
|
$PAGE->set_url('/report/outline/index.php', $pageparams);
|
||||||
$PAGE->set_pagelayout('report');
|
$PAGE->set_pagelayout('report');
|
||||||
|
|
||||||
require_login($course);
|
require_login($course);
|
||||||
$context = context_course::instance($course->id);
|
$context = context_course::instance($course->id);
|
||||||
require_capability('report/outline:view', $context);
|
require_capability('report/outline:view', $context);
|
||||||
|
|
||||||
|
// Handle form to filter access logs by date.
|
||||||
|
$filterform = new \report_outline\filter_form();
|
||||||
|
$filterform->set_data(['id' => $course->id, 'filterstartdate' => $startdate, 'filterenddate' => $enddate]);
|
||||||
|
if ($filterform->is_cancelled()) {
|
||||||
|
$redir = $PAGE->url;
|
||||||
|
$redir->remove_params(['startdate', 'enddate']);
|
||||||
|
redirect($redir);
|
||||||
|
}
|
||||||
|
if ($filter = $filterform->get_data()) {
|
||||||
|
$redir = $PAGE->url;
|
||||||
|
if ($filter->filterstartdate) {
|
||||||
|
$redir->param('startdate', $filter->filterstartdate);
|
||||||
|
}
|
||||||
|
if ($filter->filterenddate) {
|
||||||
|
$redir->param('enddate', $filter->filterenddate);
|
||||||
|
}
|
||||||
|
redirect($redir);
|
||||||
|
}
|
||||||
|
|
||||||
// Trigger an activity report viewed event.
|
// Trigger an activity report viewed event.
|
||||||
$event = \report_outline\event\activity_report_viewed::create(array('context' => $context));
|
$event = \report_outline\event\activity_report_viewed::create(array('context' => $context));
|
||||||
$event->trigger();
|
$event->trigger();
|
||||||
|
@ -85,6 +114,8 @@ if ($useinternalreader) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$filterform->display();
|
||||||
|
|
||||||
echo $OUTPUT->container(get_string('computedfromlogs', 'admin', userdate($minlog)), 'loginfo');
|
echo $OUTPUT->container(get_string('computedfromlogs', 'admin', userdate($minlog)), 'loginfo');
|
||||||
|
|
||||||
$outlinetable = new html_table();
|
$outlinetable = new html_table();
|
||||||
|
@ -107,9 +138,19 @@ $modinfo = get_fast_modinfo($course);
|
||||||
if ($uselegacyreader) {
|
if ($uselegacyreader) {
|
||||||
// If we are going to use the internal (not legacy) log table, we should only get records
|
// If we are going to use the internal (not legacy) log table, we should only get records
|
||||||
// from the legacy table that exist before we started adding logs to the new table.
|
// from the legacy table that exist before we started adding logs to the new table.
|
||||||
|
$params = array('courseid' => $course->id, 'action' => 'view%', 'visible' => 1);
|
||||||
$limittime = '';
|
$limittime = '';
|
||||||
if (!empty($minloginternalreader)) {
|
if (!empty($minloginternalreader)) {
|
||||||
$limittime = ' AND time < :timeto ';
|
$limittime = ' AND time < :timeto ';
|
||||||
|
$params['timeto'] = $minloginternalreader;
|
||||||
|
}
|
||||||
|
if ($startdate) {
|
||||||
|
$limittime .= ' AND time >= :startdate ';
|
||||||
|
$params['startdate'] = $startdate;
|
||||||
|
}
|
||||||
|
if ($enddate) {
|
||||||
|
$limittime .= ' AND time < :enddate ';
|
||||||
|
$params['enddate'] = $enddate;
|
||||||
}
|
}
|
||||||
// Check if we need to show the last access.
|
// Check if we need to show the last access.
|
||||||
$sqllasttime = '';
|
$sqllasttime = '';
|
||||||
|
@ -127,10 +168,6 @@ if ($uselegacyreader) {
|
||||||
AND $logactionlike
|
AND $logactionlike
|
||||||
AND m.visible = :visible $limittime
|
AND m.visible = :visible $limittime
|
||||||
GROUP BY cm.id";
|
GROUP BY cm.id";
|
||||||
$params = array('courseid' => $course->id, 'action' => 'view%', 'visible' => 1);
|
|
||||||
if (!empty($minloginternalreader)) {
|
|
||||||
$params['timeto'] = $minloginternalreader;
|
|
||||||
}
|
|
||||||
$views = $DB->get_records_sql($sql, $params);
|
$views = $DB->get_records_sql($sql, $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,14 +178,24 @@ if ($useinternalreader) {
|
||||||
if ($showlastaccess) {
|
if ($showlastaccess) {
|
||||||
$sqllasttime = ", MAX(timecreated) AS lasttime";
|
$sqllasttime = ", MAX(timecreated) AS lasttime";
|
||||||
}
|
}
|
||||||
|
$params = array('courseid' => $course->id, 'contextmodule' => CONTEXT_MODULE);
|
||||||
|
$limittime = '';
|
||||||
|
if ($startdate) {
|
||||||
|
$limittime .= ' AND timecreated >= :startdate ';
|
||||||
|
$params['startdate'] = $startdate;
|
||||||
|
}
|
||||||
|
if ($enddate) {
|
||||||
|
$limittime .= ' AND timecreated < :enddate ';
|
||||||
|
$params['enddate'] = $enddate;
|
||||||
|
}
|
||||||
$sql = "SELECT contextinstanceid as cmid, COUNT('x') AS numviews, COUNT(DISTINCT userid) AS distinctusers $sqllasttime
|
$sql = "SELECT contextinstanceid as cmid, COUNT('x') AS numviews, COUNT(DISTINCT userid) AS distinctusers $sqllasttime
|
||||||
FROM {" . $logtable . "} l
|
FROM {" . $logtable . "} l
|
||||||
WHERE courseid = :courseid
|
WHERE courseid = :courseid
|
||||||
AND anonymous = 0
|
AND anonymous = 0
|
||||||
AND crud = 'r'
|
AND crud = 'r'
|
||||||
AND contextlevel = :contextmodule
|
AND contextlevel = :contextmodule
|
||||||
|
$limittime
|
||||||
GROUP BY contextinstanceid";
|
GROUP BY contextinstanceid";
|
||||||
$params = array('courseid' => $course->id, 'contextmodule' => CONTEXT_MODULE);
|
|
||||||
$v = $DB->get_records_sql($sql, $params);
|
$v = $DB->get_records_sql($sql, $params);
|
||||||
|
|
||||||
if (empty($views)) {
|
if (empty($views)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue