DEFAULT_DB_HOSTNAME
DEFAULT_DB_HOSTNAME
Database Source, through PDO.
$pagination : \Charcoal\Source\Pagination|null
The `Pagination` object
$model : \Charcoal\Model\ModelInterface
reset() : \Charcoal\Source\AbstractSource
Reset everything but the model.
Chainable
setData(array $data) : \Charcoal\Source\AbstractSource
Initialize the source's properties with an array of data.
array | $data | The source data. |
Chainable
setModel(\Charcoal\Model\ModelInterface $model) : \Charcoal\Source\AbstractSource
Set the source's Model.
\Charcoal\Model\ModelInterface | $model | The source's model. |
Chainable
model() : \Charcoal\Model\ModelInterface
Return the source's Model.
If not model was previously set.
setProperties(array $properties) : \Charcoal\Source\ColelectionLoader
Set the properties of the source to fetch.
This method accepts an array of property identifiers (property ident, as string) that will, if supported, be fetched from the source.
If no properties are set, it is assumed that all the Model's properties are to be fetched.
array | $properties | The properties. |
Chainable
addFilter(string|array|\Charcoal\Source\Filter $param, mixed $val = null, array $options = null) : \Charcoal\Source\CollectionLoader
Add a collection filter to the loader.
There are 3 different ways of adding a filter:
Filter
object, in which case it will be added directly.
addFilter($obj);
Filter
object
addFilter(['property' => 'foo', 'val' => 42, 'operator' => '<=']);
property
, val
and options
addFilter('foo', 42, ['operator' => '<=']);
string|array|\Charcoal\Source\Filter | $param | The filter property, or a Filter object / array. |
mixed | $val | Optional: Only used if the first argument is a string. |
array | $options | Optional: Only used if the first argument is a string. |
If property is not a string or empty.
(Chainable)
addOrder(string|array|\Charcoal\Source\Order $param, string $mode = 'asc', array $orderOptions = null) : \Charcoal\Source\CollectionLoader
string|array|\Charcoal\Source\Order | $param | The order property, or an Order object / array. |
string | $mode | Optional. |
array | $orderOptions | Optional. |
If the param argument is invalid.
Chainable
pagination() : \Charcoal\Source\Pagination
Get the pagination object.
If the pagination wasn't set previously, a new (default / blank) Pagination object will be created.
(Always return a PaginationInterface
object)
createConfig(array $data = null) : \Charcoal\Source\DatabaseSourceConfig
ConfigurableTrait > createConfig()
Overrides the method defined in AbstractSource to returns a DatabaseSourceConfig
object.
array | $data | Optional. |
loadItem(mixed $ident, \Charcoal\Source\StorableInterface $item = null) : \Charcoal\Source\StorableInterface
mixed | $ident | Ident can be any scalar value. |
\Charcoal\Source\StorableInterface | $item | Optional item to load into. |
loadItems(\Charcoal\Source\StorableInterface|null $item = null) : array
\Charcoal\Source\StorableInterface|null | $item | Optional item to use as model. |
saveItem(\Charcoal\Source\StorableInterface $item) : mixed
Save an item (create a new row) in storage.
\Charcoal\Source\StorableInterface | $item | The object to save. |
If a database error occurs.
The created item ID, or false in case of an error.
updateItem(\Charcoal\Source\StorableInterface $item, array $properties = null) : boolean
Update an item in storage.
\Charcoal\Source\StorableInterface | $item | The object to update. |
array | $properties | The list of properties to update, if not all. |
Success / Failure
deleteItem(\Charcoal\Source\StorableInterface $item = null) : boolean
Delete an item from storage
\Charcoal\Source\StorableInterface | $item | Optional item to delete. If none, the current model object will be used. |
If the item does not have an ID.
Success / Failure
setTable(string $table) : \Charcoal\Source\DatabaseSource
Set the database's table to use.
string | $table | The source table. |
If argument is not a string or alphanumeric/underscore.
Chainable
loadItemFromKey(string $key, mixed $ident, \Charcoal\Source\StorableInterface|null $item = null) : \Charcoal\Source\StorableInterface
Load item from a custom column's name ($key)
string | $key | Column name. |
mixed | $ident | Value of said column. |
\Charcoal\Source\StorableInterface|null | $item | Optional. Item (storable object) to load into. |
If the query fails.
Item
loadItemFromQuery(string $query, array $binds = array(), \Charcoal\Source\StorableInterface $item = null) : \Charcoal\Source\StorableInterface
string | $query | The SQL query. |
array | $binds | Optional. The query parameters. |
\Charcoal\Source\StorableInterface | $item | Optional. Item (storable object) to load into. |
If there is a query error.
Item.
loadItemsFromQuery(string $q, array $binds = array(), \Charcoal\Source\StorableInterface|null $item = null) : array
Loads items to a list from a query Allows external use.
string | $q | The actual query. |
array | $binds | This has to be done. |
\Charcoal\Source\StorableInterface|null | $item | Model Item. |
Collection of Items | Model
dbQuery(string $q, array $binds = array(), array $binds_types = array()) : \Charcoal\Source\PDOStatement|false
Execute a SQL query, with PDO, and returns the PDOStatement.
If the query fails, this method will return false.
string | $q | The SQL query to executed. |
array | $binds | Optional. Query parameter binds. |
array | $binds_types | Optional. Types of parameter bindings. |
The PDOStatement, or false in case of error
createFilter() : \Charcoal\Source\FilterInterface
createOrder() : \Charcoal\Source\OrderInterface
createPagination() : \Charcoal\Source\PaginationInterface
getter(string $key, string $case = 'camel') : string
Allow an object to define how the key getter are called.
string | $key | The key to get the getter from. |
string | $case | Optional. The type of case to return. camel, pascal or snake. |
The getter method name, for a given key.
setter(string $key, string $case = 'camel') : string
Allow an object to define how the key setter are called.
string | $key | The key to get the setter from. |
string | $case | Optional. The type of case to return. camel, pascal or snake. |
The setter method name, for a given key.
getModelFields(\Charcoal\Model\ModelInterface $model, array|null $properties = null) : array
Get all the fields of a model.
\Charcoal\Model\ModelInterface | $model | The model to get fields from. |
array|null | $properties | Optional list of properties to get. If null, retrieve all (from metadata). |