\Disco\classesLookUp

Provides the base functionality for lookup classes. All classes that extend this class must at a minimum set `$this->Model`, `$this->fields`, `$this->searchableFields`. To extend the functionality of the fetch method override `$this->preFetch()` and `$this->postFetch`.

Summary

Methods
Properties
Constants
__construct()
__call()
fetch()
first()
last()
search()
limit()
page()
order()
total()
getLimit()
No public properties found
No constants found
preFetch()
postFetch()
prepareSearch()
prepareOrder()
prepareLimit()
prepareConditions()
prepareAll()
resolveFieldAlias()
$searchableFields
$fields
$select
$callStack
$limit
$page
$search
$order
$total
$Model
N/A
No private methods found
No private properties found
N/A

Properties

$searchableFields

$searchableFields : array

Type

array — The fields that can have a LIKE expression used on them when searching via the lookup.

$fields

$fields : array

Type

array — The fields that the lookup can be used to query against. The keys of the array become the magic __call methods used to define the comparison which will actually be compared in the models query to the value of the key. For example `'fieldName' => 'alias.field_name'`, where `fieldName` will be the method and `alias.field_name` is the actual field in the database.

$select

$select : string|array

Type

string|array — The fields to be selected when the lookup is performed. If this isn't set at some point during `__construct()` or `preFetch()` then when `fetch()` is executed the values from `$this->fields` will be used.

$callStack

$callStack : array

Type

array — Store of method chain calls and arguements.

$limit

$limit : null|integer

Type

null|integer — Limit the number of results returned.

$page

$page : integer

Type

integer — The current page being looked up.

$search

$search : null|string

Type

null|string — Return only results matching this string.

$order

$order : null|string

Type

null|string — Column to order on.

$total

$total : null|integer

Type

null|integer — The total number of results.

$Model

$Model : mixed

Type

mixed — The instance of the model were fetching results from.

Methods

__construct()

__construct(array  $stack = array()) : void

Optionally push method and arguements onto the call stack.

Parameters

array $stack

Method and arguements and key/value pairs.

__call()

__call(string  $method, mixed  $args) : mixed

Magic call method for calling methods that don't exist but are used to set key/value to push onto the call stack. The call stack is used to determine the where condition of how to look up results.

Parameters

string $method

The method that doesn't exist on the class.

mixed $args

The arguements passed to the method.

Returns

mixed

fetch()

fetch() : integer|array

Perform the lookup. Calling `$this->preFetch()` to set up any pre conditions (ie joins, where etc). If the total number of results of the lookup are being requested ie `total()` was called, the total will be returned. If not the fields to be selected will be set from `$this->select` on the model and the result of calling `$this->postFetch()` will be returned.

Returns

integer|array —

Either the total results of the lookup as an integer, or an array of results provided by $this->postFetch().

first()

first() : array

Return the first result from a fetch.

Returns

array

last()

last() : array

Return the last result from a fetch.

Returns

array

search()

search(string  $s) : mixed

Set `$this->search` for use in fetching results.

Parameters

string $s

The string to search for.

Returns

mixed

limit()

limit(integer  $limit) : mixed

Set `$this->limit` for use in fetching results.

Parameters

integer $limit

The limit.

Returns

mixed

page()

page(integer  $page) : mixed

Set `$this->page` for use in fetching results.

Parameters

integer $page

The page to fetch.

Returns

mixed

order()

order(string  $order) : mixed

Set `$this->order` for use in fetching results.

Parameters

string $order

The column to order the results on.

Returns

mixed

total()

total() : mixed

Make it so the total number of results is fetched from the conditions rather than the actual results.

Returns

mixed

getLimit()

getLimit() : null|integer

Get `$this->limit`.

Returns

null|integer

preFetch()

preFetch() 

Set up any pre conditions necessary to perform the lookup ie joins, wheres etc.

postFetch()

postFetch() : array

Responsible for returing the results of the lookup as an array. By default `$this->Model->asArray()` is called and returned.

Returns

array —

The array of results of the lookup.

prepareSearch()

prepareSearch() : void

Prepare the search on the model.

prepareOrder()

prepareOrder() : void

Prepare the order on the model.

prepareLimit()

prepareLimit() : void

Prepare the limit on the model.

prepareConditions()

prepareConditions() : void

Build the conditions to fetch results using the `$this->callStack` making sure that each method/attribute is found in the field list `$this->fields` of attributes.

prepareAll()

prepareAll() 

Prepare all possible lookup conditions. Calls - `$this->prepareConditions()` - `$this->prepareSearch()` - `$this->prepareLimit()` - `$this->prepareOrder()` internally.

resolveFieldAlias()

resolveFieldAlias(string  $alias) : string

Resolve an aliased field via `$this->fields`.

Parameters

string $alias

The aliased field.

Throws

\Exception

The field doesn't exist.

Returns

string —

The unaliased field.