From a72d1e7e75646088f852983e9c5fac28e4c16292 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Tue, 28 Nov 2023 15:57:43 +0000 Subject: [PATCH 1/2] MDL-79681 user: fix participant filter "never accessed" options. For courses, determine whether "Never accessed" should be available, and correct the used value to match that expected by the API (-1). --- user/classes/output/participants_filter.php | 16 ++++++++++++---- user/tests/behat/filter_participants.feature | 20 ++++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/user/classes/output/participants_filter.php b/user/classes/output/participants_filter.php index c04fd771e55..54ba6630d3c 100644 --- a/user/classes/output/participants_filter.php +++ b/user/classes/output/participants_filter.php @@ -237,7 +237,17 @@ class participants_filter extends \core\output\datafilter { ]; $select = 'courseid = :courseid AND timeaccess != :timeaccess'; $minlastaccess = $DB->get_field_select('user_lastaccess', 'MIN(timeaccess)', $select, $params); - $lastaccess0exists = $DB->record_exists('user_lastaccess', $params); + + // Determine enrolled users, who do not have accompanying lastaccess to the course. + [$enrolledsql, $enrolledparams] = get_enrolled_sql($this->context); + + $sql = "SELECT 'x' + FROM {user} u + JOIN ({$enrolledsql}) je ON je.id = u.id + LEFT JOIN {user_lastaccess} ula ON ula.userid = je.id AND ula.courseid = :courseid + WHERE COALESCE(ula.timeaccess, 0) = :timeaccess"; + + $lastaccess0exists = $DB->record_exists_sql($sql, array_merge($params, $enrolledparams)); } else { // Front page. $params = ['lastaccess' => 0]; @@ -247,8 +257,6 @@ class participants_filter extends \core\output\datafilter { } $now = usergetmidnight(time()); - $timeoptions = []; - $criteria = get_string('usersnoaccesssince'); $getoptions = function(int $count, string $singletype, string $type) use ($now, $minlastaccess): array { $values = []; @@ -282,7 +290,7 @@ class participants_filter extends \core\output\datafilter { if ($lastaccess0exists) { $values[] = [ - 'value' => time(), + 'value' => -1, 'title' => get_string('never', 'moodle'), ]; } diff --git a/user/tests/behat/filter_participants.feature b/user/tests/behat/filter_participants.feature index 4beee4578bf..9376e4266ab 100644 --- a/user/tests/behat/filter_participants.feature +++ b/user/tests/behat/filter_participants.feature @@ -286,6 +286,26 @@ Feature: Course participants can be filtered And I should not see "Student 4" in the "participants" "table" And I should not see "Patricia Pea" in the "participants" "table" + @javascript + Scenario: Filter users who have not accessed a course + Given I am on the "C1" "Enrolled users" page logged in as "patricia" + When I set the field "type" in the "Filter 1" "fieldset" to "Inactive for more than" + + # Everyone has accessed the course. + And I open the autocomplete suggestions list in the "Filter 1" "fieldset" + And I should not see "Never" in the ".form-autocomplete-suggestions" "css_element" + + # Switch to a course which only some participants have accessed. + And I am on the "C2" "Enrolled users" page + And I set the field "type" in the "Filter 1" "fieldset" to "Inactive for more than" + And I set the field "Type or select..." in the "Filter 1" "fieldset" to "Never" + And I click on "Apply filters" "button" + Then I should see "Student 2" in the "participants" "table" + And I should see "Student 3" in the "participants" "table" + And I should see "Trendy Learnson" in the "participants" "table" + And I should not see "Student 1" in the "participants" "table" + And I should not see "Patricia Pea" in the "participants" "table" + @javascript Scenario: Multiple filters applied (All filterset match type) Given I am on the "C1" "Course" page logged in as "patricia" From a5f9878fc5dcb3690faddf2a5f8600077163e091 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20D=C3=A9niz?= Date: Fri, 19 Aug 2022 13:14:36 +0100 Subject: [PATCH 2/2] MDL-79681 user: fix conditional to get the last access to a course --- user/classes/output/participants_filter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user/classes/output/participants_filter.php b/user/classes/output/participants_filter.php index 54ba6630d3c..a43825bfc16 100644 --- a/user/classes/output/participants_filter.php +++ b/user/classes/output/participants_filter.php @@ -229,7 +229,7 @@ class participants_filter extends \core\output\datafilter { // Get minimum lastaccess for this course and display a dropbox to filter by lastaccess going back this far. // We need to make it diferently for normal courses and site course. - if (!$this->course->id == SITEID) { + if (!($this->course->id == SITEID)) { // Regular course. $params = [ 'courseid' => $this->course->id,