class Selection implements Iterator, IRowContainer, ArrayAccess, Countable

Filtered table representation.

Selection is based on the great library NotORM http://www.notorm.com written by Jakub Vrana.

Properties

protected Context $context
protected IConventions $conventions
protected Cache $cache
protected SqlBuilder $sqlBuilder
protected string $name
protected string|array|null $primary
protected string|bool $primarySequence
protected IRow[] $rows
protected IRow[] $data
protected bool $dataRefreshed
protected mixed $globalRefCache
protected mixed $refCache
protected string $generalCacheKey
protected string $specificCacheKey
protected array $aggregation
protected array $accessedColumns
protected array $previousAccessedColumns
protected bool $observeCache
protected array $keys

Methods

__construct(Context $context, IConventions $conventions, $tableName, IStorage $cacheStorage = null)

Creates filtered table representation.

__destruct()

No description

__clone()

No description

string
getName()

No description

string|array|null
getPrimary($throw = true)

No description

string|null
getPrimarySequence()

No description

setPrimarySequence($sequence)

No description

string
getSql()

No description

array|false
getPreviousAccessedColumns()

Loads cache of previous accessed columns and returns it.

getSqlBuilder()

No description

ActiveRow|false
get($key)

Returns row specified by primary key.

IRow|bool
fetch()

No description

mixed|false
fetchField($column = null)

Fetches single field.

array
fetchPairs($key = null, $value = null)

No description

IRow[]
fetchAll()

No description

array
fetchAssoc($path)

No description

select($columns, ...$params)

Adds select clause, more calls appends to the end.

wherePrimary($key)

Adds condition for primary key.

where($condition, ...$params)

Adds where condition, more calls appends with AND.

joinWhere($tableChain, $condition, ...$params)

Adds ON condition when joining specified table, more calls appends with AND.

void
condition($condition, array $params, $tableChain = null)

Adds condition, more calls appends with AND.

whereOr(array $parameters)

Adds where condition using the OR operator between parameters.

order($columns, ...$params)

Adds order clause, more calls appends to the end.

limit($limit, $offset = null)

Sets limit clause, more calls rewrite old values.

page($page, $itemsPerPage, $numOfPages = null)

Sets offset using page number, more calls rewrite old values.

group($columns, ...$params)

Sets group clause, more calls rewrite old value.

having($having, ...$params)

Sets having clause, more calls rewrite old value.

alias($tableChain, $alias)

Aliases table. Example ':book:book_tag.tag', 'tg'

int
aggregation($function, $groupFunction = null)

Executes aggregation function.

int
count($column = null)

Counts number of rows.

int
min($column)

Returns minimum value from a column.

int
max($column)

Returns maximum value from a column.

int
sum($column)

Returns sum of values in a column.

execute()

No description

createRow(array $row)

No description

createSelectionInstance($table = null)

No description

createGroupedSelectionInstance($table, $column)

No description

query($query)

No description

emptyResultSet($clearCache = true, $deleteRererencedCache = true)

No description

saveCacheState()

No description

getRefTable($refPath)

Returns Selection parent for caching.

loadRefCache()

Loads refCache references

string
getGeneralCacheKey()

Returns general cache key independent on query parameters or sql limit Used e.g. for previously accessed columns caching

string
getSpecificCacheKey()

Returns object specific cache key dependent on query parameters Used e.g. for reference memory caching

bool
accessColumn($key, $selectColumn = true)

No description

removeAccessColumn($key)

No description

bool
getDataRefreshed()

Returns if selection requeried for more columns.

ActiveRow|int|bool
insert($data)

Inserts row in a table.

int
update($data)

Updates all rows in result set.

int
delete()

Deletes all rows in result set.

ActiveRow|null|false
getReferencedTable(ActiveRow $row, $table, $column = null)

Returns referenced row.

getReferencingTable($table, $column, $active = null)

Returns referencing rows.

rewind()

No description

ActiveRow|bool
current()

No description

string|int
key()

No description

next()

No description

valid()

No description

void
offsetSet($key, $value)

Mimic row.

ActiveRow|null
offsetGet($key)

Returns specified row.

bool
offsetExists($key)

Tests if row exists.

void
offsetUnset($key)

Removes row from result set.

Details

at line 88
__construct(Context $context, IConventions $conventions, $tableName, IStorage $cacheStorage = null)

Creates filtered table representation.

Parameters

Context $context
IConventions $conventions
$tableName
IStorage $cacheStorage

at line 101
__destruct()

No description

at line 107
__clone()

No description

at line 116
string getName()

No description

Return Value

string

at line 126
string|array|null getPrimary($throw = true)

No description

Parameters

$throw

Return Value

string|array|null

at line 138
string|null getPrimarySequence()

No description

Return Value

string|null

at line 152
Selection setPrimarySequence($sequence)

No description

Parameters

$sequence

Return Value

Selection

at line 162
string getSql()

No description

Return Value

string

at line 173
array|false getPreviousAccessedColumns()

internal  
 

Loads cache of previous accessed columns and returns it.

Return Value

array|false

at line 190
SqlBuilder getSqlBuilder()

internal  
 

No description

Return Value

SqlBuilder

at line 204
ActiveRow|false get($key)

Returns row specified by primary key.

Parameters

$key

Return Value

ActiveRow|false

if there is no such row

at line 215
IRow|bool fetch()

No description

Return Value

IRow|bool

at line 229
mixed|false fetchField($column = null)

Fetches single field.

Parameters

$column

Return Value

mixed|false

at line 247
array fetchPairs($key = null, $value = null)

No description

Parameters

$key
$value

Return Value

array

at line 256
IRow[] fetchAll()

No description

Return Value

IRow[]

at line 265
array fetchAssoc($path)

No description

