Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MBS-9395: Fix pagination on userstats table #20

Merged
merged 7 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions classes/local/userstats_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,26 +90,26 @@ public function __construct(
$tenantfield = get_config('local_ai_manager', 'tenantcolumn');
if (!empty($purpose)) {
$fields = 'u.id as id, lastname, firstname, locked, COUNT(value) AS requestcount, SUM(value) AS tokens';
$from = '{local_ai_manager_request_log} rl LEFT JOIN {local_ai_manager_userinfo} ui ON rl.userid = ui.userid'
. ' JOIN {user} u ON u.id = rl.userid';
$where = $tenantfield . ' = :tenant AND purpose = :purpose GROUP BY u.id';
$from = '{local_ai_manager_request_log} rl '
. 'LEFT JOIN {local_ai_manager_userinfo} ui ON rl.userid = ui.userid '
. 'JOIN {user} u ON u.id = rl.userid';
$where = $tenantfield . ' = :tenant AND purpose = :purpose GROUP BY u.id ORDER BY u.lastname';
$params = [
'tenant' => $tenant->get_sql_identifier(),
'purpose' => $purpose,
];
$this->set_count_sql(
"SELECT COUNT(DISTINCT userid) FROM {local_ai_manager_request_log} rl JOIN {user} u ON rl.userid = u.id "
"SELECT COUNT(DISTINCT rl.userid) FROM " . $from . " "
. "WHERE " . $tenantfield . " = :tenant AND purpose = :purpose",
$params
);
} else {
$fields = 'u.id as id, lastname, firstname, COUNT(value) AS requestcount';
$from =
'{local_ai_manager_request_log} rl LEFT JOIN {user} u ON rl.userid = u.id';
$where = 'u.' . $tenantfield . ' = :tenant GROUP BY u.id';
$from = '{local_ai_manager_request_log} rl LEFT JOIN {user} u ON rl.userid = u.id';
$where = 'u.' . $tenantfield . ' = :tenant GROUP BY u.id ORDER BY u.lastname';
$params = ['tenant' => $tenant->get_sql_identifier()];
$this->set_count_sql(
"SELECT COUNT(DISTINCT id) FROM {user} WHERE " . $tenantfield . " = :tenant",
"SELECT COUNT(DISTINCT u.id) FROM " . $from . " WHERE u." . $tenantfield . " = :tenant",
$params
);
}
Expand Down
2 changes: 1 addition & 1 deletion purpose_statistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
echo html_writer::div(get_string('userwithusageonlyshown', 'local_ai_manager'));

$table = new \local_ai_manager\local\userstats_table($uniqid, $purpose, $tenant, $baseurl);
$table->out(5, false);
$table->out(20, false);
PhMemmel marked this conversation as resolved.
Show resolved Hide resolved
} else {
echo html_writer::div(get_string('nodata', 'local_ai_manager'), 'alert alert-info');
}
Expand Down
2 changes: 1 addition & 1 deletion user_statistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

$baseurl = new moodle_url('/local/ai_manager/user_statistics.php', ['tenant' => $tenant->get_sql_identifier()]);
$table = new \local_ai_manager\local\userstats_table($uniqid, '', $tenant, $baseurl);
$table->out(5, false);
$table->out(20, false);
} else {
echo html_writer::div(get_string('nodata', 'local_ai_manager'), 'alert alert-info');
}
Expand Down