class GroupedSelection extends Selection

Representation of filtered table grouped by some column.

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

Properties

protected $refTable

referenced table

protected $refCacheCurrent

current assigned referencing array

protected $column

grouping column name

protected $active

primary key

Methods

__construct(Explorer $explorer, Conventions $conventions, string $tableName, string $column, Selection $refTable, Storage|null $cacheStorage = null)

Creates filtered and grouped table representation.

setActive(int|string $active)

Sets active group.

select(string|string[] $columns, ...$params)

Adds select clause, more calls appends to the end.

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

Adds order clause, more calls appends to the end.

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

Executes aggregation function.

int
count(string|null $column = null)

Counts number of rows.

void
execute()

No description

getRefTable($refPath)

Returns Selection parent for caching.

void
loadRefCache()

Loads refCache references

void
emptyResultSet(bool $saveCache = true, bool $deleteRererencedCache = true)

No description

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

Inserts row in a table.

int
update(iterable $data)

Updates all rows in result set.

int
delete()

Deletes all rows in result set.

Details

at line 39
__construct(Explorer $explorer, Conventions $conventions, string $tableName, string $column, Selection $refTable, Storage|null $cacheStorage = null)

Creates filtered and grouped table representation.

Parameters

Explorer $explorer
Conventions $conventions
string $tableName
string $column
Selection $refTable
Storage|null $cacheStorage

at line 58
GroupedSelection setActive(int|string $active)

internal  
 

Sets active group.

Parameters

int|string $active

primary key of grouped rows

Return Value

GroupedSelection

at line 65
Selection select(string|string[] $columns, ...$params)

Adds select clause, more calls appends to the end.

Parameters

string|string[] $columns

for example "column, MD5(column) AS column_md5"

...$params

Return Value

Selection

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

Adds order clause, more calls appends to the end.

Parameters

string $columns

for example 'column1, column2 DESC'

...$params

Return Value

Selection

at line 89
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 126
int count(string|null $column = null)

Counts number of rows.

Parameters

string|null $column

if it is not provided returns count of result rows, otherwise runs new sql counting query

Return Value

int

at line 136
protected void execute()

No description

Return Value

void

at line 196
protected Selection getRefTable($refPath)

Returns Selection parent for caching.

Parameters

$refPath

Return Value

Selection

at line 209
protected void loadRefCache()

Loads refCache references

Return Value

void

at line 225
protected void emptyResultSet(bool $saveCache = true, bool $deleteRererencedCache = true)

No description

Parameters

bool $saveCache
bool $deleteRererencedCache

Return Value

void

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

Inserts row in a table.

Parameters

iterable $data

[$column => $value]|\Traversable|Selection for INSERT ... SELECT

Return Value

ActiveRow|array|int|bool

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

at line 252
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 265
int delete()

Deletes all rows in result set.

Return Value

int

number of affected rows