class Selection extends Object 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 array $generalCacheTraceKey
protected string $specificCacheKey
protected array $aggregation
protected array $accessedColumns
protected array $previousAccessedColumns
protected bool $observeCache
protected array $keys
string read-only $sql

Methods

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

Creates filtered table representation.

__destruct()

No description

__clone()

No description

getConnection() deprecated

No description

getDatabaseReflection() deprecated

No description

string
getName()

No description

string|array|null
getPrimary($need = TRUE)

No description

string
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

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)

Adds select clause, more calls appends to the end.

wherePrimary($key)

Adds condition for primary key.

where($condition, $parameters = array())

Adds where condition, more calls appends with AND.

order($columns)

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)

Sets group clause, more calls rewrite old value.

having($having)

Sets having clause, more calls rewrite old value.

string
aggregation($function)

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($saveCache = 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.

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

current()

No description

string
key()

No description

next()

No description

valid()

No description

null
offsetSet($key, $value)

Mimic row.

offsetGet($key)

Returns specified row.

bool
offsetExists($key)

Tests if row exists.

null
offsetUnset($key)

Removes row from result set.

Details

at line 91
__construct(Context $context, IConventions $conventions, $tableName, IStorage $cacheStorage = NULL)

Creates filtered table representation.

Parameters

Context $context
IConventions $conventions
$tableName
IStorage $cacheStorage

at line 104
__destruct()

No description

at line 110
__clone()

No description

at line 117
getConnection() deprecated

deprecated

No description

at line 125
getDatabaseReflection() deprecated

deprecated

No description

at line 135
string getName()

No description

Return Value

string

at line 145
string|array|null getPrimary($need = TRUE)

No description

Parameters

$need

Return Value

string|array|null

at line 157
string getPrimarySequence()

No description

Return Value

string

at line 171
Selection setPrimarySequence($sequence)

No description

Parameters

$sequence

Return Value

Selection

at line 181
string getSql()

No description

Return Value

string

at line 192
array|false getPreviousAccessedColumns()

internal  
 

Loads cache of previous accessed columns and returns it.

Return Value

array|false

at line 209
SqlBuilder getSqlBuilder()

internal  
 

No description

Return Value

SqlBuilder

at line 223
IRow get($key)

Returns row specified by primary key.

Parameters

$key

Return Value

IRow

or FALSE if there is no such row

at line 233
IRow|bool fetch()

No description

Return Value

IRow|bool

at line 247
mixed|false fetchField($column = NULL)

Fetches single field.

Parameters

$column

Return Value

mixed|false

at line 265
array fetchPairs($key = NULL, $value = NULL)

No description

Parameters

$key
$value

Return Value

array

at line 274
IRow[] fetchAll()

No description

Return Value

IRow[]

at line 283
array fetchAssoc($path)

No description

Parameters

$path

Return Value

array

at line 298
Selection select($columns)

Adds select clause, more calls appends to the end.

Parameters

$columns

Return Value

Selection

at line 311
Selection wherePrimary($key)

Adds condition for primary key.

Parameters

$key

Return Value

Selection

at line 338
Selection where($condition, $parameters = array())

Adds where condition, more calls appends with AND.

Parameters

$condition
$parameters

Return Value

Selection

at line 362
Selection order($columns)

Adds order clause, more calls appends to the end.

Parameters

$columns

Return Value

Selection

at line 376
Selection limit($limit, $offset = NULL)

Sets limit clause, more calls rewrite old values.

Parameters

$limit
$offset

Return Value

Selection

at line 390
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 404
Selection group($columns)

Sets group clause, more calls rewrite old value.

Parameters

$columns

Return Value

Selection

at line 417
Selection having($having)

Sets having clause, more calls rewrite old value.

Parameters

$having

Return Value

Selection

at line 433
string aggregation($function)

Executes aggregation function.

Parameters

$function

Return Value

string

at line 449
int count($column = NULL)

Counts number of rows.

Parameters

$column

Return Value

int

at line 464
int min($column)

Returns minimum value from a column.

Parameters

$column

Return Value

int

at line 475
int max($column)

Returns maximum value from a column.

Parameters

$column

Return Value

int

at line 486
int sum($column)

Returns sum of values in a column.

Parameters

$column

Return Value

int

at line 495
protected execute()

No description

at line 538
protected createRow(array $row)

No description

Parameters

array $row

at line 544
createSelectionInstance($table = NULL)

No description

Parameters

$table

at line 550
protected createGroupedSelectionInstance($table, $column)

No description

Parameters

$table
$column

at line 556
protected query($query)

No description

Parameters

$query

at line 562
protected emptyResultSet($saveCache = TRUE, $deleteRererencedCache = TRUE)

No description

Parameters

$saveCache
$deleteRererencedCache

at line 583
protected saveCacheState()

No description

at line 605
protected Selection getRefTable($refPath)

Returns Selection parent for caching.

Parameters

$refPath

Return Value

Selection

at line 614
protected loadRefCache()

Loads refCache references

at line 624
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 649
protected string getSpecificCacheKey()

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

Return Value

string

at line 665
bool accessColumn($key, $selectColumn = TRUE)

internal  
 

No description

Parameters

$key
$selectColumn

Return Value

bool

if selection requeried for more columns.

at line 721
removeAccessColumn($key)

internal  
 

No description

Parameters

$key

at line 733
bool getDataRefreshed()

Returns if selection requeried for more columns.

Return Value

bool

at line 747
IRow|int|bool insert($data)

Inserts row in a table.

Parameters

$data

Return Value

IRow|int|bool

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

at line 816
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 840
int delete()

Deletes all rows in result set.

Return Value

int

number of affected rows

at line 856
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 905
GroupedSelection getReferencingTable($table, $column, $active = NULL)

Returns referencing rows.

Parameters

$table
$column
$active

Return Value

GroupedSelection

at line 932
rewind()

No description

at line 941
IRow current()

No description

Return Value

IRow

at line 954
string key()

No description

Return Value

string

row ID

at line 960
next()

No description

at line 966
valid()

No description

at line 981
null offsetSet($key, $value)

Mimic row.

Parameters

$key
$value

Return Value

null

at line 993
IRow offsetGet($key)

Returns specified row.

Parameters

$key

Return Value

IRow

or NULL if there is no such row

at line 1005
bool offsetExists($key)

Tests if row exists.

Parameters

$key

Return Value

bool

at line 1017
null offsetUnset($key)

Removes row from result set.

Parameters

$key

Return Value

null