Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
|
Entry query builder class. More...
Public Member Functions | |
__construct ($glossary=null) | |
Constructor. More... | |
add_field ($field, $table, $alias=null) | |
Add a field to select. More... | |
add_user_fields () | |
Adds the user fields. More... | |
count_records () | |
Count the records. More... | |
filter_by_author_letter ($letter, $firstnamefirst=false) | |
Filter the author by letter. More... | |
filter_by_author_non_letter ($firstnamefirst=false) | |
Filter the author by special characters. More... | |
filter_by_concept_letter ($letter) | |
Filter the concept by letter. More... | |
filter_by_concept_non_letter () | |
Filter the concept by special characters. More... | |
filter_by_non_approved ($constant, $userid=null) | |
Filter non approved entries. More... | |
filter_by_term ($term) | |
Filter by concept or alias. More... | |
get_records () | |
Get the records. More... | |
get_recordset () | |
Get the recordset. More... | |
join_alias () | |
Join the alias table. More... | |
join_category ($categoryid) | |
Join on the category tables. More... | |
join_user ($strict=false) | |
Join the user table. More... | |
limit ($from, $num) | |
Limit the number of records to fetch. More... | |
order_by ($field, $table, $direction='') | |
Order by a field. More... | |
order_by_author ($firstnamefirst=false, $direction='') | |
Order by author name. More... | |
where ($field, $table, $value) | |
Simple where conditions. More... | |
Static Public Member Functions | |
static | get_fullname_field ($firstnamefirst=false) |
Convenience method to get get the SQL statement for the full name. More... | |
static | get_user_from_record ($record) |
Retrieve a user object from a record. More... | |
Protected Member Functions | |
build_query ($count=false) | |
Internal method to build the query. More... | |
filter_by_letter ($letter, $finalfield) | |
Filter a field using a letter. More... | |
filter_by_non_letter ($finalfield) | |
Filter a field by special characters. More... | |
normalize_direction ($direction) | |
Normalise a direction. More... | |
Static Protected Member Functions | |
static | resolve_field ($field, $table) |
Convenience method to transform a field into SQL statement. More... | |
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. |