Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * Displays live view of recent logs
19
 *
20
 * This file generates live view of recent logs.
21
 *
22
 * @package    report_loglive
23
 * @copyright  2011 Petr Skoda
24
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 */
26
 
27
use core\report_helper;
28
 
29
require('../../config.php');
30
require_once($CFG->libdir.'/adminlib.php');
31
require_once($CFG->dirroot.'/course/lib.php');
1441 ariadna 32
global $SITE, $PAGE;
1 efrain 33
 
34
$id = optional_param('id', 0, PARAM_INT);
35
$page = optional_param('page', 0, PARAM_INT);
36
$logreader = optional_param('logreader', '', PARAM_COMPONENT); // Reader which will be used for displaying logs.
37
 
1441 ariadna 38
// Get course details.
39
if (!empty($id)) {
40
    $course = $DB->get_record('course', ['id' => $id], '*');
41
    if ($course) {
42
        require_login($course);
43
        $context = context_course::instance($course->id);
44
        $coursename = format_string($course->fullname, true, ['context' => $context]);
45
    }
46
}
47
 
48
if (empty($course)) {
49
    admin_externalpage_setup('reportloglive', '', null, '', ['pagelayout' => 'report']);
1 efrain 50
    $context = context_system::instance();
1441 ariadna 51
    $coursename = format_string($SITE->fullname, true, ['context' => $context]);
1 efrain 52
}
53
require_capability('report/loglive:view', $context);
54
 
55
$params = array();
56
if ($id != 0) {
57
    $params['id'] = $id;
58
}
59
if ($page != 0) {
60
    $params['page'] = $page;
61
}
62
if ($logreader !== '') {
63
    $params['logreader'] = $logreader;
64
}
65
$url = new moodle_url("/report/loglive/index.php", $params);
66
 
67
$PAGE->set_url($url);
68
$PAGE->set_pagelayout('report');
1441 ariadna 69
$PAGE->set_context($context);
70
$strlivelogs = get_string('livelogs', 'report_loglive');
71
$PAGE->set_title("$coursename: $strlivelogs");
72
$output = $PAGE->get_renderer('report_loglive');
73
echo $output->header();
74
if (!report_helper::has_valid_group($context)) {
75
    echo $output->notification(get_string('notingroup'));
76
    echo $output->footer();
77
    exit();
78
}
1 efrain 79
 
80
$renderable = new report_loglive_renderable($logreader, $id, $url, 0, $page);
81
$refresh = $renderable->get_refresh_rate();
82
$logreader = $renderable->selectedlogreader;
83
$strupdatesevery = get_string('updatesevery', 'moodle', $refresh);
84
$PAGE->set_heading($coursename);
85
 
86
// Print selector dropdown.
87
$pluginname = get_string('pluginname', 'report_loglive');
88
report_helper::print_report_selector($pluginname);
89
echo html_writer::div(get_string('livelogswithupdate', 'report_loglive', $strupdatesevery), 'mb-3');
90
echo $output->reader_selector($renderable);
91
echo $output->toggle_liveupdate_button($renderable);
92
echo $output->render($renderable);
93
 
94
// Include and trigger ajax requests.
95
if ($page == 0 && !empty($logreader)) {
96
    // Tell Js to fetch new logs only, by passing the latest timestamp of records in the table.
97
    $until = $renderable->get_table()->get_until();
98
    $jsparams = array('since' => $until , 'courseid' => $id, 'page' => $page, 'logreader' => $logreader,
99
        'interval' => $refresh, 'perpage' => $renderable->perpage);
100
    $PAGE->requires->strings_for_js(array('pause', 'resume'), 'report_loglive');
101
    $PAGE->requires->yui_module('moodle-report_loglive-fetchlogs', 'Y.M.report_loglive.FetchLogs.init', array($jsparams));
102
}
103
 
104
// Trigger a logs viewed event.
105
$event = \report_loglive\event\report_viewed::create(array('context' => $context));
106
$event->trigger();
107
 
108
echo $output->footer();