class AbstractDataMapper implements DataMapperInterface (View source)

Abstract DataMapper.

The class can implement by any database system.

Constants

UPDATE_NULLS

Methods

__construct(string $table = null, string $keys = null)

Init this class.

mixed
find(mixed $conditions = array(), mixed $order = null, integer $start = null, integer $limit = null)

Find records and return data set.

mixed
findAll(mixed $order = null, integer $start = null, integer $limit = null)

Find records without where conditions and return data set.

mixed
findOne(mixed $conditions = array(), mixed $order = null)

Find one record and return a data.

mixed
findColumn(string $column, mixed $conditions = array(), mixed $order = null, integer $start = null, integer $limit = null)

Find column as an array.

mixed
create(mixed $dataset)

Create records by data set.

mixed
createOne(mixed $data)

Create one record by data object.

mixed
update(mixed $dataset, array $condFields = null, bool $updateNulls = false)

Update records by data set. Every data depend on this table's primary key to update itself.

mixed
updateOne(mixed $data, array $condFields = null, bool $updateNulls = false)

Same as update(), just update one row.

mixed
updateBatch(mixed $data, mixed $conditions = array())

Using one data to update multiple rows, filter by where conditions.

mixed
flush(mixed $dataset, mixed $conditions = array())

Flush records, will delete all by conditions then recreate new.

mixed
save(mixed $dataset, array $condFields = null, bool $updateNulls = false)

Save will auto detect is conditions matched in data or not.

mixed
saveOne(mixed $data, array $condFields = null, bool $updateNulls = false)

Save only one row.

boolean
delete(mixed $conditions)

Delete records by where conditions.

array
getFields(string $table = null)

Get table fields.

string
getTable()

Get table name.

setTable(string $table)

Set table name.

string
getDataClass()

Get data class.

setDataClass(string $dataClass)

Set data class.

string
getDatasetClass()

Get data set class.

setDatasetClass(string $datasetClass)

Set Data set class.

boolean
useTransaction(boolean $yn = null)

To use transaction or not.

triggerEvent(string|Event $event, array $args = array())

triggerEvent

getDispatcher()

Method to get property Dispatcher

setDispatcher(DispatcherInterface $dispatcher)

Method to set property dispatcher

array|mixed
getKeyName(boolean $multiple = false)

Method to get the primary key field name for the table.

boolean
hasPrimaryKey()

Validate that the primary key has been set.

Details

at line line 105
__construct(string $table = null, string $keys = null)

Init this class.

We don't dependency on database in abstract class, that means you can use other data provider.

Parameters

string $table Table name.
string $keys The primary key, default will be id.

Exceptions

Exception

at line line 150
mixed find(mixed $conditions = array(), mixed $order = null, integer $start = null, integer $limit = null)

Find records and return data set.

Example: - $mapper->find(array('id' => 5), 'date', 20, 10); - $mapper->find(null, 'id', 0, 1);

Parameters

mixed $conditions Where conditions, you can use array or Compare object. Example: - array('id' => 5) => id = 5 - new GteCompare('id', 20) => 'id >= 20' - new Compare('id', '%Flower%', 'LIKE') => 'id LIKE "%Flower%"'
mixed $order Order sort, can ba string, array or object. Example: - id ASC => ORDER BY id ASC - array('catid DESC', 'id') => ORDER BY catid DESC, id
integer $start Limit start number.
integer $limit Limit rows.

Return Value

mixed Found rows data set.

at line line 226
mixed findAll(mixed $order = null, integer $start = null, integer $limit = null)

Find records without where conditions and return data set.

Same as $mapper->find(null, 'id', $start, $limit);

Parameters

mixed $order Order sort, can ba string, array or object. Example: - 'id ASC' => ORDER BY id ASC - array('catid DESC', 'id') => ORDER BY catid DESC, id
integer $start Limit start number.
integer $limit Limit rows.

Return Value

mixed Found rows data set.

at line line 262
mixed findOne(mixed $conditions = array(), mixed $order = null)

Find one record and return a data.

Same as $mapper->find($conditions, 'id', 0, 1);

Parameters

mixed $conditions Where conditions, you can use array or Compare object. Example: - array('id' => 5) => id = 5 - new GteCompare('id', 20) => 'id >= 20' - new Compare('id', '%Flower%', 'LIKE') => 'id LIKE "%Flower%"'
mixed $order Order sort, can ba string, array or object. Example: - id ASC => ORDER BY id ASC - array('catid DESC', 'id') => ORDER BY catid DESC, id

Return Value

mixed Found row data.

at line line 307
mixed findColumn(string $column, mixed $conditions = array(), mixed $order = null, integer $start = null, integer $limit = null)

Find column as an array.

Parameters

string $column The column we want to select.
mixed $conditions Where conditions, you can use array or Compare object. Example: - array('id' => 5) => id = 5 - new GteCompare('id', 20) => 'id >= 20' - new Compare('id', '%Flower%', 'LIKE') => 'id LIKE "%Flower%"'
mixed $order Order sort, can ba string, array or object. Example: - id ASC => ORDER BY id ASC - array('catid DESC', 'id') => ORDER BY catid DESC, id
integer $start Limit start number.
integer $limit Limit rows.

Return Value

mixed

Exceptions

InvalidArgumentException

at line line 349
mixed create(mixed $dataset)

Create records by data set.

Parameters

