Selection
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
No description
No description
No description
Returns table primary key.
No description
No description
No description
Loads cache of previous accessed columns and returns it.
No description
Returns row specified by primary key.
Returns the next row or null if there are no more rows.
Returns all rows as associative array, where first argument specifies key column and second value column.
Returns all rows.
No description
Adds condition, more calls appends with AND.
Executes aggregation function.
Counts number of rows. If column is not provided returns count of result rows, otherwise runs new sql counting query.
Returns minimum value from a column.
Returns maximum value from a column.
Returns sum of values in a column.
No description
No description
No description
Returns Selection parent for caching.
Loads refCache references
Returns general cache key independent on query parameters or sql limit Used e.g. for previously accessed columns caching
Returns object specific cache key dependent on query parameters Used e.g. for reference memory caching
No description
No description
Returns if selection requeried for more columns.
Inserts row in a table. Returns ActiveRow or number of affected rows for Selection or table without primary key.
Updates all rows in result set.
Deletes all rows in result set.
Returns referenced row.
Returns referencing rows.
No description
Returns specified row.
Tests if row exists.
Removes row from result set.
Details
at line 66
__construct(Explorer $explorer, string $tableName)
Creates filtered table representation.
at line 79
__destruct()
No description
at line 85
__clone()
No description
at line 91
string
getName()
No description
at line 101
string|array|null
getPrimary(bool $throw = true)
Returns table primary key.
at line 111
string|null
getPrimarySequence()
No description
at line 122
Selection
setPrimarySequence(string $sequence)
No description
at line 129
string
getSql()
No description
at line 139
array|bool
getPreviousAccessedColumns()
internal |
Loads cache of previous accessed columns and returns it.
at line 153
SqlBuilder
getSqlBuilder()
internal |
No description
at line 166
ActiveRow|null
get(mixed $key)
Returns row specified by primary key.
at line 177
ActiveRow|null
fetch()
Returns the next row or null if there are no more rows.
at line 190
mixed
fetchField(string|null $column = null)
deprecated
deprecated
Fetches single field.
at line 211
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.
at line 221
array
fetchAll()
Returns all rows.
at line 231
array
fetchAssoc(string $path)
deprecated
deprecated
Returns all rows as associative tree.
at line 246
Selection
select(string $columns, ...$params)
No description
at line 258
Selection
wherePrimary(mixed $key)
No description
at line 283
Selection
where(string|array $condition, ...$params)
No description
at line 296
Selection
joinWhere(string $tableChain, string $condition, ...$params)
No description
at line 307
protected void
condition(string|array $condition, array $params, string|null $tableChain = null)
Adds condition, more calls appends with AND.
at line 333
Selection
whereOr(array $parameters)
No description
at line 368
Selection
order(string $columns, ...$params)
No description
at line 380
Selection
limit(int|null $limit, int|null $offset = null)
No description
at line 392
Selection
page(int $page, int $itemsPerPage, $numOfPages = null)
No description
at line 410
Selection
group(string $columns, ...$params)
No description
at line 422
Selection
having(string $having, ...$params)
No description
at line 434
Selection
alias(string $tableChain, string $alias)
No description
at line 448
mixed
aggregation(string $function, string|null $groupFunction = null)
Executes aggregation function.
at line 469
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.
at line 483
mixed
min(string $column)
Returns minimum value from a column.
at line 492
mixed
max(string $column)
Returns maximum value from a column.
at line 501
mixed
sum(string $column)
Returns sum of values in a column.
at line 510
protected void
execute()
No description
at line 555
Selection
createSelectionInstance(string|null $table = null)
deprecated
deprecated
No description
at line 562
protected Result
query(string $query)
No description
at line 568
protected void
emptyResultSet(bool $clearCache = true, bool $deleteReferencedCache = true)
No description
at line 590
protected void
saveCacheState()
No description
at line 618
protected Selection
getRefTable($refPath)
Returns Selection parent for caching.
at line 627
protected void
loadRefCache()
Loads refCache references
at line 636
protected string
getGeneralCacheKey()
Returns general cache key independent on query parameters or sql limit Used e.g. for previously accessed columns caching
at line 659
protected string
getSpecificCacheKey()
Returns object specific cache key dependent on query parameters Used e.g. for reference memory caching
at line 674
bool
accessColumn(string|null $key, bool $selectColumn = true)
internal |
No description
at line 740
void
removeAccessColumn(string $key)
internal |
No description
at line 751
bool
getDataRefreshed()
Returns if selection requeried for more columns.
at line 765
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.
at line 846
int
update(iterable $data)
Updates all rows in result set.
Joins in UPDATE are supported only in MySQL
at line 867
int
delete()
Deletes all rows in result set.
at line 880
ActiveRow|false|null
getReferencedTable(ActiveRow $row, string|null $table, string|null $column = null)
Returns referenced row.
at line 927
GroupedSelection|null
getReferencingTable(string $table, string|null $column = null, int|string|null $active = null)
Returns referencing rows.
at line 961
Generator
getIterator()
No description
at line 980
void
offsetSet(string $key, ActiveRow $value)
Mimic row.
at line 992
ActiveRow|null
offsetGet(string $key)
Returns specified row.
at line 1003
bool
offsetExists(string $key)
Tests if row exists.
at line 1014
void
offsetUnset(string $key)
Removes row from result set.