MMOframework
Pourquoi l'IA Playground Bibliothèques Développeurs Agence
FR EN
Créer un projet en direct
Index

CollectionQuery

MMO\editor\cms · 1 symbole · générée le 30 Nov 2026

class

CollectionQuery

CollectionQuery.php:34

A section's field of the format query: what a section shows from a collection of the application (its articles, its projects), chosen in the page editor -- filters, an order, how many to skip and how many to show -- rather than kept in the page. The schema says which collection, and what may be chosen; nothing else reaches the repository.

class MMO\editor\cms\CollectionQuery
Espace de noms
MMO\editor\cms
The field's schema: - `collection` the collection's name, `repository` its repository among [`Pages`](https://mmoframework.fr/documentation/mmo.editor/php/cms/Pages.md#pages)'s (`main` by default); - `filters` what an editor may filter on, field => `{label, type: string|boolean, enum?, options?}`: a value chosen keeps the entities whose field equals it (a list: one of them), a boolean `true` or `false` only. `options` reads the choices from a collection (`{repository, collection, value, label, where}`: the categories of the articles), as `enum` and `enumLabels` ([`ResolveFilter`](https://mmoframework.fr/documentation/mmo.editor/php/cms/CollectionQuery.md#collectionquery-resolvefilter)); - `sorts` what an editor may order by, field => label; `sort` in the data is one of them, `-` first for descending; - `where` what every query keeps whatever was chosen (`{"status": "published", "date": {"$lte": "{today}"}}`): mmo.core's filter, its `{today}` and `{now}` replaced by the day's date (`Y-m-d`) and the time (ISO 8601); - `item` the schema of an entity's fields, for the template to print them ([`SectionFields`](https://mmoframework.fr/documentation/mmo.editor/php/cms/SectionFields.md#sectionfields): `html`, `image`...); - `maxLimit` the most a section may show at once, 100 by default. Its data: `{filters: {field: value}, sort: "-date", offset: 0, limit: 6}`. Any other field of a section or a block may take its choices from a collection the same way: a field with `options` (`{repository, collection, value, label, where, empty}`: the project an article names) is offered as a list of them -- `empty`, the label of a first choice, `''` (none) -- [`Resolve`](https://mmoframework.fr/documentation/mmo.editor/php/cms/CollectionQuery.md#collectionquery-resolve).
$query = new CollectionQuery($field, ['filters' => ['category' => 'Chantier'], 'sort' => '-date', 'limit' => 3]); ['items' => $articles, 'total' => $total] = $query->run();

Index

MAX_LIMITthe most a section shows at once, unless its field says otherwise (maxLimit)
data readonly
field readonly
Clean($field, $data) staticWhat a section may hold for a field: the filters it declares and of their type, an order it declares, an offset and a limit in their bounds -- the rest dropped (SectionType::clean).
Collection($field) static
filter()
Resolve($schema) static
ResolveFilter($filter) staticA filter whose choices are a collection's (options: {repository, collection, value, label, where}), with its enum (the values of value) and enumLabels (those of label), read now: what t…
run($skip, $limit)
sort()
__construct($field, $data)

Constantes1

MAX_LIMIT

the most a section shows at once, unless its field says otherwise (maxLimit)

const MAX_LIMIT = 100

Propriétés2

data

readonly
readonly array $data
Type
array

field

readonly
readonly array $field
Type
array

Méthodes8

Clean($field, $data)

staticCollectionQuery.php:55

What a section may hold for a field: the filters it declares and of their type, an order it declares, an offset and a limit in their bounds -- the rest dropped (SectionType::clean).

static function Clean(array $field, mixed $data): array
$fieldarray
$datamixed
retournearrayarray<string, mixed>, sort: string, offset: int, limit: int}

filter()

CollectionQuery.php:133
function filter(): array
retournearraymixed> mmo.core's filter of the query: where, then what was chosen of the other fields

Resolve($schema)

staticCollectionQuery.php:118
static function Resolve(array $schema): array
$schemaarray
retournearraymixed> $schema, the filters of its queries resolved (ResolveFilter), and its fields choosing in a collection (options): what the editor gets

ResolveFilter($filter)

staticCollectionQuery.php:89

A filter whose choices are a collection's (options: {repository, collection, value, label, where}), with its enum (the values of value) and enumLabels (those of label), read now: what the editor offers, and what

static function ResolveFilter(array $filter): array
Voir
Clean keeps. A collection it cannot read gives no choice. Any other filter, as it is.
$filterarray
retournearraymixed>
CollectionQuery::ResolveFilter(['options' => ['repository' => 'content', 'collection' => 'categories', 'value' => 'slug', 'label' => 'name']]); // [..., 'enum' => ['chantier', 'engagement'], 'enumLabels' => ['Chantier', 'Engagement']]

run($skip, $limit)

CollectionQuery.php:161
function run(int $skip = 0, ?int $limit = null): array
$skip = 0intmore to skip, after the field's own offset: a « Load more » asking for the next ones
$limit = nullnull | inthow many, the field's limit by default
retournearraylist<array<string, mixed>>, total: int, offset: int, limit: int, more: bool} the entities (as arrays), how many the filter keeps in all past the field's offset, and whether some come after these
lèvefor a collection the repository does not have

sort()

CollectionQuery.php:149
function sort(): array
retournearraybool> the order, as mmo.core's Query takes it: field => true ascending, false descending