$source
$source : \Charcoal\Source\SourceInterface
The source to load objects from.
Object Collection Loader
$source : \Charcoal\Source\SourceInterface
The source to load objects from.
$model : \Charcoal\Model\ModelInterface
The model to load the collection from.
setFactory(\Charcoal\Factory\FactoryInterface $factory) : \Charcoal\Loader\CollectionLoader
Set an object model factory.
\Charcoal\Factory\FactoryInterface | $factory | The model factory, to create objects. |
Chainable
setData(array $data) : \Charcoal\Loader\CollectionLoader
Set the loader data.
array | $data | Data to assign to the loader. |
Chainable
setSource(\Charcoal\Source\SourceInterface $source) : \Charcoal\Loader\CollectionLoader
Set the source to load objects from.
\Charcoal\Source\SourceInterface | $source | A data source. |
Chainable
reset() : \Charcoal\Loader\CollectionLoader
Reset everything but the model.
Chainable
setModel(string|\Charcoal\Model\ModelInterface $model) : \Charcoal\Loader\CollectionLoader
Set the model to use for the loaded objects.
string|\Charcoal\Model\ModelInterface | $model | An object model. |
If the given argument is not a model.
CHainable
setDynamicTypeField(string $field) : \Charcoal\Loader\CollectionLoader
string | $field | The field to use for dynamic object type. |
If the field is not a string.
Chainable
setProperties(array $properties) : \Charcoal\Loader\CollectionLoader
Alias of {@see SourceInterface::setProperties()}
array | $properties | An array of property identifiers. |
Chainable
addProperty(string $property) : \Charcoal\Loader\CollectionLoader
Alias of {@see SourceInterface::addProperty()}
string | $property | A property identifier. |
Chainable
setKeywords(array $keywords) : \Charcoal\Loader\CollectionLoader
Set "search" keywords to filter multiple properties.
array | $keywords | An array of keywords and properties. |
Chainable
addKeyword(string $keyword, array $properties = null) : \Charcoal\Loader\CollectionLoader
Add a "search" keyword filter to multiple properties.
string | $keyword | A value to match among $properties. |
array | $properties | An array of property identifiers. |
Chainable
setFilters(array $filters) : \Charcoal\Model\Collection
Alias of {@see SourceInterface::setFilters()}
array | $filters | An array of filters. |
Chainable
addFilter(string|array|\Charcoal\Loader\Filter $param, mixed $val = null, array $options = null) : \Charcoal\Loader\CollectionLoader
Alias of {@see SourceInterface::addFilter()}
string|array|\Charcoal\Loader\Filter | $param | A property identifier, filter array, or Filter object. |
mixed | $val | Optional. The value to match. Only used if the first argument is a string. |
array | $options | Optional. Filter options. Only used if the first argument is a string. |
Chainable
setOrders(array $orders) : \Charcoal\Loader\CollectionLoader
Alias of {@see SourceInterface::setOrders()}
array | $orders | An array of orders. |
Chainable
addOrder(string|array|\Charcoal\Loader\Order $param, string $mode = 'asc', array $orderOptions = null) : \Charcoal\Loader\CollectionLoader
Alias of {@see SourceInterface::addOrder()}
string|array|\Charcoal\Loader\Order | $param | A property identifier, order array, or Order object. |
string | $mode | Optional. Sort order. Only used if the first argument is a string. |
array | $orderOptions | Optional. Filter options. Only used if the first argument is a string. |
Chainable
setPagination(mixed $param) : \Charcoal\Loader\CollectionLoader
Alias of {@see SourceInterface::setPagination()}
mixed | $param | An associative array of pagination settings. |
Chainable
setPage(integer $page) : \Charcoal\Loader\CollectionLoader
Alias of {@see PaginationInterface::pagination()}
integer | $page | A page number. |
Chainable
setNumPerPage(integer $num) : \Charcoal\Loader\CollectionLoader
Alias of {@see PaginationInterface::setNumPerPage()}
integer | $num | The number of items to display per page. |
Chainable
setCallback(callable $callback) : \Charcoal\Loader\CollectionLoader
Set the callback routine applied to every object added to the collection.
callable | $callback | The callback routine. |
Chainable
load(string|null $ident = null, callable $callback = null) : array|\ArrayAccess
Load a collection from source.
string|null | $ident | Optional. A pre-defined list to use from the model. |
callable | $callback | Optional. Apply a callback to every entity of the collection. Leave blank to use {@see CollectionLoader::callback()}. |
If the database connection fails.
loadFromQuery(string|array $query, callable $callback = null) : array|\ArrayAccess
Load list from query.
Example — Binding values to $query
$this->loadFromQuery([
'SELECT name, colour, calories FROM fruit WHERE calories < :calories AND colour = :colour',
[
'calories' => 150,
'colour' => 'red'
],
[ 'calories' => PDO::PARAM_INT ]
]);
string|array | $query | The SQL query as a string or an array composed of the query, parameter binds, and types of parameter bindings. |
callable | $callback | Optional. Apply a callback to every entity of the collection. Leave blank to use {@see CollectionLoader::callback()}. |
If the database connection fails.
If the SQL string/set is invalid.
setCollectionClass(string $className) : \Charcoal\Loader\AbstractPropertyDisplay
Set the class name of the collection.
string | $className | The class name of the collection. |
If the class name is not a string.
Chainable
processCollection(array|\Traversable $results, callable $callback = null) : array|\ArrayAccess
Process the collection of raw data.
array|\Traversable | $results | The raw result set. |
callable | $callback | Optional. Apply a callback to every entity of the collection. Leave blank to use {@see CollectionLoader::callback()}. |
If the SQL string/set is invalid.