Moodle PHP Documentation 4.4
Moodle 4.4.1 (Build: 20240610) (db07c09afc5)
|
Entry query builder class. More...
Public Member Functions | |
__construct ($glossary=null) | |
Constructor. | |
add_field ($field, $table, $alias=null) | |
Add a field to select. | |
add_user_fields () | |
Adds the user fields. | |
count_records () | |
Count the records. | |
filter_by_author_letter ($letter, $firstnamefirst=false) | |
Filter the author by letter. | |
filter_by_author_non_letter ($firstnamefirst=false) | |
Filter the author by special characters. | |
filter_by_concept_letter ($letter) | |
Filter the concept by letter. | |
filter_by_concept_non_letter () | |
Filter the concept by special characters. | |
filter_by_non_approved ($constant, $userid=null) | |
Filter non approved entries. | |
filter_by_term ($term) | |
Filter by concept or alias. | |
get_records () | |
Get the records. | |
get_recordset () | |
Get the recordset. | |
join_alias () | |
Join the alias table. | |
join_category ($categoryid) | |
Join on the category tables. | |
join_user ($strict=false) | |
Join the user table. | |
limit ($from, $num) | |
Limit the number of records to fetch. | |
order_by ($field, $table, $direction='') | |
Order by a field. | |
order_by_author ($firstnamefirst=false, $direction='') | |
Order by author name. | |
where ($field, $table, $value) | |
Simple where conditions. | |
Static Public Member Functions | |
static | get_fullname_field ($firstnamefirst=false) |
Convenience method to get get the SQL statement for the full name. | |
static | get_user_from_record ($record) |
Retrieve a user object from a record. | |
Protected Member Functions | |
build_query ($count=false) | |
Internal method to build the query. | |
filter_by_letter ($letter, $finalfield) | |
Filter a field using a letter. | |
filter_by_non_letter ($finalfield) | |
Filter a field by special characters. | |
normalize_direction ($direction) | |
Normalise a direction. | |
Static Protected Member Functions | |
static | resolve_field ($field, $table) |
Convenience method to transform a field into SQL statement. | |
Entry query builder class.
The purpose of this class is to avoid duplicating SQL statements to fetch entries which are very similar with each other. This builder is not meant to be smart, it will not out rule any previously set condition, or join, etc...
You should be using this builder just like you would be creating your SQL query. Only some methods are shorthands to avoid logic duplication and common mistakes.
mod_glossary_entry_query_builder::__construct | ( | $glossary = null | ) |
Constructor.
object | $glossary | The glossary. |
mod_glossary_entry_query_builder::add_field | ( | $field, | |
$table, | |||
$alias = null ) |
Add a field to select.
string | $field | The field, or *. |
string | $table | The table name, without the prefix 'glossary_'. |
string | $alias | An alias for the field. |
mod_glossary_entry_query_builder::add_user_fields | ( | ) |
Adds the user fields.
void |
|
protected |
Internal method to build the query.
bool | $count | Query to count? |
string | The SQL statement. |
mod_glossary_entry_query_builder::count_records | ( | ) |
Count the records.
int | The number of records. |
mod_glossary_entry_query_builder::filter_by_author_letter | ( | $letter, | |
$firstnamefirst = false ) |
Filter the author by letter.
string | $letter | The letter. |
bool | $firstnamefirst | Whether or not the firstname is first in the author's name. |
mod_glossary_entry_query_builder::filter_by_author_non_letter | ( | $firstnamefirst = false | ) |
Filter the author by special characters.
bool | $firstnamefirst | Whether or not the firstname is first in the author's name. |
mod_glossary_entry_query_builder::filter_by_concept_letter | ( | $letter | ) |
Filter the concept by letter.
string | $letter | The letter. |
mod_glossary_entry_query_builder::filter_by_concept_non_letter | ( | ) |
Filter the concept by special characters.
void |
|
protected |
Filter a field using a letter.
string | $letter | The letter. |
string | $finalfield | The SQL statement representing the field. |
mod_glossary_entry_query_builder::filter_by_non_approved | ( | $constant, | |
$userid = null ) |
Filter non approved entries.
string | $constant | One of the NON_APPROVED_* constants. |
int | $userid | The user ID when relevant, otherwise current user. |
|
protected |
Filter a field by special characters.
string | $finalfield | The SQL statement representing the field. |
mod_glossary_entry_query_builder::filter_by_term | ( | $term | ) |
Filter by concept or alias.
This requires the alias table to be joined in the query. See self::join_alias().
string | $term | What the concept or aliases should be. |
|
static |
Convenience method to get get the SQL statement for the full name.
bool | $firstnamefirst | Whether or not the firstname is first in the author's name. |
string | The SQL statement. |
mod_glossary_entry_query_builder::get_records | ( | ) |
Get the records.
array |
mod_glossary_entry_query_builder::get_recordset | ( | ) |
Get the recordset.
moodle_recordset |
|
static |
Retrieve a user object from a record.
This comes handy when self::add_user_fields was used.
stdClass | $record | The record. |
stdClass | A user object. |
mod_glossary_entry_query_builder::join_alias | ( | ) |
Join the alias table.
Note that this may cause the same entry to be returned more than once. You might want to add a distinct on the entry id.
void |
mod_glossary_entry_query_builder::join_category | ( | $categoryid | ) |
Join on the category tables.
Depending on the category passed the joins will be different. This is due to the display logic that assumes that when displaying all categories the non categorised entries should not be returned, etc...
int | $categoryid | The category ID, or GLOSSARY_SHOW_* constant. |
mod_glossary_entry_query_builder::join_user | ( | $strict = false | ) |
Join the user table.
bool | $strict | When strict uses a JOIN rather than a LEFT JOIN. |
mod_glossary_entry_query_builder::limit | ( | $from, | |
$num ) |
Limit the number of records to fetch.
int | $from | Fetch from. |
int | $num | Number to fetch. |
|
protected |
Normalise a direction.
This ensures that the value is either ASC or DESC.
string | $direction | The desired direction. |
string | ASC or DESC. |
mod_glossary_entry_query_builder::order_by | ( | $field, | |
$table, | |||
$direction = '' ) |
Order by a field.
string | $field | The field, or *. |
string | $table | The table name, without the prefix 'glossary_'. |
string | $direction | ASC, or DESC. |
mod_glossary_entry_query_builder::order_by_author | ( | $firstnamefirst = false, | |
$direction = '' ) |
Order by author name.
bool | $firstnamefirst | Whether or not the firstname is first in the author's name. |
string | $direction | ASC, or DESC. |
|
staticprotected |
Convenience method to transform a field into SQL statement.
string | $field | The field, or *. |
string | $table | The table name, without the prefix 'glossary_'. |
string | SQL statement. |
mod_glossary_entry_query_builder::where | ( | $field, | |
$table, | |||
$value ) |
Simple where conditions.
string | $field | The field, or *. |
string | $table | The table name, without the prefix 'glossary_'. |
mixed | $value | The value to be equal to. |