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).
This commit is contained in:
Paul Holden
2024-01-05 13:55:54 +00:00
parent d5d0774fec
commit 4e2b5137f4
2 changed files with 32 additions and 4 deletions
+12 -4
View File
@@ -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'),
];
}
@@ -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"