PHP Class LazyRecord\BaseCollection

Inheritance: implements ArrayAcces\ArrayAccess, implements Countabl\Countable, implements IteratorAggregat\IteratorAggregate
ファイルを表示 Open project: corneltek/lazyrecord Class Usage Examples

Public Properties

Property Type Description
$_readQuery
$selected
$yamlExtension

Protected Properties

Property Type Description
$_alias
$_lastSql
$_postCreate postCreate hook.
$_presetVars preset vars for creating.
$_result operation result object.
$_rows array handle data for items.
$_schema
$_vars
$defaultOrdering $this->defaultOrdering = array( array( 'id', 'desc' ), array( 'name', 'desc' ), );.
$explictSelect
$handle handle
$preferredTable

Public Methods

Method Description
__call ( $m, $a ) Dispatch undefined methods to SelectQuery object, To achieve mixin-like feature.
__clone ( ) When cloning collection object, The resources will be free, and the query builder will be cloned.
__construct ( )
__toString ( )
add ( BaseModel $record )
asPairs ( string $key, string $valueKey ) Return pair array by columns.
count ( ) This method implements the Countable interface.
create ( array $args ) : mixed Create new record or relationship record, and append the record into _rows list.
createReadQuery ( )
delete ( )
each ( callable $cb )
fetch ( ) : OperationResult Build sql and Fetch from current query, make a query to database.
fetchRow ( )
filter ( callable $cb )
first ( )
free ( ) Free cached row data and result handle, But still keep the same query.
fromArray ( array $list ) Create a collection object from an data array.
getAlias ( )
getCurrentReadQuery ( )
getExplicitColumnSelect ( BaseDriver $driver ) xxx: this might be used in other join statements.
getIterator ( )
getLastSql ( )
getQueryDriver ( $dsId ) Because it's used in BaseModel class too
getReadQueryDriver ( )
getResult ( )
getRows ( )
getSchema ( )
getSelected ( )
getSql ( )
getTable ( )
getVars ( )
getWriteQueryDriver ( )
items ( ) : BaseModel[] Get items.
join ( mixed $target, string $type = 'LEFT', string $alias = null, $relationId = null ) : QueryBuilder Override QueryBuilder->join method, to enable explict selection.
last ( )
limit ( integer $number ) Query Limit for QueryBuilder.
loadQuery ( string $sql, array $args = [], string $dsId = null ) Load Collection from a SQL query statement.
newModel ( ) : object Create model object.
offset ( integer $number ) Query offset for QueryBuilder.
offsetExists ( $name )
offsetGet ( $name )
offsetSet ( $name, $value ) array access interface
offsetUnset ( $name )
page ( integer $page, integer $pageSize = 20 ) A Short helper method for using limit and offset of QueryBuilder.
pager ( $page = 1, $pageSize = 10 ) : LazyRecord\CollectionPager Get selected items and wrap it into a CollectionPager object.
prepareHandle ( $force = false ) prepare data handle, call fetch method to read data from database, and catch the handle.
queryCount ( ) : integer Clone current read query and apply select to count(*) So that we can use the same conditions to query item count.
reset ( ) Free resources and reset query,arguments and data.
select ( $sels )
selectAll ( )
setAlias ( $alias )
setExplictSelect ( $boolean = true )
setPostCreate ( callable $cb )
setPreferredTable ( $tableName )
setPresetVars ( array $vars )
setRecords ( array $records ) Set record objects.
size ( ) : integer Get current selected item size by using php function count.
splice ( $pos, $count = null )
sql ( )
toArray ( )
toInflatedArray ( )
toJson ( )
toLabelValuePairs ( )
toPairs ( $key, $valueKey )
toSql ( ) Convert query to plain sql.
toXml ( )
toYaml ( )
update ( array $data ) Update collection.
where ( array $args = null ) Override QueryBuilder->where method, to enable explict selection.

Protected Methods

Method Description
readRows ( ) : model_class[] Read rows from database handle.

Method Details

__call() public method

Dispatch undefined methods to SelectQuery object, To achieve mixin-like feature.
public __call ( $m, $a )

__clone() public method

When cloning collection object, The resources will be free, and the query builder will be cloned.
public __clone ( )

__construct() public method

public __construct ( )

__toString() public method

public __toString ( )

add() public method

public add ( BaseModel $record )
$record BaseModel

asPairs() public method

Return pair array by columns.
public asPairs ( string $key, string $valueKey )
$key string
$valueKey string

count() public method

This method implements the Countable interface.
public count ( )

create() public method

Create new record or relationship record, and append the record into _rows list.
public create ( array $args ) : mixed
$args array Arguments for creating record
return mixed record object

createReadQuery() public method

public createReadQuery ( )

delete() public method

public delete ( )

each() public method

public each ( callable $cb )
$cb callable

fetch() public method

Build sql and Fetch from current query, make a query to database.
public fetch ( ) : OperationResult
return OperationResult

fetchRow() public method

public fetchRow ( )

filter() public method

public filter ( callable $cb )
$cb callable

first() public method

public first ( )

free() public method

Free cached row data and result handle, But still keep the same query.
public free ( )

fromArray() public static method

Create a collection object from an data array.
public static fromArray ( array $list )
$list array

getAlias() public method

public getAlias ( )

