query_builder implements query_builder_interface
Immutable Query Object.
This object is a pure data-structure describing the query the developer wants. It holds NO SQL and does not know Moodle's DB API.
It is final to preserve immutability integrity.
Table of Contents
Interfaces
- query_builder_interface
Properties
- $as_std_class : bool
- $domain_class : item_interface>
- $excluded_scopes : array<string|int, string>
- $joins : array<int, array{table: string, alias: string, on: string, type: string}>
- $metadata_keys : array<string|int, string>
- $page : int|null
- $per_page : int|null
- $relations : array<string|int, string>
- $select : null|array<string|int, string>
- $sort : null|string
- $where : array<int, operator, value: mixed, value2: null|mixed}>
- $where_meta : array<int, operator, value: mixed, value2: null|mixed}>
Methods
- as_std_class() : self
- Toggle returning stdClass instead of domain entities.
- domain() : self
- Set the target domain class for hydration.
- get_domain_class() : item_interface>
- Get the target domain class for hydration.
- get_excluded_scopes() : array<string|int, string>
- Get excluded global scopes.
- get_joins() : array<int, array<string, mixed>>
- Get JOIN definitions.
- get_meta_wheres() : array<int, operator, value: mixed, value2: null|mixed}>
- Get metadata WHERE filters.
- get_metadata_keys() : array<string|int, string>
- Get metadata keys requested for eager loading.
- get_page() : int|null
- Get current page for pagination (0-based).
- get_per_page() : int|null
- Get per-page limit for pagination.
- get_relations() : array<string|int, string>
- Get requested relations for eager loading.
- get_select() : null|array<string|int, string>
- Get explicit select columns if defined.
- get_sort() : string|null
- Get ORDER BY clause string.
- get_wheres() : array<int, array<string, mixed>>
- Get base WHERE filters.
- join() : self
- Add a generic JOIN clause.
- join_course() : self
- Join against Moodle course table.
- join_item() : self
- Join against the items table with defaults for parent->id.
- join_user() : self
- Join against Moodle user table.
- limit() : self
- Limit the number of returned rows (no pagination metadata).
- make() : self
- Create a new empty immutable Query.
- order_by() : self
- Define ORDER BY clause (raw string, e.g., "fullname ASC").
- paginate() : self
- Enable pagination with page and per-page values.
- select() : self
- Define explicit SELECT columns.
- wants_std_class() : bool
- Check if results should be hydrated as stdClass.
- where() : self
- Add a base WHERE condition.
- where_between() : self
- Add a BETWEEN constraint for a field.
- where_in() : self
- Add an IN filter for a field.
- where_meta() : self
- Add a WHERE condition targeting metadata table.
- where_meta_in() : self
- Add an IN filter for metadata values.
- where_not_in() : self
- Add a NOT IN filter for a field.
- with_metadata() : self
- Request eager-loading of specific metadata keys.
- with_relation() : self
- Request eager-loading of a registered relation.
- without_global_scope() : self
- Disable a specific global scope.
- without_global_scopes() : self
- Disable all global scopes.
- copy() : self
- Clone the current object and apply modifications.
Properties
$as_std_class
private
bool
$as_std_class
= false
$domain_class
private
item_interface>
$domain_class
= \local_middag\framework\domain\item\item_interface::class
$excluded_scopes
private
array<string|int, string>
$excluded_scopes
= []
List of global scopes to exclude
$joins
private
array<int, array{table: string, alias: string, on: string, type: string}>
$joins
= []
$metadata_keys
private
array<string|int, string>
$metadata_keys
= []
List of metadata keys to eager load
$page
private
int|null
$page
= null
$per_page
private
int|null
$per_page
= null
$relations
private
array<string|int, string>
$relations
= []
List of relation names to eager load
$select
private
null|array<string|int, string>
$select
= null
Specific columns to select (null = all)
$sort
private
null|string
$sort
= null
ORDER BY clause
$where
private
array<int, operator, value: mixed, value2: null|mixed}>
$where
= []
$where_meta
private
array<int, operator, value: mixed, value2: null|mixed}>
$where_meta
= []
Methods
as_std_class()
Toggle returning stdClass instead of domain entities.
public
as_std_class([bool $enabled = true ]) : self
Parameters
- $enabled : bool = true
Return values
selfdomain()
Set the target domain class for hydration.
public
domain(item_interface> $class) : self
Parameters
- $class : item_interface>
Return values
selfget_domain_class()
Get the target domain class for hydration.
public
get_domain_class() : item_interface>
Return values
item_interface>get_excluded_scopes()
Get excluded global scopes.
public
get_excluded_scopes() : array<string|int, string>
Return values
array<string|int, string>get_joins()
Get JOIN definitions.
public
get_joins() : array<int, array<string, mixed>>
Return values
array<int, array<string, mixed>>get_meta_wheres()
Get metadata WHERE filters.
public
get_meta_wheres() : array<int, operator, value: mixed, value2: null|mixed}>
Return values
array<int, operator, value: mixed, value2: null|mixed}>get_metadata_keys()
Get metadata keys requested for eager loading.
public
get_metadata_keys() : array<string|int, string>
Return values
array<string|int, string>get_page()
Get current page for pagination (0-based).
public
get_page() : int|null
Return values
int|nullget_per_page()
Get per-page limit for pagination.
public
get_per_page() : int|null
Return values
int|nullget_relations()
Get requested relations for eager loading.
public
get_relations() : array<string|int, string>
Return values
array<string|int, string>get_select()
Get explicit select columns if defined.
public
get_select() : null|array<string|int, string>
Return values
null|array<string|int, string>get_sort()
Get ORDER BY clause string.
public
get_sort() : string|null
Return values
string|nullget_wheres()
Get base WHERE filters.
public
get_wheres() : array<int, array<string, mixed>>
Return values
array<int, array<string, mixed>>join()
Add a generic JOIN clause.
public
join(string $table, string $alias, string $on[, string $type = 'INNER' ]) : self
Parameters
- $table : string
- $alias : string
- $on : string
- $type : string = 'INNER'
Return values
selfjoin_course()
Join against Moodle course table.
public
join_course([string $alias = 'c' ][, string $local_field = 'courseid' ][, string $foreign_field = 'id' ]) : self
Parameters
- $alias : string = 'c'
- $local_field : string = 'courseid'
- $foreign_field : string = 'id'
Return values
selfjoin_item()
Join against the items table with defaults for parent->id.
public
join_item(string $alias[, string $local_field = 'parent' ][, string $foreign_field = 'id' ]) : self
Parameters
- $alias : string
- $local_field : string = 'parent'
- $foreign_field : string = 'id'
Return values
selfjoin_user()
Join against Moodle user table.
public
join_user([string $alias = 'u' ][, string $local_field = 'userid' ][, string $foreign_field = 'id' ]) : self
Parameters
- $alias : string = 'u'
- $local_field : string = 'userid'
- $foreign_field : string = 'id'
Return values
selflimit()
Limit the number of returned rows (no pagination metadata).
public
limit(int $limit) : self
Parameters
- $limit : int
Return values
selfmake()
Create a new empty immutable Query.
public
static make() : self
Return values
selforder_by()
Define ORDER BY clause (raw string, e.g., "fullname ASC").
public
order_by(string $sort) : self
Parameters
- $sort : string
Return values
selfpaginate()
Enable pagination with page and per-page values.
public
paginate(int $page, int $per_page) : self
Parameters
- $page : int
- $per_page : int
Return values
selfselect()
Define explicit SELECT columns.
public
select(array<string|int, mixed> $fields) : self
Parameters
- $fields : array<string|int, mixed>
Return values
selfwants_std_class()
Check if results should be hydrated as stdClass.
public
wants_std_class() : bool
Return values
boolwhere()
Add a base WHERE condition.
public
where(string $field, operator $operator[, mixed $value = null ][, mixed $value2 = null ]) : self
Parameters
- $field : string
- $operator : operator
- $value : mixed = null
- $value2 : mixed = null
Return values
selfwhere_between()
Add a BETWEEN constraint for a field.
public
where_between(string $field, mixed $start, mixed $end) : self
Parameters
- $field : string
- $start : mixed
- $end : mixed
Return values
selfwhere_in()
Add an IN filter for a field.
public
where_in(string $field, array<string|int, mixed> $values) : self
Parameters
- $field : string
- $values : array<string|int, mixed>
Return values
selfwhere_meta()
Add a WHERE condition targeting metadata table.
public
where_meta(string $key, operator $operator[, mixed $value = null ][, mixed $value2 = null ]) : self
Parameters
- $key : string
- $operator : operator
- $value : mixed = null
- $value2 : mixed = null
Return values
selfwhere_meta_in()
Add an IN filter for metadata values.
public
where_meta_in(string $key, array<string|int, mixed> $values) : self
Parameters
- $key : string
- $values : array<string|int, mixed>
Return values
selfwhere_not_in()
Add a NOT IN filter for a field.
public
where_not_in(string $field, array<string|int, mixed> $values) : self
Parameters
- $field : string
- $values : array<string|int, mixed>
Return values
selfwith_metadata()
Request eager-loading of specific metadata keys.
public
with_metadata(array<string|int, mixed> $keys) : self
Parameters
- $keys : array<string|int, mixed>
Return values
selfwith_relation()
Request eager-loading of a registered relation.
public
with_relation(string $relation) : self
Parameters
- $relation : string
Return values
selfwithout_global_scope()
Disable a specific global scope.
public
without_global_scope(string $identifier) : self
Parameters
- $identifier : string
Return values
selfwithout_global_scopes()
Disable all global scopes.
public
without_global_scopes() : self
Return values
selfcopy()
Clone the current object and apply modifications.
private
copy(callable $modifier) : self
Parameters
- $modifier : callable