Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
9 ariadna 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
 * Log report table
19
 *
20
 * @package    block_openai_chat
21
 * @copyright  2024 Bryce Yoder <me@bryceyoder.com>
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
use \block_openai_chat\report;
26
 
27
require_once('../../config.php');
28
require_once($CFG->libdir.'/tablelib.php');
29
global $DB;
30
 
31
$courseid = required_param('courseid', PARAM_INT);
32
$download = optional_param('download', '', PARAM_ALPHA);
33
$user = optional_param('user', '', PARAM_TEXT);
34
$starttime = optional_param('starttime', '', PARAM_TEXT);
35
$endtime = optional_param('endtime', '', PARAM_TEXT);
36
 
37
$pageurl = $CFG->wwwroot . "/blocks/openai_chat/report.php?courseid=$courseid" .
38
    "&user=$user" .
39
    "&starttime=$starttime" .
40
    "&endtime=$endtime";
41
$starttime_ts = strtotime($starttime);
42
$endtime_ts = strtotime($endtime);
43
$course = $DB->get_record('course', ['id' => $courseid]);
44
 
45
$PAGE->set_url($pageurl);
46
require_login($course);
47
$context = context_course::instance($courseid);
48
require_capability('block/openai_chat:viewreport', $context);
49
 
50
$datetime = new DateTime();
51
$table = new \block_openai_chat\report(time());
52
$table->show_download_buttons_at(array(TABLE_P_BOTTOM));
53
$table->is_downloading(
54
    $download,
55
    get_string('downloadfilename', 'block_openai_chat')
56
        . '_'
57
        . $datetime->format(DateTime::ATOM)
58
);
59
 
60
if (!$table->is_downloading()) {
61
    $PAGE->set_pagelayout('report');
62
    $PAGE->set_title(get_string('openai_chat_logs', 'block_openai_chat'));
63
    $PAGE->set_heading(get_string('openai_chat_logs', 'block_openai_chat'));
64
    $PAGE->navbar->add($course->shortname, new moodle_url('/course/view.php', ['id' => $course->id]));
65
    $PAGE->navbar->add(get_string('openai_chat_logs', 'block_openai_chat'), new moodle_url($pageurl));
66
 
67
    echo $OUTPUT->header();
68
    echo $OUTPUT->render_from_template('block_openai_chat/report_page', [
69
        "courseid" => $courseid,
70
        "user" => $user,
71
        "starttime" => $starttime,
72
        "endtime" => $endtime,
73
        "link" => (new moodle_url("/blocks/openai_chat/report.php"))->out()
74
    ]);
75
}
76
 
77
$where = "1=1";
78
$out = 10;
79
 
80
// If courseid is 1, we're assuming this is an admin report wanting the entire log table
81
// otherwise, we'll limit it to responses in the course context for this course
82
if ($courseid !== 1) {
83
    $where = "c.contextlevel = 50 AND co.id = $courseid";
84
}
85
 
86
// filter by user, starttime, endtime
87
if ($user) {
88
    $where .= " AND CONCAT(u.firstname, ' ', u.lastname) like '%$user%'";
89
}
90
if ($starttime_ts) {
91
    $where .= " AND ocl.timecreated > $starttime_ts";
92
}
93
if ($endtime_ts) {
94
    $where .= " AND ocl.timecreated < $endtime_ts";
95
}
96
 
97
$table->set_sql(
98
    "ocl.*, CONCAT(u.firstname, ' ', u.lastname) as user_name",
99
    "{block_openai_chat_log} ocl
100
        JOIN {user} u ON u.id = ocl.userid
101
        JOIN {context} c ON c.id = ocl.contextid
102
        LEFT JOIN {course} co ON co.id = c.instanceid",
103
    $where
104
);
105
$table->define_baseurl($pageurl);
106
$table->out($out, true);
107
 
108
if (!$table->is_downloading()) {
109
    echo $OUTPUT->footer();
110
}