From 6c78b8b74c301d882e5a1772c96cb68b019b0c9d Mon Sep 17 00:00:00 2001 From: Tobias Garske Date: Thu, 26 Sep 2024 13:13:12 +0000 Subject: [PATCH 1/7] MBS-9395: Fix pagination on userstats table --- classes/local/userstats_table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/local/userstats_table.php b/classes/local/userstats_table.php index db13e36..6e0c5b6 100644 --- a/classes/local/userstats_table.php +++ b/classes/local/userstats_table.php @@ -109,7 +109,7 @@ public function __construct( $where = 'u.' . $tenantfield . ' = :tenant GROUP BY u.id'; $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 ); } From 62e8d570ae556ccdd7dcd38bfae277f49f9ecff8 Mon Sep 17 00:00:00 2001 From: Tobias Garske Date: Tue, 1 Oct 2024 08:13:55 +0000 Subject: [PATCH 2/7] Changes after CR --- classes/local/userstats_table.php | 16 +++++++++------- purpose_statistics.php | 2 +- user_statistics.php | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/classes/local/userstats_table.php b/classes/local/userstats_table.php index 6e0c5b6..6c71463 100644 --- a/classes/local/userstats_table.php +++ b/classes/local/userstats_table.php @@ -90,23 +90,25 @@ 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 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 {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", $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 lastname'; $params = ['tenant' => $tenant->get_sql_identifier()]; $this->set_count_sql( "SELECT COUNT(DISTINCT u.id) FROM $from WHERE u.$tenantfield = :tenant", diff --git a/purpose_statistics.php b/purpose_statistics.php index a7d30fe..d686c9a 100644 --- a/purpose_statistics.php +++ b/purpose_statistics.php @@ -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); } else { echo html_writer::div(get_string('nodata', 'local_ai_manager'), 'alert alert-info'); } diff --git a/user_statistics.php b/user_statistics.php index ceff384..4914877 100644 --- a/user_statistics.php +++ b/user_statistics.php @@ -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'); } From 592823d80c344af7ef5ceca021b523517ad80280 Mon Sep 17 00:00:00 2001 From: Tobias Garske Date: Wed, 2 Oct 2024 10:24:21 +0200 Subject: [PATCH 3/7] Update classes/local/userstats_table.php Co-authored-by: PhMemmel <65113153+PhMemmel@users.noreply.github.com> --- classes/local/userstats_table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/local/userstats_table.php b/classes/local/userstats_table.php index 6c71463..063a102 100644 --- a/classes/local/userstats_table.php +++ b/classes/local/userstats_table.php @@ -93,7 +93,7 @@ public function __construct( $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 lastname'; + $where = $tenantfield . ' = :tenant AND purpose = :purpose GROUP BY u.id ORDER BY u.lastname'; $params = [ 'tenant' => $tenant->get_sql_identifier(), 'purpose' => $purpose, From abc6daf5f2a24a24bdbde44222fa82398ceac5a0 Mon Sep 17 00:00:00 2001 From: Tobias Garske Date: Wed, 2 Oct 2024 10:24:29 +0200 Subject: [PATCH 4/7] Update classes/local/userstats_table.php Co-authored-by: PhMemmel <65113153+PhMemmel@users.noreply.github.com> --- classes/local/userstats_table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/local/userstats_table.php b/classes/local/userstats_table.php index 063a102..eff8ae2 100644 --- a/classes/local/userstats_table.php +++ b/classes/local/userstats_table.php @@ -108,7 +108,7 @@ public function __construct( } 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 ORDER BY lastname'; + $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 u.id) FROM $from WHERE u.$tenantfield = :tenant", From f2e59f1003930240a51682f30341245639c84732 Mon Sep 17 00:00:00 2001 From: Tobias Garske Date: Wed, 2 Oct 2024 08:26:23 +0000 Subject: [PATCH 5/7] Changes after CR --- classes/local/userstats_table.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/classes/local/userstats_table.php b/classes/local/userstats_table.php index eff8ae2..4e719d8 100644 --- a/classes/local/userstats_table.php +++ b/classes/local/userstats_table.php @@ -99,9 +99,7 @@ public function __construct( 'purpose' => $purpose, ]; $this->set_count_sql( - "SELECT COUNT(DISTINCT rl.userid) 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 " + "SELECT COUNT(DISTINCT rl.userid) FROM $from " . "WHERE " . $tenantfield . " = :tenant AND purpose = :purpose", $params ); From 8a4963c6ad32faf89aa5dc91eaaff75f42b9fc35 Mon Sep 17 00:00:00 2001 From: Philipp Memmel Date: Wed, 2 Oct 2024 11:06:43 +0200 Subject: [PATCH 6/7] Code style --- classes/local/userstats_table.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/local/userstats_table.php b/classes/local/userstats_table.php index 4e719d8..9a0be5d 100644 --- a/classes/local/userstats_table.php +++ b/classes/local/userstats_table.php @@ -99,7 +99,7 @@ public function __construct( 'purpose' => $purpose, ]; $this->set_count_sql( - "SELECT COUNT(DISTINCT rl.userid) FROM $from " + "SELECT COUNT(DISTINCT rl.userid) FROM " . $from . " " . "WHERE " . $tenantfield . " = :tenant AND purpose = :purpose", $params ); @@ -109,7 +109,7 @@ public function __construct( $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 u.id) FROM $from WHERE u.$tenantfield = :tenant", + "SELECT COUNT(DISTINCT u.id) FROM $from WHERE u." . $tenantfield . " = :tenant", $params ); } From 3d53069a5a9fd0ce5f2740363aaed04998242031 Mon Sep 17 00:00:00 2001 From: Philipp Memmel Date: Wed, 2 Oct 2024 11:09:23 +0200 Subject: [PATCH 7/7] Again codestyle --- classes/local/userstats_table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/local/userstats_table.php b/classes/local/userstats_table.php index 9a0be5d..ffbcdc3 100644 --- a/classes/local/userstats_table.php +++ b/classes/local/userstats_table.php @@ -109,7 +109,7 @@ public function __construct( $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 u.id) FROM $from WHERE u." . $tenantfield . " = :tenant", + "SELECT COUNT(DISTINCT u.id) FROM " . $from . " WHERE u." . $tenantfield . " = :tenant", $params ); }