NAME

WeBWorK::Utils::FilterRecords - utilities for filtering database records.

SYNOPSIS

use WeBWorK::Utils::FilterRecords qw/getFiltersForClass/;

# Get a list of filters
my $filters = getFiltersForClass(@users);

use WeBWorK::Utils::FilterRecords qw/filterRecords/;

# Start with a list of records
my @users = $db->getUsers($db->listUsers);

# Filter the records using a list of provided filters.
@filteredUsers = filterRecords([ 'section:1', 'recitation:2' ], @nsers);

    # Get all records (This isn't useful and just returns the passed in
    # array of records.  So don't actually do this.)
@filteredUsers = filterRecords(undef, @users);

DESCRIPTION

This module provides functions for filtering records from the database.

FUNCTIONS

getFiltersForClass($class)

Given a list of database records, returns the filters available for those records. For all database records from the WeBWorK::DB::Record::User class the filters are by section or recitation or no filter at all. For all other classes the only filter is no filter at all.

The return value is a reference to a list of two element lists. The first element in each list is a 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.

filterRecords($filters, @records)

Given a list of filters and a list of records, returns a list of the records after the selected filters are applied.

$filters should be a reference to an array of filters or be undefined.