PHP Class yii2tech\balance\ManagerDb

Configuration example: php return [ 'components' => [ 'balanceManager' => [ 'class' => 'yii2tech\balance\ManagerDb', 'accountTable' => '{{%BalanceAccount}}', 'transactionTable' => '{{%BalanceTransaction}}', 'accountBalanceAttribute' => 'balance', 'extraAccountLinkAttribute' => 'extraAccountId', 'dataAttribute' => 'data', ], ], ... ]; Database migration example: php $this->createTable('BalanceAccount', [ 'id' => $this->primaryKey(), 'balance' => $this->integer()->notNull()->defaultValue(0), ... ]); $this->createTable('BalanceTransaction', [ 'id' => $this->primaryKey(), 'date' => $this->integer()->notNull(), 'accountId' => $this->integer()->notNull(), 'extraAccountId' => $this->integer()->notNull(), 'amount' => $this->integer()->notNull()->defaultValue(0), 'data' => $this->text(), ... ]);
See also: Manager
Since: 1.0
Author: Paul Klimov ([email protected])
Inheritance: extends ManagerDbTransaction, use trait ManagerDataSerializeTrait
Show file Open project: yii2tech/balance

Public Properties

Property Type Description
$accountTable name of the database table, which should store account records.
$db the DB connection object or the application component ID of the DB connection. After the ManagerDb object is created, if you want to change this property, you should only assign it with a DB connection object.
$transactionTable name of the database table, which should store transaction records.

Public Methods

Method Description
calculateBalance ( $account )
getAccountIdAttribute ( ) : string
getTransactionIdAttribute ( ) : string
init ( )
setAccountIdAttribute ( string $accountIdAttribute )
setTransactionIdAttribute ( string $transactionIdAttribute )

Protected Methods

Method Description
createAccount ( $attributes )
createDbTransaction ( )
createTransaction ( $attributes )
findAccountId ( $attributes )
findTransaction ( $id )
incrementAccountBalance ( $accountId, $amount )

Method Details

calculateBalance() public method

public calculateBalance ( $account )

createAccount() protected method

protected createAccount ( $attributes )

createDbTransaction() protected method

protected createDbTransaction ( )

createTransaction() protected method

protected createTransaction ( $attributes )

findAccountId() protected method

protected findAccountId ( $attributes )

findTransaction() protected method

protected findTransaction ( $id )

getAccountIdAttribute() public method

public getAccountIdAttribute ( ) : string
return string

getTransactionIdAttribute() public method

incrementAccountBalance() protected method

protected incrementAccountBalance ( $accountId, $amount )

init() public method

public init ( )

setAccountIdAttribute() public method

public setAccountIdAttribute ( string $accountIdAttribute )
$accountIdAttribute string

setTransactionIdAttribute() public method

public setTransactionIdAttribute ( string $transactionIdAttribute )
$transactionIdAttribute string

Property Details

$accountTable public property

name of the database table, which should store account records.
public $accountTable

$db public property

the DB connection object or the application component ID of the DB connection. After the ManagerDb object is created, if you want to change this property, you should only assign it with a DB connection object.
public $db

$transactionTable public property

name of the database table, which should store transaction records.
public $transactionTable