class Selection implements IteratorAggregate, ArrayAccess, Countable

Represents filtered table result.

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

Properties

protected $explorer
protected $cache
protected $sqlBuilder
protected $name

table name

protected string|string[]|null $primary
protected $primarySequence

primary column sequence name, false for autodetection

protected T[]|null $rows
protected T[]|null $data
protected $dataRefreshed
protected $globalRefCache

cache array of Selection and GroupedSelection prototypes

protected $refCache
protected $generalCacheKey
protected $specificCacheKey
protected $aggregation

of [conditions => [key => ActiveRow]]; used by GroupedSelection

protected $accessedColumns
protected $previousAccessedColumns
protected $observeCache

should instance observe accessed columns caching

Methods

__construct(Explorer $explorer, string $tableName)

Creates filtered table representation.

__destruct()

No description

__clone()

No description

string
getName()

No description

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

Returns table primary key.

string|null
getPrimarySequence()

No description

setPrimarySequence(string $sequence)

No description

string
getSql()

No description

array|bool
getPreviousAccessedColumns()

Loads cache of previous accessed columns and returns it.

getSqlBuilder()

No description

ActiveRow|null
get(mixed $key)

Returns row specified by primary key.

ActiveRow|null
fetch()

Returns the next row or null if there are no more rows.

mixed
fetchField(string|null $column = null) deprecated

Fetches single field.

array
fetchPairs(string|int|Closure|null $keyOrCallback = null, string|int|null $value = null)

Returns all rows as associative array, where first argument specifies key column and second value column.

array
fetchAll()

Returns all rows.

array
fetchAssoc(string $path) deprecated

Returns all rows as associative tree.

select(string $columns, ...$params)

No description

wherePrimary(mixed $key)

No description

where(string|array $condition, ...$params)

No description

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

No description

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

Adds condition, more calls appends with AND.

whereOr(array $parameters)

No description

order(string $columns, ...$params)

No description

limit(int|null $limit, int|null $offset = null)

No description

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

No description

group(string $columns, ...$params)

No description

having(string $having, ...$params)

No description

alias(string $tableChain, string $alias)

No description

mixed
aggregation(string $function, string|null $groupFunction = null)

Executes aggregation function.

int
count(string|null $column = null)

Counts number of rows. If column is not provided returns count of result rows, otherwise runs new sql counting query.

mixed
min(string $column)

Returns minimum value from a column.

mixed
max(string $column)

Returns maximum value from a column.

mixed
sum(string $column)

Returns sum of values in a column.

void
execute()

No description

createSelectionInstance(string|null $table = null) deprecated

No description

query(string $query)

No description

void
emptyResultSet(bool $clearCache = true, bool $deleteReferencedCache = true)

No description

void
saveCacheState()

No description

getRefTable($refPath)

Returns Selection parent for caching.

void
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(string|null $key, bool $selectColumn = true)

No description

void
removeAccessColumn(string $key)

No description

bool
getDataRefreshed()

Returns if selection requeried for more columns.

ActiveRow|array|int|bool
insert(iterable $data)

Inserts row in a table. Returns ActiveRow or number of affected rows for Selection or table without primary key.

int
update(iterable $data)

Updates all rows in result set.

int
delete()

Deletes all rows in result set.

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

Returns referenced row.

GroupedSelection|null
getReferencingTable(string $table, string|null $column = null, int|string|null $active = null)

Returns referencing rows.

getIterator()

No description

void
offsetSet(string $key, ActiveRow $value)

Mimic row.

ActiveRow|null
offsetGet(string $key)

Returns specified row.

bool
offsetExists(string $key)

Tests if row exists.

void
offsetUnset(string $key)

Removes row from result set.

Details

at line 65
__construct(Explorer $explorer, string $tableName)

Creates filtered table representation.

Parameters

Explorer $explorer
string $tableName

at line 78
__destruct()

No description

at line 84
__clone()

No description

at line 90
string getName()

No description

Return Value

string

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

Returns table primary key.

Parameters

bool $throw

Return Value

string|array|null

at line 110
string|null getPrimarySequence()

No description

Return Value

string|null

at line 121
Selection setPrimarySequence(string $sequence)

No description

Parameters

string $sequence

Return Value

Selection

at line 128
string getSql()

No description

Return Value

string

at line 138
array|bool getPreviousAccessedColumns()

internal  
 

Loads cache of previous accessed columns and returns it.

Return Value

array|bool

at line 152
SqlBuilder getSqlBuilder()

internal  
 

No description

Return Value

SqlBuilder

at line 165
ActiveRow|null get(mixed $key)

Returns row specified by primary key.

Parameters

mixed $key

Return Value

ActiveRow|null

at line 176
ActiveRow|null fetch()

Returns the next row or null if there are no more rows.

Return Value

ActiveRow|null

at line 189
mixed fetchField(string|null $column = null) deprecated

deprecated

Fetches single field.

Parameters

string|null $column

Return Value

mixed

at line 210
array fetchPairs(string|int|Closure|null $keyOrCallback = null, string|int|null $value = null)

Returns all rows as associative array, where first argument specifies key column and second value column.

For duplicate keys, the last value is used. When using null as key, array is indexed from zero. Alternatively accepts callback returning value or key-value pairs.

