MDL-57491 report_log: Improve filtering code by using static entries

This commit is contained in:
Stephen Bourget 2016-12-22 16:11:36 -05:00
parent c4cf1c60f5
commit e762783dc0
3 changed files with 18 additions and 9 deletions

View File

@ -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;
}

View File

@ -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)) {

View File

@ -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';