PHP Class Prado\Data\ActiveRecord\TActiveRecordGateway

Since: 3.1
Inheritance: extends Prado\TComponent
显示文件 Open project: pradosoft/prado

Public Methods

Method Description
__construct ( TActiveRecordManager $manager ) Record gateway constructor.
countRecords ( TActiveRecord $record, $criteria ) : integer Returns the number of records that match the given criteria.
delete ( TActiveRecord $record ) : integer Delete the record.
deleteRecordsByCriteria ( TActiveRecord $record, $criteria ) : integer Delete multiple records by criteria.
deleteRecordsByPk ( TActiveRecord $record, $keys ) : integer Delete multiple records using primary keys.
findRecordByPK ( TActiveRecord $record, $keys ) : array Returns record data matching the given primary key(s). If the table uses composite key, specify the name value pairs as an array.
findRecordBySql ( TActiveRecord $record, $criteria ) : array Return record data from sql query.
findRecordsByCriteria ( TActiveRecord $record, $criteria, $iterator = false ) : mixed Returns record data matching the given critera. If $iterator is true, it will return multiple rows as TDbDataReader otherwise it returns the first row data.
findRecordsByIndex ( TActiveRecord $record, $criteria, $fields, $values )
findRecordsByPks ( TActiveRecord $record, $keys ) : array Returns records matching the list of given primary keys.
findRecordsBySql ( TActiveRecord $record, $criteria ) : TDbDataReader Return record data from sql query.
getCommand ( TActiveRecord $record ) : TDataGatewayCommand
getRecordTableInfo ( TActiveRecord $record ) : TDbTableInfo Returns table information, trys the application cache first.
getTableInfo ( TDbConnection $connection, $tableName ) : TDbTableInfo Returns table information for table in the database connection.
insert ( TActiveRecord $record ) : integer Insert a new record.
onCreateCommand ( $sender, $param ) Raised when a command is prepared and parameter binding is completed.
onExecuteCommand ( $sender, $param ) Raised when a command is executed and the result from the database was returned.
update ( TActiveRecord $record ) : integer Update the record.

Protected Methods

Method Description
getInsertValues ( TActiveRecord $record ) : array
getManager ( ) : TActiveRecordManager
getPrimaryKeyValues ( TActiveRecord $record )
getRecordTableName ( TActiveRecord $record ) : string Gets the table name from the 'TABLE' constant of the active record class if defined, otherwise use the class name as table name.
getUpdateValues ( TActiveRecord $record )
raiseCommandEvent ( $event, $command, $record, $criteria ) Raise the corresponding command event, insert, update, delete or select.
updateAssociatedRecords ( TActiveRecord $record, $updateBelongsTo = false )
updatePostInsert ( $record ) Sets the last insert ID to the corresponding property of the record if available.

Method Details

__construct() public method

Record gateway constructor.
public __construct ( TActiveRecordManager $manager )
$manager TActiveRecordManager

countRecords() public method

Returns the number of records that match the given criteria.
public countRecords ( TActiveRecord $record, $criteria ) : integer
$record TActiveRecord
return integer number of records.

delete() public method

Delete the record.
public delete ( TActiveRecord $record ) : integer
$record TActiveRecord
return integer number of rows affected.

deleteRecordsByCriteria() public method

Delete multiple records by criteria.
public deleteRecordsByCriteria ( TActiveRecord $record, $criteria ) : integer
$record TActiveRecord
return integer number of records.

deleteRecordsByPk() public method

Delete multiple records using primary keys.
public deleteRecordsByPk ( TActiveRecord $record, $keys ) : integer
$record TActiveRecord
return integer number of rows deleted.

findRecordByPK() public method

Returns record data matching the given primary key(s). If the table uses composite key, specify the name value pairs as an array.
public findRecordByPK ( TActiveRecord $record, $keys ) : array
$record TActiveRecord
return array record data

findRecordBySql() public method

Return record data from sql query.
public findRecordBySql ( TActiveRecord $record, $criteria ) : array
$record TActiveRecord
return array result.

findRecordsByCriteria() public method

Returns record data matching the given critera. If $iterator is true, it will return multiple rows as TDbDataReader otherwise it returns the first row data.
public findRecordsByCriteria ( TActiveRecord $record, $criteria, $iterator = false ) : mixed
$record TActiveRecord
return mixed matching data.

findRecordsByIndex() public method

public findRecordsByIndex ( TActiveRecord $record, $criteria, $fields, $values )
$record TActiveRecord

findRecordsByPks() public method

Returns records matching the list of given primary keys.
public findRecordsByPks ( TActiveRecord $record, $keys ) : array
$record TActiveRecord
return array matching data.

findRecordsBySql() public method

Return record data from sql query.
public findRecordsBySql ( TActiveRecord $record, $criteria ) : TDbDataReader
$record TActiveRecord
return TDbDataReader result iterator.

getCommand() public method

public getCommand ( TActiveRecord $record ) : TDataGatewayCommand
$record TActiveRecord
return Prado\Data\DataGateway\TDataGatewayCommand

getInsertValues() protected method

protected getInsertValues ( TActiveRecord $record ) : array
$record TActiveRecord
return array insert values.

getManager() protected method

protected getManager ( ) : TActiveRecordManager
return TActiveRecordManager record manager.

getPrimaryKeyValues() protected method

protected getPrimaryKeyValues ( TActiveRecord $record )
$record TActiveRecord

getRecordTableInfo() public method

Returns table information, trys the application cache first.
public getRecordTableInfo ( TActiveRecord $record ) : TDbTableInfo
$record TActiveRecord
return TDbTableInfo table information.

getRecordTableName() protected method

Gets the table name from the 'TABLE' constant of the active record class if defined, otherwise use the class name as table name.
protected getRecordTableName ( TActiveRecord $record ) : string
$record TActiveRecord
return string table name for the given record class.

getTableInfo() public method

Returns table information for table in the database connection.
public getTableInfo ( TDbConnection $connection, $tableName ) : TDbTableInfo
$connection Prado\Data\TDbConnection
return TDbTableInfo table details.

getUpdateValues() protected method

protected getUpdateValues ( TActiveRecord $record )
$record TActiveRecord

insert() public method

Insert a new record.
public insert ( TActiveRecord $record ) : integer
$record TActiveRecord
return integer number of rows affected.

onCreateCommand() public method

The parameter object is TDataGatewayEventParameter of which the {@link TDataGatewayEventParameter::getCommand Command} property can be inspected to obtain the sql query to be executed. This method also raises the OnCreateCommand event on the ActiveRecord object calling this gateway.
public onCreateCommand ( $sender, $param )

onExecuteCommand() public method

The parameter object is TDataGatewayResultEventParameter of which the {@link TDataGatewayEventParameter::getResult Result} property contains the data return from the database. The data returned can be changed by setting the {@link TDataGatewayEventParameter::setResult Result} property. This method also raises the OnCreateCommand event on the ActiveRecord object calling this gateway.
public onExecuteCommand ( $sender, $param )

raiseCommandEvent() protected method

Raise the corresponding command event, insert, update, delete or select.
protected raiseCommandEvent ( $event, $command, $record, $criteria )

update() public method

Update the record.
public update ( TActiveRecord $record ) : integer
$record TActiveRecord
return integer number of rows affected.

updateAssociatedRecords() protected method

protected updateAssociatedRecords ( TActiveRecord $record, $updateBelongsTo = false )
$record TActiveRecord

updatePostInsert() protected method

Sets the last insert ID to the corresponding property of the record if available.
protected updatePostInsert ( $record )