WeBWorK::Utils::FilterRecords - utilities for filtering database records.
use WeBWorK::Utils::FilterRecords qw/getFiltersForClass filterRecords/;
# Start with a list of records
my @users = $db->getUsers($db->listUsers);
# Get a list of all filters
my $filters = getFiltersForClass($c, undef, @users);
# Alternative, get a list of section or recitation filters.
my $filters = getFiltersForClass($c, ['section', 'recitation'], @users);
# Filter the records using a list of provided filters.
my @filteredUsers = filterRecords($c, 1, [ 'section:1', 'recitation:2' ], @users);
This module provides functions for filtering user or set records from the database.
Given a list of database records, returns the filters available for those records. $include
is an array reference that lists the filters to include. If this is empty, all possible filters are returned.
For user records (WeBWorK::DB::Record::User), filters can be by section, recitation, status, or permission level in the permissionLevel table. The possible $include
are: 'section', 'recitation', 'status', or 'permission'.
For set records (WeBWorK::DB::Record::Set), filters can be assignment type, or visibility. The possible $include
are: 'assignment_type', or 'visibility'.
The return value is a reference to a list of two element lists. The first element in each list is a string description of the filter and the second element is the filter name. The return value is suitable for passing as the second value argument to the Mojolicious select_field tag helper method.
Given a list of filters and a list of records, returns a list of the records after the selected filters are applied. If $intersect
is true then the intersection of the records that match the filters is returned. Otherwise the union of the records that match the filters is returned.
$filters
should be a reference to an array of filters or be undefined.