-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsettings_user.php
More file actions
106 lines (95 loc) · 4.09 KB
/
settings_user.php
File metadata and controls
106 lines (95 loc) · 4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Student-facing settings page for AI Course Assistant.
*
* @package local_ai_course_assistant
* @copyright 2025 AI Course Assistant
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__ . '/../../config.php');
require_login();
$courseid = optional_param('courseid', 0, PARAM_INT);
$action = optional_param('action', '', PARAM_ALPHA);
$confirm = optional_param('confirm', 0, PARAM_INT);
$PAGE->set_url('/local/ai_course_assistant/settings_user.php', ['courseid' => $courseid]);
$PAGE->set_context(context_system::instance());
$PAGE->set_title(get_string('usersettings:title', 'local_ai_course_assistant'));
$PAGE->set_heading(get_string('usersettings:title', 'local_ai_course_assistant'));
// Handle delete actions.
if ($action === 'delete_course' && $courseid && confirm_sesskey()) {
if ($confirm) {
$manager = new \local_ai_course_assistant\conversation_manager();
$manager->delete_course_data($courseid, $USER->id);
redirect($PAGE->url, get_string('usersettings:data_deleted', 'local_ai_course_assistant'), null, \core\output\notification::NOTIFY_SUCCESS);
} else {
// Show confirmation page.
echo $OUTPUT->header();
$course = get_course($courseid);
echo $OUTPUT->confirm(
get_string('usersettings:confirm_delete_course', 'local_ai_course_assistant', $course->fullname),
new moodle_url($PAGE->url, ['action' => 'delete_course', 'courseid' => $courseid, 'confirm' => 1, 'sesskey' => sesskey()]),
$PAGE->url
);
echo $OUTPUT->footer();
die;
}
}
if ($action === 'delete_all' && confirm_sesskey()) {
if ($confirm) {
$manager = new \local_ai_course_assistant\conversation_manager();
$manager->delete_user_data($USER->id);
redirect($PAGE->url, get_string('usersettings:data_deleted', 'local_ai_course_assistant'), null, \core\output\notification::NOTIFY_SUCCESS);
} else {
// Show confirmation page.
echo $OUTPUT->header();
echo $OUTPUT->confirm(
get_string('usersettings:confirm_delete_all', 'local_ai_course_assistant'),
new moodle_url($PAGE->url, ['action' => 'delete_all', 'confirm' => 1, 'sesskey' => sesskey()]),
$PAGE->url
);
echo $OUTPUT->footer();
die;
}
}
// Get user's data usage stats.
$manager = new \local_ai_course_assistant\conversation_manager();
$stats = $manager->get_user_stats($USER->id);
// Get per-course breakdown.
$coursedata = [];
foreach ($stats['courses'] as $cid => $coursestat) {
$course = get_course($cid);
$coursedata[] = [
'courseid' => $cid,
'coursename' => $course->fullname,
'messagecount' => $coursestat['messages'],
'lastactivity' => $coursestat['lastactivity'] ? userdate($coursestat['lastactivity']) : get_string('never'),
'deleteurl' => new moodle_url($PAGE->url, [
'action' => 'delete_course',
'courseid' => $cid,
'sesskey' => sesskey()
]),
];
}
$templatedata = [
'totalmessages' => $stats['total_messages'],
'totalconversations' => $stats['total_conversations'],
'coursedata' => $coursedata,
'deleteallurl' => new moodle_url($PAGE->url, ['action' => 'delete_all', 'sesskey' => sesskey()]),
];
echo $OUTPUT->header();
echo $OUTPUT->render_from_template('local_ai_course_assistant/user_settings', $templatedata);
echo $OUTPUT->footer();