Skip to content

Commit

Permalink
MDL-43682 Some imporvements to loglive report
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitagarwal committed Apr 7, 2014
1 parent 1ac341e commit 1722da6
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 27 deletions.
21 changes: 19 additions & 2 deletions report/loglive/classes/renderable.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function get_readers($nameonly = false) {
/**
* Setup table log.
*/
public function setup_table() {
protected function setup_table() {
$filter = $this->setup_filters();
$this->tablelog = new report_loglive_table_log('report_loglive', $filter);
$this->tablelog->define_baseurl($this->url);
Expand All @@ -156,7 +156,7 @@ public function setup_table() {
/**
* Setup table log for ajax output.
*/
public function setup_table_ajax() {
protected function setup_table_ajax() {
$filter = $this->setup_filters();
$this->tablelog = new report_loglive_table_log_ajax('report_loglive', $filter);
$this->tablelog->define_baseurl($this->url);
Expand Down Expand Up @@ -210,4 +210,21 @@ public function get_refresh_rate() {
return $this->refresh;
}

/**
* Setup table and return it.
*
* @param bool $ajax If set to true report_loglive_table_log_ajax is set instead of report_loglive_table_log.
*
* @return report_loglive_table_log|report_loglive_table_log_ajax table object
*/
public function get_table($ajax = false) {
if (empty($this->tablelog)) {
if ($ajax) {
$this->setup_table_ajax();
} else {
$this->setup_table();
}
}
return $this->tablelog;
}
}
33 changes: 26 additions & 7 deletions report/loglive/classes/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,19 @@
class report_loglive_renderer extends plugin_renderer_base {

/**
* Render log report page.
* Return html to render the loglive page..
*
* @param report_loglive_renderable $reportloglive object of report_log.
*
* @return string html used to render the page;
*/
public function render_report_loglive_renderable(report_loglive_renderable $reportloglive) {
if (empty($reportloglive->selectedlogreader)) {
echo $this->output->notification(get_string('nologreaderenabled', 'report_loglive'), 'notifyproblem');
return;
return $this->output->notification(get_string('nologreaderenabled', 'report_loglive'), 'notifyproblem');
}

$reportloglive->setup_table();
$reportloglive->tablelog->out($reportloglive->perpage, true);
$table = $reportloglive->get_table();
return $this->render_table($table, $reportloglive->perpage);
}

/**
Expand All @@ -59,7 +60,7 @@ public function reader_selector(report_loglive_renderable $reportloglive) {
$readers = $reportloglive->get_readers(true);
if (count($readers) <= 1) {
// One or no readers found, no need of this drop down.
return;
return '';
}
$select = new single_select($reportloglive->url, 'logreader', $readers, $reportloglive->selectedlogreader, null);
$select->set_label(get_string('selectlogreader', 'report_loglive'));
Expand All @@ -80,7 +81,25 @@ public function toggle_liveupdate_button(report_loglive_renderable $reportlogliv
$icon = new pix_icon('i/loading_small', 'loading', 'moodle', array('class' => 'spinner'));
return $this->output->render($icon);
}
return null;
return '';
}

/**
* Get the html for the table.
*
* @param report_loglive_table_log $table table object.
* @param int $perpage entries to display perpage.
*
* @return string table html
*/
protected function render_table(report_loglive_table_log $table, $perpage) {
$o = '';
ob_start();
$table->out($perpage, true);
$o = ob_get_contents();
ob_end_clean();

return $o;
}
}

4 changes: 2 additions & 2 deletions report/loglive/classes/renderer_ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function render_report_loglive_renderable(report_loglive_renderable $repo
if (empty($reportloglive->selectedlogreader)) {
return null;
}
$reportloglive->setup_table_ajax();
$reportloglive->tablelog->out($reportloglive->perpage, false);
$table = $reportloglive->get_table(true);
return $table->out($reportloglive->perpage, false);
}
}
32 changes: 22 additions & 10 deletions report/loglive/classes/table_log.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,16 @@ public function col_fullnameuser($event) {
// Add username who did the action.
if (!empty($logextra['realuserid'])) {
$a = new stdClass();
$params = array();
$params = array('id' => $logextra['realuserid']);
if ($event->courseid) {
$params['course'] = $event->courseid;
}
$a->realusername = html_writer::link(new moodle_url("/user/view.php", array('id' => $event->userid) + $params),
$a->realusername = html_writer::link(new moodle_url("/user/view.php", $params),
$this->userfullnames[$logextra['realuserid']]);
$a->asusername = html_writer::link(new moodle_url("/user/view.php", array('id' => $event->userid) + $params),
$params['id'] = $event->userid;
$a->asusername = html_writer::link(new moodle_url("/user/view.php", $params),
$this->userfullnames[$event->userid]);
$username = get_string('eventloggedas', 'report_log', $a);
$username = get_string('eventloggedas', 'report_loglive', $a);
} else if (!empty($event->userid) && !empty($this->userfullnames[$event->userid])) {
$params = array('id' => $event->userid);
if ($event->courseid) {
Expand Down Expand Up @@ -294,7 +295,6 @@ protected function action_link(moodle_url $url, $text, $name = 'popup') {
global $OUTPUT;
$link = new action_link($url, $text, new popup_action('click', $url, $name, array('height' => 440, 'width' => 700)));
return $OUTPUT->render($link);

}

/**
Expand All @@ -320,7 +320,8 @@ public function query_db($pagesize, $useinitialsbar = true) {
}

if (!empty($this->filterparams->date)) {
$joins[] = "anonymous = {$this->filterparams->anonymous}";
$joins[] = "anonymous = :anon";
$params['anon'] = $this->filterparams->anonymous;
}

$selector = implode(' AND ', $joins);
Expand Down Expand Up @@ -382,12 +383,23 @@ public function update_users_and_courses_used() {

// Get course shortname and put that in return list.
if (!empty($courseids)) { // If all logs don't belog to site level then get course info.
list($coursesql, $courseparams) = $DB->get_in_or_equal($courseids);
$courses = $DB->get_records_sql("SELECT id,shortname FROM {course} WHERE id " . $coursesql, $courseparams);
list($coursesql, $courseparams) = $DB->get_in_or_equal($courseids, SQL_PARAMS_NAMED);
$ccselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
$ccjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
$courseparams['contextlevel'] = CONTEXT_COURSE;
$sql = "SELECT c.id,c.shortname $ccselect FROM {course} as c
$ccjoin
WHERE c.id " . $coursesql;

$courses = $DB->get_records_sql($sql, $courseparams);
foreach ($courses as $courseid => $course) {
$url = new moodle_url("/course/view.php", array('id' => $courseid));
$this->courseshortnames[$courseid] = html_writer::link($url, format_string($course->shortname));
context_helper::preload_from_record($course);
$context = context_course::instance($courseid, IGNORE_MISSING);
// Method format_string() takes care of missing contexts.
$this->courseshortnames[$courseid] = html_writer::link($url, format_string($course->shortname, true,
array('context' => $context)));
}
}
}
}
}
4 changes: 2 additions & 2 deletions report/loglive/classes/table_log_ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class report_loglive_table_log_ajax extends report_loglive_table_log {
* @param bool $useinitialsbar Not used, present only for compatibility with parent.
* @param string $downloadhelpbutton Not used, present only for compatibility with parent.
*
* @return array|void
* @return string json encoded data containing html of new rows.
*/
public function out($pagesize, $useinitialsbar, $downloadhelpbutton = '') {
$this->query_db($pagesize, false);
Expand All @@ -56,6 +56,6 @@ public function out($pagesize, $useinitialsbar, $downloadhelpbutton = '') {
}
}
$result = array('logs' => $html, 'until' => $until);
echo json_encode($result);
return json_encode($result);
}
}
4 changes: 2 additions & 2 deletions report/loglive/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@

$id = optional_param('id', 0, PARAM_INT);
$page = optional_param('page', 0, PARAM_INT);
$logreader = optional_param('logreader', '', PARAM_COMPONENT); // Reader which will be used for displaying logs.
$logreader = optional_param('logreader', '', PARAM_COMPONENT); // Reader which will be used for displaying logs.

if (empty($id)) {
require_login();
$context = context_system::instance();
$coursename = format_string($SITE->fullname, true, array('context' => $context));
} else {
$course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST);
$course = get_course($id);
require_login($course);
$context = context_course::instance($course->id);
$coursename = format_string($course->fullname, true, array('context' => $context));
Expand Down
4 changes: 2 additions & 2 deletions report/loglive/loglive_ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
require_login();
$context = context_system::instance();
} else {
$course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST);
$course = get_course($id);
require_login($course);
$context = context_course::instance($course->id);
}
Expand All @@ -47,4 +47,4 @@
}
$renderable = new report_loglive_renderable($logreader, $id, '', $since, $page);
$output = $PAGE->get_renderer('report_loglive');
$output->render($renderable);
echo $output->render($renderable);

0 comments on commit 1722da6

Please sign in to comment.