From e762783dc099fb6686f73cb9ef2cc948edf95341 Mon Sep 17 00:00:00 2001 From: Stephen Bourget Date: Thu, 22 Dec 2016 16:11:36 -0500 Subject: [PATCH] MDL-57491 report_log: Improve filtering code by using static entries --- report/log/classes/renderable.php | 12 +++++------- report/log/classes/table_log.php | 14 ++++++++++++-- report/log/lang/en/report_log.php | 1 + 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/report/log/classes/renderable.php b/report/log/classes/renderable.php index f5f12fa9e42..56ae1a64cb9 100644 --- a/report/log/classes/renderable.php +++ b/report/log/classes/renderable.php @@ -442,15 +442,13 @@ class report_log_renderable implements renderable { * @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'); - } - } + $ret['cli'] = get_string('cli', 'report_log'); + $ret['restore'] = get_string('restore', 'report_log'); + $ret['web'] = get_string('web', 'report_log'); + $ret['ws'] = get_string('ws', 'report_log'); + $ret['---'] = get_string('other', 'report_log'); return $ret; } diff --git a/report/log/classes/table_log.php b/report/log/classes/table_log.php index c1f3ff969db..ad9e44a97be 100644 --- a/report/log/classes/table_log.php +++ b/report/log/classes/table_log.php @@ -486,10 +486,20 @@ 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->origin !== '---') { + // Filter by a single origin. + $joins[] = "origin = :origin"; + $params['origin'] = $this->filterparams->origin; + } else { + // Filter by everything else. + list($originsql, $originparams) = $DB->get_in_or_equal(array('cli', 'restore', 'ws', 'web'), + SQL_PARAMS_NAMED, 'origin', false); + $joins[] = "origin " . $originsql; + $params = array_merge($params, $originparams); + } } if (!($this->filterparams->logreader instanceof logstore_legacy\log\store)) { diff --git a/report/log/lang/en/report_log.php b/report/log/lang/en/report_log.php index d764bdd511a..f37d48f9220 100644 --- a/report/log/lang/en/report_log.php +++ b/report/log/lang/en/report_log.php @@ -39,6 +39,7 @@ $string['page'] = 'Page {$a}'; $string['logsformat'] = 'Logs format'; $string['nologreaderenabled'] = 'No log reader enabled'; $string['origin'] = 'Source'; +$string['other'] = 'Other'; $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';