\Dewdrop\Db\Select\FilterDate

A filter implementation for date (and related datatypes such as timestamps) fields. This is the most complex filter. It provides many different operators to help select common date ranges (e.g. "This Month").

Internally, this filter divides a lot of its code between operators that require a single input (e.g. OP_IS) and those that require two inputs to check a range of dates (e.g. OP_BETWEEN).

Summary

Methods
Properties
Constants
__construct()
setTruncateTimestamps()
apply()
filterOnOrBetween()
filterBetween()
filterBefore()
filterOnOrBefore()
filterAfter()
filterOnOrAfter()
filterIs()
No public properties found
OP_ON_OR_BETWEEN
OP_BETWEEN
OP_ON_OR_BEFORE
OP_BEFORE
OP_ON_OR_AFTER
OP_AFTER
OP_IS
OP_TODAY
OP_YESTERDAY
OP_THIS_WEEK
OP_THIS_MONTH
OP_THIS_YEAR
No protected methods found
No protected properties found
N/A
filterBetweenInternal()
filterSingleInputInternal()
getAliasForComparison()
validate()
isValidOperator()
$tableName
$columnName
$inflector
$truncateTimestamps
N/A

Constants

OP_ON_OR_BETWEEN

OP_ON_OR_BETWEEN

Operator constant for dates in a range (inclusive).

OP_BETWEEN

OP_BETWEEN

Operator constant for dates in a range (exclusive).

OP_ON_OR_BEFORE

OP_ON_OR_BEFORE

Operator constant for dates before value (inclusive).

OP_BEFORE

OP_BEFORE

Operator constant for dates before value (exclusive).

OP_ON_OR_AFTER

OP_ON_OR_AFTER

Operator constant for dates after value (inclusive).

OP_AFTER

OP_AFTER

Operator constant for dates after value (exclusive).

OP_IS

OP_IS

Operator constant for exact date match.

OP_TODAY

OP_TODAY

Operator constant for today.

OP_YESTERDAY

OP_YESTERDAY

Operator constant for yesterday.

OP_THIS_WEEK

OP_THIS_WEEK

Operator constant for this week.

OP_THIS_MONTH

OP_THIS_MONTH

Operator constant for this month.

OP_THIS_YEAR

OP_THIS_YEAR

Operator constant for this year.

Properties

$tableName

$tableName : string

The name of the table in which the filtered column is present.

Type

string

$columnName

$columnName : string

The name of the DB column you need to filter.

Type

string

$inflector

$inflector : \Dewdrop\Inflector

Inflector object used when converting from operator to filter method name.

Type

\Dewdrop\Inflector

$truncateTimestamps

$truncateTimestamps : boolean

Whether to cut off time values on timestamps when filtering input.

Type

boolean

Methods

__construct()

__construct(string  $tableName, string  $columnName, \Dewdrop\Inflector  $inflector = null) 

Provide the table and column names that will be filtered by this object.

Parameters

string $tableName
string $columnName
\Dewdrop\Inflector $inflector

setTruncateTimestamps()

setTruncateTimestamps(boolean  $truncateTimestamps) : $this

Set whether time values should be truncated from timestamps when filtering input.

Parameters

boolean $truncateTimestamps

Returns

$this

apply()

apply(\Dewdrop\Db\Select  $select, string  $conditionSetName, array  $queryVars) : \Dewdrop\Db\Select

Apply the filter to the supplied Select object.

Parameters

\Dewdrop\Db\Select $select
string $conditionSetName
array $queryVars

Throws

\Dewdrop\Db\Select\Filter\Exception\InvalidOperator
\Dewdrop\Db\Select\Filter\Exception\MissingQueryVar

Returns

\Dewdrop\Db\Select

filterOnOrBetween()

filterOnOrBetween(\Dewdrop\Db\Select  $select, string  $conditionSetName, string  $start, string  $end) : \Dewdrop\Db\Select

Filter the Select to find records on or between the start and end dates.

Parameters

\Dewdrop\Db\Select $select
string $conditionSetName
string $start
string $end

Returns

\Dewdrop\Db\Select

filterBetween()

filterBetween(\Dewdrop\Db\Select  $select, string  $conditionSetName, string  $start, string  $end) : \Dewdrop\Db\Select

Filter the Select to find records between the start and end dates.

Parameters

\Dewdrop\Db\Select $select
string $conditionSetName
string $start
string $end

Returns

\Dewdrop\Db\Select

filterBefore()

filterBefore(\Dewdrop\Db\Select  $select,   $conditionSetName,   $start,   $end) 

Parameters

\Dewdrop\Db\Select $select
$conditionSetName
$start
$end

filterOnOrBefore()

filterOnOrBefore(\Dewdrop\Db\Select  $select,   $conditionSetName,   $start,   $end) 

Parameters

\Dewdrop\Db\Select $select
$conditionSetName
$start
$end

filterAfter()

filterAfter(\Dewdrop\Db\Select  $select,   $conditionSetName,   $start,   $end) 

Parameters

\Dewdrop\Db\Select $select
$conditionSetName
$start
$end

filterOnOrAfter()

filterOnOrAfter(\Dewdrop\Db\Select  $select,   $conditionSetName,   $start,   $end) 

Parameters

\Dewdrop\Db\Select $select
$conditionSetName
$start
$end

filterIs()

filterIs(\Dewdrop\Db\Select  $select,   $conditionSetName,   $start,   $end) 

Parameters

\Dewdrop\Db\Select $select
$conditionSetName
$start
$end

filterBetweenInternal()

filterBetweenInternal(boolean  $inclusive, \Dewdrop\Db\Select  $select, string  $conditionSetName, string  $start, string  $end) : \Dewdrop\Db\Select

This method does the heavy-lifting for the two "between" operators (both inclusive and exclusive). This method will attempt to handle situations where we don't actually have a start or end date by delegating to other methods.

Parameters

boolean $inclusive
\Dewdrop\Db\Select $select
string $conditionSetName
string $start
string $end

Returns

\Dewdrop\Db\Select

filterSingleInputInternal()

filterSingleInputInternal(boolean  $inclusive, \Dewdrop\Db\Select  $select, string  $conditionSetName, string  $type, string  $value) : $this

This method does the heavy lifting for all the single-input operators this filter supports.

Parameters

boolean $inclusive
\Dewdrop\Db\Select $select
string $conditionSetName
string $type
string $value

Throws

\Exception
\Dewdrop\Db\Select\SelectException

Returns

$this

getAliasForComparison()

getAliasForComparison(\Dewdrop\Db\Select  $select) 

Parameters

\Dewdrop\Db\Select $select

validate()

validate(array  $vars) 

Ensure the expected input vars were supplied before we attempt to apply a filter. We need the "comp" variable, which gives us the operator, along with a start and end date.

Parameters

array $vars

Throws

\Dewdrop\Db\Select\Filter\Exception\InvalidOperator
\Dewdrop\Db\Select\Filter\Exception\MissingQueryVar

isValidOperator()

isValidOperator(string  $operator) : boolean

Check to see if the supplied operator is valid.

Parameters

string $operator

Returns

boolean