PHP Class JamesMoss\Flywheel\Result

A collection of Documents returned from a Query. This class acts like an array but also has some helper methods for manipulating the collection in useful ways.
Inheritance: implements IteratorAggregate, implements ArrayAccess, implements Countable
Show file Open project: jamesmoss/flywheel Class Usage Examples

Protected Properties

Property Type Description
$documents
$total

Public Methods

Method Description
__construct ( array $documents, integer $total ) Constructor
count ( ) : integer Returns the number of documents in this result
first ( ) : mixed Gets the first document from the result.
getIterator ( )
hash ( string $keyField, string $valueField ) : array Returns an assoiative array (a hash), where for each document the value of one property is the key, and another property is the value.
last ( ) : mixed Gets the last document from the results.
offsetExists ( $offset )
offsetGet ( $offset )
offsetSet ( $offset, $value )
offsetUnset ( $offset )
pick ( string $field ) : array Returns an array where each value is a single property from each document. If the property doesnt exist on the document then it won't be in the returned array.
total ( ) : integer Returns the total number of documents (if using limit in a query).
value ( $key ) : mixed Get the value specified by $key of the first object in the result.

Method Details

__construct() public method

Constructor
public __construct ( array $documents, integer $total )
$documents array An array of Documents
$total integer If this result only represents a small slice of the total (when using limit), this parameter represents the total number of documents.

count() public method

Returns the number of documents in this result
public count ( ) : integer
return integer The number of documents

first() public method

Gets the first document from the result.
public first ( ) : mixed
return mixed The first document, or false if the result is empty.

getIterator() public method

public getIterator ( )

hash() public method

Returns an assoiative array (a hash), where for each document the value of one property is the key, and another property is the value.
public hash ( string $keyField, string $valueField ) : array
$keyField string The name of the property to use for the key.
$valueField string Name of the property to use for the value.
return array An associative array.

last() public method

Gets the last document from the results.
public last ( ) : mixed
return mixed The last document, or false if the result is empty.

offsetExists() public method

public offsetExists ( $offset )

offsetGet() public method

public offsetGet ( $offset )

offsetSet() public method

public offsetSet ( $offset, $value )

offsetUnset() public method

public offsetUnset ( $offset )

pick() public method

Returns an array where each value is a single property from each document. If the property doesnt exist on the document then it won't be in the returned array.
public pick ( string $field ) : array
$field string The name of the field to pick.
return array The array of values, one from each document.

total() public method

Useful for working out pagination.
public total ( ) : integer
return integer The total number of documents

value() public method

Get the value specified by $key of the first object in the result.
public value ( $key ) : mixed
return mixed The value, or false if there are no documents or the key doesnt exist.

Property Details

$documents protected property

protected $documents

$total protected property

protected $total