class DataMapper extends AbstractDataMapper implements DatabaseMapperInterface (View source)

Main Database Mapper class.

Constants

UPDATE_NULLS

Methods

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

Constructor.

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.

static DataMapper
newRelation(string $alias = null, string $table = null, string $keys = null, AbstractDatabaseDriver $db = null)

newRelation

alias(string $alias)

Method to set property alias

getDb()

Get DB adapter.

setDb(AbstractDatabaseDriver $db)

Set db adapter.

getQuery(bool $new = false)

Method to get property Query

setQuery(QueryInterface $query)

Method to set property query

getQueryHelper()

Method to get property QueryHelper

setQueryHelper(QueryHelper $queryHelper)

Method to set property queryHelper

reset()

reset

join(string $joinType = 'LEFT', string $alias, string $table, mixed $condition = null, boolean $prefix = null)

join

mixed
__call(string $name, array $args)

__call

Details

at line line 99
__construct(string $table = null, string $keys = null, AbstractDatabaseDriver $db = null)

Constructor.

Parameters

string $table Table name.
string $keys The primary key, default will be id.
AbstractDatabaseDriver $db Database adapter.

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.

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.

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 482
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

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

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

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.

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.

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

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.

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.

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.

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 520
array getFields(string $table = null)

Get table fields.

Parameters

string $table Table name.

Return Value

array

string getTable()

Get table name.

Return Value

string Table name.

AbstractDataMapper setTable(string $table)

Set table name.

Parameters

string $table Table name.

Return Value

AbstractDataMapper Return self to support chaining.

string getDataClass()

Get data class.

Return Value

string Dat class.

AbstractDataMapper setDataClass(string $dataClass)

Set data class.

Parameters

string $dataClass Data class.

Return Value

AbstractDataMapper Return self to support chaining.

string getDatasetClass()

Get data set class.

Return Value

string Data set class.

AbstractDataMapper setDatasetClass(string $datasetClass)

Set Data set class.

Parameters

string $datasetClass Dat set class.

Return Value

AbstractDataMapper Return self to support chaining.

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

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

triggerEvent

Parameters

string|Event $event
array $args

Return Value

Event

DispatcherInterface getDispatcher()

Method to get property Dispatcher

Return Value

DispatcherInterface

AbstractDataMapper setDispatcher(DispatcherInterface $dispatcher)

Method to set property dispatcher

Parameters

DispatcherInterface $dispatcher

Return Value

AbstractDataMapper Return self to support chaining.

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.

boolean hasPrimaryKey()

Validate that the primary key has been set.

Return Value

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

at line line 85
static DataMapper newRelation(string $alias = null, string $table = null, string $keys = null, AbstractDatabaseDriver $db = null)

newRelation

Parameters

string $alias
string $table
string $keys
AbstractDatabaseDriver $db

Return Value

DataMapper

at line line 113
DataMapper alias(string $alias)

Method to set property alias

Parameters

string $alias

Return Value

DataMapper Return self to support chaining.

at line line 494
AbstractDatabaseDriver getDb()

Get DB adapter.

Return Value

AbstractDatabaseDriver Db adapter.

at line line 506
DataMapper setDb(AbstractDatabaseDriver $db)

Set db adapter.

Parameters

AbstractDatabaseDriver $db Db adapter.

Return Value

DataMapper Return self to support chaining.

at line line 581
QueryInterface getQuery(bool $new = false)

Method to get property Query

Parameters

bool $new

Return Value

QueryInterface

at line line 598
DataMapper setQuery(QueryInterface $query)

Method to set property query

Parameters

QueryInterface $query

Return Value

DataMapper Return self to support chaining.

at line line 610
QueryHelper getQueryHelper()

Method to get property QueryHelper

Return Value

QueryHelper

at line line 632
DataMapper setQueryHelper(QueryHelper $queryHelper)

Method to set property queryHelper

Parameters

QueryHelper $queryHelper

Return Value

DataMapper Return self to support chaining.

at line line 644
DataMapper reset()

reset

Return Value

DataMapper

at line line 663
DataMapper join(string $joinType = 'LEFT', string $alias, string $table, mixed $condition = null, boolean $prefix = null)

join

Parameters

string $joinType
string $alias
string $table
mixed $condition
boolean $prefix

Return Value

DataMapper

at line line 678
mixed __call(string $name, array $args)

__call

Parameters

string $name
array $args

Return Value

mixed