mixed $dataset The data set contains data we want to store.

Return Value

mixed Data set data with inserted id.

Exceptions

UnexpectedValueException
InvalidArgumentException

at line line 379
mixed createOne(mixed $data)

Create one record by data object.

Parameters

mixed $data Send a data in and store.

Return Value

mixed Data with inserted id.

Exceptions

InvalidArgumentException

at line line 408
mixed update(mixed $dataset, array $condFields = null, bool $updateNulls = false)

Update records by data set. Every data depend on this table's primary key to update itself.

Parameters

mixed $dataset Data set contain data we want to update.
array $condFields The where condition tell us record exists or not, if not set, will use primary key instead.
bool $updateNulls Update empty fields or not.

Return Value

mixed Updated data set.

at line line 445
mixed updateOne(mixed $data, array $condFields = null, bool $updateNulls = false)

Same as update(), just update one row.

Parameters

mixed $data The data we want to update.
array $condFields The where condition tell us record exists or not, if not set, will use primary key instead.
bool $updateNulls Update empty fields or not.

Return Value

mixed Updated data.

at line line 482
mixed updateBatch(mixed $data, mixed $conditions = array())

Using one data to update multiple rows, filter by where conditions.

Example: $mapper->updateAll(new Data(array('published' => 0)), array('date' => '2014-03-02')) Means we make every records which date is 2014-03-02 unpublished.

Parameters

mixed $data The data we want to update to every rows.
mixed $conditions Where conditions, you can use array or Compare object. Example: - array('id' => 5) => id = 5 - new GteCompare('id', 20) => 'id >= 20' - new Compare('id', '%Flower%', 'LIKE') => 'id LIKE "%Flower%"'

Return Value

mixed Updated data set.

Exceptions

InvalidArgumentException

at line line 512
mixed flush(mixed $dataset, mixed $conditions = array())

Flush records, will delete all by conditions then recreate new.

Parameters

mixed $dataset Data set contain data we want to update.
mixed $conditions Where conditions, you can use array or Compare object. Example: - array('id' => 5) => id = 5 - new GteCompare('id', 20) => 'id >= 20' - new Compare('id', '%Flower%', 'LIKE') => 'id LIKE "%Flower%"'

Return Value

mixed Updated data set.

at line line 554
mixed save(mixed $dataset, array $condFields = null, bool $updateNulls = false)

Save will auto detect is conditions matched in data or not.

If matched, using update, otherwise we will create it as new record.

Parameters

mixed $dataset The data set contains data we want to save.
array $condFields The where condition tell us record exists or not, if not set, will use primary key instead.
bool $updateNulls Update empty fields or not.

Return Value

mixed Saved data set.

at line line 626
mixed saveOne(mixed $data, array $condFields = null, bool $updateNulls = false)

Save only one row.

Parameters

mixed $data The data we want to save.
array $condFields The where condition tell us record exists or not, if not set, will use primary key instead.
bool $updateNulls Update empty fields or not.

Return Value

mixed Saved data.

at line line 658
boolean delete(mixed $conditions)

Delete records by where conditions.

Parameters

mixed $conditions Where conditions, you can use array or Compare object. Example: - array('id' => 5) => id = 5 - new GteCompare('id', 20) => 'id >= 20' - new Compare('id', '%Flower%', 'LIKE') => 'id LIKE "%Flower%"'

Return Value

boolean Will be always true.

at line line 773
abstract array getFields(string $table = null)

Get table fields.

Parameters

string $table Table name.

Return Value

array

at line line 780
string getTable()

Get table name.

Return Value

string Table name.

at line line 792
AbstractDataMapper setTable(string $table)

Set table name.

Parameters

string $table Table name.

Return Value

AbstractDataMapper Return self to support chaining.

at line line 870
string getDataClass()

Get data class.

Return Value

string Dat class.

at line line 882
AbstractDataMapper setDataClass(string $dataClass)

Set data class.

Parameters

string $dataClass Data class.

Return Value

AbstractDataMapper Return self to support chaining.

at line line 894
string getDatasetClass()

Get data set class.

Return Value

string Data set class.

at line line 906
AbstractDataMapper setDatasetClass(string $datasetClass)

Set Data set class.

Parameters

string $datasetClass Dat set class.

Return Value

AbstractDataMapper Return self to support chaining.

at line line 920
boolean useTransaction(boolean $yn = null)

To use transaction or not.

Parameters

boolean $yn Yes or no, keep default that we get this value.

Return Value

boolean

at line line 938
Event triggerEvent(string|Event $event, array $args = array())

triggerEvent

Parameters

string|Event $event
array $args

Return Value

Event

at line line 966
DispatcherInterface getDispatcher()

Method to get property Dispatcher

Return Value

DispatcherInterface

at line line 988
AbstractDataMapper setDispatcher(DispatcherInterface $dispatcher)

Method to set property dispatcher

Parameters

DispatcherInterface $dispatcher

Return Value

AbstractDataMapper Return self to support chaining.

at line line 1004
array|mixed getKeyName(boolean $multiple = false)

Method to get the primary key field name for the table.

Parameters

boolean $multiple True to return all primary keys (as an array) or false to return just the first one (as a string).

Return Value

array|mixed Array of primary key field names or string containing the first primary key field.

at line line 1031
boolean hasPrimaryKey()

Validate that the primary key has been set.

Return Value

boolean True if the primary key(s) have been set.