getCurrentReadQuery() public method

public getCurrentReadQuery ( )

getExplicitColumnSelect() public method

xxx: this might be used in other join statements.
public getExplicitColumnSelect ( BaseDriver $driver )
$driver SQLBuilder\Driver\BaseDriver

getIterator() public method

public getIterator ( )

getLastSql() public method

public getLastSql ( )

getQueryDriver() public method

Because it's used in BaseModel class too
public getQueryDriver ( $dsId )

getReadQueryDriver() public method

public getReadQueryDriver ( )

getResult() public method

public getResult ( )

getRows() public method

public getRows ( )

getSchema() public method

public getSchema ( )

getSelected() public method

public getSelected ( )

getSql() public method

public getSql ( )

getTable() public method

public getTable ( )

getVars() public method

public getVars ( )

getWriteQueryDriver() public method

public getWriteQueryDriver ( )

items() public method

Get items.
public items ( ) : BaseModel[]
return BaseModel[]

join() public method

For model/collection objects, we should convert it to table name Usage: $collection->join( new Author, 'LEFT', 'a' ); // left join with alias 'a' $collection->join('authors'); // left join without alias $collection->join( new Author, 'LEFT' , 'a' ) ->on('m.author_id', array('a.id') ); // LEFT JOIN authors table on m.author_id = a.id $collection->join('authors','RIGHT','a'); // right join with alias 'a'
public join ( mixed $target, string $type = 'LEFT', string $alias = null, $relationId = null ) : QueryBuilder
$target mixed (Model object or table name)
$type string Join Type (default 'LEFT')
$alias string Alias
return QueryBuilder

last() public method

public last ( )

limit() public method

Query Limit for QueryBuilder.
public limit ( integer $number )
$number integer

loadQuery() public method

Load Collection from a SQL query statement.
public loadQuery ( string $sql, array $args = [], string $dsId = null )
$sql string
$args array
$dsId string

newModel() public method

Create model object.
public newModel ( ) : object
return object BaseModel

offset() public method

Query offset for QueryBuilder.
public offset ( integer $number )
$number integer

offsetExists() public method

public offsetExists ( $name )

offsetGet() public method

public offsetGet ( $name )

offsetSet() public method

array access interface
public offsetSet ( $name, $value )

offsetUnset() public method

public offsetUnset ( $name )

page() public method

A Short helper method for using limit and offset of QueryBuilder.
public page ( integer $page, integer $pageSize = 20 )
$page integer
$pageSize integer

pager() public method

CollectionPager is a simple data pager, do not depends on database.
public pager ( $page = 1, $pageSize = 10 ) : LazyRecord\CollectionPager
return LazyRecord\CollectionPager

prepareHandle() public method

Which calls doFetch() to do a query operation.
public prepareHandle ( $force = false )

queryCount() public method

Clone current read query and apply select to count(*) So that we can use the same conditions to query item count.
public queryCount ( ) : integer
return integer

readRows() protected method

Read rows from database handle.
protected readRows ( ) : model_class[]
return model_class[]

reset() public method

Free resources and reset query,arguments and data.
public reset ( )

select() public method

public select ( $sels )

selectAll() public method

public selectAll ( )

setAlias() public method

public setAlias ( $alias )

setExplictSelect() public method

public setExplictSelect ( $boolean = true )

setPostCreate() public method

public setPostCreate ( callable $cb )
$cb callable

setPreferredTable() public method

public setPreferredTable ( $tableName )

setPresetVars() public method

public setPresetVars ( array $vars )
$vars array

setRecords() public method

Set record objects.
public setRecords ( array $records )
$records array

size() public method

Get current selected item size by using php function count.
public size ( ) : integer
return integer size

splice() public method

public splice ( $pos, $count = null )

sql() public method

public sql ( )

toArray() public method

public toArray ( )

toInflatedArray() public method

public toInflatedArray ( )

toJson() public method

public toJson ( )

toLabelValuePairs() public method

public toLabelValuePairs ( )

toPairs() public method

public toPairs ( $key, $valueKey )

toSql() public method

Convert query to plain sql.
public toSql ( )

toXml() public method

public toXml ( )

toYaml() public method

public toYaml ( )

update() public method

FIXME
public update ( array $data )
$data array

where() public method

Override QueryBuilder->where method, to enable explict selection.
public where ( array $args = null )
$args array

Property Details

$_alias protected_oe property

protected $_alias

$_lastSql protected_oe property

protected $_lastSql

$_postCreate protected_oe property

postCreate hook.
protected $_postCreate

$_presetVars protected_oe property

preset vars for creating.
protected $_presetVars

$_readQuery public_oe property

public $_readQuery

$_result protected_oe property

operation result object.
protected $_result

$_rows protected_oe property

handle data for items.
protected array $_rows
return array

$_schema protected_oe property

protected $_schema

$_vars protected_oe property

protected $_vars

$defaultOrdering protected_oe property

$this->defaultOrdering = array( array( 'id', 'desc' ), array( 'name', 'desc' ), );.
protected $defaultOrdering

$explictSelect protected_oe property

protected $explictSelect

$handle protected_oe property

handle
protected $handle

$preferredTable protected_oe property

protected $preferredTable

$selected public_oe property

public $selected

$yamlExtension public_oe static_oe property

public static $yamlExtension