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 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
namespace block_openai_chat;
26
defined('MOODLE_INTERNAL') || die;
27
 
28
class report extends \table_sql {
29
    function __construct($uniqueid) {
30
        parent::__construct($uniqueid);
31
        // Define the list of columns to show.
32
        $columns = array('userid', 'user_name', 'usermessage', 'airesponse', 'contextid', 'timecreated');
33
        $this->define_columns($columns);
34
        $this->no_sorting('usermessage');
35
        $this->no_sorting('airesponse');
36
 
37
        // Define the titles of columns to show in header.
38
        $headers = array('User ID', 'User Name', 'User Message', 'AI Response', 'Context', 'Time');
39
        $this->define_headers($headers);
40
    }
41
 
42
    function col_user_name($values) {
43
        global $DB;
44
        $user = $DB->get_record('user', ['id' => $values->userid]);
45
 
46
        if ($this->is_downloading()) {
47
            return "$user->firstname $user->lastname";
48
        } else {
49
            return "<a href='/user/profile.php?id=$values->userid'>$user->firstname $user->lastname</a>";
50
        }
51
    }
52
 
53
    function col_contextid($values) {
54
        if ($this->is_downloading()) {
55
            return $values->contextid;
56
        } else {
57
            $context = \context::instance_by_id($values->contextid);
58
            return "<a href='" . $context->get_url() . "'>" . $context->get_context_name() ."</a>";
59
        }
60
    }
61
 
62
    function col_timecreated($values) {
63
        if ($this->is_downloading()) {
64
            return $values->timecreated;
65
        } else {
66
            return userdate($values->timecreated);
67
        }
68
    }
69
}