Skip to content

Commit

Permalink
Remove deleted and suspended user in ranking
Browse files Browse the repository at this point in the history
  • Loading branch information
davidherney committed Apr 9, 2024
1 parent e2cf47c commit 3a2fb99
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion classes/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ public static function get_topbycourse($courseid, $includecurrent = true) {
$sql = " SELECT lu.userid AS id, g.nickname, " . $DB->sql_ceil('SUM(lu.points)') . " AS points " .
" FROM {block_ludifica_userpoints} lu " .
" INNER JOIN {block_ludifica_general} g ON g.userid = lu.userid" .
" INNER JOIN {user} u ON u.id = lu.userid AND u.deleted = 0 AND u.suspended = 0" .
" LEFT JOIN {tool_tenant_user} tu ON tu.userid = lu.userid" .
" LEFT JOIN {tool_tenant} t ON t.id = tu.tenantid AND t.archived = 0" .
" WHERE t.id = $usertenant AND lu.courseid = :courseid" .
Expand All @@ -559,6 +560,7 @@ public static function get_topbycourse($courseid, $includecurrent = true) {
$sql = "SELECT lu.userid AS id, g.nickname, " . $DB->sql_ceil('SUM(lu.points)') . " AS points " .
" FROM {block_ludifica_userpoints} lu " .
" INNER JOIN {block_ludifica_general} g ON g.userid = lu.userid" .
" INNER JOIN {user} u ON u.id = lu.userid AND u.deleted = 0 AND u.suspended = 0" .
" WHERE lu.courseid = :courseid" .
" GROUP BY lu.userid, g.nickname" .
" ORDER BY points DESC, g.nickname ASC";
Expand Down Expand Up @@ -587,6 +589,7 @@ public static function get_topbysite($includecurrent = true) {
$sql = " SELECT lu.userid AS id, g.nickname, " . $DB->sql_ceil('SUM(lu.points)') . " AS points " .
" FROM {block_ludifica_userpoints} lu " .
" INNER JOIN {block_ludifica_general} g ON g.userid = lu.userid" .
" INNER JOIN {user} u ON u.id = lu.userid AND u.deleted = 0 AND u.suspended = 0" .
" LEFT JOIN {tool_tenant_user} tu ON tu.userid = lu.userid" .
" LEFT JOIN {tool_tenant} t ON t.id = tu.tenantid AND t.archived = 0" .
" WHERE t.id = $usertenant" .
Expand All @@ -596,6 +599,7 @@ public static function get_topbysite($includecurrent = true) {
$sql = "SELECT lu.userid AS id, g.nickname, " . $DB->sql_ceil('SUM(lu.points)') . " AS points " .
" FROM {block_ludifica_userpoints} lu " .
" INNER JOIN {block_ludifica_general} g ON g.userid = lu.userid" .
" INNER JOIN {user} u ON u.id = lu.userid AND u.deleted = 0 AND u.suspended = 0" .
" GROUP BY lu.userid, g.nickname" .
" ORDER BY points DESC, g.nickname ASC";
}
Expand Down Expand Up @@ -632,6 +636,7 @@ public static function get_lastmonth($courseid, $includecurrent = true) {
$sql = " SELECT lu.userid AS id, g.nickname, " . $DB->sql_ceil('SUM(lu.points)') . " AS points " .
" FROM {block_ludifica_userpoints} lu " .
" INNER JOIN {block_ludifica_general} g ON g.userid = lu.userid" .
" INNER JOIN {user} u ON u.id = lu.userid AND u.deleted = 0 AND u.suspended = 0" .
" LEFT JOIN {tool_tenant_user} tu ON tu.userid = lu.userid" .
" LEFT JOIN {tool_tenant} t ON t.id = tu.tenantid AND t.archived = 0" .
" WHERE t.id = $usertenant AND " . $coursecondition . " lu.timecreated >= :timeinit" .
Expand All @@ -641,6 +646,7 @@ public static function get_lastmonth($courseid, $includecurrent = true) {
$sql = "SELECT lu.userid AS id, g.nickname, " . $DB->sql_ceil('SUM(lu.points)') . " AS points " .
" FROM {block_ludifica_userpoints} lu " .
" INNER JOIN {block_ludifica_general} g ON g.userid = lu.userid" .
" INNER JOIN {user} u ON u.id = lu.userid AND u.deleted = 0 AND u.suspended = 0" .
" WHERE " . $coursecondition . " lu.timecreated >= :timeinit" .
" GROUP BY lu.userid, g.nickname" .
" ORDER BY points DESC, g.nickname ASC";
Expand Down Expand Up @@ -683,9 +689,13 @@ public static function get_customranking($custom, $courseid = null, $includecurr
'uid.fieldid = :fieldid AND uid.data = :fieldvalue AND uid.userid = lu.userid ';
$conditions['fieldid'] = $custom->field->id;
$conditions['fieldvalue'] = $custom->value;

$tables[] = " INNER JOIN {user} u ON u.id = lu.userid AND u.deleted = 0 AND u.suspended = 0";

} else {
// It is a profile user field.
$tables[] = ' INNER JOIN {user} u ON u.' . $custom->key . ' = :fieldvalue AND u.id = lu.userid ';
$tables[] = ' INNER JOIN {user} u ON u.' . $custom->key . ' = :fieldvalue
AND u.id = lu.userid AND u.deleted = 0 AND u.suspended = 0 ';
$conditions['fieldvalue'] = $custom->value;
}

Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2021031216.01; // The current plugin version (Date: YYYYMMDDXX).
$plugin->version = 2021031216.02; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2019052002; // Requires this Moodle version.
$plugin->component = 'block_ludifica'; // Full name of the plugin (used for diagnostics).

0 comments on commit 3a2fb99

Please sign in to comment.