Parameters

string|int|Closure|null $keyOrCallback
string|int|null $value

Return Value

array

at line 220
array fetchAll()

Returns all rows.

Return Value

array

at line 230
array fetchAssoc(string $path) deprecated

deprecated

Returns all rows as associative tree.

Parameters

string $path

Return Value

array

at line 245
Selection select(string $columns, ...$params)

No description

Parameters

string $columns
...$params

Return Value

Selection

at line 257
Selection wherePrimary(mixed $key)

No description

Parameters

mixed $key

Return Value

Selection

at line 282
Selection where(string|array $condition, ...$params)

No description

Parameters

string|array $condition
...$params

Return Value

Selection

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

No description

Parameters

string $tableChain
string $condition
...$params

Return Value

Selection

at line 306
protected void condition(string|array $condition, array $params, string|null $tableChain = null)

Adds condition, more calls appends with AND.

Parameters

string|array $condition

possibly containing ?

array $params
string|null $tableChain

Return Value

void

at line 332
Selection whereOr(array $parameters)

No description

Parameters

array $parameters

Return Value

Selection

at line 367
Selection order(string $columns, ...$params)

No description

Parameters

string $columns
...$params

Return Value

Selection

at line 379
Selection limit(int|null $limit, int|null $offset = null)

No description

Parameters

int|null $limit
int|null $offset

Return Value

Selection

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

No description

Parameters

int $page
int $itemsPerPage
$numOfPages

Return Value

Selection

at line 409
Selection group(string $columns, ...$params)

No description

Parameters

string $columns
...$params

Return Value

Selection

at line 421
Selection having(string $having, ...$params)

No description

Parameters

string $having
...$params

Return Value

Selection

at line 433
Selection alias(string $tableChain, string $alias)

No description

Parameters

string $tableChain
string $alias

Return Value

Selection

at line 447
mixed aggregation(string $function, string|null $groupFunction = null)

Executes aggregation function.

Parameters

string $function

select call in "FUNCTION(column)" format

string|null $groupFunction

Return Value

mixed

at line 468
int count(string|null $column = null)

Counts number of rows. If column is not provided returns count of result rows, otherwise runs new sql counting query.

Parameters

string|null $column

Return Value

int

at line 482
mixed min(string $column)

Returns minimum value from a column.

Parameters

string $column

Return Value

mixed

at line 491
mixed max(string $column)

Returns maximum value from a column.

Parameters

string $column

Return Value

mixed

at line 500
mixed sum(string $column)

Returns sum of values in a column.

Parameters

string $column

Return Value

mixed

at line 509
protected void execute()

No description

Return Value

void

at line 554
Selection createSelectionInstance(string|null $table = null) deprecated

deprecated

No description

Parameters

string|null $table

Return Value

Selection

at line 561
protected Result query(string $query)

No description

Parameters

string $query

Return Value

Result

at line 567
protected void emptyResultSet(bool $clearCache = true, bool $deleteReferencedCache = true)

No description

Parameters

bool $clearCache
bool $deleteReferencedCache

Return Value

void

at line 589
protected void saveCacheState()

No description

Return Value

void

at line 617
protected Selection getRefTable($refPath)

Returns Selection parent for caching.

Parameters

$refPath

Return Value

Selection

at line 626
protected void loadRefCache()

Loads refCache references

Return Value

void

at line 635
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 658
protected string getSpecificCacheKey()

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

Return Value

string

at line 673
bool accessColumn(string|null $key, bool $selectColumn = true)

internal  
 

No description

Parameters

string|null $key
bool $selectColumn

Return Value

bool

if selection requeried for more columns.

at line 739
void removeAccessColumn(string $key)

internal  
 

No description

Parameters

string $key

Return Value

void

at line 750
bool getDataRefreshed()

Returns if selection requeried for more columns.

Return Value

bool

at line 764
ActiveRow|array|int|bool insert(iterable $data)

Inserts row in a table. Returns ActiveRow or number of affected rows for Selection or table without primary key.

Parameters

iterable $data

Return Value

ActiveRow|array|int|bool

at line 845
int update(iterable $data)

Updates all rows in result set.

Joins in UPDATE are supported only in MySQL

Parameters

iterable $data

Return Value

int

number of affected rows

at line 866
int delete()

Deletes all rows in result set.

Return Value

int

number of affected rows

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

Returns referenced row.

Parameters

ActiveRow $row
string|null $table
string|null $column

Return Value

ActiveRow|false|null

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

at line 926
GroupedSelection|null getReferencingTable(string $table, string|null $column = null, int|string|null $active = null)

Returns referencing rows.

Parameters

string $table
string|null $column
int|string|null $active

Return Value

GroupedSelection|null

at line 960
Generator getIterator()

No description

Return Value

Generator

at line 979
void offsetSet(string $key, ActiveRow $value)

Mimic row.

Parameters

string $key
ActiveRow $value

Return Value

void

at line 991
ActiveRow|null offsetGet(string $key)

Returns specified row.

Parameters

string $key

Return Value

ActiveRow|null

at line 1002
bool offsetExists(string $key)

Tests if row exists.

Parameters

string $key

Return Value

bool

at line 1013
void offsetUnset(string $key)

Removes row from result set.

Parameters

string $key

Return Value

void