Parameters

$path

Return Value

array

at line 280
Selection select($columns, ...$params)

Adds select clause, more calls appends to the end.

Parameters

$columns
...$params

Return Value

Selection

at line 293
Selection wherePrimary($key)

Adds condition for primary key.

Parameters

$key

Return Value

Selection

at line 319
Selection where($condition, ...$params)

Adds where condition, more calls appends with AND.

Parameters

$condition
...$params

Return Value

Selection

at line 333
Selection joinWhere($tableChain, $condition, ...$params)

Adds ON condition when joining specified table, more calls appends with AND.

Parameters

$tableChain
$condition
...$params

Return Value

Selection

at line 345
protected void condition($condition, array $params, $tableChain = null)

Adds condition, more calls appends with AND.

Parameters

$condition
array $params
$tableChain

Return Value

void

at line 371
Selection whereOr(array $parameters)

Adds where condition using the OR operator between parameters.

More calls appends with AND.

Parameters

array $parameters

Return Value

Selection

Exceptions

InvalidArgumentException

at line 403
Selection order($columns, ...$params)

Adds order clause, more calls appends to the end.

Parameters

$columns
...$params

Return Value

Selection

at line 417
Selection limit($limit, $offset = null)

Sets limit clause, more calls rewrite old values.

Parameters

$limit
$offset

Return Value

Selection

at line 431
Selection page($page, $itemsPerPage, $numOfPages = null)

Sets offset using page number, more calls rewrite old values.

Parameters

$page
$itemsPerPage
$numOfPages

Return Value

Selection

at line 448
Selection group($columns, ...$params)

Sets group clause, more calls rewrite old value.

Parameters

$columns
...$params

Return Value

Selection

at line 461
Selection having($having, ...$params)

Sets having clause, more calls rewrite old value.

Parameters

$having
...$params

Return Value

Selection

at line 475
Selection alias($tableChain, $alias)

Aliases table. Example ':book:book_tag.tag', 'tg'

Parameters

$tableChain
$alias

Return Value

Selection

at line 491
int aggregation($function, $groupFunction = null)

Executes aggregation function.

Parameters

$function
$groupFunction

Return Value

int

at line 513
int count($column = null)

Counts number of rows.

Parameters

$column

Return Value

int

at line 528
int min($column)

Returns minimum value from a column.

Parameters

$column

Return Value

int

at line 539
int max($column)

Returns maximum value from a column.

Parameters

$column

Return Value

int

at line 550
int sum($column)

Returns sum of values in a column.

Parameters

$column

Return Value

int

at line 559
protected execute()

No description

at line 605
protected ActiveRow createRow(array $row)

No description

Parameters

array $row

Return Value

ActiveRow

at line 614
Selection createSelectionInstance($table = null)

No description

Parameters

$table

Return Value

Selection

at line 623
protected GroupedSelection createGroupedSelectionInstance($table, $column)

No description

Parameters

$table
$column

Return Value

GroupedSelection

at line 632
protected ResultSet query($query)

No description

Parameters

$query

Return Value

ResultSet

at line 638
protected emptyResultSet($clearCache = true, $deleteRererencedCache = true)

No description

Parameters

$clearCache
$deleteRererencedCache

at line 660
protected saveCacheState()

No description

at line 682
protected Selection getRefTable($refPath)

Returns Selection parent for caching.

Parameters

$refPath

Return Value

Selection

at line 691
protected loadRefCache()

Loads refCache references

at line 701
protected string getGeneralCacheKey()

Returns general cache key independent on query parameters or sql limit Used e.g. for previously accessed columns caching

Return Value

string

at line 723
protected string getSpecificCacheKey()

Returns object specific cache key dependent on query parameters Used e.g. for reference memory caching

Return Value

string

at line 739
bool accessColumn($key, $selectColumn = true)

internal  
 

No description

Parameters

$key
$selectColumn

Return Value

bool

if selection requeried for more columns.

at line 795
removeAccessColumn($key)

internal  
 

No description

Parameters

$key

at line 807
bool getDataRefreshed()

Returns if selection requeried for more columns.

Return Value

bool

at line 821
ActiveRow|int|bool insert($data)

Inserts row in a table.

Parameters

$data

Return Value

ActiveRow|int|bool

Returns IRow or number of affected rows for Selection or table without primary key

at line 902
int update($data)

Updates all rows in result set.

Joins in UPDATE are supported only in MySQL

Parameters

$data

Return Value

int

number of affected rows

at line 926
int delete()

Deletes all rows in result set.

Return Value

int

number of affected rows

at line 942
ActiveRow|null|false getReferencedTable(ActiveRow $row, $table, $column = null)

Returns referenced row.

Parameters

ActiveRow $row
$table
$column

Return Value

ActiveRow|null|false

null if the row does not exist, false if the relationship does not exist

at line 991
GroupedSelection|null getReferencingTable($table, $column, $active = null)

Returns referencing rows.

Parameters

$table
$column
$active

Return Value

GroupedSelection|null

at line 1018
rewind()

No description

at line 1027
ActiveRow|bool current()

No description

Return Value

ActiveRow|bool

at line 1040
string|int key()

No description

Return Value

string|int

row ID

at line 1046
next()

No description

at line 1054
valid()

No description

at line 1069
void offsetSet($key, $value)

Mimic row.

Parameters

$key
$value

Return Value

void

at line 1081
ActiveRow|null offsetGet($key)

Returns specified row.

Parameters

$key

Return Value

ActiveRow|null

if there is no such row

at line 1093
bool offsetExists($key)

Tests if row exists.

Parameters

$key

Return Value

bool

at line 1105
void offsetUnset($key)

Removes row from result set.

Parameters

$key

Return Value

void

Traits

SmartObject