FilterBuilder
in package
implements
BuilderInterface
Builder for making filtered list queries.
Tags
Table of Contents
Interfaces
Properties
- $filters : array<string|int, mixed>
Methods
- __construct() : void
- Builder for making filtered list queries.
- between() : self
- Filters results where the provided field is between two values.
- boolean() : self
- Filters results where the field is equal to true or false.
- build() : string
- Builds the query string parameters from the Builder.
- datetime() : self
- Filters for entries that come before or after a particular time, as specified by the field.
- equals() : self
- Filters results where the field is equal to the provided value.
- inList() : self
- Filters if the provided field matches a value in a list.
- like() : self
- Filters for a match contained within the field being searched. For example, "leaf" will Like-match "aleaf" and "leafy", but not "leav", and "leafs" would not Like-match "leaf".
- convertBetweenKey() : string
- convertBetweenValue() : string
Properties
$filters
public
array<string|int, mixed>
$filters
Methods
__construct()
Builder for making filtered list queries.
public
__construct() : void
between()
Filters results where the provided field is between two values.
public
between(string $key[, mixed $min = null ][, mixed $max = null ]) : self
In general 'between' filters end in a _min
or _max
(as in amount_min
or amount_max
)
or _date
(as in start_date
, end_date
). If the provided field does not end in
_min
/_max
or _date
, then the appropriate _min
/_max
will be appended.
For date fields, you can pass the iso format 2020-10-17
or a datetime
or date
object, which
will be converted to the proper string format.
Examples:
-
$filter->between('amount', 1, 10)
will yield filters&search[amount_min]=1&search[amount_max]=10
-
$filter->between('amount_min', min: 1)
will yield filter&search[amount_min]=1
-
$filter->between('amount_max', max: 10)
will yield filter&search[amount_max]=10
-
$filter->between('start_date', min: '2020-10-17')
will yield filter&search[start_date]=2020-10-17
-
$filter->between('start_date', min: new DateTime('2020-10-17'))
will yield filter&search[start_date]=2020-10-17
Parameters
- $key : string
-
The API response field to filter on
- $min : mixed = null
-
(Optional) The value the field should be greater than (or equal to)
- $max : mixed = null
-
(Optional) The value the field should be less than (or equal to)
Return values
self —The FilterBuilder instance
boolean()
Filters results where the field is equal to true or false.
public
boolean(string $key, bool $value) : self
Example:
$filter->boolean('active', false)
will yield the filter &active=false
Parameters
- $key : string
-
The API response field to filter on
- $value : bool
-
true or false
Return values
self —The FilterBuilder instance
build()
Builds the query string parameters from the Builder.
public
build([string $resourceName = null ]) : string
Parameters
- $resourceName : string = null
-
The type of resource to generate the query string for. Eg. AccountingResource, ProjectsResource
Return values
string —The built query string
datetime()
Filters for entries that come before or after a particular time, as specified by the field.
public
datetime(string $key, mixed $value) : self
Eg. "updated_since" on Time Entries will return time entries updated after the provided time.
If a string is provided, it must be in ISO 8601 format (eg. '2010-10-17T05:45:53')
Example:
$filter->datetime('updated_since', '2020-10-17T07:03:01')
will yield the filter
&updated_since=2020-10-17T07:03:01
Similarly:
$filter->datetime('updated_since', new DateTime('2020-10-17T07:03:01.012345Z', new DateTimeZone('UTC')))
will yield the same.
Parameters
- $key : string
-
The API response field to filter on
- $value : mixed
-
The DateTime object or ISO 8601 format string value
Return values
self —The FilterBuilder instance
equals()
Filters results where the field is equal to the provided value.
public
equals(string $key, mixed $value) : self
Example:
$filter->equals('username', 'Bob')
will yield the filter &search[username]=Bob
Parameters
- $key : string
-
The API response field to filter on
- $value : mixed
-
The value the field should equal
Return values
self —The FilterBuilder instance
inList()
Filters if the provided field matches a value in a list.
public
inList(string $key, array<string|int, mixed> $values) : self
Example:
$filter->equals('username', 'Bob')
will yield the filter &search[username]=Bob
Parameters
- $key : string
-
The API response field to filter on
- $values : array<string|int, mixed>
Return values
self —The FilterBuilder instance
like()
Filters for a match contained within the field being searched. For example, "leaf" will Like-match "aleaf" and "leafy", but not "leav", and "leafs" would not Like-match "leaf".
public
like(string $key, mixed $value) : self
Parameters
- $key : string
-
The API response field to filter on
- $value : mixed
-
The value the field should contain
Return values
self —The FilterBuilder instance
convertBetweenKey()
private
convertBetweenKey(string $key, string $suffix) : string
Parameters
- $key : string
- $suffix : string
Return values
stringconvertBetweenValue()
private
convertBetweenValue(mixed $value) : string
Parameters
- $value : mixed