From 3dee255163ce897bccb124e6f5f62bd3f7dda0a3 Mon Sep 17 00:00:00 2001 From: Stephen Bourget Date: Sun, 31 Jul 2016 21:45:27 -0400 Subject: [PATCH] MDL-50286 report_log: Allow filtering by event origin. --- report/log/classes/renderable.php | 26 ++++++++++++++++++++++++-- report/log/classes/renderer.php | 5 +++++ report/log/classes/table_log.php | 5 +++++ report/log/index.php | 3 ++- report/log/lang/en/report_log.php | 6 ++++++ 5 files changed, 42 insertions(+), 3 deletions(-) diff --git a/report/log/classes/renderable.php b/report/log/classes/renderable.php index 2dd164652e6..8bdb8b4b5f1 100644 --- a/report/log/classes/renderable.php +++ b/report/log/classes/renderable.php @@ -84,6 +84,9 @@ class report_log_renderable implements renderable { /** @var string order to sort */ public $order; + /** @var string origin to filter event origin */ + public $origin; + /** @var int group id */ public $groupid; @@ -113,7 +116,7 @@ class report_log_renderable implements renderable { */ public function __construct($logreader = "", $course = 0, $userid = 0, $modid = 0, $action = "", $groupid = 0, $edulevel = -1, $showcourses = false, $showusers = false, $showreport = true, $showselectorform = true, $url = "", $date = 0, - $logformat='showashtml', $page = 0, $perpage = 100, $order = "timecreated ASC") { + $logformat='showashtml', $page = 0, $perpage = 100, $order = "timecreated ASC", $origin ='') { global $PAGE; @@ -157,6 +160,7 @@ class report_log_renderable implements renderable { $this->showreport = $showreport; $this->showselectorform = $showselectorform; $this->logformat = $logformat; + $this->origin = $origin; } /** @@ -432,6 +436,24 @@ class report_log_renderable implements renderable { return $dates; } + /** + * Return list of components to show in selector. + * + * @return array list of origins. + */ + public function get_origin_options() { + global $DB; + $origins = $DB->get_records_sql('select distinct origin from {logstore_standard_log} order by origin ASC'); + $ret = array(); + $ret[''] = get_string('allsources', 'report_log'); + foreach ($origins as $origin) { + if (!empty($origin->origin)) { + $ret[$origin->origin] = get_string($origin->origin, 'report_log'); + } + } + return $ret; + } + /** * Return list of edulevel. * @@ -469,7 +491,7 @@ class report_log_renderable implements renderable { $filter->action = $this->action; $filter->date = $this->date; $filter->orderby = $this->order; - + $filter->origin = $this->origin; // If showing site_errors. if ('site_errors' === $this->modid) { $filter->siteerrors = true; diff --git a/report/log/classes/renderer.php b/report/log/classes/renderer.php index b3e1cd760d1..dc7cbea2cc0 100644 --- a/report/log/classes/renderer.php +++ b/report/log/classes/renderer.php @@ -164,6 +164,11 @@ class report_log_renderer extends plugin_renderer_base { echo html_writer::label(get_string('actions'), 'menumodaction', false, array('class' => 'accesshide')); echo html_writer::select($reportlog->get_actions(), 'modaction', $reportlog->action, get_string("allactions")); + // Add origin. + $origin = $reportlog->get_origin_options(); + echo html_writer::label(get_string('origin', 'report_log'), 'menuorigin', false, array('class' => 'accesshide')); + echo html_writer::select($origin, 'origin', $reportlog->origin, false); + // Add edulevel. $edulevel = $reportlog->get_edulevel_options(); echo html_writer::label(get_string('edulevel'), 'menuedulevel', false, array('class' => 'accesshide')); diff --git a/report/log/classes/table_log.php b/report/log/classes/table_log.php index e0ee4b737f7..58860ceb930 100644 --- a/report/log/classes/table_log.php +++ b/report/log/classes/table_log.php @@ -485,6 +485,11 @@ class report_log_table_log extends table_sql { $joins[] = "edulevel ".$edulevelsql; $params = array_merge($params, $edulevelparams); } + // Origin. + if (isset($this->filterparams->origin) && ($this->filterparams->origin != '')) { + $joins[] = "origin = :origin"; + $params['origin'] = $this->filterparams->origin; + } if (!($this->filterparams->logreader instanceof logstore_legacy\log\store)) { // Filter out anonymous actions, this is N/A for legacy log because it never stores them. diff --git a/report/log/index.php b/report/log/index.php index d5e00ee29df..bb3b514918a 100644 --- a/report/log/index.php +++ b/report/log/index.php @@ -42,6 +42,7 @@ $chooselog = optional_param('chooselog', false, PARAM_BOOL); $logformat = optional_param('download', '', PARAM_ALPHA); $logreader = optional_param('logreader', '', PARAM_COMPONENT); // Reader which will be used for displaying logs. $edulevel = optional_param('edulevel', -1, PARAM_INT); // Educational level. +$origin = optional_param('origin', '', PARAM_TEXT); // Event origin. $params = array(); if (!empty($id)) { @@ -146,7 +147,7 @@ if (empty($course) || ($course->id == $SITE->id)) { } $reportlog = new report_log_renderable($logreader, $course, $user, $modid, $modaction, $group, $edulevel, $showcourses, $showusers, - $chooselog, true, $url, $date, $logformat, $page, $perpage, 'timecreated DESC'); + $chooselog, true, $url, $date, $logformat, $page, $perpage, 'timecreated DESC', $origin); $readers = $reportlog->get_readers(); $output = $PAGE->get_renderer('report_log'); diff --git a/report/log/lang/en/report_log.php b/report/log/lang/en/report_log.php index 5985ed604ab..d764bdd511a 100644 --- a/report/log/lang/en/report_log.php +++ b/report/log/lang/en/report_log.php @@ -24,6 +24,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +$string['allsources'] = 'All sources'; +$string['cli'] = 'CLI'; $string['eventcomponent'] = 'Component'; $string['eventcontext'] = 'Event context'; $string['eventloggedas'] = '{$a->realusername} as {$a->asusername}'; @@ -36,8 +38,12 @@ $string['log:viewtoday'] = 'View today\'s logs'; $string['page'] = 'Page {$a}'; $string['logsformat'] = 'Logs format'; $string['nologreaderenabled'] = 'No log reader enabled'; +$string['origin'] = 'Source'; $string['page-report-log-x'] = 'Any log report'; $string['page-report-log-index'] = 'Course log report'; $string['page-report-log-user'] = 'User course log report'; $string['pluginname'] = 'Logs'; +$string['restore'] = 'Restore'; $string['selectlogreader'] = 'Select log reader'; +$string['web'] = 'Web'; +$string['ws'] = 'Web service';