Oihana PHP Arango

CountByDimensionTrait

Aggregates a model's documents by one facet dimension into a compact `{ total, counts }` payload — the controller counterpart of {@see \oihana\arango\models\traits\documents\DocumentsFacetCountsTrait::facetCount()}.

It answers the recurring "how many per <dimension>, in one round-trip?" question (a favorites-by-type badge, a status breakdown, a per-category tally) without a query per value: a single COLLECT ... WITH COUNT produces the whole map. The dimension must be a declared facet (Arango::FACETS) of the passed model.

The helper takes the model and the base options explicitly, so a caller stays in control of the counted set: pass an already-scoped Arango::CONDITIONS / Arango::BINDS (e.g. _from == <current user>) and the aggregation inherits it. It performs no access control of its own — it counts exactly the set it is handed — so any permission masking belongs upstream, in the conditions.

It returns the payload rather than an HTTP response, so it is reusable from a controller (wrap it in success()) or a command alike.

Tags
since
1.0.0
author

Marc Alcaraz

Table of Contents

Constants

COUNTS  : string = 'counts'
The payload key holding the `value => count` map.

Methods

countByDimension()  : array{total: int, counts: array}
Aggregates a model's documents by one facet dimension.

Constants

Methods

countByDimension()

Aggregates a model's documents by one facet dimension.

protected countByDimension(Documents $model, string $dimension[, array<string|int, mixed> $init = [] ]) : array{total: int, counts: array}

total is the sum of the per-value counts — exact for a scalar facet (each document lands in one bucket); for a multi-valued (array-membership) facet a document contributes to several buckets, so the sum over-counts.

Parameters
$model : Documents

The model to aggregate (any Documents / Edges).

$dimension : string

The facet key to count (declared in Arango::FACETS).

$init : array<string|int, mixed> = []

The filtered-set options (conditions, binds, filter, search, facets, ...).

Tags
throws
ArangoException
BindException
ConstantException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
UnsupportedOperationException
ValidationException
Return values
array{total: int, counts: array}

The { total, counts } payload.

On this page

Search results