Skip to content

Commit

Permalink
MDL-50286 report_log: Allow filtering by event origin.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbourget committed Aug 1, 2016
1 parent d1a3ea6 commit 3dee255
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
26 changes: 24 additions & 2 deletions report/log/classes/renderable.php
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -157,6 +160,7 @@ public function __construct($logreader = "", $course = 0, $userid = 0, $modid =
$this->showreport = $showreport;
$this->showselectorform = $showselectorform;
$this->logformat = $logformat;
$this->origin = $origin;
}

/**
Expand Down Expand Up @@ -432,6 +436,24 @@ public function get_date_options() {
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.
*
Expand Down Expand Up @@ -469,7 +491,7 @@ public function setup_table() {
$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;
Expand Down
5 changes: 5 additions & 0 deletions report/log/classes/renderer.php
Expand Up @@ -164,6 +164,11 @@ public function report_selector_form(report_log_renderable $reportlog) {
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'));
Expand Down
5 changes: 5 additions & 0 deletions report/log/classes/table_log.php
Expand Up @@ -485,6 +485,11 @@ public function query_db($pagesize, $useinitialsbar = true) {
$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.
Expand Down
3 changes: 2 additions & 1 deletion report/log/index.php
Expand Up @@ -42,6 +42,7 @@
$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)) {
Expand Down Expand Up @@ -146,7 +147,7 @@
}

$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');

Expand Down
6 changes: 6 additions & 0 deletions report/log/lang/en/report_log.php
Expand Up @@ -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}';
Expand All @@ -36,8 +38,12 @@
$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';

0 comments on commit 3dee255

Please sign in to comment.